tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r1127870 - in /tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src: main/java/helloworld/ main/java/implementation/lifecycle/ main/resources/ main/resources/META-INF/services/ test/java/org/apache/tuscany/sca/itest/lifecycle/
Date Thu, 26 May 2011 11:09:55 GMT
Author: slaws
Date: Thu May 26 11:09:54 2011
New Revision: 1127870

URL: http://svn.apache.org/viewvc?rev=1127870&view=rev
Log:
Add a test implementation provider and extend the test case to cover init and destroy exceptions

Added:
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd
Modified:
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite
    tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java

Modified: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java?rev=1127870&r1=1127869&r2=1127870&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/Helloworld.java
Thu May 26 11:09:54 2011
@@ -25,5 +25,7 @@ import org.oasisopen.sca.annotation.Remo
 public interface Helloworld {
     
     String sayHello(String name) throws Exception;
+    
+    String throwException(String name) throws Exception;
 
 }

Modified: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java?rev=1127870&r1=1127869&r2=1127870&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java
Thu May 26 11:09:54 2011
@@ -28,23 +28,41 @@ import org.oasisopen.sca.annotation.Scop
 @EagerInit
 @Scope("COMPOSITE")
 public class HelloworldClientImpl implements Helloworld {
+    
+    public static boolean throwTestExceptionOnInit = false;
+    public static boolean throwTestExceptionOnDestroy = false;
+    
 
     @Reference
     public Helloworld service;
     
     @Init
     public void initialize() throws Exception{
+        if (throwTestExceptionOnInit) {
+            StatusImpl.statusString += "Exception on init ";
+            throw new Exception("Exception on init");
+        }
+        
         StatusImpl.statusString += "HelloworldClientImpl init ";
     	System.out.println(">>>>>> " + sayHello("init"));
     }
     
     @Destroy
     public void destroy() throws Exception{
+        if (throwTestExceptionOnDestroy) {
+            StatusImpl.statusString += "Exception on destroy ";
+            throw new Exception("Exception on destroy");
+        }
+        
         StatusImpl.statusString += "HelloworldClientImpl destroy ";
     }    
     
     public String sayHello(String name) throws Exception {
         return "Hi " + service.sayHello(name);
     }
+    
+    public String throwException(String name) throws Exception {
+        throw new Exception("test exception");
+    }
 
 }

Modified: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java?rev=1127870&r1=1127869&r2=1127870&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldServiceImpl.java
Thu May 26 11:09:54 2011
@@ -26,5 +26,10 @@ public class HelloworldServiceImpl imple
         System.out.println("At service - " + response);
         return response;
     }
+    
+    public String throwException(String name) throws Exception {
+        // not used
+        return null;
+    }
 
 }

Added: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java?rev=1127870&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java
(added)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementation.java
Thu May 26 11:09:54 2011
@@ -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;
+    }
+
+}

