diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-26 11:09:54 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-26 11:09:54 +0000 |
commit | 77be27896a4e45c3e1eb3c6e94231327b39eb5e8 (patch) | |
tree | 69582723f2387d036bea35ce07696285e46e25b4 /sca-java-2.x/trunk | |
parent | ff3f060f0668d9eb49a5525cac5fc439449eca77 (diff) |
Add a test implementation provider and extend the test case to cover init and destroy exceptions
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1127870 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
14 files changed, 564 insertions, 5 deletions
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java index 73030e16d3..7b9c17cf59 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java @@ -25,5 +25,7 @@ import org.oasisopen.sca.annotation.Remotable; public interface Helloworld {
String sayHello(String name) throws Exception;
+
+ String throwException(String name) throws Exception;
}
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java index a1c06afbb5..9328b53bac 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java @@ -28,23 +28,41 @@ import org.oasisopen.sca.annotation.Scope; @EagerInit
@Scope("COMPOSITE")
public class HelloworldClientImpl implements Helloworld {
+
+ public static boolean throwTestExceptionOnInit = false;
+ public static boolean throwTestExceptionOnDestroy = false;
+
@Reference
public Helloworld service;
@Init
public void initialize() throws Exception{
+ if (throwTestExceptionOnInit) {
+ StatusImpl.statusString += "Exception on init ";
+ throw new Exception("Exception on init");
+ }
+
StatusImpl.statusString += "HelloworldClientImpl init ";
System.out.println(">>>>>> " + sayHello("init"));
}
@Destroy
public void destroy() throws Exception{
+ if (throwTestExceptionOnDestroy) {
+ StatusImpl.statusString += "Exception on destroy ";
+ throw new Exception("Exception on destroy");
+ }
+
StatusImpl.statusString += "HelloworldClientImpl destroy ";
}
public String sayHello(String name) throws Exception {
return "Hi " + service.sayHello(name);
}
+
+ public String throwException(String name) throws Exception {
+ throw new Exception("test exception");
+ }
}
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java index d761dd4350..2d27ec8f58 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java @@ -26,5 +26,10 @@ public class HelloworldServiceImpl implements Helloworld { System.out.println("At service - " + response);
return response;
}
+
+ public String throwException(String name) throws Exception {
+ // not used
+ return null;
+ }
}
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java new file mode 100644 index 0000000000..ebed204b87 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java @@ -0,0 +1,41 @@ +/* + * 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 implementation.lifecycle; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; + +/** + * Model representing a Sample implementation in an SCA assembly. + * + * @version $Rev$ $Date$ + */ +public class LifecycleImplementation extends ImplementationImpl { + static final QName QN = new QName(SCA11_TUSCANY_NS, "implementation.lifecycle"); + + final String name; + Class<?> clazz; + + LifecycleImplementation(final String name) { + super(QN); + this.name = name; + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java new file mode 100644 index 0000000000..c7989b291c --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java @@ -0,0 +1,105 @@ +/* + * 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 implementation.lifecycle; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; + +/** + * StAX artifact processor for Sample implementations. + * + * @version $Rev$ $Date$ + */ +public class LifecycleImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<LifecycleImplementation> { + final AssemblyFactory af; + final JavaInterfaceFactory jif; + final WSDLFactory wf; + + public LifecycleImplementationProcessor(final ExtensionPointRegistry ep) { + final FactoryExtensionPoint fep = ep.getExtensionPoint(FactoryExtensionPoint.class); + this.af = fep.getFactory(AssemblyFactory.class); + this.jif = fep.getFactory(JavaInterfaceFactory.class); + this.wf = fep.getFactory(WSDLFactory.class); + } + + public QName getArtifactType() { + return LifecycleImplementation.QN; + } + + public Class<LifecycleImplementation> getModelType() { + return LifecycleImplementation.class; + } + + public LifecycleImplementation read(final XMLStreamReader r, final ProcessorContext ctx) throws ContributionReadException, XMLStreamException { + // not actually going to read any config for this test + // so just create a model + LifecycleImplementation impl = new LifecycleImplementation("helloworld.Helloworld"); + impl.setUnresolved(true); + return impl; + } + + public void resolve(final LifecycleImplementation impl, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException { + try { + Class c = Class.forName("helloworld.Helloworld"); + Service s = af.createService(); + s.setName("Helloworld"); + JavaInterfaceContract ic = jif.createJavaInterfaceContract(); + ic.setInterface(jif.createJavaInterface(c)); + s.setInterfaceContract(ic); + impl.getServices().add(s); + impl.setUnresolved(false); + } catch (Exception ex){ + throw new ContributionResolveException(ex); + } + } + + public void write(final LifecycleImplementation impl, final XMLStreamWriter w, final ProcessorContext ctx) throws ContributionWriteException, XMLStreamException { + // not required for this test + } + +} diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java new file mode 100644 index 0000000000..ac750fe040 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java @@ -0,0 +1,46 @@ +/* + * 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 implementation.lifecycle; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Invoker for Sample components that implement a Java interface. + * + * @version $Rev$ $Date$ + */ +class SampleJavaInvoker implements Invoker { + final Object instance; + final Method method; + + SampleJavaInvoker(final JavaOperation op, final Class<?> clazz, final Object instance) throws SecurityException, NoSuchMethodException { + this.instance = instance; + this.method = clazz.getMethod(op.getJavaMethod().getName(), op.getJavaMethod().getParameterTypes()); + } + + public Message invoke(final Message msg) { + // we don't actually do anything here + return msg; + } +} diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java new file mode 100644 index 0000000000..c06346d8d3 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java @@ -0,0 +1,77 @@ +/* + * 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 implementation.lifecycle; + +import helloworld.StatusImpl; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation provider for Sample component implementations. + * + * @version $Rev$ $Date$ + */ +class LifecycleProvider implements ImplementationProvider { + final RuntimeComponent comp; + final LifecycleImplementation impl; + final ProxyFactory pxf; + final ExtensionPointRegistry ep; + Object instance; + + // make this static rather than worrying about persistence on the reference side + static Map<String, Object> asyncMessageMap = new HashMap<String, Object>(); + + LifecycleProvider(final RuntimeComponent comp, final LifecycleImplementation impl, ProxyFactory pf, ExtensionPointRegistry ep) { + this.comp = comp; + this.impl = impl; + this.pxf = pf; + this.ep = ep; + } + + public void start() { + StatusImpl.statusString += "Implementation start "; + } + + public void stop() { + StatusImpl.statusString += "Implementation stop "; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public Invoker createInvoker(final RuntimeComponentService s, final Operation op) { + try { + return new SampleJavaInvoker((JavaOperation)op, impl.clazz, instance); + } catch(Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java new file mode 100644 index 0000000000..dfd39716fd --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java @@ -0,0 +1,50 @@ +/* + * 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 implementation.lifecycle; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory for Sample implementation providers. + * + * @version $Rev$ $Date$ + */ +public class LifecycleProviderFactory implements ImplementationProviderFactory<LifecycleImplementation> { + final ProxyFactory pxf; + final ExtensionPointRegistry ep; + + public LifecycleProviderFactory(final ExtensionPointRegistry ep) { + this.ep = ep; + pxf = ExtensibleProxyFactory.getInstance(ep); + } + + public ImplementationProvider createImplementationProvider(final RuntimeComponent comp, final LifecycleImplementation impl) { + return new LifecycleProvider(comp, impl, pxf, ep); + } + + public Class<LifecycleImplementation> getModelType() { + return LifecycleImplementation.class; + } +} diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor index 6536e872e1..09a474a567 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -17,4 +17,5 @@ # Implementation class for the artifact processor extension
org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.lifecycle,model=binding.lifecycle.LifecycleBinding,factory=binding.lifecycle.LifecycleBindingFactory
+implementation.lifecycle.LifecycleImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#implementation.lifecycle,model=implementation.lifecycle.LifecycleImplementation
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema index 4e577c2728..e436702181 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -15,5 +15,7 @@ # specific language governing permissions and limitations
# under the License.
#
+implementation-lifecycle.xsd
binding-lifecycle.xsd
+
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..c9b5077888 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -0,0 +1,20 @@ +# 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.
+
+# Implementation provider for Sample components
+implementation.lifecycle.LifecycleProviderFactory;model=implementation.lifecycle.LifecycleImplementation
+
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd new file mode 100644 index 0000000000..c029a43922 --- /dev/null +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" + elementFormDefault="qualified"> + + <import namespace="http://docs.oasis-open.org/ns/opencsa/sca/200912"/> + + <element name="implementation.lifecycle" type="t:LifecycleImplementation" substitutionGroup="sca:implementation"/> + + <complexType name="LifecycleImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <attribute name="class" type="string" use="required"/> + </extension> + </complexContent> + </complexType> + +</schema> diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite index 2284d0920f..2c48cc4bf9 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite @@ -22,16 +22,23 @@ targetNamespace="http://sample"
name="domainview">
- <component name="HelloworldService">
+ <component name="HelloworldService1">
<implementation.java class="helloworld.HelloworldServiceImpl"/>
<service name="Helloworld">
<tuscany:binding.lifecycle name="lifecycle"/>
</service>
- </component>
+ </component>
+
+ <component name="HelloworldService2">
+ <tuscany:implementation.lifecycle class="helloworld.HelloworldServiceImpl"/>
+ <service name="Helloworld">
+ <tuscany:binding.lifecycle name="lifecycle"/>
+ </service>
+ </component>
<component name="HelloworldClient">
<implementation.java class="helloworld.HelloworldClientImpl"/>
- <reference name="service" target="HelloworldService"/>
+ <reference name="service" target="HelloworldService1"/>
</component>
</composite>
diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java index 4342dd63bd..dbffc8ce8c 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java @@ -20,6 +20,8 @@ package org.apache.tuscany.sca.itest.lifecycle;
+import helloworld.Helloworld;
+import helloworld.HelloworldClientImpl;
import helloworld.StatusImpl;
import junit.framework.Assert;
@@ -46,7 +48,7 @@ public class LifecycleTestCase { }
@Test
- public void test1() throws Exception{
+ public void testNormalShutdown() throws Exception{
TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
@@ -74,13 +76,158 @@ public class LifecycleTestCase { // see what happened
System.out.println(StatusImpl.statusString);
Assert.assertEquals("Service binding start " +
+ "Implementation start " +
+ "Service binding start " +
"HelloworldClientImpl init " +
"Reference binding start " +
"Service binding stop " +
+ "Service binding stop " +
+ "Implementation stop " +
"Reference binding stop " +
"HelloworldClientImpl destroy ",
StatusImpl.statusString);
-
}
+ @Test
+ public void testInitExceptionShutdown() throws Exception{
+
+ HelloworldClientImpl.throwTestExceptionOnInit = true;
+
+ TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+ // create a Tuscany node
+ node = tuscanyRuntime.createNode();
+
+ // install a contribution
+ node.installContribution("HelloworldContrib", "target/classes", null, null);
+
+ // start a composite
+ try {
+ node.startComposite("HelloworldContrib", "lifecycle.composite");
+ } catch (Exception exception) {
+ // it's thrown from the HelloworldClientImpl @Init method
+ }
+
+ // stop a composite
+ node.stopComposite("HelloworldContrib", "lifecycle.composite");
+
+ // uninstall a constribution
+ node.uninstallContribution("HelloworldContrib");
+
+ // stop a Tuscany node
+ node.stop();
+
+ // stop the runtime
+ tuscanyRuntime.stop();
+
+ // see what happened
+ System.out.println(StatusImpl.statusString);
+ Assert.assertEquals("Service binding start " +
+ "Implementation start " +
+ "Service binding start " +
+ "HelloworldClientImpl init " +
+ "Reference binding start " +
+ "Service binding stop " +
+ "Service binding stop " +
+ "Implementation stop " +
+ "Reference binding stop " +
+ "HelloworldClientImpl destroy ",
+ StatusImpl.statusString);
+
+ HelloworldClientImpl.throwTestExceptionOnInit = false;
+ }
+
+ @Test
+ public void testDestroyExceptionShutdown() throws Exception{
+
+ HelloworldClientImpl.throwTestExceptionOnDestroy = true;
+
+ TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+ // create a Tuscany node
+ node = tuscanyRuntime.createNode();
+
+ // install a contribution
+ node.installContribution("HelloworldContrib", "target/classes", null, null);
+
+ // start a composite
+ node.startComposite("HelloworldContrib", "lifecycle.composite");
+
+ // stop a composite
+ node.stopComposite("HelloworldContrib", "lifecycle.composite");
+
+ // uninstall a constribution
+ node.uninstallContribution("HelloworldContrib");
+
+ // stop a Tuscany node
+ node.stop();
+
+ // stop the runtime
+ tuscanyRuntime.stop();
+
+ // see what happened
+ System.out.println(StatusImpl.statusString);
+ Assert.assertEquals("Service binding start " +
+ "Implementation start " +
+ "Service binding start " +
+ "HelloworldClientImpl init " +
+ "Reference binding start " +
+ "Service binding stop " +
+ "Service binding stop " +
+ "Implementation stop " +
+ "Reference binding stop " +
+ "HelloworldClientImpl destroy ",
+ StatusImpl.statusString);
+
+ HelloworldClientImpl.throwTestExceptionOnDestroy = false;
+ }
+
+ @Test
+ public void testAppExceptionShutdown() throws Exception{
+
+ TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+ // create a Tuscany node
+ node = tuscanyRuntime.createNode();
+
+ // install a contribution
+ node.installContribution("HelloworldContrib", "target/classes", null, null);
+
+ // start a composite
+ node.startComposite("HelloworldContrib", "lifecycle.composite");
+
+ try {
+ Helloworld hw = node.getService(Helloworld.class, "Helloworld1");
+ hw.throwException("name");
+ } catch (Exception ex) {
+ // do nothing
+ }
+
+ // stop a composite
+ node.stopComposite("HelloworldContrib", "lifecycle.composite");
+
+ // uninstall a constribution
+ node.uninstallContribution("HelloworldContrib");
+
+ // stop a Tuscany node
+ node.stop();
+
+ // stop the runtime
+ tuscanyRuntime.stop();
+
+ // see what happened
+ System.out.println(StatusImpl.statusString);
+ Assert.assertEquals("Service binding start " +
+ "Implementation start " +
+ "Service binding start " +
+ "HelloworldClientImpl init " +
+ "Reference binding start " +
+ "Service binding stop " +
+ "Service binding stop " +
+ "Implementation stop " +
+ "Reference binding stop " +
+ "HelloworldClientImpl destroy ",
+ StatusImpl.statusString);
+ }
+
}
|