summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/trunk
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-02-08 15:58:16 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-02-08 15:58:16 +0000
commitf559f75fcacd8ace82bc05c9b4965ee5b37c5e55 (patch)
treeb0f4e09154279bccdfe1cdecf8d395e2ba6f0ffa /sca-java-1.x/trunk
parent9a960d4c27f82b6ff390dcbdb674c777c29fc576 (diff)
TUSCANY-3834 - Extend the test case to look at exceptions thrown from within @Destroy operations.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1068456 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/trunk')
-rw-r--r--sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java58
-rw-r--r--sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite16
-rw-r--r--sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java35
3 files changed, 106 insertions, 3 deletions
diff --git a/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java b/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java
new file mode 100644
index 0000000000..92e12a33d1
--- /dev/null
+++ b/sca-java-1.x/trunk/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/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite b/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite
index 3a1a897def..593757e90c 100644
--- a/sca-java-1.x/trunk/itest/java-init-exceptions/src/main/resources/test.composite
+++ b/sca-java-1.x/trunk/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/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java b/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
index f6a1da5b79..e84d6ab55f 100644
--- a/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
+++ b/sca-java-1.x/trunk/itest/java-init-exceptions/src/test/java/itest/InitTestCase.java
@@ -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() {