TUSCANY-3834 - Extend the test case to look at exceptions thrown from within @Destroy operations. 

git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk@1068456 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java b/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java
new file mode 100644
index 0000000..92e12a3
--- /dev/null
+++ b/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java
@@ -0,0 +1,58 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ * 

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ * 

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.    

+ */

+

+package itest;

+

+import org.osoa.sca.annotations.Destroy;

+import org.osoa.sca.annotations.Init;

+import org.osoa.sca.annotations.Scope;

+

+@Scope("COMPOSITE")

+public class DestroyCompositeScopeException implements Service {

+

+    public static boolean initRun;

+    public static boolean destroyRun;

+    public static boolean doitRun;

+    public static int count = 0;

+    

+    public void doit() {

+        doitRun = true;

+        if (!initRun) {

+            throw new RuntimeException("initRun false");

+        }

+        if (destroyRun) {

+            throw new RuntimeException("destroyRun true");

+        }

+    }

+    

+    @Init

+    public void init() {

+        initRun = true;

+    }

+    

+    @Destroy

+    public void destroy() {

+        destroyRun = true;  

+        if (count++ < 1) {

+        	throw new NullPointerException();

+           // throw new RuntimeException("bang");

+        }

+    }

+

+}

diff --git a/itest/java-init-exceptions/src/main/resources/test.composite b/itest/java-init-exceptions/src/main/resources/test.composite
index 3a1a897..593757e 100644
--- a/itest/java-init-exceptions/src/main/resources/test.composite
+++ b/itest/java-init-exceptions/src/main/resources/test.composite
@@ -32,12 +32,22 @@
 

     <component name="InitCompositeScopeException">

         <implementation.java class="itest.InitCompositeScopeException"/>

-    </component>       

+    </component> 

+      

     <component name="InitRequestScopeException">

         <implementation.java class="itest.InitRequestScopeException"/>

-    </component>       

+    </component> 

+      

     <component name="InitStatelessScopeException">

         <implementation.java class="itest.InitStatelessScopeException"/>

-    </component>       

+    </component> 

+

+    <component name="DestroyCompositeScopeException">

+        <implementation.java class="itest.DestroyCompositeScopeException"/>

+    </component>  

+    

+    <component name="DestroyCompositeScopeException2">

+        <implementation.java class="itest.DestroyCompositeScopeException"/>

+    </component> 

 

 </composite>

diff --git a/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java b/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
index f6a1da5..e84d6ab 100644
--- a/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
+++ b/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
@@ -21,6 +21,7 @@
 import static org.junit.Assert.assertFalse;

 import static org.junit.Assert.assertTrue;

 import static org.junit.Assert.fail;

+import junit.framework.Assert;

 

 import org.apache.tuscany.sca.host.embedded.SCADomain;

 import org.junit.After;

@@ -140,6 +141,40 @@
         scaDomain = null;

         assertTrue(InitRequestScopeException.destroyRun);

     }

+    

+    @Test

+    public void testDestroyCompositeScopeException() throws Exception {

+        Service client1 = scaDomain.getService(Service.class, "DestroyCompositeScopeException");

+        try {

+            client1.doit();

+        } catch (RuntimeException e) {

+        	fail();

+        }

+        assertTrue(DestroyCompositeScopeException.initRun);

+        assertTrue(DestroyCompositeScopeException.doitRun);

+        assertFalse(DestroyCompositeScopeException.destroyRun);

+        

+        Service client2 = scaDomain.getService(Service.class, "DestroyCompositeScopeException2");

+        try {

+            client2.doit();

+        } catch (RuntimeException e) {

+        	fail();

+        }

+

+        // close the domain to case @Destroy to run

+        try {

+        	scaDomain.close();

+        } catch (RuntimeException e) {

+        	e.printStackTrace();

+        	fail();

+        }

+        scaDomain = null;

+        

+        // check that it has run twice

+        // The first run having caused an exception

+        assertTrue(DestroyCompositeScopeException.destroyRun);

+        Assert.assertEquals(2, DestroyCompositeScopeException.count);

+    }    

 

     @After

     public void end() {