From 132aa8a77685ec92bc90c03f987650d275a7b639 Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 30 Sep 2013 06:59:11 +0000 Subject: 2.0.1 RC1 release tag git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1527464 13f79535-47bb-0310-9956-ffa450edef68 --- .../tags/2.0.1-RC1/testing/itest/lifecycle/pom.xml | 43 ++ .../java/binding/lifecycle/LifecycleBinding.java | 49 ++ .../binding/lifecycle/LifecycleBindingFactory.java | 32 + .../lifecycle/LifecycleBindingProviderFactory.java | 47 ++ .../LifecycleReferenceBindingProvider.java | 63 ++ .../lifecycle/LifecycleReferenceInvoker.java | 48 ++ .../lifecycle/LifecycleServiceBindingProvider.java | 56 ++ .../binding/lifecycle/LifecycleServiceInvoker.java | 40 + .../src/main/java/helloworld/Helloworld.java | 31 + .../java/helloworld/HelloworldClientImplC.java | 78 ++ .../java/helloworld/HelloworldClientImplCE.java | 80 ++ .../java/helloworld/HelloworldClientImplS.java | 78 ++ .../java/helloworld/HelloworldServiceImpl.java | 35 + .../src/main/java/helloworld/StatusImpl.java | 32 + .../lifecycle/LifecycleImplementation.java | 41 + .../LifecycleImplementationProcessor.java | 105 +++ .../lifecycle/LifecycleJavaInvoker.java | 46 ++ .../lifecycle/LifecycleProvider.java | 77 ++ .../lifecycle/LifecycleProviderFactory.java | 50 ++ .../services/binding.lifecycle.BindingFactory | 20 + ...ca.contribution.processor.StAXArtifactProcessor | 21 + ...any.sca.contribution.processor.ValidationSchema | 21 + ...che.tuscany.sca.provider.BindingProviderFactory | 20 + ...cany.sca.provider.ImplementationProviderFactory | 20 + .../src/main/resources/binding-lifecycle.xsd | 37 + .../main/resources/implementation-lifecycle.xsd | 38 + .../src/main/resources/lifecycle.composite | 55 ++ .../sca/itest/lifecycle/LifecycleTestCase.java | 836 +++++++++++++++++++++ 28 files changed, 2099 insertions(+) create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/pom.xml create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBinding.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceInvoker.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceInvoker.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplC.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplCE.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplS.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/binding.lifecycle.BindingFactory create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/binding-lifecycle.xsd create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/lifecycle.composite create mode 100644 sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java (limited to 'sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle') diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/pom.xml b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/pom.xml new file mode 100644 index 0000000000..d9352969f3 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-itest + 2.0.1 + ../pom.xml + + itest-lifecycle + Apache Tuscany SCA iTest Lifecycle + 2.0.1 + + + + + org.apache.tuscany.sca + tuscany-base-runtime-pom + pom + 2.0.1 + + + + + diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBinding.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBinding.java new file mode 100644 index 0000000000..ecd4393e4d --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBinding.java @@ -0,0 +1,49 @@ +/* + * 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 binding.lifecycle; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.provider.BaseBindingImpl; + +/** + * Represents a binding to a Sample service. + */ +public class LifecycleBinding extends BaseBindingImpl { + + public static final QName TYPE = new QName(SCA11_TUSCANY_NS, "binding.lifecycle"); + + private String someAttr; + + public LifecycleBinding() { + } + + public QName getType() { + return TYPE; + } + + public String getSomeAttr() { + return someAttr; + } + + public void setSomeAttr(String someAttr) { + this.someAttr = someAttr; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingFactory.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingFactory.java new file mode 100644 index 0000000000..4fdf09bdf0 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingFactory.java @@ -0,0 +1,32 @@ +/* + * 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 binding.lifecycle; + + +/** + * Factory implementation to create Sample Models + */ +public class LifecycleBindingFactory { + + public LifecycleBinding createLifecycleBinding() { + return new LifecycleBinding(); + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingProviderFactory.java new file mode 100644 index 0000000000..f197578e84 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleBindingProviderFactory.java @@ -0,0 +1,47 @@ +/* + * 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 binding.lifecycle; + +import binding.lifecycle.LifecycleBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +public class LifecycleBindingProviderFactory implements BindingProviderFactory { + + public LifecycleBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + } + + public Class getModelType() { + return LifecycleBinding.class; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpoint) { + return new LifecycleReferenceBindingProvider(endpoint); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { + return new LifecycleServiceBindingProvider(endpoint); + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java new file mode 100644 index 0000000000..5c2ca0bf77 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java @@ -0,0 +1,63 @@ +/* + * 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 binding.lifecycle; + +import helloworld.StatusImpl; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.impl.EndpointImpl; +import org.apache.tuscany.sca.assembly.impl.EndpointReferenceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; + +public class LifecycleReferenceBindingProvider implements ReferenceBindingProvider { + + private EndpointReference endpoint; + private InterfaceContract contract; + + public LifecycleReferenceBindingProvider(EndpointReference endpoint) { + this.endpoint = endpoint; + } + + public Invoker createInvoker(Operation operation) { + return new LifecycleReferenceInvoker(operation, endpoint); + } + + public void start() { + StatusImpl.appendStatus("Reference binding start", + ((EndpointReferenceImpl)endpoint).toStringWithoutHash()); + } + + public void stop() { + StatusImpl.appendStatus("Reference binding stop", + ((EndpointReferenceImpl)endpoint).toStringWithoutHash()); + } + + public InterfaceContract getBindingInterfaceContract() { + return contract; + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceInvoker.java new file mode 100644 index 0000000000..023be8613b --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceInvoker.java @@ -0,0 +1,48 @@ +/* + * 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 binding.lifecycle; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +public class LifecycleReferenceInvoker implements Invoker { + + protected Operation operation; + protected EndpointReference endpoint; + + public LifecycleReferenceInvoker(Operation operation, EndpointReference endpoint) { + this.operation = operation; + this.endpoint = endpoint; + } + + public Message invoke(Message msg) { + try { + Object[] body = msg.getBody(); + msg.setBody(body[0]); + return msg; + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java new file mode 100644 index 0000000000..158aa27201 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java @@ -0,0 +1,56 @@ +/* + * 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 binding.lifecycle; + +import helloworld.StatusImpl; + +import org.apache.tuscany.sca.assembly.impl.EndpointImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +public class LifecycleServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeEndpoint endpoint; + private InterfaceContract contract; + + public LifecycleServiceBindingProvider(RuntimeEndpoint endpoint) { + this.endpoint = endpoint; + } + + public void start() { + StatusImpl.appendStatus("Service binding start", + ((EndpointImpl)endpoint).toStringWithoutHash()); + } + + public void stop() { + StatusImpl.appendStatus("Service binding stop", + ((EndpointImpl)endpoint).toStringWithoutHash()); + } + + public InterfaceContract getBindingInterfaceContract() { + return contract; + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceInvoker.java new file mode 100644 index 0000000000..09ca7a051e --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceInvoker.java @@ -0,0 +1,40 @@ +/* + * 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 binding.lifecycle; + +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +public class LifecycleServiceInvoker { + + private RuntimeEndpoint wire; + + public LifecycleServiceInvoker(RuntimeEndpoint wire) { + this.wire = wire; + } + + /** + * Send the request down the wire to invoke the service + */ + public Message invokeService(Message msg) { + return wire.invoke(msg); + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java new file mode 100644 index 0000000000..7b9c17cf59 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java @@ -0,0 +1,31 @@ +/* + * 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 helloworld; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Helloworld { + + String sayHello(String name) throws Exception; + + String throwException(String name) throws Exception; + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplC.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplC.java new file mode 100644 index 0000000000..931e61677d --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplC.java @@ -0,0 +1,78 @@ +/* + * 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 helloworld; + +import org.oasisopen.sca.annotation.Destroy; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +/* + * C = a composite scoped component that throws exceptions + */ + +@Scope("COMPOSITE") +public class HelloworldClientImplC implements Helloworld { + + public static boolean throwTestExceptionOnConstruction = false; + public static boolean throwTestExceptionOnInit = false; + public static boolean throwTestExceptionOnDestroy = false; + + + @Reference + public Helloworld service; + + public HelloworldClientImplC() throws Exception { + if(throwTestExceptionOnConstruction){ + StatusImpl.appendStatus("Exception on construction", "HelloworldClientImplC"); + throw new Exception("Exception on construction"); + } + } + + @Init + public void initialize() throws Exception{ + if (throwTestExceptionOnInit) { + StatusImpl.appendStatus("Exception on init", "HelloworldClientImplC"); + throw new Exception("Exception on init"); + } + + StatusImpl.appendStatus("Init", "HelloworldClientImplC"); + System.out.println(">>>>>> " + sayHello("init")); + } + + @Destroy + public void destroy() throws Exception{ + if (throwTestExceptionOnDestroy) { + StatusImpl.appendStatus("Exception on destroy", "HelloworldClientImplC"); + throw new Exception("Exception on destroy"); + } + + StatusImpl.appendStatus("Destroy", "HelloworldClientImplC"); + } + + 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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplCE.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplCE.java new file mode 100644 index 0000000000..af97452ee9 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplCE.java @@ -0,0 +1,80 @@ +/* + * 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 helloworld; + +import org.oasisopen.sca.annotation.Destroy; +import org.oasisopen.sca.annotation.EagerInit; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +/* + * CE = a composite scoped component with EagerInit that throws exceptions + */ + +@EagerInit +@Scope("COMPOSITE") +public class HelloworldClientImplCE implements Helloworld { + + public static boolean throwTestExceptionOnConstruction = false; + public static boolean throwTestExceptionOnInit = false; + public static boolean throwTestExceptionOnDestroy = false; + + + @Reference + public Helloworld service; + + public HelloworldClientImplCE() throws Exception { + if(throwTestExceptionOnConstruction){ + StatusImpl.appendStatus("Exception on construction", "HelloworldClientImplCE"); + throw new Exception("Exception on construction"); + } + } + + @Init + public void initialize() throws Exception{ + if (throwTestExceptionOnInit) { + StatusImpl.appendStatus("Exception on init", "HelloworldClientImplCE"); + throw new Exception("Exception on init"); + } + + StatusImpl.appendStatus("Init", "HelloworldClientImplCE"); + System.out.println(">>>>>> " + sayHello("init")); + } + + @Destroy + public void destroy() throws Exception{ + if (throwTestExceptionOnDestroy) { + StatusImpl.appendStatus("Exception on destroy", "HelloworldClientImplCE"); + throw new Exception("Exception on destroy"); + } + + StatusImpl.appendStatus("Destroy", "HelloworldClientImplCE"); + } + + 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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplS.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplS.java new file mode 100644 index 0000000000..493ccca972 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImplS.java @@ -0,0 +1,78 @@ +/* + * 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 helloworld; + +import org.oasisopen.sca.annotation.Destroy; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +/* + * S = a stateless scoped component that throws exceptions + */ + +@Scope("STATELESS") +public class HelloworldClientImplS implements Helloworld { + + public static boolean throwTestExceptionOnConstruction = false; + public static boolean throwTestExceptionOnInit = false; + public static boolean throwTestExceptionOnDestroy = false; + + + @Reference + public Helloworld service; + + public HelloworldClientImplS() throws Exception { + if(throwTestExceptionOnConstruction){ + StatusImpl.appendStatus("Exception on construction", "HelloworldClientImplS"); + throw new Exception("Exception on construction"); + } + } + + @Init + public void initialize() throws Exception{ + if (throwTestExceptionOnInit) { + StatusImpl.appendStatus("Exception on init", "HelloworldClientImplS"); + throw new Exception("Exception on init"); + } + + StatusImpl.appendStatus("Init", "HelloworldClientImplS"); + System.out.println(">>>>>> " + sayHello("init")); + } + + @Destroy + public void destroy() throws Exception{ + if (throwTestExceptionOnDestroy) { + StatusImpl.appendStatus("Exception on destroy", "HelloworldClientImplS"); + throw new Exception("Exception on destroy"); + } + + StatusImpl.appendStatus("Destroy", "HelloworldClientImplS"); + } + + 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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java new file mode 100644 index 0000000000..2d27ec8f58 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 helloworld; + +public class HelloworldServiceImpl implements Helloworld { + + public String sayHello(String name) { + String response = "Hello " + name; + 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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java new file mode 100644 index 0000000000..644853d6c2 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java @@ -0,0 +1,32 @@ +/* + * 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 helloworld; + +public class StatusImpl { + + public static String statusString = ""; + + public static void appendStatus(String event, String location){ + // remove any addresses from the strings + location = location.replaceAll("\\(@.*Endpoint", "Endpoint"); + statusString += event + " - " + location + "\n"; + } + +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java new file mode 100644 index 0000000000..ebed204b87 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java new file mode 100644 index 0000000000..c7989b291c --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 { + 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 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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java new file mode 100644 index 0000000000..ac750fe040 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java new file mode 100644 index 0000000000..f1e303882f --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 asyncMessageMap = new HashMap(); + + 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.appendStatus("Implementation start", comp.getName()); + } + + public void stop() { + StatusImpl.appendStatus("Implementation stop", comp.getName()); + } + + 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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java new file mode 100644 index 0000000000..dfd39716fd --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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 { + 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 getModelType() { + return LifecycleImplementation.class; + } +} diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/binding.lifecycle.BindingFactory b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/binding.lifecycle.BindingFactory new file mode 100644 index 0000000000..357cf65727 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/binding.lifecycle.BindingFactory @@ -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 class for model factory +binding.lifecycle.LifecycleBindingFactory + diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..09a474a567 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,21 @@ +# 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 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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema new file mode 100644 index 0000000000..e436702181 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -0,0 +1,21 @@ +# 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-lifecycle.xsd +binding-lifecycle.xsd + + diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..9a814793b2 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -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 class for the binding extension +binding.lifecycle.LifecycleBindingProviderFactory;model=binding.lifecycle.LifecycleBinding + diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/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/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/binding-lifecycle.xsd b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/binding-lifecycle.xsd new file mode 100644 index 0000000000..b798446c26 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/binding-lifecycle.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd new file mode 100644 index 0000000000..c029a43922 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/lifecycle.composite b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/lifecycle.composite new file mode 100644 index 0000000000..f08f6fe57b --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/main/resources/lifecycle.composite @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java new file mode 100644 index 0000000000..b1b0c84376 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java @@ -0,0 +1,836 @@ +/* + * 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 org.apache.tuscany.sca.itest.lifecycle; + + +import helloworld.Helloworld; +import helloworld.HelloworldClientImplC; +import helloworld.HelloworldClientImplCE; +import helloworld.HelloworldClientImplS; +import helloworld.StatusImpl; +import junit.framework.Assert; + +import org.apache.tuscany.sca.Node; +import org.apache.tuscany.sca.TuscanyRuntime; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class LifecycleTestCase { + + public Node node = null; + + + @Before + public void setUp() throws Exception { + StatusImpl.statusString = ""; + } + + @After + public void tearDown() throws Exception { + + } + + /* + * Start up the composite and don't send any messages. No exception + * should be thrown. + */ + @Test + public void testNoExceptionNoMessageShutdown() throws Exception{ + + StatusImpl.statusString = ""; + + 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"); + + // we don't send any messages in this case and just shut down directly + + // 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 - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite and send a message. No exception + * should be thrown. + */ + @Test + public void testNoExceptionMessageShutdown() 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"); + + // send a message to each client + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientCE"); + System.out.println(hwCE.sayHello("name")); + Helloworld hwC = node.getService(Helloworld.class, "HelloworldClientC"); + System.out.println(hwC.sayHello("name")); + Helloworld hwS = node.getService(Helloworld.class, "HelloworldClientC"); + System.out.println(hwS.sayHello("name")); + + // 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 - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplC\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientC#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientC#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplC\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + + /*$self$ reference of client is not stopped here - should it be? */ + } + + /* + * Start up the composite. Exception thrown in constructor of composite + * scoped component with eager init set + */ + @Test + public void testConstructorExceptionShutdownCE() throws Exception{ + + HelloworldClientImplCE.throwTestExceptionOnConstruction = 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 + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testConstructorExceptionShutdownCE"); + } + + // don't need to send a message as eager init ensures that + // the component instance is created at start time + + // stop a composite + try { + // not required in this test as the exception during EagerInit will cause the stop + //node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testConstructorExceptionShutdownCE"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplCE.throwTestExceptionOnConstruction = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Exception on construction - HelloworldClientImplCE\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Exception caught on node.startComposite - LifecycleTestCase.testConstructorExceptionShutdownCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite. Exception thrown in constructor of composite + * scoped component + */ + @Test + public void testConstructorExceptionShutdownC() throws Exception{ + + HelloworldClientImplC.throwTestExceptionOnConstruction = 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 + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testConstructorExceptionShutdownC"); + } + + // send a message to the appropriate client + try { + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientC"); + System.out.println(hwCE.sayHello("name")); + } catch (Exception exception) { + // the component throws an error on construction + StatusImpl.appendStatus("Exception caught on sayHello()", "LifecycleTestCase.testConstructorExceptionShutdownC"); + } + + // stop a composite + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testConstructorExceptionShutdownC"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplC.throwTestExceptionOnConstruction = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception on construction - HelloworldClientImplC\n" + + "Exception caught on sayHello() - LifecycleTestCase.testConstructorExceptionShutdownC\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite. Exception thrown in constructor of stateless + * scoped component + */ + @Test + public void testConstructorExceptionShutdownS() throws Exception{ + + HelloworldClientImplS.throwTestExceptionOnConstruction = 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 + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testConstructorExceptionShutdownS"); + } + + // send a message to the appropriate client + try { + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientS"); + System.out.println(hwCE.sayHello("name")); + } catch (Exception exception) { + // the component throws an error on construction + StatusImpl.appendStatus("Exception caught on sayHello()", "LifecycleTestCase.testConstructorExceptionShutdownS"); + } + + // stop a composite + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testConstructorExceptionShutdownS"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplS.throwTestExceptionOnConstruction = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception on construction - HelloworldClientImplS\n" + + "Exception caught on sayHello() - LifecycleTestCase.testConstructorExceptionShutdownS\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite. Exception thrown in init of composite + * scoped component with eager init + */ + @Test + public void testInitExceptionShutdownCE() throws Exception{ + + HelloworldClientImplCE.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 + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testInitExceptionShutdownCE"); + } + + // don't need to send a message as eager init ensures that + // the component instance is created and inited at start time + + // stop a composite + try { + // not required in this test as the exception during EagerInit will cause the stop + //node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testInitExceptionShutdownCE"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplCE.throwTestExceptionOnInit = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n"+ + "Implementation start - HelloworldServiceTestImpl\n"+ + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n"+ + "Exception on init - HelloworldClientImplCE\n"+ + "Destroy - HelloworldClientImplCE\n"+ + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n"+ + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n"+ + "Implementation stop - HelloworldServiceTestImpl\n" + + "Exception caught on node.startComposite - LifecycleTestCase.testInitExceptionShutdownCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite. Exception thrown in init of composite + * scoped component + */ + @Test + public void testInitExceptionShutdownC() throws Exception{ + + HelloworldClientImplC.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 + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testInitExceptionShutdownC"); + } + + // send a message to the appropriate client + try { + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientC"); + System.out.println(hwCE.sayHello("name")); + } catch (Exception exception) { + // the component throws an error on init + StatusImpl.appendStatus("Exception caught on sayHello()", "LifecycleTestCase.testInitExceptionShutdownC"); + } + + // stop a composite + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testInitExceptionShutdownC"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplC.throwTestExceptionOnInit = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception on init - HelloworldClientImplC\n" + + "Destroy - HelloworldClientImplC\n" + + "Exception caught on sayHello() - LifecycleTestCase.testInitExceptionShutdownC\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite. Exception thrown in init of stateless + * scoped component + */ + @Test + public void testInitExceptionShutdownS() throws Exception{ + + HelloworldClientImplS.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 + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testInitExceptionShutdownS"); + } + + // send a message to the appropriate client + try { + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientS"); + System.out.println(hwCE.sayHello("name")); + } catch (Exception exception) { + // the component throws an error on init + StatusImpl.appendStatus("Exception caught on sayHello()", "LifecycleTestCase.testInitExceptionShutdownS"); + } + + // stop a composite + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testInitExceptionShutdownS"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplS.throwTestExceptionOnInit = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception on init - HelloworldClientImplS\n" + + "Destroy - HelloworldClientImplS\n" + + "Exception caught on sayHello() - LifecycleTestCase.testInitExceptionShutdownS\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite and then stop it. Exception thrown in destory of composite + * scoped component with eager init set + */ + @Test + public void testDestroyExceptionShutdownCE() throws Exception{ + + HelloworldClientImplCE.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 + try { + node.startComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it's thrown from the HelloworldClientImpl @Destroy method + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testDestroyExceptionShutdownCE"); + } + + // don't need to send a message as eager init ensures that + // the component instance is created start time and hence should + // be destroyed + + // stop a composite + try { + // not required in this test as the exception during EagerInit will cause the stop + //node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testDestroyExceptionShutdownCE"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplCE.throwTestExceptionOnDestroy = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception on destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite and then stop it. Exception thrown in destory of composite + * scoped component + */ + @Test + public void testDestroyExceptionShutdownC() throws Exception{ + + HelloworldClientImplC.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 + try { + node.startComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it's thrown from the HelloworldClientImpl @Destroy method + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testDestroyExceptionShutdownC"); + } + + // send a message to the appropriate client + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientC"); + System.out.println(hwCE.sayHello("name")); + // don't need to catch exception here as the component instance won't + // be destroyed until shutdown + + // stop a composite + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on node.stopComposite", "LifecycleTestCase.testDestroyExceptionShutdownC"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplC.throwTestExceptionOnDestroy = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplC\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientC#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientC#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception on destroy - HelloworldClientImplC\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + + /* + * Start up the composite and then stop it. Exception thrown in destory of stateless + * scoped component + */ + @Test + public void testDestroyExceptionShutdownS() throws Exception{ + + HelloworldClientImplS.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 + try { + node.startComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it's thrown from the HelloworldClientImpl @Destroy method + StatusImpl.appendStatus("Exception caught on node.startComposite", "LifecycleTestCase.testDestroyExceptionShutdownS"); + } + + // send a message to the appropriate client + try { + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientS"); + System.out.println(hwCE.sayHello("name")); + } catch (Exception exception) { + // exception will be thrown when component instance is discarded + // after the message has been processed + } + + // stop a composite + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + StatusImpl.appendStatus("Exception caught on sayHello()", "LifecycleTestCase.testDestroyExceptionShutdownS"); + } + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + HelloworldClientImplS.throwTestExceptionOnDestroy = false; + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplS\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientS#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception on destroy - HelloworldClientImplS\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientS#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n", + StatusImpl.statusString); + } + + /* + * Start up the composite. Send a message where the processing sends an + * exception. App exception has no material affect and the scenario is the + * same as just sending normal messages and stopping the runtime + */ + @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"); + + // send a message to each client. The last one throws and exception + Helloworld hwCE = node.getService(Helloworld.class, "HelloworldClientCE"); + System.out.println(hwCE.sayHello("name")); + Helloworld hwC = node.getService(Helloworld.class, "HelloworldClientC"); + System.out.println(hwC.sayHello("name")); + Helloworld hwS = node.getService(Helloworld.class, "HelloworldClientC"); + System.out.println(hwS.sayHello("name")); + try { + Helloworld hw = node.getService(Helloworld.class, "HelloworldC"); + hw.throwException("name"); + } catch (Exception ex) { + // do nothing + StatusImpl.appendStatus("Exception caught on throwException()", "LifecycleTestCase.testAppExceptionShutdown"); + } + + // 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 - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldServiceTestImpl\n" + + "Service binding start - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplCE\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImplC\n" + + "Reference binding start - EndpointReference: URI = HelloworldClientC#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Exception caught on throwException() - LifecycleTestCase.testAppExceptionShutdown\n" + + "Service binding stop - Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldServiceTestImpl#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldServiceTestImpl\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientC#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplC\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClientCE#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImplCE\n", + StatusImpl.statusString); + } + +} -- cgit v1.2.3