Added: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java?rev=1127870&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java
(added)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleImplementationProcessor.java
Thu May 26 11:09:54 2011
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package implementation.lifecycle;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject;
+
+/**
+ * StAX artifact processor for Sample implementations.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class LifecycleImplementationProcessor extends BaseStAXArtifactProcessor implements
StAXArtifactProcessor<LifecycleImplementation> {
+    final AssemblyFactory af;
+    final JavaInterfaceFactory jif;
+    final WSDLFactory wf;
+
+    public LifecycleImplementationProcessor(final ExtensionPointRegistry ep) {
+        final FactoryExtensionPoint fep = ep.getExtensionPoint(FactoryExtensionPoint.class);
+        this.af = fep.getFactory(AssemblyFactory.class);
+        this.jif = fep.getFactory(JavaInterfaceFactory.class);
+        this.wf = fep.getFactory(WSDLFactory.class);
+    }
+
+    public QName getArtifactType() {
+        return LifecycleImplementation.QN;
+    }
+
+    public Class<LifecycleImplementation> getModelType() {
+        return LifecycleImplementation.class;
+    }
+
+    public LifecycleImplementation read(final XMLStreamReader r, final ProcessorContext ctx)
throws ContributionReadException, XMLStreamException {
+        // not actually going to read any config for this test
+        // so just create a model
+        LifecycleImplementation impl = new LifecycleImplementation("helloworld.Helloworld");
+        impl.setUnresolved(true);
+        return impl;
+    }
+
+    public void resolve(final LifecycleImplementation impl, final ModelResolver res, final
ProcessorContext ctx) throws ContributionResolveException {
+        try {
+            Class c = Class.forName("helloworld.Helloworld");
+            Service s = af.createService();
+            s.setName("Helloworld");
+            JavaInterfaceContract ic = jif.createJavaInterfaceContract();
+            ic.setInterface(jif.createJavaInterface(c));
+            s.setInterfaceContract(ic);
+            impl.getServices().add(s);
+            impl.setUnresolved(false);
+        } catch (Exception ex){
+            throw new ContributionResolveException(ex);
+        }               
+    }
+
+    public void write(final LifecycleImplementation impl, final XMLStreamWriter w, final
ProcessorContext ctx) throws ContributionWriteException, XMLStreamException {
+        // not required for this test
+    }
+
+}

Added: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java?rev=1127870&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java
(added)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleJavaInvoker.java
Thu May 26 11:09:54 2011
@@ -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;
+    }
+}

Added: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java?rev=1127870&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java
(added)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java
Thu May 26 11:09:54 2011
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package implementation.lifecycle;
+
+import helloworld.StatusImpl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * Implementation provider for Sample component implementations.
+ * 
+ * @version $Rev$ $Date$
+ */
+class LifecycleProvider implements ImplementationProvider {
+    final RuntimeComponent comp;
+    final LifecycleImplementation impl;
+    final ProxyFactory pxf;
+    final ExtensionPointRegistry ep;
+    Object instance;
+    
+    // make this static rather than worrying about persistence on the reference side
+    static Map<String, Object> asyncMessageMap = new HashMap<String, Object>();
+
+    LifecycleProvider(final RuntimeComponent comp, final LifecycleImplementation impl, ProxyFactory
pf, ExtensionPointRegistry ep) {
+        this.comp = comp;
+        this.impl = impl;
+        this.pxf = pf;
+        this.ep = ep;
+    }
+
+    public void start() {
+        StatusImpl.statusString += "Implementation start ";
+    }
+
+    public void stop() {
+        StatusImpl.statusString += "Implementation stop ";
+    }
+
+    public boolean supportsOneWayInvocation() {
+        return false;
+    }
+
+    public Invoker createInvoker(final RuntimeComponentService s, final Operation op) {
+        try {
+            return new SampleJavaInvoker((JavaOperation)op, impl.clazz, instance);
+        } catch(Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

Added: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java?rev=1127870&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java
(added)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProviderFactory.java
Thu May 26 11:09:54 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package implementation.lifecycle;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Factory for Sample implementation providers.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class LifecycleProviderFactory implements ImplementationProviderFactory<LifecycleImplementation>
{
+    final ProxyFactory pxf;
+    final ExtensionPointRegistry ep;
+
+    public LifecycleProviderFactory(final ExtensionPointRegistry ep) {
+        this.ep = ep;
+        pxf = ExtensibleProxyFactory.getInstance(ep);
+    }
+
+    public ImplementationProvider createImplementationProvider(final RuntimeComponent comp,
final LifecycleImplementation impl) {
+        return new LifecycleProvider(comp, impl, pxf, ep);
+    }
+
+    public Class<LifecycleImplementation> getModelType() {
+        return LifecycleImplementation.class;
+    }
+}

Modified: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor?rev=1127870&r1=1127869&r2=1127870&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
Thu May 26 11:09:54 2011
@@ -17,4 +17,5 @@
 
 # Implementation class for the artifact processor extension
 org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.lifecycle,model=binding.lifecycle.LifecycleBinding,factory=binding.lifecycle.LifecycleBindingFactory
+implementation.lifecycle.LifecycleImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#implementation.lifecycle,model=implementation.lifecycle.LifecycleImplementation
 

Modified: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema?rev=1127870&r1=1127869&r2=1127870&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema
Thu May 26 11:09:54 2011
@@ -15,5 +15,7 @@
 # specific language governing permissions and limitations
 # under the License. 
 #
+implementation-lifecycle.xsd
 binding-lifecycle.xsd
 
+

Added: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory?rev=1127870&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
(added)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
Thu May 26 11:09:54 2011
@@ -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
+

Added: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd?rev=1127870&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd
(added)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/implementation-lifecycle.xsd
Thu May 26 11:09:54 2011
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+    targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1"
+    xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+    xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+    elementFormDefault="qualified">
+
+    <import namespace="http://docs.oasis-open.org/ns/opencsa/sca/200912"/>
+
+    <element name="implementation.lifecycle" type="t:LifecycleImplementation" substitutionGroup="sca:implementation"/>
+
+    <complexType name="LifecycleImplementation">
+        <complexContent>
+            <extension base="sca:Implementation">
+                <attribute name="class" type="string" use="required"/>
+            </extension>
+        </complexContent>
+    </complexType>
+
+</schema>

Modified: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite?rev=1127870&r1=1127869&r2=1127870&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite
Thu May 26 11:09:54 2011
@@ -22,16 +22,23 @@
            targetNamespace="http://sample"
            name="domainview">
            
-    <component name="HelloworldService">
+    <component name="HelloworldService1">
        <implementation.java class="helloworld.HelloworldServiceImpl"/>
        <service name="Helloworld">
            <tuscany:binding.lifecycle name="lifecycle"/>
        </service>
-    </component>            
+    </component>  
+    
+    <component name="HelloworldService2">
+       <tuscany:implementation.lifecycle class="helloworld.HelloworldServiceImpl"/>
+       <service name="Helloworld">
+           <tuscany:binding.lifecycle name="lifecycle"/>
+       </service>
+    </component>               
 
     <component name="HelloworldClient">
        <implementation.java class="helloworld.HelloworldClientImpl"/>
-       <reference name="service" target="HelloworldService"/>       
+       <reference name="service" target="HelloworldService1"/>       
     </component> 
 
 </composite>

Modified: tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java?rev=1127870&r1=1127869&r2=1127870&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java
Thu May 26 11:09:54 2011
@@ -20,6 +20,8 @@
 package org.apache.tuscany.sca.itest.lifecycle;
 
 
+import helloworld.Helloworld;
+import helloworld.HelloworldClientImpl;
 import helloworld.StatusImpl;
 import junit.framework.Assert;
 
@@ -46,7 +48,7 @@ public class LifecycleTestCase {
     }
 
     @Test
-    public void test1() throws Exception{
+    public void testNormalShutdown() throws Exception{
         
         TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
 
@@ -74,13 +76,158 @@ public class LifecycleTestCase {
         // see what happened
         System.out.println(StatusImpl.statusString);
         Assert.assertEquals("Service binding start " + 
+                            "Implementation start " +
+                            "Service binding start " +
                             "HelloworldClientImpl init " +
                             "Reference binding start " + 
                             "Service binding stop " + 
+                            "Service binding stop " + 
+                            "Implementation stop " +
                             "Reference binding stop " +
                             "HelloworldClientImpl destroy ", 
                             StatusImpl.statusString);
-        
     }
     
+    @Test
+    public void testInitExceptionShutdown() throws Exception{
+        
+        HelloworldClientImpl.throwTestExceptionOnInit = true;
+        
+        TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+        // create a Tuscany node
+        node = tuscanyRuntime.createNode();
+        
+        // install a contribution
+        node.installContribution("HelloworldContrib", "target/classes", null, null);
+        
+        // start a composite
+        try {
+            node.startComposite("HelloworldContrib", "lifecycle.composite");
+        } catch (Exception exception) {
+            // it's thrown from the HelloworldClientImpl @Init method
+        }
+        
+        // stop a composite
+        node.stopComposite("HelloworldContrib", "lifecycle.composite");
+        
+        // uninstall a constribution
+        node.uninstallContribution("HelloworldContrib");
+        
+        // stop a Tuscany node
+        node.stop();
+        
+        // stop the runtime
+        tuscanyRuntime.stop();
+        
+        // see what happened
+        System.out.println(StatusImpl.statusString);
+        Assert.assertEquals("Service binding start " + 
+                            "Implementation start " +
+                            "Service binding start " +
+                            "HelloworldClientImpl init " +
+                            "Reference binding start " + 
+                            "Service binding stop " + 
+                            "Service binding stop " + 
+                            "Implementation stop " +
+                            "Reference binding stop " +
+                            "HelloworldClientImpl destroy ", 
+                            StatusImpl.statusString);
+        
+        HelloworldClientImpl.throwTestExceptionOnInit = false;
+    }    
+    
+    @Test
+    public void testDestroyExceptionShutdown() throws Exception{
+        
+        HelloworldClientImpl.throwTestExceptionOnDestroy = true;
+        
+        TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+        // create a Tuscany node
+        node = tuscanyRuntime.createNode();
+        
+        // install a contribution
+        node.installContribution("HelloworldContrib", "target/classes", null, null);
+        
+        // start a composite
+        node.startComposite("HelloworldContrib", "lifecycle.composite");
+        
+        // stop a composite
+        node.stopComposite("HelloworldContrib", "lifecycle.composite");
+        
+        // uninstall a constribution
+        node.uninstallContribution("HelloworldContrib");
+        
+        // stop a Tuscany node
+        node.stop();
+        
+        // stop the runtime
+        tuscanyRuntime.stop();
+        
+        // see what happened
+        System.out.println(StatusImpl.statusString);
+        Assert.assertEquals("Service binding start " + 
+                            "Implementation start " +
+                            "Service binding start " +
+                            "HelloworldClientImpl init " +
+                            "Reference binding start " + 
+                            "Service binding stop " + 
+                            "Service binding stop " + 
+                            "Implementation stop " +
+                            "Reference binding stop " +
+                            "HelloworldClientImpl destroy ", 
+                            StatusImpl.statusString);
+        
+        HelloworldClientImpl.throwTestExceptionOnDestroy = false;
+    }     
+    
+    @Test
+    public void testAppExceptionShutdown() throws Exception{
+        
+        TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+        // create a Tuscany node
+        node = tuscanyRuntime.createNode();
+        
+        // install a contribution
+        node.installContribution("HelloworldContrib", "target/classes", null, null);
+        
+        // start a composite
+        node.startComposite("HelloworldContrib", "lifecycle.composite");
+        
+        try {
+            Helloworld hw = node.getService(Helloworld.class, "Helloworld1");
+            hw.throwException("name");
+        } catch (Exception ex) {
+            // do nothing
+        }
+        
+        // stop a composite
+        node.stopComposite("HelloworldContrib", "lifecycle.composite");
+        
+        // uninstall a constribution
+        node.uninstallContribution("HelloworldContrib");
+        
+        // stop a Tuscany node
+        node.stop();
+        
+        // stop the runtime
+        tuscanyRuntime.stop();
+        
+        // see what happened
+        System.out.println(StatusImpl.statusString);
+        Assert.assertEquals("Service binding start " + 
+                            "Implementation start " +
+                            "Service binding start " +
+                            "HelloworldClientImpl init " +
+                            "Reference binding start " + 
+                            "Service binding stop " + 
+                            "Service binding stop " + 
+                            "Implementation stop " +
+                            "Reference binding stop " +
+                            "HelloworldClientImpl destroy ", 
+                            StatusImpl.statusString);
+    }    
+    
 }



Mime
View raw message