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
This commit is contained in:
parent
9a960d4c27
commit
f559f75fca
3 changed files with 106 additions and 3 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue