From f559f75fcacd8ace82bc05c9b4965ee5b37c5e55 Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 8 Feb 2011 15:58:16 +0000 Subject: 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 --- .../java/itest/DestroyCompositeScopeException.java | 58 ++++++++++++++++++++++ .../src/main/resources/test.composite | 16 ++++-- .../src/test/java/itest/InitTestCase.java | 35 +++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 sca-java-1.x/trunk/itest/java-init-exceptions/src/main/java/itest/DestroyCompositeScopeException.java (limited to 'sca-java-1.x/trunk') 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 @@ - + + - + + - + + + + + + + + + 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() { -- cgit v1.2.3