You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2011/02/08 16:58:16 UTC

svn commit: r1068456 - in /tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src: main/java/itest/DestroyCompositeScopeException.java main/resources/test.composite test/java/itest/InitTestCase.java

Author: slaws
Date: Tue Feb  8 15:58:16 2011
New Revision: 1068456

URL: http://svn.apache.org/viewvc?rev=1068456&view=rev
Log:
TUSCANY-3834 - Extend the test case to look at exceptions thrown from within @Destroy operations. 

Added:
    tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java
Modified:
    tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite
    tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java

Added: tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java?rev=1068456&view=auto
==============================================================================
--- tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java (added)
+++ tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java Tue Feb  8 15:58:16 2011
@@ -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");
+        }
+    }
+
+}

Modified: tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite?rev=1068456&r1=1068455&r2=1068456&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite (original)
+++ tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite Tue Feb  8 15:58:16 2011
@@ -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>

Modified: tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java?rev=1068456&r1=1068455&r2=1068456&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java (original)
+++ tuscany/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java Tue Feb  8 15:58:16 2011
@@ -21,6 +21,7 @@ package itest;
 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 @@ public class InitTestCase {
         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() {