summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/1.0-incubator-M2/test/src
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:26:33 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:26:33 +0000
commita40e527938d76ba71f211da7e327adb50384ba69 (patch)
treecb8f99f1727122b040a3f0fbb6649292b6a74302 /sca-java-1.x/tags/1.0-incubator-M2/test/src
parent968721109881107520d7aefa91d7fcc0519d7739 (diff)
Moving 1.x tags
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835157 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/tags/1.0-incubator-M2/test/src')
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/ArtifactFactory.java147
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/Bootstrapper.java105
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/SCATestCase.java137
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/TestLauncher.java34
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBinding.java32
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingBuilder.java53
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingLoader.java56
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingReference.java40
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingRuntimeException.java42
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingService.java38
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestInvoker.java67
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBinding.java45
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingBuilder.java55
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingLoader.java63
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingReference.java50
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingService.java143
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketInvoker.java141
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/system.scdl130
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/test.binding.system.scdl44
-rw-r--r--sca-java-1.x/tags/1.0-incubator-M2/test/src/test/java/org/apache/tuscany/test/SCATestCaseTestCase.java35
20 files changed, 1457 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/ArtifactFactory.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/ArtifactFactory.java
new file mode 100644
index 0000000000..ff893d8c3a
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/ArtifactFactory.java
@@ -0,0 +1,147 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/Bootstrapper.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/Bootstrapper.java
new file mode 100644
index 0000000000..aed0fe2765
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/Bootstrapper.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 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/SCATestCase.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
new file mode 100644
index 0000000000..ed3f23881f
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
@@ -0,0 +1,137 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/TestLauncher.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/TestLauncher.java
new file mode 100644
index 0000000000..b66716bac0
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/TestLauncher.java
@@ -0,0 +1,34 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBinding.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBinding.java
new file mode 100644
index 0000000000..36d204cedc
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBinding.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 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingBuilder.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingBuilder.java
new file mode 100644
index 0000000000..7140320c08
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingBuilder.java
@@ -0,0 +1,53 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingLoader.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingLoader.java
new file mode 100644
index 0000000000..db7ba3df6a
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingLoader.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 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingReference.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingReference.java
new file mode 100644
index 0000000000..a76362da08
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingReference.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 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingRuntimeException.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingRuntimeException.java
new file mode 100644
index 0000000000..21f8bd1067
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingRuntimeException.java
@@ -0,0 +1,42 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingService.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingService.java
new file mode 100644
index 0000000000..66ef7ab879
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestBindingService.java
@@ -0,0 +1,38 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestInvoker.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestInvoker.java
new file mode 100644
index 0000000000..4a6bed766e
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestInvoker.java
@@ -0,0 +1,67 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBinding.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBinding.java
new file mode 100644
index 0000000000..edb191501e
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBinding.java
@@ -0,0 +1,45 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingBuilder.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingBuilder.java
new file mode 100644
index 0000000000..b674a518bb
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingBuilder.java
@@ -0,0 +1,55 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingLoader.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingLoader.java
new file mode 100644
index 0000000000..98393e1baa
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingLoader.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 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingReference.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingReference.java
new file mode 100644
index 0000000000..211b173d63
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingReference.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 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingService.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingService.java
new file mode 100644
index 0000000000..6710094b4a
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketBindingService.java
@@ -0,0 +1,143 @@
+/*
+ * 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/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketInvoker.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketInvoker.java
new file mode 100644
index 0000000000..154c1422a1
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/java/org/apache/tuscany/test/binding/TestSocketInvoker.java
@@ -0,0 +1,141 @@
+/*
+ * 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();
+ }
+
+}
diff --git a/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/system.scdl b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/system.scdl
new file mode 100644
index 0000000000..ab3a29364f
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/system.scdl
@@ -0,0 +1,130 @@
+<?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.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://incubator.apache.org/tuscany/xmlns/system/1.0-incubator-M2"
+ name="org.apache.tuscany.launcher.System">
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="workContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="wireService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKWireService"/>
+ </component>
+
+ <!-- Scope infrastructure -->
+ <component name="scopeRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ScopeRegistryImpl"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.module">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ModuleScopeObjectFactory"/>
+ </component>
+ <component name="scope.stateless">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeObjectFactory"/>
+ </component>
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.launcher.Loader" scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.launcher.Implementation" scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.launcher.InterfaceJava" scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.launcher.Composite" scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.launcher.SystemImplementation" scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.launcher.JavaImplementation" scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- Data Binding -->
+ <include name="org.apache.tuscany.launcher.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.test.TestBindingImplementation" scdlLocation="test.binding.system.scdl"/>
+
+ <!-- service for resolving artifacts against the user's local Maven repository -->
+ <component name="artifactRepository">
+ <system:implementation.system class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
+ <property name="repository">.m2/repository</property>
+ </component>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/test.binding.system.scdl b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/test.binding.system.scdl
new file mode 100644
index 0000000000..f59ece0b05
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/main/resources/META-INF/tuscany/test.binding.system.scdl
@@ -0,0 +1,44 @@
+<?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.
+-->
+<!--
+ JavaScript configuration for the launcher environment.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://incubator.apache.org/tuscany/xmlns/system/1.0-incubator-M2"
+
+ name="org.apache.tuscany.test.TestBindingImplementation">
+
+ <component name="BindingLoader">
+ <system:implementation.system class="org.apache.tuscany.test.binding.TestBindingLoader"/>
+ </component>
+
+ <component name="BindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.test.binding.TestBindingBuilder"/>
+ </component>
+
+ <component name="SocketBindingLoader">
+ <system:implementation.system class="org.apache.tuscany.test.binding.TestSocketBindingLoader"/>
+ </component>
+
+ <component name="SocketBindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.test.binding.TestSocketBindingBuilder"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/tags/1.0-incubator-M2/test/src/test/java/org/apache/tuscany/test/SCATestCaseTestCase.java b/sca-java-1.x/tags/1.0-incubator-M2/test/src/test/java/org/apache/tuscany/test/SCATestCaseTestCase.java
new file mode 100644
index 0000000000..fac190b02e
--- /dev/null
+++ b/sca-java-1.x/tags/1.0-incubator-M2/test/src/test/java/org/apache/tuscany/test/SCATestCaseTestCase.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 org.apache.tuscany.test;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCATestCaseTestCase extends TestCase {
+ public void testGetRoot() throws MalformedURLException {
+ URL classUrl = getClass().getResource("SCATestCaseTestCase.class");
+ URL root = SCATestCase.getRoot(getClass());
+ assertEquals(classUrl, new URL(root, "org/apache/tuscany/test/SCATestCaseTestCase.class"));
+ }
+}