Author: antelder
Date: Thu Apr 16 11:37:42 2009
New Revision: 765582

URL: http://svn.apache.org/viewvc?rev=765582&view=rev
Log:
Add more complete test for the various lifecycle exceptions

Added:
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitCompositeScopeException.java
      - copied, changed from r765542, 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitException.java
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitRequestScopeException.java
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitStatelessScopeException.java
Removed:
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitException.java
Modified:
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/ConstructorException.java
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/OkImpl.java
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/resources/test.composite
    
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java

Modified: 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/ConstructorException.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/ConstructorException.java?rev=765582&r1=765581&r2=765582&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/ConstructorException.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/ConstructorException.java
 Thu Apr 16 11:37:42 2009
@@ -26,12 +26,14 @@
 
     public static boolean initRun;
     public static boolean destroyRun;
+    public static boolean doitRun;
     
     public ConstructorException() {
         throw new RuntimeException();
     }
     
     public void doit() {
+        doitRun = true;
     }
     
     @Init

Copied: 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitCompositeScopeException.java
 (from r765542, 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitException.java)
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitCompositeScopeException.java?p2=tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitCompositeScopeException.java&p1=tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitException.java&r1=765542&r2=765582&rev=765582&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitException.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitCompositeScopeException.java
 Thu Apr 16 11:37:42 2009
@@ -21,18 +21,32 @@
 
 import org.osoa.sca.annotations.Destroy;
 import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
 
-public class InitException implements Service {
+...@scope("COMPOSITE")
+public class InitCompositeScopeException 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() {
-        throw new RuntimeException();
+        initRun = true;
+        if (count++ < 1) {
+            throw new RuntimeException("bang");
+        }
     }
     
     @Destroy

Added: 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitRequestScopeException.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitRequestScopeException.java?rev=765582&view=auto
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitRequestScopeException.java
 (added)
+++ 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitRequestScopeException.java
 Thu Apr 16 11:37:42 2009
@@ -0,0 +1,57 @@
+/*
+ * 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("REQUEST")
+public class InitRequestScopeException 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;
+        if (count++ < 1) {
+            throw new RuntimeException("bang");
+        }
+    }
+    
+    @Destroy
+    public void destroy() {
+        destroyRun = true;   
+    }
+
+}

Added: 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitStatelessScopeException.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitStatelessScopeException.java?rev=765582&view=auto
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitStatelessScopeException.java
 (added)
+++ 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/InitStatelessScopeException.java
 Thu Apr 16 11:37:42 2009
@@ -0,0 +1,57 @@
+/*
+ * 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("STATELESS")
+public class InitStatelessScopeException 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;
+        if (count++ < 1) {
+            throw new RuntimeException("bang");
+        }
+    }
+    
+    @Destroy
+    public void destroy() {
+        destroyRun = true;   
+    }
+
+}

Modified: 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/OkImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/OkImpl.java?rev=765582&r1=765581&r2=765582&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/OkImpl.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/java/itest/OkImpl.java
 Thu Apr 16 11:37:42 2009
@@ -31,6 +31,12 @@
     }
     
     public void doit() {
+        if (!initRun) {
+            throw new RuntimeException("initRun false");
+        }
+        if (destroyRun) {
+            throw new RuntimeException("destroyRun true");
+        }
     }
     
     @Init

Modified: 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/resources/test.composite
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/resources/test.composite?rev=765582&r1=765581&r2=765582&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/resources/test.composite
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/main/resources/test.composite
 Thu Apr 16 11:37:42 2009
@@ -30,8 +30,14 @@
         <implementation.java class="itest.ConstructorException"/>
     </component>       
 
-    <component name="InitException">
-        <implementation.java class="itest.InitException"/>
+    <component name="InitCompositeScopeException">
+        <implementation.java class="itest.InitCompositeScopeException"/>
+    </component>       
+    <component name="InitRequestScopeException">
+        <implementation.java class="itest.InitRequestScopeException"/>
+    </component>       
+    <component name="InitStatelessScopeException">
+        <implementation.java class="itest.InitStatelessScopeException"/>
     </component>       
 
 </composite>

Modified: 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java?rev=765582&r1=765581&r2=765582&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
 Thu Apr 16 11:37:42 2009
@@ -18,7 +18,9 @@
  */
 package itest;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.apache.tuscany.sca.host.embedded.SCADomain;
 import org.junit.After;
@@ -41,20 +43,102 @@
         Service client1 = scaDomain.getService(Service.class, "OkService");
         client1.doit();
         assertTrue(OkImpl.initRun);
+        assertTrue(OkImpl.destroyRun); // its stateless so destory is called 
after every service invocations
     }
 
