diff options
Diffstat (limited to 'branches/sca-java-M2/sca/test/src/main/java')
17 files changed, 0 insertions, 1248 deletions
diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/ArtifactFactory.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/ArtifactFactory.java deleted file mode 100644 index ff893d8c3a..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/ArtifactFactory.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.test; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.builder.Connector; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; - -/** - * A factory for creating runtime artifacts to facilitate testing without directly instantiating core implementation - * classes - * - * @version $$Rev$$ $$Date$$ - */ -public final class ArtifactFactory { - - private ArtifactFactory() { - } - - public static Connector createConnector() { - return new ConnectorImpl(createWireService(), null, null, null); - } - - public static WireService createWireService() { - return new JDKWireService(new WorkContextImpl(), null); - } - - /** - * Creates an inbound wire. After a wire is returned, client code must call {@link - * #terminateWire(org.apache.tuscany.spi.wire.InboundWire)}. These two methods have been separated to allow wires - * to be decorated with interceptors or handlers prior to their completion - * - * @param serviceName the service name associated with the wire - * @param interfaze the interface associated with the wire - */ - public static <T> InboundWire createInboundWire(String serviceName, Class<T> interfaze) - throws InvalidServiceContractException { - InboundWire wire = new InboundWireImpl(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(interfaze); - wire.setServiceContract(contract); - wire.setServiceName(serviceName); - wire.addInvocationChains(createInboundChains(interfaze)); - return wire; - } - - /** - * Creates an outbound wire. After a wire is returned, client code must call {@link - * #terminateWire(org.apache.tuscany.spi.wire.OutboundWire)}. These two methods have been separated to allow - * wires to be decorated with interceptors or handlers prior to their completion - * - * @param refName the reference name the wire is associated with on the client - * @param interfaze the interface associated with the wire - */ - public static <T> OutboundWire createOutboundWire(String refName, Class<T> interfaze) - throws InvalidServiceContractException { - OutboundWire wire = new OutboundWireImpl(); - wire.setReferenceName(refName); - wire.addInvocationChains(createOutboundChains(interfaze)); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(interfaze); - wire.setServiceContract(contract); - return wire; - } - - - /** - * Finalizes the target wire - */ - public static <T> void terminateWire(InboundWire wire) { - for (InboundInvocationChain chain : wire.getInvocationChains().values()) { - // add tail interceptor - chain.addInterceptor(new InvokerInterceptor()); - } - } - - public static <T> void terminateWire(OutboundWire wire) { - for (OutboundInvocationChain chain : wire.getInvocationChains().values()) { - // add tail interceptor - chain.addInterceptor(new InvokerInterceptor()); - } - } - - private static Map<Operation<?>, OutboundInvocationChain> createOutboundChains(Class<?> interfaze) - throws InvalidServiceContractException { - Map<Operation<?>, OutboundInvocationChain> invocations = new HashMap<Operation<?>, OutboundInvocationChain>(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(interfaze); - for (Operation operation : contract.getOperations().values()) { - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - invocations.put(operation, chain); - } - return invocations; - } - - private static Map<Operation<?>, InboundInvocationChain> createInboundChains(Class<?> interfaze) - throws InvalidServiceContractException { - Map<Operation<?>, InboundInvocationChain> invocations = new HashMap<Operation<?>, InboundInvocationChain>(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(interfaze); - for (Operation<?> operation : contract.getOperations().values()) { - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - // add tail interceptor - //chain.addInterceptor(new InvokerInterceptor()); - invocations.put(operation, chain); - } - return invocations; - } - - -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/Bootstrapper.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/Bootstrapper.java deleted file mode 100644 index aed0fe2765..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/Bootstrapper.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.test; - -import java.net.URL; -import java.net.URLClassLoader; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.Deployer; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.model.ComponentDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation; -import org.apache.tuscany.core.launcher.CompositeContextImpl; -import org.apache.tuscany.core.launcher.LauncherImpl; -import org.apache.tuscany.core.monitor.NullMonitorFactory; - -/** - * @version $Rev$ $Date$ - */ -public class Bootstrapper extends TestCase { - protected CompositeComponent component; - private CompositeContextImpl context; - private Map<String, URL> extensions = new HashMap<String, URL>(); - private String applicationSCDL = LauncherImpl.METAINF_APPLICATION_SCDL_PATH; - - protected void setUp() throws Exception { - super.setUp(); - ClassLoader cl = getClass().getClassLoader(); - TestLauncher launcher = new TestLauncher(); - launcher.setApplicationLoader(cl); - CompositeComponent composite = launcher.bootRuntime(cl.getResource(LauncherImpl.METAINF_SYSTEM_SCDL_PATH), - new NullMonitorFactory()); - - for (String extensionName : extensions.keySet()) { - deployExtension(composite, extensionName, extensions.get(extensionName)); - } - - URL applicationScdlURL = cl.getResource(applicationSCDL); - if (applicationScdlURL == null) { - throw new RuntimeException("application SCDL not found: " + applicationSCDL); - } - component = launcher.bootApplication("application", applicationScdlURL); - component.start(); - context = new CompositeContextImpl(component); - context.start(); - } - - /** - * A TestCase can use this to overide the default SCDL location of "META-INF/sca/default.scdl" - */ - protected void setApplicationSCDL(String applicationSCDL) { - this.applicationSCDL = applicationSCDL; - } - - /** - * A TestCase can use this to add the SCDL location of an extention to be deployed to the runtime - */ - protected void addExtension(String extensionName, URL extentionSCDL) { - extensions.put(extensionName, extentionSCDL); - } - - protected void deployExtension(CompositeComponent composite, String extensionName, URL scdlURL) - throws LoaderException { - SystemCompositeImplementation implementation = new SystemCompositeImplementation(); - implementation.setScdlLocation(scdlURL); - URLClassLoader classLoader = new URLClassLoader(new URL[]{scdlURL}, getClass().getClassLoader()); - implementation.setClassLoader(classLoader); - - ComponentDefinition<SystemCompositeImplementation> definition = - new ComponentDefinition<SystemCompositeImplementation>(extensionName, - implementation); - - Deployer deployer = (Deployer) composite.getSystemChild("deployer").getServiceInstance(); - Component component = deployer.deploy(composite, definition); - - component.start(); - } - - protected void tearDown() throws Exception { - context.stop(); - component.stop(); - super.tearDown(); - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java deleted file mode 100644 index ed3f23881f..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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.test; - -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.HashMap; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation; -import org.apache.tuscany.core.launcher.CompositeContextImpl; -import org.apache.tuscany.core.launcher.LauncherImpl; -import org.apache.tuscany.core.monitor.NullMonitorFactory; -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.Deployer; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.model.ComponentDefinition; - -/** - * Base class for JUnit tests that want to run in an SCA client environment. - * - * @version $Rev$ $Date$ - */ -public abstract class SCATestCase extends TestCase { - protected CompositeComponent component; - private CompositeContextImpl context; - private Map<String, URL> extensions = new HashMap<String, URL>(); - private URL applicationSCDL; - - protected void setUp() throws Exception { - super.setUp(); - ClassLoader cl = getClass().getClassLoader(); - LauncherImpl launcher = new LauncherImpl(); - launcher.setApplicationLoader(cl); - CompositeComponent composite = launcher.bootRuntime(cl.getResource(LauncherImpl.METAINF_SYSTEM_SCDL_PATH), - new NullMonitorFactory()); - - for (String extensionName : extensions.keySet()) { - deployExtension(composite, extensionName, extensions.get(extensionName)); - } - - if (applicationSCDL == null) { - throw new RuntimeException("application SCDL not found: " + applicationSCDL); - } - component = launcher.bootApplication("application", applicationSCDL); - component.start(); - context = new CompositeContextImpl(component); - context.start(); - } - - /** - * A TestCase can use this to overide the default SCDL location of "META-INF/sca/default.scdl" - */ - protected void setApplicationSCDL(URL applicationSCDL) { - this.applicationSCDL = applicationSCDL; - } - - /** - * Set the application scdl based on the classpath entry for a class. - * Normally this will be a class in the production code associated with this test case. - * - * @param aClass a Class from which to determine the resource base url - * @param path location of the application SCDL relative to the base class - * @throws MalformedURLException if the path is malformed - */ - protected void setApplicationSCDL(Class<?> aClass, String path) throws MalformedURLException { - URL root = getRoot(aClass); - setApplicationSCDL(new URL(root, path)); - } - - /** - * A TestCase can use this to add the SCDL location of an extention to be deployed to the runtime - */ - protected void addExtension(String extensionName, URL extentionSCDL) { - extensions.put(extensionName, extentionSCDL); - } - - protected void deployExtension(CompositeComponent composite, String extensionName, URL scdlURL) - throws LoaderException { - SystemCompositeImplementation implementation = new SystemCompositeImplementation(); - implementation.setScdlLocation(scdlURL); - implementation.setClassLoader(new URLClassLoader(new URL[]{scdlURL}, getClass().getClassLoader())); - - ComponentDefinition<SystemCompositeImplementation> definition = - new ComponentDefinition<SystemCompositeImplementation>(extensionName, implementation); - - Deployer deployer = (Deployer) composite.getSystemChild("deployer").getServiceInstance(); - Component component = deployer.deploy(composite, definition); - - component.start(); - } - - - protected static URL getRoot(Class<?> aClass) { - String name = aClass.getName(); - String classPath = "/" + name.replace('.', '/') + ".class"; - URL classURL = aClass.getResource(classPath); - assert classURL != null; - StringBuilder prefix = new StringBuilder(); - for (int i = 0; i < name.length(); i++) { - if (name.charAt(i) == '.') { - prefix.append("../"); - } - } - try { - return new URL(classURL, prefix.toString()); - } catch (MalformedURLException e) { - throw new AssertionError(); - } - } - - protected void tearDown() throws Exception { - context.stop(); - component.stop(); - super.tearDown(); - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/TestLauncher.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/TestLauncher.java deleted file mode 100644 index b66716bac0..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/TestLauncher.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.test; - -import java.io.File; - -import org.apache.tuscany.core.launcher.LauncherImpl; - -/** - * @version $Rev$ $Date$ - */ -public class TestLauncher extends LauncherImpl { - - public File getInstallDirectory() { - return new File("."); - } - -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBinding.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBinding.java deleted file mode 100644 index 36d204cedc..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBinding.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.spi.model.Binding; - - -/** - * A simple binding for test purposes. - * - * @version $$Rev$$ $$Date$$ - */ -public class TestBinding extends Binding { - - -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingBuilder.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingBuilder.java deleted file mode 100644 index 7140320c08..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.extension.BindingBuilderExtension; -import org.apache.tuscany.spi.model.BoundServiceDefinition; -import org.apache.tuscany.spi.model.BoundReferenceDefinition; - -/** - * @version $Rev$ $Date$ - */ -public class TestBindingBuilder extends BindingBuilderExtension<TestBinding> { - - @SuppressWarnings("unchecked") - public Service build(CompositeComponent parent, - BoundServiceDefinition<TestBinding> definition, - DeploymentContext context) { - Class<?> interfaze = definition.getServiceContract().getInterfaceClass(); - return new TestBindingService(definition.getName(), interfaze, parent, wireService); - } - - public Reference build(CompositeComponent parent, - BoundReferenceDefinition<TestBinding> definition, - DeploymentContext context) { - Class<?> interfaze = definition.getServiceContract().getInterfaceClass(); - String name = definition.getName(); - return new TestBindingReference(name, interfaze, parent, wireService); - } - - protected Class<TestBinding> getBindingType() { - return TestBinding.class; - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingLoader.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingLoader.java deleted file mode 100644 index db7ba3df6a..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingLoader.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.test.binding; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.osoa.sca.Version; -import org.osoa.sca.annotations.Constructor; - -import org.apache.tuscany.spi.annotation.Autowire; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.extension.LoaderExtension; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; - -/** - * @version $Rev$ $Date$ - */ -public class TestBindingLoader extends LoaderExtension<TestBinding> { - - public static final QName BINDING_TEST = new QName(Version.XML_NAMESPACE_1_0, "binding.test"); - - @Constructor - public TestBindingLoader(@Autowire LoaderRegistry registry) { - super(registry); - } - - public QName getXMLType() { - return BINDING_TEST; - } - - public TestBinding load(CompositeComponent parent, - XMLStreamReader reader, - DeploymentContext context) throws XMLStreamException, LoaderException { - return new TestBinding(); - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingReference.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingReference.java deleted file mode 100644 index a76362da08..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingReference.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.extension.ReferenceExtension; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -/** - * @version $Rev$ $Date$ - */ -public class TestBindingReference extends ReferenceExtension { - - public TestBindingReference(String name, Class<?> interfaze, CompositeComponent parent, WireService wireService) { - super(name, interfaze, parent, wireService); - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) { - return new TestInvoker(); - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingRuntimeException.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingRuntimeException.java deleted file mode 100644 index 21f8bd1067..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingRuntimeException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.api.TuscanyRuntimeException; - -/** - * @version $Rev$ $Date$ - */ -public class TestBindingRuntimeException extends TuscanyRuntimeException { - - public TestBindingRuntimeException() { - } - - public TestBindingRuntimeException(String message) { - super(message); - } - - public TestBindingRuntimeException(String message, Throwable cause) { - super(message, cause); - } - - public TestBindingRuntimeException(Throwable cause) { - super(cause); - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingService.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingService.java deleted file mode 100644 index 66ef7ab879..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestBindingService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.spi.CoreRuntimeException; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.extension.ServiceExtension; -import org.apache.tuscany.spi.wire.WireService; - -/** - * - * @version $Rev$ $Date$ - */ -public class TestBindingService extends ServiceExtension { - public TestBindingService(String name, - Class<?> interfaze, - CompositeComponent parent, - WireService wireService) throws CoreRuntimeException { - super(name, interfaze, parent, wireService); - // do nothing, but this could register with the host environment - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestInvoker.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestInvoker.java deleted file mode 100644 index 4a6bed766e..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestInvoker.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.test.binding; - -import java.lang.reflect.InvocationTargetException; - -import org.apache.tuscany.spi.wire.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.TargetInvoker; - -/** - * @version $Rev$ $Date$ - */ -public class TestInvoker implements TargetInvoker { - - private boolean cacheable; - - public boolean isCacheable() { - return cacheable; - } - - public void setCacheable(boolean cacheable) { - this.cacheable = cacheable; - } - - public boolean isOptimizable() { - return isCacheable(); - } - - public Object invokeTarget(final Object payload) throws InvocationTargetException { - // echo back the result, a real binding would invoke some API for flowing the request - return ((Object[]) payload)[0]; - } - - public Message invoke(Message msg) throws InvocationRuntimeException { - try { - Object resp = invokeTarget(msg.getBody()); - msg.setBody(resp); - } catch (InvocationTargetException e) { - msg.setBodyWithFault(e.getCause()); - } catch (Throwable e) { - msg.setBodyWithFault(e); - } - return msg; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBinding.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBinding.java deleted file mode 100644 index edb191501e..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBinding.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.spi.model.Binding; - -/** - * A simple socket-based binding. Service operations may onyl take one parameter that is <code>Serializable</code> - * - * @version $$Rev$$ $$Date$$ - */ -public class TestSocketBinding extends Binding { - private String host; - private int port; - - public TestSocketBinding(String host, int port) { - this.host = host; - this.port = port; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingBuilder.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingBuilder.java deleted file mode 100644 index b674a518bb..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.extension.BindingBuilderExtension; -import org.apache.tuscany.spi.model.BoundReferenceDefinition; -import org.apache.tuscany.spi.model.BoundServiceDefinition; - -/** - * @version $Rev$ $Date$ - */ -public class TestSocketBindingBuilder extends BindingBuilderExtension<TestSocketBinding> { - - public Service build(CompositeComponent parent, - BoundServiceDefinition<TestSocketBinding> definition, - DeploymentContext context) { - Class<?> interfaze = definition.getServiceContract().getInterfaceClass(); - int port = definition.getBinding().getPort(); - return new TestSocketBindingService(definition.getName(), port, interfaze, parent, wireService); - } - - public Reference build(CompositeComponent parent, - BoundReferenceDefinition<TestSocketBinding> definition, - DeploymentContext context) { - Class<?> interfaze = definition.getServiceContract().getInterfaceClass(); - String name = definition.getName(); - int port = definition.getBinding().getPort(); - String host = definition.getBinding().getHost(); - return new TestSocketBindingReference(name, host, port, interfaze, parent, wireService); - } - - protected Class<TestSocketBinding> getBindingType() { - return TestSocketBinding.class; - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingLoader.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingLoader.java deleted file mode 100644 index 98393e1baa..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingLoader.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.test.binding; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.osoa.sca.Version; -import org.osoa.sca.annotations.Constructor; - -import org.apache.tuscany.spi.annotation.Autowire; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.extension.LoaderExtension; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; - -/** - * @version $Rev$ $Date$ - */ -public class TestSocketBindingLoader extends LoaderExtension<TestSocketBinding> { - - public static final QName BINDING_TEST = new QName(Version.XML_NAMESPACE_1_0, "binding.socket"); - - @Constructor - public TestSocketBindingLoader(@Autowire LoaderRegistry registry) { - super(registry); - } - - public QName getXMLType() { - return TestSocketBindingLoader.BINDING_TEST; - } - - public TestSocketBinding load(CompositeComponent parent, - XMLStreamReader reader, - DeploymentContext context) throws XMLStreamException, LoaderException { - String host = reader.getAttributeValue(null, "host"); - int port; - try { - port = Integer.parseInt(reader.getAttributeValue(null, "port")); - } catch (NumberFormatException e) { - throw new LoaderException("Invalid port specified", e); - } - return new TestSocketBinding(host, port); - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingReference.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingReference.java deleted file mode 100644 index 211b173d63..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingReference.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.test.binding; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.extension.ReferenceExtension; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -/** - * @version $Rev$ $Date$ - */ -public class TestSocketBindingReference extends ReferenceExtension { - - private String host; - private int port; - - public TestSocketBindingReference(String name, - String host, - int port, - Class<?> interfaze, - CompositeComponent parent, - WireService wireService) { - super(name, interfaze, parent, wireService); - this.port = port; - this.host = host; - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) { - return new TestSocketInvoker(host, port, operation.getName()); - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingService.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingService.java deleted file mode 100644 index 6710094b4a..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingService.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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.test.binding; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.apache.tuscany.spi.CoreRuntimeException; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.extension.ServiceExtension; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.WireService; - -/** - * Implements a very simple remote, socket-based binding for test purposes. This binding exposes services using a socket - * on a given port. Service operations must take only one paramter that is <code>Serializable</code>. - * - * @version $Rev$ $Date$ - */ -public class TestSocketBindingService extends ServiceExtension { - private int port; - private ServerSocket socket; - private ExecutorService executor; - private TestSocketBindingService.ServerRunnable runnable; - - public TestSocketBindingService(String name, - int port, - Class<?> interfaze, - CompositeComponent parent, - WireService wireService) throws CoreRuntimeException { - super(name, interfaze, parent, wireService); - this.port = port; - } - - public void start() { - executor = Executors.newSingleThreadExecutor(); - // create a listener, note that a work scheduler should normally be used to spawn work in different threads - runnable = new ServerRunnable(); - executor.execute(runnable); - } - - public void stop() { - try { - runnable.setEnd(true); - socket.close(); - executor.shutdownNow(); - } catch (IOException e) { - throw new TestBindingRuntimeException(e); - } - } - - /** - * Creates a socket listener in another thread which handles one client at a time. For a real binding, a work - * scheduler should be used - */ - private class ServerRunnable implements Runnable { - - private boolean end; - - public void setEnd(boolean end) { - this.end = end; - } - - public void run() { - Socket clientSocket; - ObjectInputStream is = null; - ObjectOutputStream os = null; - try { - socket = new ServerSocket(port); - } catch (IOException e) { - throw new TestBindingRuntimeException(e); - } - while (!end) { - try { - clientSocket = socket.accept(); - is = new ObjectInputStream(clientSocket.getInputStream()); - String operation = is.readUTF(); - int argn = is.readInt(); - Object[] args = new Object[argn]; - for (int i = 0; i<argn; i++) { - args[i] = is.readObject(); - } - Map<Operation<?>, InboundInvocationChain> chains = getInboundWire().getInvocationChains(); - for (InboundInvocationChain chain : chains.values()) { - if (chain.getOperation().getName().equals(operation)) { - Message message = new MessageImpl(); - message.setTargetInvoker(chain.getTargetInvoker()); - message.setBody(args); - message = chain.getHeadInterceptor().invoke(message); - os = new ObjectOutputStream(clientSocket.getOutputStream()); - os.writeObject(message.getBody()); - os.flush(); - } - } - } catch (IOException e) { - throw new TestBindingRuntimeException(e); - } catch (ClassNotFoundException e) { - throw new TestBindingRuntimeException(e); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - // ingore - } - } - if (is != null) { - try { - is.close(); - } catch (IOException e) { - // ignore - } - } - } - } - } - } -} diff --git a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketInvoker.java b/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketInvoker.java deleted file mode 100644 index 154c1422a1..0000000000 --- a/branches/sca-java-M2/sca/test/src/main/java/org/apache/tuscany/test/binding/TestSocketInvoker.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.test.binding; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.lang.reflect.InvocationTargetException; -import java.net.Socket; -import java.net.UnknownHostException; - -import org.apache.tuscany.spi.wire.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.TargetInvoker; - -/** - * Responsible for serializing an operation parameter flowing the invocation through the socket - * - * @version $Rev$ $Date$ - */ -public class TestSocketInvoker implements TargetInvoker { - private String host; - private int port; - private String operation; - - private boolean cacheable; - - public TestSocketInvoker(String host, int port, String operation) { - this.host = host; - this.port = port; - this.operation = operation; - } - - public boolean isCacheable() { - return cacheable; - } - - public void setCacheable(boolean cacheable) { - this.cacheable = cacheable; - } - - public boolean isOptimizable() { - return isCacheable(); - } - - public Message invoke(Message msg) throws InvocationRuntimeException { - try { - Object resp = invokeTarget(msg.getBody()); - msg.setBody(resp); - } catch (InvocationTargetException e) { - msg.setBodyWithFault(e.getCause()); - } catch (Throwable e) { - msg.setBodyWithFault(e); - } - return msg; - } - - /** - * Sends the payload over a socket - */ - public Object invokeTarget(final Object object) throws InvocationTargetException { - int argn; - if (object == null) { - argn = 0; - } else if (!object.getClass().isArray()) { - argn = 1; - } else { - argn = ((Object[])object).length; - } - - Socket socket = null; - ObjectOutputStream os = null; - ObjectInputStream is = null; - try { - socket = new Socket(host, port); - os = new ObjectOutputStream(socket.getOutputStream()); - os.writeUTF(operation); - os.writeInt(argn); - for (int i=0; i<argn; i++) { - if (!object.getClass().isArray()) { - os.writeObject(object); - } - else { - os.writeObject(((Object[])object)[i]); - } - } - os.flush(); - is = new ObjectInputStream(socket.getInputStream()); - return is.readObject(); - } catch (ClassNotFoundException e) { - throw new InvocationTargetException(e); - } catch (UnknownHostException e) { - throw new InvocationTargetException(e); - } catch (IOException e) { - throw new InvocationTargetException(e); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - // ignore - } - } - if (is != null) { - try { - is.close(); - } catch (IOException e) { - // ignore - } - } - if (socket != null) { - try { - socket.close(); - } catch (IOException e) { - // ignore - } - } - } - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - -} |