summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/implementation-bsf/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/old/contrib/implementation-bsf/src/test')
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java118
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java90
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java111
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.java34
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java78
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java132
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.java35
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java106
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java46
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java78
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java27
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.componentType9
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.mock1
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType9
-rw-r--r--sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock1
15 files changed, 875 insertions, 0 deletions
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java
new file mode 100644
index 0000000000..aa86fa4d7d
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentBuilderTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.container.script;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import org.easymock.IAnswer;
+
+public class ScriptComponentBuilderTestCase extends TestCase {
+
+ public void testGetImplementationType() {
+ ScriptComponentBuilder builder = new ScriptComponentBuilder();
+ assertEquals(ScriptImplementation.class, builder.getImplementationType());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testBuild() throws Exception {
+ ScriptComponentBuilder builder = new ScriptComponentBuilder();
+ DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+ final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.COMPOSITE;
+ }
+ });
+ expect(deploymentContext.getCompositeScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return scopeContainer;
+ }
+ });
+ replay(deploymentContext);
+ ComponentDefinition<ScriptImplementation> impl =
+ new ComponentDefinition<ScriptImplementation>(new ScriptImplementation());
+ ScriptComponentType componentType = new ScriptComponentType();
+ componentType.setLifecycleScope(Scope.COMPOSITE);
+ ServiceDefinition service = new ServiceDefinition();
+ ServiceContract serviceContract = new JavaServiceContract();
+ service.setServiceContract(serviceContract);
+ componentType.add(service);
+ impl.getImplementation().setComponentType(componentType);
+
+ PropertyValue<String> pv = new PropertyValue<String>("foo", "", "");
+ ObjectFactory<String> pvFactory = (ObjectFactory<String>) createMock(ObjectFactory.class);
+ expect(pvFactory.getInstance()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return null;
+ }
+ });
+ replay(pvFactory);
+ pv.setValueFactory(pvFactory);
+ impl.add(pv);
+
+ Component component = builder.build(null, impl, deploymentContext);
+ assertNotNull(component);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testBuildCompositeScope() throws Exception {
+ ScriptComponentBuilder builder = new ScriptComponentBuilder();
+ DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+ final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.COMPOSITE;
+ }
+ });
+ expect(deploymentContext.getCompositeScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return scopeContainer;
+ }
+ });
+ replay(deploymentContext);
+ ComponentDefinition<ScriptImplementation> impl =
+ new ComponentDefinition<ScriptImplementation>(new ScriptImplementation());
+ ScriptComponentType componentType = new ScriptComponentType();
+ ServiceDefinition service = new ServiceDefinition();
+ ServiceContract serviceContract = new JavaServiceContract();
+ service.setServiceContract(serviceContract);
+ componentType.add(service);
+ impl.getImplementation().setComponentType(componentType);
+ Component component = builder.build(null, impl, deploymentContext);
+ assertNotNull(component);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java
new file mode 100644
index 0000000000..a16bcb67cb
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTestCase.java
@@ -0,0 +1,90 @@
+/*
+ * 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.container.script;
+
+import java.lang.reflect.Type;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+public class ScriptComponentTestCase extends TestCase {
+
+ private ScopeContainer container;
+
+ @SuppressWarnings("unchecked")
+ public void testCreateTargetInvoker() {
+ ComponentConfiguration config = new ComponentConfiguration();
+ config.setName("foo");
+ config.setScopeContainer(container);
+ ScriptComponent component = new ScriptComponent(config);
+ Operation<Type> operation = new Operation<Type>("hashCode", null, null, null, false, null, NO_CONVERSATION);
+ operation.setServiceContract(new Contract<Type>(List.class));
+ TargetInvoker invoker = component.createTargetInvoker("hashCode", operation, null);
+ assertNotNull(invoker);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ container = EasyMock.createMock(ScopeContainer.class);
+ EasyMock.expect(container.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(container);
+ }
+
+ private class Contract<T> extends ServiceContract<T> {
+
+ public Contract(Class interfaceClass) {
+ super(interfaceClass);
+ }
+ }
+
+// TODO commented out the following test since it doesn't test refernences.
+// TODO have a reference injeciton test in ScriptInstanceFactory that tests an actual invocation
+//
+// @SuppressWarnings("unchecked")
+// public void testCreateInstanceWithRef() throws IOException {
+// WireService wireService = createMock(WireService.class);
+// expect(wireService.createProxy(isA(Wire.class))).andStubAnswer(new IAnswer() {
+// public Object answer() throws Throwable {
+// return Scope.MODULE;
+// }
+// });
+//
+// ScriptComponent pc = new ScriptComponent(null, createBSFEasy(), new HashMap(), null, null,
+// scopeContainer, wireService, null, null);
+// OutboundWire wire = EasyMock.createMock(OutboundWire.class);
+// EasyMock.expect(wire.getReferenceName()).andReturn("foo").atLeastOnce();
+// EasyMock.replay(wire);
+// pc.addOutboundWire(wire);
+// Object o = pc.createInstance();
+// assertNotNull(o);
+// assertTrue(o instanceof ScriptInstance);
+// }
+//
+
+
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java
new file mode 100644
index 0000000000..d9fedfd316
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeLoaderTestCase.java
@@ -0,0 +1,111 @@
+/*
+ * 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.container.script;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+public class ScriptComponentTypeLoaderTestCase extends TestCase {
+
+ public void testGetSideFileName() {
+ ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader();
+ assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase.mock"));
+ }
+
+ public void testGetSideFileNameNoDot() {
+ ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader();
+ assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase"));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testLoad() throws MalformedURLException, LoaderException, XMLStreamException {
+ CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
+ DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.eq(parent),
+ EasyMock.isA(ScriptComponentType.class),
+ EasyMock.isA(URL.class),
+ EasyMock.isA(Class.class),
+ EasyMock.eq(context));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return EasyMock.getCurrentArguments()[1];
+ }
+ });
+ EasyMock.replay(registry);
+
+ ScriptImplementation implementation = new ScriptImplementation();
+ implementation.setResourceName("org/apache/tuscany/container/script/helper/foo.componentType");
+ implementation.setClassLoader(getClass().getClassLoader());
+ ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader();
+ loader.setLoaderRegistry(registry);
+ loader.load(parent, implementation, context);
+ assertNotNull(implementation.getComponentType());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testLoadMissingSideFile() throws MalformedURLException, LoaderException, XMLStreamException {
+ CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
+ DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.eq(parent),
+ EasyMock.isA(ScriptComponentType.class),
+ EasyMock.isA(URL.class),
+ EasyMock.isA(Class.class),
+ EasyMock.eq(context));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return EasyMock.getCurrentArguments()[1];
+ }
+ });
+ EasyMock.replay(registry);
+
+ ScriptImplementation implementation = new ScriptImplementation();
+ implementation.setResourceName("notthere");
+ implementation.setClassLoader(getClass().getClassLoader());
+ ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader();
+ loader.setLoaderRegistry(registry);
+ try {
+ loader.load(parent, implementation, context);
+ fail();
+ } catch (MissingSideFileException e) {
+ //expected
+ }
+ }
+
+ public void testGetImplementationClass() {
+ ScriptComponentTypeLoader loader = new ScriptComponentTypeLoader();
+ assertEquals(ScriptImplementation.class, loader.getImplementationClass());
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.java
new file mode 100644
index 0000000000..3fe6f9a47e
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptComponentTypeTestCase.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.container.script;
+
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+
+public class ScriptComponentTypeTestCase extends TestCase {
+
+ public void testLifecycleScope() {
+ ScriptComponentType ct = new ScriptComponentType();
+ assertEquals(Scope.COMPOSITE, ct.getLifecycleScope());
+ ct.setLifecycleScope(Scope.SYSTEM);
+ assertEquals(Scope.SYSTEM, ct.getLifecycleScope());
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java
new file mode 100644
index 0000000000..f30c1dca65
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderLoadingTestCase.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.container.script;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import junit.framework.TestCase;
+import static org.easymock.classextension.EasyMock.createMock;
+
+/**
+ *
+ */
+public class ScriptImplementationLoaderLoadingTestCase extends TestCase {
+
+ private LoaderRegistry registry;
+
+ private ScriptImplementationLoader loader;
+
+ public void testLoadSource() throws LoaderException {
+ String script =
+ loader.loadSource(getClass().getClassLoader(), "org/apache/tuscany/container/script/helper/foo.mock");
+ assertTrue(script.startsWith("hello"));
+ }
+
+ public void testLoadSourceMissingResource() throws LoaderException {
+ try {
+ loader.loadSource(getClass().getClassLoader(), "doesnt.exist");
+ fail();
+ } catch (MissingResourceException e) {
+ // expected
+ }
+ }
+
+ public void testGetXMLType() throws LoaderException {
+ assertEquals("http://foo", loader.getXMLType().getNamespaceURI());
+ assertEquals("bar", loader.getXMLType().getLocalPart());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ loader = new ScriptImplementationLoader(registry) {
+ public QName getXMLType() {
+ return new QName("http://foo", "bar");
+ }
+
+ public ScriptImplementation load(CompositeComponent arg0, ModelObject arg1, XMLStreamReader arg2,
+ DeploymentContext arg3) throws XMLStreamException, LoaderException {
+ return null;
+ }
+ };
+ }
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
new file mode 100644
index 0000000000..6c22bb7c99
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
@@ -0,0 +1,132 @@
+/*
+ * 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.container.script;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+
+/**
+ *
+ */
+public class ScriptImplementationLoaderTestCase extends TestCase {
+ private CompositeComponent parent;
+
+ private XMLStreamReader reader;
+
+ private DeploymentContext deploymentContext;
+
+ private ClassLoader classLoader;
+
+ private LoaderRegistry registry;
+
+ private ScriptImplementationLoader loader;
+
+ public void testLoadNoScriptAttribute() throws LoaderException, XMLStreamException {
+ expect(reader.getAttributeValue(null, "script")).andReturn(null);
+ replay(reader);
+ replay(deploymentContext);
+
+ try {
+ loader.load(parent, null, reader, deploymentContext);
+ fail();
+ } catch (MissingResourceException e) {
+ // ok
+ }
+ verify(reader);
+ verify(deploymentContext);
+ }
+
+ public void testLoad() throws LoaderException, XMLStreamException {
+ expect(reader.getAttributeValue(null, "script")).andReturn("foo.mock");
+ expect(reader.getAttributeValue(null, "class")).andReturn(null);
+ expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ expect(deploymentContext.getClassLoader()).andReturn(classLoader);
+
+ replay(reader);
+ replay(deploymentContext);
+
+ ScriptImplementationLoader mockLoader = new ScriptImplementationLoader(registry) {
+ protected String loadSource(ClassLoader cl, String resource) throws LoaderException {
+ assertSame(classLoader, cl);
+ assertEquals("foo.mock", resource);
+ return "bar";
+ }
+ };
+ mockLoader.load(parent, null, reader, deploymentContext);
+ verify(reader);
+ verify(deploymentContext);
+ }
+
+ public void testLoadNoScriptPresent() throws LoaderException, XMLStreamException {
+ expect(reader.getAttributeValue(null, "script")).andReturn("foo.py");
+ expect(reader.getAttributeValue(null, "class")).andReturn(null);
+ expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ expect(deploymentContext.getClassLoader()).andReturn(classLoader);
+
+ replay(reader);
+ replay(deploymentContext);
+
+ ScriptImplementationLoader mockLoader = new ScriptImplementationLoader(registry) {
+ protected String loadSource(ClassLoader cl, String resource) throws LoaderException {
+ assertSame(classLoader, cl);
+ assertEquals("foo.py", resource);
+ throw new MissingResourceException(resource);
+ }
+ };
+ try {
+ mockLoader.load(parent, null, reader, deploymentContext);
+ fail();
+ } catch (MissingResourceException e) {
+ assertEquals("foo.py", e.getMessage());
+ }
+ verify(reader);
+ verify(deploymentContext);
+ }
+
+ public void testGetXMLType() throws LoaderException {
+ assertEquals(XML_NAMESPACE_1_0, loader.getXMLType().getNamespaceURI());
+ assertEquals("implementation.script", loader.getXMLType().getLocalPart());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ loader = new ScriptImplementationLoader(registry);
+
+ parent = createMock(CompositeComponent.class);
+ reader = createMock(XMLStreamReader.class);
+ deploymentContext = createMock(DeploymentContext.class);
+ classLoader = createMock(ClassLoader.class);
+ }
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.java
new file mode 100644
index 0000000000..11a99b5854
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptImplementationTestCase.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.container.script;
+
+import junit.framework.TestCase;
+
+public class ScriptImplementationTestCase extends TestCase {
+
+ public void testGetResourceName() {
+ ScriptImplementation impl = new ScriptImplementation();
+ impl.setResourceName("foo");
+ assertEquals("foo", impl.getResourceName());
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
new file mode 100644
index 0000000000..554b6de6ad
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
@@ -0,0 +1,106 @@
+/*
+ * 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.container.script;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Map;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+import junit.framework.TestCase;
+import org.apache.bsf.BSFManager;
+import org.apache.tuscany.container.script.mock.MockBSFEngine;
+
+public class ScriptInstanceFactoryTestCase extends TestCase {
+
+ public void testCreateInstance() throws InvocationTargetException {
+ BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]{"mock"});
+ ScriptInstanceFactory factory =
+ new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader());
+ factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar"));
+ ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance();
+ assertNotNull(instance);
+ assertNotNull(instance.bsfEngine);
+ }
+
+ public void testCreateInstanceNoClass() throws InvocationTargetException {
+ BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]{"mock"});
+ ScriptInstanceFactory factory =
+ new ScriptInstanceFactory("foo.mock", null, "baz", getClass().getClassLoader());
+ factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar"));
+ ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance();
+ assertNotNull(instance);
+ assertNotNull(instance.bsfEngine);
+ }
+
+ public void testCreateInstanceRuby() throws InvocationTargetException {
+ BSFManager.registerScriptingEngine("ruby", MockBSFEngine.class.getName(), new String[]{"mock"});
+ ScriptInstanceFactory factory =
+ new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader());
+ factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar"));
+ ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance();
+ assertNotNull(instance);
+ assertNotNull(instance.bsfEngine);
+ }
+
+ public void testBadCreateInstance() throws InvocationTargetException {
+ ScriptInstanceFactory factory =
+ new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader());
+ try {
+ factory.getInstance();
+ fail();
+ } catch (ObjectCreationException e) {
+ // expected
+ }
+ }
+
+ public void testGetters() throws InvocationTargetException {
+ ScriptInstanceFactory factory =
+ new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader());
+ assertEquals(getClass().getClassLoader(), factory.getClassLoader());
+ }
+
+
+ public void testGetResponseClasses() {
+ ScriptInstanceFactory factory =
+ new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader());
+ Map<String, Class> classes = factory.getResponseClasses(Arrays.asList(new Class[]{Runnable.class}));
+ assertEquals(1, classes.size());
+ assertEquals("run", classes.keySet().iterator().next());
+ assertEquals(void.class, classes.get("run"));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private class SingletonObjectFactory implements ObjectFactory<Object> {
+ private Object instance;
+
+ public SingletonObjectFactory(Object instance) {
+ this.instance = instance;
+ }
+
+ public Object getInstance() throws ObjectCreationException {
+ return instance;
+ }
+ }
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java
new file mode 100644
index 0000000000..0f5f646cb5
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceImplTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.container.script;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.container.script.mock.MockBSFEngine;
+
+public class ScriptInstanceImplTestCase extends TestCase {
+ private ScriptInstanceImpl instance;
+
+ public void testInvokeTarget() throws InvocationTargetException {
+ assertEquals("hello:", instance.invokeTarget("hello", null));
+ }
+
+ public void testInvokeTargetException() throws InvocationTargetException {
+ try {
+ instance.invokeTarget("bang", null);
+ fail();
+ } catch (InvocationTargetException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.instance = new ScriptInstanceImpl(new MockBSFEngine(), null);
+ }
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java
new file mode 100644
index 0000000000..5597d37e60
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/ScriptInvokerTestCase.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.container.script;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+
+public class ScriptInvokerTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testInvokeTarget() throws Exception {
+ ScriptInstance instance = EasyMock.createMock(ScriptInstance.class);
+ instance.invokeTarget(EasyMock.eq("operation"), (Object[]) EasyMock.notNull());
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ assertEquals(2, EasyMock.getCurrentArguments().length);
+ assertEquals("operation", EasyMock.getCurrentArguments()[0]);
+ return "hello";
+ }
+ });
+
+ EasyMock.replay(instance);
+ ScriptComponent component = EasyMock.createMock(ScriptComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(instance);
+ EasyMock.replay(component);
+ ScriptTargetInvoker invoker = new ScriptTargetInvoker("operation", component);
+ assertEquals("hello", invoker.invokeTarget(new Object[]{"petra"}, TargetInvoker.NONE));
+ EasyMock.verify(instance);
+ EasyMock.verify(component);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testInvokeTargetException() throws Exception {
+ ScriptInstance instance = EasyMock.createMock(ScriptInstance.class);
+ instance.invokeTarget(EasyMock.eq("operation"), (Object[]) EasyMock.notNull());
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ throw new RuntimeException();
+ }
+ });
+
+ EasyMock.replay(instance);
+ ScriptComponent component = EasyMock.createMock(ScriptComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(instance);
+ EasyMock.replay(component);
+ ScriptTargetInvoker invoker = new ScriptTargetInvoker("operation", component);
+ try {
+ invoker.invokeTarget(new Object[]{"petra"}, TargetInvoker.NONE);
+ fail();
+ } catch (InvocationTargetException e) {
+ // expected
+ }
+ EasyMock.verify(instance);
+ EasyMock.verify(component);
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
new file mode 100644
index 0000000000..1ae65737f9
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
@@ -0,0 +1,27 @@
+package org.apache.tuscany.container.script.mock;
+
+import org.apache.bsf.BSFException;
+import org.apache.bsf.util.BSFEngineImpl;
+
+public class MockBSFEngine extends BSFEngineImpl {
+
+ public Object call(Object object, String name, Object[] args) throws BSFException {
+ if ("bang".equals(name)) {
+ throw new RuntimeException(name);
+ }
+
+ String resp = name + ":";
+ if (args != null) {
+ for (Object o : args) {
+ resp += " " + String.valueOf(o);
+ }
+ }
+ return resp;
+ }
+
+ public Object eval(String source, int lineNo, int columnNo, Object expr) throws BSFException {
+ // not used for the mock tests
+ return null;
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.componentType b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.componentType
new file mode 100644
index 0000000000..9c37e1cb3e
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.componentType
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <service name="HelloWorldService">
+ <interface.java interface="not.used"/>
+ </service>
+
+</componentType>
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.mock b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.mock
new file mode 100644
index 0000000000..b6fc4c620b
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/foo.mock
@@ -0,0 +1 @@
+hello \ No newline at end of file
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType
new file mode 100644
index 0000000000..9c37e1cb3e
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <service name="HelloWorldService">
+ <interface.java interface="not.used"/>
+ </service>
+
+</componentType>
diff --git a/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock
new file mode 100644
index 0000000000..b6fc4c620b
--- /dev/null
+++ b/sandbox/old/contrib/implementation-bsf/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock
@@ -0,0 +1 @@
+hello \ No newline at end of file