summaryrefslogtreecommitdiffstats
path: root/sandbox/ant/container.script/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/ant/container.script/src/test')
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java132
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java69
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java30
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java211
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentBuilderTestCase.java107
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTestCase.java145
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeLoaderTestCase.java144
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeTestCase.java37
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationLoaderTestCase.java78
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationTestCase.java30
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInstanceFactoryTestCase.java56
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInvokerTestCase.java64
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/AsyncTarget.java26
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/MockInstanceFactory.java30
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/jsr223/JSR223BSFEngineTestCase.java45
-rw-r--r--sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java27
-rw-r--r--sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType9
-rw-r--r--sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock1
-rw-r--r--sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType9
-rw-r--r--sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock1
20 files changed, 1251 insertions, 0 deletions
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptImplementationLoaderTestCase.java
new file mode 100644
index 0000000000..6db6cf1200
--- /dev/null
+++ b/sandbox/ant/container.script/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/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
new file mode 100644
index 0000000000..2e72de6074
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
@@ -0,0 +1,69 @@
+package org.apache.tuscany.container.script;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.bsf.BSFManager;
+import org.apache.tuscany.container.script.mock.MockBSFEngine;
+import org.apache.tuscany.spi.ObjectCreationException;
+
+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());
+ Map<String, Object> context = new HashMap<String, Object>();
+ context.put("foo", "bar");
+ ScriptInstance instance = factory.createInstance(null, context);
+ assertNotNull(instance);
+ assertNotNull(instance.bsfEngine);
+// assertNotNull(instance.clazz);
+ }
+
+ public void testCreateInstanceNoClass() throws InvocationTargetException {
+ BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[] {"mock"});
+ ScriptInstanceFactory factory = new ScriptInstanceFactory("foo.mock", null, "baz", getClass().getClassLoader());
+ Map<String, Object> context = new HashMap<String, Object>();
+ context.put("foo", "bar");
+ ScriptInstance instance = factory.createInstance(null, context);
+ 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());
+ Map<String, Object> context = new HashMap<String, Object>();
+ context.put("foo", "bar");
+ ScriptInstance instance = factory.createInstance(null, context);
+ assertNotNull(instance);
+ assertNotNull(instance.bsfEngine);
+// assertNotNull(instance.clazz);
+ }
+
+ public void testBadCreateInstance() throws InvocationTargetException {
+ ScriptInstanceFactory factory = new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader());
+ Map<String, Object> context = new HashMap<String, Object>();
+ try {
+ factory.createInstance(null, context);
+ fail();
+ } catch (ObjectCreationException e) {
+ // expected
+ }
+ }
+
+ public void testGetters() throws InvocationTargetException {
+ ScriptInstanceFactory factory = new ScriptInstanceFactory("foo", "bar", "baz", getClass().getClassLoader());
+// assertEquals("foo", factory.getScriptName());
+// assertEquals("bar", factory.getClassName());
+// assertEquals("baz", factory.getScriptSource());
+ assertEquals(getClass().getClassLoader(), factory.getClassLoader());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
new file mode 100644
index 0000000000..9784721b83
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/ScriptInstanceTestCase.java
@@ -0,0 +1,30 @@
+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 ScriptInstanceTestCase extends TestCase {
+
+ private ScriptInstance 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 ScriptInstance(new MockBSFEngine(), null);
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java
new file mode 100644
index 0000000000..9c99cf306f
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/AsyncInvokerTestCase.java
@@ -0,0 +1,211 @@
+/*
+ * 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.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.AsyncInvoker;
+import org.apache.tuscany.container.script.helper.AsyncMonitor;
+import org.apache.tuscany.container.script.helper.ScriptHelperComponent;
+import org.apache.tuscany.container.script.helper.ScriptHelperInstance;
+import org.apache.tuscany.container.script.helper.AsyncInvoker.ContextBinder;
+import org.apache.tuscany.container.script.helper.AsyncInvoker.ImmutableMessage;
+import org.apache.tuscany.container.script.helper.mock.AsyncTarget;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+
+/**
+ */
+public class AsyncInvokerTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testInvoke() throws Exception {
+ ScriptHelperInstance instance = createMock(ScriptHelperInstance.class);
+ expect(instance.invokeTarget("invoke", null)).andReturn(null).once();
+ replay(instance);
+ ScriptHelperComponent component = EasyMock.createMock(ScriptHelperComponent.class);
+ expect(component.getTargetInstance()).andReturn(instance);
+ EasyMock.replay(component);
+ AsyncMonitor monitor = createMock(AsyncMonitor.class);
+ replay(monitor);
+
+ WorkScheduler scheduler = createMock(WorkScheduler.class);
+ scheduler.scheduleWork(isA(Runnable.class));
+ expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ runnable.run();
+ return null;
+ }
+ });
+ replay(scheduler);
+ WorkContext context = createMock(WorkContext.class);
+ Method method = AsyncTarget.class.getMethod("invoke");
+ method.setAccessible(true);
+ InboundWire wire = createMock(InboundWire.class);
+ AsyncInvoker invoker = new AsyncInvoker("invoke", wire, component, scheduler, monitor, context);
+ Message msg = new MessageImpl();
+ invoker.invoke(msg);
+ verify(instance);
+ }
+
+ public void testClone() {
+ AsyncInvoker invoker = new AsyncInvoker(null, null, null,null,null,null);
+ assertNotNull(invoker.clone());
+ }
+
+ public void testGetInstance() {
+ ScriptHelperComponent component = EasyMock.createMock(ScriptHelperComponent.class);
+ expect(component.getTargetInstance()).andReturn("petra");
+ EasyMock.replay(component);
+ AsyncInvoker invoker = new AsyncInvoker(null, null, component,null,null,null);
+ assertEquals("petra", invoker.getInstance());
+ }
+
+ public void testGetInstanceCacheable() {
+ ScriptHelperComponent component = EasyMock.createMock(ScriptHelperComponent.class);
+ expect(component.getTargetInstance()).andReturn("petra");
+ EasyMock.replay(component);
+ AsyncInvoker invoker = new AsyncInvoker(null, null, component,null,null,null);
+ invoker.setCacheable(true);
+ assertEquals("petra", invoker.getInstance());
+ }
+
+ public void testGetBody() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ assertNull(message.getBody());
+ }
+
+ public void testSetBody() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ try {
+ message.setBody(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testGetTargetInvoker() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ assertNull(message.getTargetInvoker());
+ }
+
+ public void testSetTargetInvoker() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ try {
+ message.setTargetInvoker(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testGetFromAddress() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ assertNull(message.getFromAddress());
+ }
+
+ public void testSetFromAddress() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ try {
+ message.setFromAddress(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testGetMessageId() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ assertNull(message.getMessageId());
+ }
+
+ public void testSetMessageId() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ try {
+ message.setMessageId(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testGetCorrelationId() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ assertNull(message.getCorrelationId());
+ }
+
+ public void testSetCorrelationId() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ try {
+ message.setCorrelationId(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testIsFault() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ assertFalse(message.isFault());
+ }
+
+ public void testSetBodyWithFault() {
+ ImmutableMessage message = new AsyncInvoker.ImmutableMessage();
+ try {
+ message.setBodyWithFault(null);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testContextBinder() {
+ ContextBinder contextBinder = new AsyncInvoker.ContextBinder();
+ contextBinder.setContext(null);
+ try {
+ contextBinder.start();
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ try {
+ contextBinder.stop();
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentBuilderTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentBuilderTestCase.java
new file mode 100644
index 0000000000..5b93df3d76
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentBuilderTestCase.java
@@ -0,0 +1,107 @@
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperComponentBuilder;
+import org.apache.tuscany.container.script.helper.ScriptHelperComponentType;
+import org.apache.tuscany.container.script.helper.ScriptHelperImplementation;
+import org.apache.tuscany.core.component.scope.ModuleScopeObjectFactory;
+import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+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.component.ScopeRegistry;
+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 org.easymock.IAnswer;
+
+public class ScriptHelperComponentBuilderTestCase extends TestCase {
+
+ public void testGetImplementationType() {
+ ScriptHelperComponentBuilder builder = new ScriptHelperComponentBuilder();
+ assertEquals(ScriptHelperImplementation.class, builder.getImplementationType());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testBuild() {
+ ScriptHelperComponentBuilder builder = new ScriptHelperComponentBuilder();
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ scopeRegistry.registerFactory(Scope.COMPOSITE, new ModuleScopeObjectFactory(scopeRegistry));
+ builder.setScopeRegistry(scopeRegistry);
+ 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.getModuleScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return scopeContainer;
+ }
+ });
+ replay(deploymentContext);
+ ComponentDefinition<ScriptHelperImplementation> impl = new ComponentDefinition<ScriptHelperImplementation>(new ScriptHelperImplementation());
+ ScriptHelperComponentType componentType = new ScriptHelperComponentType();
+ componentType.setLifecycleScope(Scope.COMPOSITE);
+ ServiceDefinition service = new ServiceDefinition();
+ ServiceContract serviceContract = new JavaServiceContract();
+ service.setServiceContract(serviceContract);
+ componentType.add(service);
+ impl.getImplementation().setComponentType(componentType);
+
+ PropertyValue pv = new PropertyValue("foo", "", "");
+ ObjectFactory pvFactory = 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 testBuildModuleScope() {
+ ScriptHelperComponentBuilder builder = new ScriptHelperComponentBuilder();
+ DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+ final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+ expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return scopeContainer;
+ }
+ });
+ replay(deploymentContext);
+ ComponentDefinition<ScriptHelperImplementation> impl = new ComponentDefinition<ScriptHelperImplementation>(new ScriptHelperImplementation());
+ ScriptHelperComponentType componentType = new ScriptHelperComponentType();
+ 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/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTestCase.java
new file mode 100644
index 0000000000..a1e300051d
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTestCase.java
@@ -0,0 +1,145 @@
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperComponent;
+import org.apache.tuscany.container.script.helper.ScriptHelperInstance;
+import org.apache.tuscany.container.script.helper.ScriptHelperInstanceFactory;
+import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory;
+import org.apache.tuscany.core.wire.InboundWireImpl;
+import org.apache.tuscany.core.wire.OutboundWireImpl;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.RuntimeWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireService;
+import org.easymock.IAnswer;
+
+public class ScriptHelperComponentTestCase extends TestCase {
+
+ private ScopeContainer scopeContainer;
+
+ @SuppressWarnings("unchecked")
+ public void testCreateTargetInvoker() {
+ ScriptHelperComponent component = new ScriptHelperComponent(null,null, null, null, null, scopeContainer, null, null, null);
+
+ Operation operation = new Operation("hashCode", null,null,null,false,null);
+ ServiceContract contract = new ServiceContract(List.class){};
+ operation.setServiceContract(contract);
+ TargetInvoker invoker = component.createTargetInvoker("hashCode", operation);
+
+ assertNotNull(invoker);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testCreateInstance() throws IOException {
+ ScriptHelperComponent pc = new ScriptHelperComponent(null,createBSFEasy(), new HashMap(), null, null, scopeContainer, null, null, null);
+ Object o = pc.createInstance();
+ assertNotNull(o);
+ assertTrue(o instanceof ScriptHelperInstance);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testCreateInstanceWithRef() throws IOException {
+ WireService wireService = createMock(WireService.class);
+ expect(wireService.createProxy(isA(RuntimeWire.class))).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+
+ ScriptHelperComponent pc = new ScriptHelperComponent(null,createBSFEasy(), new HashMap(), null, null, scopeContainer, wireService, null, null);
+ OutboundWire wire = new OutboundWireImpl();
+ wire.setReferenceName("foo");
+ pc.addOutboundWire(wire);
+ Object o = pc.createInstance();
+ assertNotNull(o);
+ assertTrue(o instanceof ScriptHelperInstance);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetServiceInstance() {
+ WireService wireService = createMock(WireService.class);
+ expect(wireService.createProxy(isA(RuntimeWire.class))).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return "foo";
+ }
+ });
+ replay(wireService);
+ ScriptHelperComponent pc = new ScriptHelperComponent(null,null, null, null, null, scopeContainer, wireService, null, null);
+ InboundWire wire = new InboundWireImpl();
+ pc.addInboundWire(wire);
+ assertEquals("foo", pc.getServiceInstance());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetServiceInstanceFail() {
+ ScriptHelperComponent pc = new ScriptHelperComponent(null,null, null, null, null, scopeContainer, null, null, null);
+ try {
+ pc.getServiceInstance();
+ fail();
+ } catch (TargetException e) {
+ // expected
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetproperties() {
+ ScriptHelperComponent pc = new ScriptHelperComponent(null,null, new HashMap(), null, null, scopeContainer, null, null, null);
+ assertNotNull(pc.getProperties());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetServiceInterfaces() {
+ List services = new ArrayList();
+ ScriptHelperComponent pc = new ScriptHelperComponent(null,null,null, services, null, scopeContainer, null, null, null);
+ assertEquals(services, pc.getServiceInterfaces());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testCreateAsyncTargetInvoker() {
+ ScriptHelperComponent pc = new ScriptHelperComponent(null,null,null, new ArrayList<Class<?>>(), null, scopeContainer, null, null, null);
+ assertNotNull(pc.createAsyncTargetInvoker(null, new Operation("foo", null,null,null)));
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+ }
+
+ public ScriptHelperInstanceFactory createBSFEasy() throws IOException {
+// URL scriptURL = getClass().getResource("foo.mock");
+// InputStream is = scriptURL.openStream();
+// StringBuilder sb = new StringBuilder();
+// int i = 0;
+// while ((i = is.read()) != -1) {
+// sb.append((char) i);
+// }
+// is.close();
+// String script = sb.toString();
+ MockInstanceFactory bsfEasy = new MockInstanceFactory("foo.mock", null);
+ return bsfEasy;
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeLoaderTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeLoaderTestCase.java
new file mode 100644
index 0000000000..4686d1b9f1
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeLoaderTestCase.java
@@ -0,0 +1,144 @@
+/*
+ * 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.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperComponentTypeLoader;
+import org.apache.tuscany.container.script.helper.ScriptHelperImplementation;
+import org.apache.tuscany.container.script.helper.ScriptHelperInstanceFactory;
+import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory;
+import org.apache.tuscany.core.loader.LoaderRegistryImpl;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+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.model.ComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Scope;
+import org.easymock.IAnswer;
+
+/**
+ *
+ */
+public class ScriptHelperComponentTypeLoaderTestCase extends TestCase {
+
+ public void testGetSideFileName() {
+ ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader();
+ assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase.mock"));
+ }
+
+ public void testGetSideFileNameNoDot() {
+ ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader();
+ assertEquals("BSFEasyTestCase.componentType", loader.getSideFileName("BSFEasyTestCase"));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testLoadFromSideFile() throws MalformedURLException, LoaderException, XMLStreamException {
+ ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader();
+ LoaderRegistry loaderRegistry = new LoaderRegistryImpl() {
+ public <MO extends ModelObject> MO load(CompositeComponent parent, ModelObject mo, URL url, Class<MO> type, DeploymentContext ctx) throws LoaderException {
+ return (MO) new ComponentType();
+ }
+ };
+ loader.setLoaderRegistry(loaderRegistry);
+ loader.loadFromSidefile(null, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testLoad() throws LoaderException {
+ ScriptHelperInstanceFactory bsfEasy = new MockInstanceFactory("org/apache/tuscany/container/script/helper/foo.mock", getClass().getClassLoader());
+ ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader();
+ LoaderRegistry loaderRegistry = new LoaderRegistryImpl() {
+ public <MO extends ModelObject> MO load(CompositeComponent parent,
+ ModelObject mo,
+ URL url,
+ Class<MO> type,
+ DeploymentContext ctx) throws LoaderException {
+ return (MO) new ComponentType();
+ }
+ };
+ loader.setLoaderRegistry(loaderRegistry);
+ ScriptHelperImplementation implementation = new ScriptHelperImplementation();
+ implementation.setResourceName("org/apache/tuscany/container/script/helper/foo.mock");
+ implementation.setScriptInstanceFactory(bsfEasy);
+ DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+ final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+ expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return scopeContainer;
+ }
+ });
+ replay(deploymentContext);
+ loader.load(null, implementation, deploymentContext);
+ assertNotNull(implementation.getComponentType());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testLoadMissingSideFile() throws LoaderException {
+ ScriptHelperInstanceFactory bsfEasy = new MockInstanceFactory("org/apche/tuscany/container/script/helper/foo.mock", getClass().getClassLoader());
+ ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader();
+ ScriptHelperImplementation implementation = new ScriptHelperImplementation();
+ implementation.setResourceName("org/apache/tuscany/container/script/helper/doesntExist");
+ implementation.setScriptInstanceFactory(bsfEasy);
+ DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+ final ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+ expect(deploymentContext.getModuleScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return scopeContainer;
+ }
+ });
+ replay(deploymentContext);
+ try {
+ loader.load(null, implementation, deploymentContext);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testGetImplementationClass() {
+ ScriptHelperComponentTypeLoader loader = new ScriptHelperComponentTypeLoader();
+ assertEquals(ScriptHelperImplementation.class, loader.getImplementationClass());
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeTestCase.java
new file mode 100644
index 0000000000..dd29f85e44
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperComponentTypeTestCase.java
@@ -0,0 +1,37 @@
+package org.apache.tuscany.container.script.helper;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperComponentType;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+public class ScriptHelperComponentTypeTestCase extends TestCase {
+
+ public void testLifecycleScope() {
+ ScriptHelperComponentType ct = new ScriptHelperComponentType();
+ assertEquals(Scope.MODULE, ct.getLifecycleScope());
+ ct.setLifecycleScope(Scope.COMPOSITE);
+ assertEquals(Scope.COMPOSITE, ct.getLifecycleScope());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testComponentTypeConstructor() {
+ ComponentType ct = new ComponentType();
+ Property property = new Property();
+ ct.add(property);
+ ReferenceDefinition reference = new ReferenceDefinition();
+ ct.add(reference);
+ ServiceDefinition service = new ServiceDefinition();
+ ct.add(service);
+
+ ScriptHelperComponentType pct = new ScriptHelperComponentType(ct);
+
+ assertEquals(property, pct.getProperties().values().iterator().next());
+ assertEquals(reference, pct.getReferences().values().iterator().next());
+ assertEquals(service, pct.getServices().values().iterator().next());
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationLoaderTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationLoaderTestCase.java
new file mode 100644
index 0000000000..be3d4de909
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationLoaderTestCase.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.helper;
+
+import static org.easymock.classextension.EasyMock.createMock;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperImplementation;
+import org.apache.tuscany.container.script.helper.ScriptHelperImplementationLoader;
+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;
+
+/**
+ *
+ */
+public class ScriptHelperImplementationLoaderTestCase extends TestCase {
+
+ private LoaderRegistry registry;
+
+ private ScriptHelperImplementationLoader 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 ScriptHelperImplementationLoader(registry){
+ public QName getXMLType() {
+ return new QName("http://foo", "bar");
+ }
+// @Override
+ public ScriptHelperImplementation load(CompositeComponent arg0, ModelObject arg1, XMLStreamReader arg2, DeploymentContext arg3) throws XMLStreamException, LoaderException {
+ return null;
+ }};
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationTestCase.java
new file mode 100644
index 0000000000..f906c701f3
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperImplementationTestCase.java
@@ -0,0 +1,30 @@
+package org.apache.tuscany.container.script.helper;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperImplementation;
+import org.apache.tuscany.container.script.helper.ScriptHelperInstanceFactory;
+import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory;
+
+public class ScriptHelperImplementationTestCase extends TestCase {
+
+ private ScriptHelperInstanceFactory bsfEasy;
+
+ public void testGetBSFEasy() {
+ ScriptHelperImplementation impl = new ScriptHelperImplementation();
+ impl.setScriptInstanceFactory(bsfEasy);
+ assertEquals(bsfEasy, impl.getScriptInstanceFactory());
+ }
+
+ public void testGetResourceName() {
+ ScriptHelperImplementation impl = new ScriptHelperImplementation();
+ impl.setResourceName("foo");
+ assertEquals("foo", impl.getResourceName());
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ bsfEasy = new MockInstanceFactory("BSFEasyTestCase", null);
+ }
+
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInstanceFactoryTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInstanceFactoryTestCase.java
new file mode 100644
index 0000000000..132ea2bdfc
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInstanceFactoryTestCase.java
@@ -0,0 +1,56 @@
+package org.apache.tuscany.container.script.helper;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperInstance;
+import org.apache.tuscany.container.script.helper.mock.MockInstanceFactory;
+
+public class ScriptHelperInstanceFactoryTestCase extends TestCase {
+
+ public void testCreateInstance() throws InvocationTargetException {
+ MockInstanceFactory factory = new MockInstanceFactory("foo.mock", getClass().getClassLoader());
+ Map<String, Object> context = new HashMap<String, Object>();
+ context.put("foo", "bar");
+ ScriptHelperInstance instance = factory.createInstance(null, context);
+ assertNotNull(instance);
+ }
+
+ public void testCreateInstanceNoClass() throws InvocationTargetException {
+ MockInstanceFactory factory = new MockInstanceFactory("foo.mock", getClass().getClassLoader());
+ Map<String, Object> context = new HashMap<String, Object>();
+ context.put("foo", "bar");
+ ScriptHelperInstance instance = factory.createInstance(null, context);
+ assertNotNull(instance);
+ }
+
+ public void testCreateInstanceRuby() throws InvocationTargetException {
+ MockInstanceFactory factory = new MockInstanceFactory("foo.mock", getClass().getClassLoader());
+ Map<String, Object> context = new HashMap<String, Object>();
+ context.put("foo", "bar");
+ ScriptHelperInstance instance = factory.createInstance(null, context);
+ assertNotNull(instance);
+ }
+
+ public void testGetters() throws InvocationTargetException {
+ MockInstanceFactory factory = new MockInstanceFactory("foo", getClass().getClassLoader());
+ assertEquals("foo", factory.getResourceName());
+ assertEquals(getClass().getClassLoader(), factory.getClassLoader());
+ }
+
+ public void testGetResponseClasses() {
+ MockInstanceFactory factory = new MockInstanceFactory("foo", 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();
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInvokerTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInvokerTestCase.java
new file mode 100644
index 0000000000..6a40eae163
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/ScriptHelperInvokerTestCase.java
@@ -0,0 +1,64 @@
+package org.apache.tuscany.container.script.helper;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperComponent;
+import org.apache.tuscany.container.script.helper.ScriptHelperInstance;
+import org.apache.tuscany.container.script.helper.ScriptHelperInvoker;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.model.Scope;
+import org.easymock.IAnswer;
+
+public class ScriptHelperInvokerTestCase extends TestCase {
+
+ private ScriptHelperComponent component;
+
+ public void testInvokeTarget() throws InvocationTargetException {
+ ScriptHelperInvoker invoker = new ScriptHelperInvoker("hello", component);
+ assertEquals("hello petra", invoker.invokeTarget(null));
+ }
+
+ public void testInvokeTargetException() throws InvocationTargetException, SecurityException, NoSuchMethodException {
+ ScriptHelperInvoker badInvoker = new ScriptHelperInvoker("bang", component);
+ try {
+ badInvoker.invokeTarget(null);
+ fail();
+ } catch (InvocationTargetException e) {
+ // expected
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ ScopeContainer scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+ expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return new ScriptHelperInstance(){
+ public Object invokeTarget(String operationName, Object[] args) throws InvocationTargetException {
+ if ("bang".equals(operationName)) {
+ throw new RuntimeException("bang");
+ }
+ return "hello petra";
+ }};
+ }
+ });
+ replay(scopeContainer);
+
+ this.component = new ScriptHelperComponent(null, null, null, null, null, scopeContainer, null, null, null);
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/AsyncTarget.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/AsyncTarget.java
new file mode 100644
index 0000000000..8961f882f1
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/AsyncTarget.java
@@ -0,0 +1,26 @@
+/*
+ * 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.helper.mock;
+
+/**
+ */
+public interface AsyncTarget {
+
+ void invoke();
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/MockInstanceFactory.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/MockInstanceFactory.java
new file mode 100644
index 0000000000..6f90913938
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/helper/mock/MockInstanceFactory.java
@@ -0,0 +1,30 @@
+package org.apache.tuscany.container.script.helper.mock;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.container.script.helper.ScriptHelperInstance;
+import org.apache.tuscany.container.script.helper.ScriptHelperInstanceFactory;
+
+public class MockInstanceFactory extends ScriptHelperInstanceFactory<MockInstance> {
+
+ public MockInstanceFactory(String scriptName, ClassLoader classLoader) {
+ super(scriptName, classLoader);
+ }
+
+ @Override
+ public MockInstance createInstance(List<Class> services, Map<String, Object> context) {
+ return new MockInstance();
+ }
+
+}
+
+class MockInstance implements ScriptHelperInstance {
+
+ public Object invokeTarget(String operationName, Object[] args) throws InvocationTargetException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/jsr223/JSR223BSFEngineTestCase.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/jsr223/JSR223BSFEngineTestCase.java
new file mode 100644
index 0000000000..a9cc459627
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/jsr223/JSR223BSFEngineTestCase.java
@@ -0,0 +1,45 @@
+package org.apache.tuscany.container.script.jsr223;
+
+import junit.framework.TestCase;
+
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFException;
+import org.apache.bsf.BSFManager;
+import org.mozilla.javascript.EcmaError;
+
+public class JSR223BSFEngineTestCase extends TestCase {
+
+ public void testRegisterAllJSR223Engines() throws BSFException {
+ JSR223BSFEngine.registerAllJSR223Engines();
+ BSFEngine engine = new BSFManager().loadScriptingEngine("rhino");
+ assertTrue(engine instanceof JSR223BSFEngine);
+ }
+
+ public void testDeclareBean() throws BSFException {
+ JSR223BSFEngine.registerAllJSR223Engines();
+ BSFManager manager = new BSFManager();
+ manager.declareBean("foo", "foo", String.class);
+ BSFEngine engine = manager.loadScriptingEngine("rhino");
+ assertEquals("foo", engine.eval("testDeclareBean", 0, 0, "foo"));
+ manager.undeclareBean("foo");
+ try {
+ engine.eval("testDeclareBean", 0, 0, "foo");
+ fail();
+ } catch (EcmaError e) {
+ //expected
+ }
+ }
+
+ public void testEval() throws BSFException {
+ JSR223BSFEngine.registerAllJSR223Engines();
+ BSFEngine engine = new BSFManager().loadScriptingEngine("rhino");
+ assertEquals(true, engine.eval("testDeclareBean", 0, 0, "true"));
+ }
+
+ public void testCall() throws BSFException {
+ JSR223BSFEngine.registerAllJSR223Engines();
+ BSFEngine engine = new BSFManager().loadScriptingEngine("rhino");
+ engine.eval("testDeclareBean", 0, 0, "function foo() { return true;}");
+ assertEquals(true, engine.call(null, "foo", new Object[]{}));
+ }
+}
diff --git a/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java b/sandbox/ant/container.script/src/test/java/org/apache/tuscany/container/script/mock/MockBSFEngine.java
new file mode 100644
index 0000000000..7c2434ea13
--- /dev/null
+++ b/sandbox/ant/container.script/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/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType b/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.componentType
new file mode 100644
index 0000000000..9c37e1cb3e
--- /dev/null
+++ b/sandbox/ant/container.script/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/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock b/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock
new file mode 100644
index 0000000000..b6fc4c620b
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/foo.mock
@@ -0,0 +1 @@
+hello \ No newline at end of file
diff --git a/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType b/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.componentType
new file mode 100644
index 0000000000..9c37e1cb3e
--- /dev/null
+++ b/sandbox/ant/container.script/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/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock b/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock
new file mode 100644
index 0000000000..b6fc4c620b
--- /dev/null
+++ b/sandbox/ant/container.script/src/test/resources/org/apache/tuscany/container/script/helper/foo.mock
@@ -0,0 +1 @@
+hello \ No newline at end of file