-    //@Test
+    @Test
     public void testConstructorException() throws Exception {
         Service client1 = scaDomain.getService(Service.class, 
"ConstructorException");
+        try {
+            client1.doit();
+            fail();
+        } catch (RuntimeException e) {
+            // expected
+        }
+        assertFalse(ConstructorException.initRun);
+        assertFalse(ConstructorException.doitRun);
+        assertFalse(ConstructorException.destroyRun);
+    }
+
+    @Test
+    public void testInitCompositeScopeException() throws Exception {
+        Service client1 = scaDomain.getService(Service.class, 
"InitCompositeScopeException");
+        try {
+            client1.doit();
+            fail();
+        } catch (RuntimeException e) {
+            // expected
+        }
+        assertTrue(InitCompositeScopeException.initRun);
+        assertFalse(InitCompositeScopeException.doitRun);
+        assertTrue(InitCompositeScopeException.destroyRun);
+
+        // reset and try again to verify init init still gets run again
+        InitCompositeScopeException.initRun = false;    
+        InitCompositeScopeException.doitRun = false;    
+        InitCompositeScopeException.destroyRun = false;    
+
         client1.doit();
-        assertTrue(OkImpl.initRun);
+
+        assertTrue(InitCompositeScopeException.initRun);
+        assertTrue(InitCompositeScopeException.doitRun);
+        scaDomain.close();
+        scaDomain = null;
+        assertTrue(InitCompositeScopeException.destroyRun);
     }
 
-    //@Test
-    public void testInitException() throws Exception {
-        Service client1 = scaDomain.getService(Service.class, "InitException");
+    @Test
+    public void testInitStatelessScopeException() throws Exception {
+        Service client1 = scaDomain.getService(Service.class, 
"InitStatelessScopeException");
+        try {
+            client1.doit();
+            fail();
+        } catch (RuntimeException e) {
+            // expected
+        }
+        assertTrue(InitStatelessScopeException.initRun);
+        assertFalse(InitStatelessScopeException.doitRun);
+        assertTrue(InitStatelessScopeException.destroyRun);
+
+        // reset and try again to verify init init still gets run again
+        InitStatelessScopeException.initRun = false;    
+        InitStatelessScopeException.doitRun = false;    
+        InitStatelessScopeException.destroyRun = false;    
+
         client1.doit();
-        assertTrue(OkImpl.initRun);
+
+        assertTrue(InitStatelessScopeException.initRun);
+        assertTrue(InitStatelessScopeException.doitRun);
+        scaDomain.close();
+        scaDomain = null;
+        assertTrue(InitStatelessScopeException.destroyRun);
+    }
+
+    @Test
+    public void testInitRequestScopeException() throws Exception {
+        Service client1 = scaDomain.getService(Service.class, 
"InitRequestScopeException");
+        try {
+            client1.doit();
+            fail();
+        } catch (RuntimeException e) {
+            // expected
+        }
+        assertTrue(InitRequestScopeException.initRun);
+        assertFalse(InitRequestScopeException.doitRun);
+        assertTrue(InitRequestScopeException.destroyRun);
+
+        // reset and try again to verify init init still gets run again
+        InitRequestScopeException.initRun = false;    
+        InitRequestScopeException.doitRun = false;    
+        InitRequestScopeException.destroyRun = false;    
+
+        client1.doit();
+
+        assertTrue(InitRequestScopeException.initRun);
+        assertTrue(InitRequestScopeException.doitRun);
+        scaDomain.close();
+        scaDomain = null;
+        assertTrue(InitRequestScopeException.destroyRun);
     }
 
     @After


Reply via email to