summaryrefslogtreecommitdiffstats
path: root/sandbox/ant/tuscany-container-rhino/src/test/java/org
diff options
context:
space:
mode:
authordims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
committerdims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
commitbdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch)
tree38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/ant/tuscany-container-rhino/src/test/java/org
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/ant/tuscany-container-rhino/src/test/java/org')
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilderTestCase.java121
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XInterceptorTestCase.java131
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java325
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java46
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java27
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XServiceRefsTestCase.java31
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java29
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java26
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java33
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java33
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java27
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java30
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/Foo.java16
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoFunctionInvokerTestCase.java173
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptInstanceTestCase.java47
-rw-r--r--sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java80
16 files changed, 1175 insertions, 0 deletions
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilderTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilderTestCase.java
new file mode 100644
index 0000000000..8d25183386
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/builder/JavaScriptContextFactoryBuilderTestCase.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.rhino.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
+import org.apache.tuscany.container.rhino.assembly.JavaScriptImplementation;
+import org.apache.tuscany.container.rhino.context.JavaScriptComponentContext;
+import org.apache.tuscany.core.builder.ContextFactory;
+import org.apache.tuscany.core.extension.ExternalServiceInvoker;
+import org.apache.tuscany.model.assembly.AssemblyContext;
+import org.apache.tuscany.model.assembly.AssemblyInitializationException;
+import org.apache.tuscany.model.assembly.AssemblyVisitor;
+import org.apache.tuscany.model.assembly.ComponentType;
+import org.apache.tuscany.model.assembly.Property;
+import org.apache.tuscany.model.assembly.Reference;
+import org.apache.tuscany.model.assembly.Service;
+
+/**
+ * Tests for the RhinoScript
+ */
+public class JavaScriptContextFactoryBuilderTestCase extends TestCase {
+
+ public JavaScriptContextFactoryBuilderTestCase() {
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testSimpleConstructor() {
+ JavaScriptContextFactoryBuilder builder = new JavaScriptContextFactoryBuilder();
+ JavaScriptImplementation jsImpl = createMockJSImpl();
+ jsImpl.setScript("function foo() { return 'petra';}");
+
+ ContextFactory cf = builder.createContextFactory("foo", jsImpl, null);
+ assertNotNull(cf);
+
+ JavaScriptComponentContext context = (JavaScriptComponentContext) cf.createContext();
+ assertNotNull(context);
+
+ ExternalServiceInvoker invoker = (ExternalServiceInvoker) context.getTargetInstance();
+ assertNotNull(invoker);
+
+ Object response = invoker.invoke("foo", new Object[0]);
+ assertEquals("petra", response);
+ }
+
+ private JavaScriptImplementation createMockJSImpl() {
+ JavaScriptImplementation jsImpl = new JavaScriptImplementation();
+
+ jsImpl.setComponentType(new ComponentType() {
+
+ public List<Service> getServices() {
+ return new ArrayList<Service>();
+ }
+
+ public Service getService(String name) {
+ return null;
+ }
+
+ public List<Reference> getReferences() {
+ return null;
+ }
+
+ public Reference getReference(String name) {
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ return new ArrayList<Property>();
+ }
+
+ public Property getProperty(String name) {
+ return null;
+ }
+
+ public List<Object> getExtensibilityElements() {
+ return null;
+ }
+
+ public List<Object> getExtensibilityAttributes() {
+ return null;
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+ });
+
+ jsImpl.setResourceLoader(new ResourceLoaderImpl(getClass().getClassLoader()));
+
+ return jsImpl;
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XInterceptorTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XInterceptorTestCase.java
new file mode 100644
index 0000000000..a5c778acf2
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XInterceptorTestCase.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.rhino.e4x;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.message.Message;
+import org.apache.tuscany.core.wire.Interceptor;
+import org.apache.tuscany.core.wire.MessageChannel;
+import org.apache.tuscany.core.wire.TargetInvoker;
+import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.apache.tuscany.sdo.util.SDOUtil;
+import org.apache.xmlbeans.XmlObject;
+
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * Tests for the E4XInterceptor
+ */
+public class E4XInterceptorTestCase extends TestCase {
+
+ private E4XInterceptor interceptor;
+
+ private Message msg;
+
+ public E4XInterceptorTestCase() {
+ }
+
+ public void testFromXmlObject() {
+ msg.setBody(new Object[] { "petra" });
+
+ interceptor.toXmlObject(msg);
+ assertTrue(((Object[])msg.getBody())[0] instanceof XmlObject);
+
+ msg.setBody(((Object[])msg.getBody())[0]);
+ interceptor.fromXmlObject(msg);
+ assertEquals("petra", msg.getBody());
+ }
+
+ public void testToXmlObject() {
+ msg.setBody(new Object[] { "petra" });
+ interceptor.toXmlObject(msg);
+ assertTrue(((Object[])msg.getBody())[0] instanceof XmlObject);
+ }
+
+ public void testInvoke() {
+ msg.setBody(new Object[] { "petra" });
+ interceptor.invoke(msg);
+ assertEquals("petra", msg.getBody());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ DataObjectUtil.initRuntime();
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
+ TypeHelper typeHelper = SDOUtil.createTypeHelper();
+ XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper);
+
+ URL url = getClass().getResource("helloworld.wsdl");
+ xsdHelper.define(url.openStream(), null);
+
+ QName qn = new QName("http://integration.rhino.container.tuscany.apache.org", "getGreetings");
+ this.interceptor = new E4XInterceptor(qn, typeHelper, getClass().getClassLoader());
+ interceptor.setNext(new Interceptor() {
+ public Message invoke(Message msg) {
+ msg.setBody(((Object[])msg.getBody())[0]);
+ return msg;
+ }
+ public void setNext(Interceptor next) {
+ }});
+
+ this.msg = createMessage();
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+ }
+
+ private Message createMessage() {
+ Message msg = new Message() {
+
+ Object body;
+
+ public Object getBody() {
+ return body;
+ }
+
+ public void setBody(Object body) {
+ this.body = body;
+ }
+
+ public void setTargetInvoker(TargetInvoker invoker) {
+ }
+
+ public TargetInvoker getTargetInvoker() {
+ return null;
+ }
+
+ public MessageChannel getCallbackChannel() {
+ return null;
+ }
+
+ public Message getRelatedCallbackMessage() {
+ return null;
+ }
+ };
+ return msg;
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java
new file mode 100644
index 0000000000..09638e7eae
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/e4x/E4XPolicyBuilderTestCase.java
@@ -0,0 +1,325 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.rhino.e4x;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Part;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
+import org.apache.tuscany.container.rhino.assembly.JavaScriptImplementation;
+import org.apache.tuscany.core.wire.Interceptor;
+import org.apache.tuscany.core.wire.TargetInvocationConfiguration;
+import org.apache.tuscany.core.wire.WireTargetConfiguration;
+import org.apache.tuscany.model.assembly.AssemblyContext;
+import org.apache.tuscany.model.assembly.AssemblyInitializationException;
+import org.apache.tuscany.model.assembly.AssemblyVisitor;
+import org.apache.tuscany.model.assembly.AtomicComponent;
+import org.apache.tuscany.model.assembly.AtomicImplementation;
+import org.apache.tuscany.model.assembly.ComponentType;
+import org.apache.tuscany.model.assembly.Composite;
+import org.apache.tuscany.model.assembly.ConfiguredProperty;
+import org.apache.tuscany.model.assembly.ConfiguredReference;
+import org.apache.tuscany.model.assembly.ConfiguredService;
+import org.apache.tuscany.model.assembly.Property;
+import org.apache.tuscany.model.assembly.Reference;
+import org.apache.tuscany.model.assembly.Service;
+import org.apache.tuscany.model.assembly.ServiceContract;
+import org.apache.tuscany.model.types.wsdl.impl.WSDLServiceContractImpl;
+
+import com.ibm.wsdl.InputImpl;
+import com.ibm.wsdl.MessageImpl;
+import com.ibm.wsdl.OperationImpl;
+import com.ibm.wsdl.PartImpl;
+import com.ibm.wsdl.PortTypeImpl;
+
+/**
+ * Tests for the E4XPolicyBuilder
+ */
+public class E4XPolicyBuilderTestCase extends TestCase {
+
+ public E4XPolicyBuilderTestCase() {
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testGetElementQName() {
+ E4XPolicyBuilder builder = new E4XPolicyBuilder();
+ QName qn = new QName("foo");
+ JavaScriptImplementation jsImpl = createMockJSImpl("foo", qn);
+ QName qn2 = builder.getElementQName(jsImpl, "foo");
+ assertEquals(qn, qn2);
+ }
+
+ public void testBuild() throws SecurityException, NoSuchMethodException {
+ E4XPolicyBuilder builder = new E4XPolicyBuilder();
+ ConfiguredService service = createMockConfiguredService();
+ WireTargetConfiguration config = createMockWireTargetConfiguration();
+ builder.build(service, config);
+ Map<Method, TargetInvocationConfiguration> configs = config.getInvocationConfigurations();
+ assertNotNull(configs);
+ assertEquals(1, configs.size());
+ TargetInvocationConfiguration tic = configs.values().iterator().next();
+ Interceptor interceptor = tic.getHeadInterceptor();
+ assertTrue(interceptor instanceof E4XInterceptor);
+ }
+
+ private WireTargetConfiguration createMockWireTargetConfiguration() throws SecurityException, NoSuchMethodException {
+ Map<Method, TargetInvocationConfiguration> configs = new HashMap<Method, TargetInvocationConfiguration>();
+ Method foo = Foo.class.getMethod("foo", new Class[0]);
+ TargetInvocationConfiguration config = new TargetInvocationConfiguration(foo);
+ configs.put(foo, config);
+ WireTargetConfiguration wtf = new WireTargetConfiguration(null, configs, null, null);
+ return wtf;
+ }
+
+ interface Foo {
+ public void foo();
+ }
+
+ private ConfiguredService createMockConfiguredService() {
+ ConfiguredService service = new ConfiguredService() {
+
+ public String getName() {
+ return null;
+ }
+
+ public void setName(String name) {
+ }
+
+ public Service getPort() {
+ return null;
+ }
+
+ public void setPort(Service port) {
+ }
+
+ public org.apache.tuscany.model.assembly.Part getPart() {
+ return createPart();
+ }
+
+ public void setPart(org.apache.tuscany.model.assembly.Part part) {
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+
+ public void setProxyFactory(Object proxyFactory) {
+ }
+
+ public Object getProxyFactory() {
+ return null;
+ }
+ };
+
+ return service;
+ }
+
+ private org.apache.tuscany.model.assembly.Part createPart() {
+ org.apache.tuscany.model.assembly.Part part = new AtomicComponent() {
+
+ public AtomicImplementation getImplementation() {
+ return createMockJSImpl("foo", new QName("foo"));
+ }
+
+ public void setImplementation(AtomicImplementation value) {
+ }
+
+ public List<ConfiguredProperty> getConfiguredProperties() {
+ return null;
+ }
+
+ public ConfiguredProperty getConfiguredProperty(String name) {
+ return null;
+ }
+
+ public List<ConfiguredReference> getConfiguredReferences() {
+ return null;
+ }
+
+ public ConfiguredReference getConfiguredReference(String name) {
+ return null;
+ }
+
+ public List<ConfiguredService> getConfiguredServices() {
+ return null;
+ }
+
+ public ConfiguredService getConfiguredService(String name) {
+ return null;
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public void setName(String value) {
+ }
+
+ public Composite getComposite() {
+ return null;
+ }
+
+ public void setComposite(Composite composite) {
+ }
+
+ public List<Object> getExtensibilityElements() {
+ return null;
+ }
+
+ public List<Object> getExtensibilityAttributes() {
+ return null;
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+
+ public void setContextFactory(Object contextFactory) {
+ }
+
+ public Object getContextFactory() {
+ return null;
+ }
+ };
+ return part;
+ }
+
+ private JavaScriptImplementation createMockJSImpl(final String name, final QName qn) {
+ JavaScriptImplementation jsImpl = new JavaScriptImplementation();
+
+ jsImpl.setComponentType(new ComponentType() {
+
+ public List<Service> getServices() {
+ return Arrays.asList(new Service[] { createMockService(name, qn) });
+ }
+
+ public Service getService(String name) {
+ return null;
+ }
+
+ public List<Reference> getReferences() {
+ return null;
+ }
+
+ public Reference getReference(String name) {
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ return new ArrayList<Property>();
+ }
+
+ public Property getProperty(String name) {
+ return null;
+ }
+
+ public List<Object> getExtensibilityElements() {
+ return null;
+ }
+
+ public List<Object> getExtensibilityAttributes() {
+ return null;
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+ });
+
+ jsImpl.setResourceLoader(new ResourceLoaderImpl(getClass().getClassLoader()));
+
+ return jsImpl;
+ }
+
+ private Service createMockService(final String name, final QName qn) {
+ Service service = new Service() {
+
+ public ServiceContract getServiceContract() {
+ WSDLServiceContractImpl sc = new WSDLServiceContractImpl();
+ PortType pt = new PortTypeImpl();
+ Operation op = new OperationImpl();
+ op.setName(name);
+ Input input = new InputImpl();
+ Message msg = new MessageImpl();
+ Part p = new PartImpl();
+ p.setElementName(qn);
+ msg.addPart(p);
+ input.setMessage(msg);
+ op.setInput(input);
+ pt.addOperation(op);
+ sc.setPortType(pt);
+ return sc;
+ }
+
+ public void setServiceContract(ServiceContract contract) {
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public void setName(String name) {
+ }
+
+ public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException {
+ }
+
+ public void freeze() {
+ }
+
+ public boolean accept(AssemblyVisitor visitor) {
+ return false;
+ }
+ };
+ return service;
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java
new file mode 100644
index 0000000000..ee6b533ddf
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/AbstractJavaScriptTestCase.java
@@ -0,0 +1,46 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.client.TuscanyRuntime;
+import org.osoa.sca.CurrentModuleContext;
+import org.osoa.sca.ModuleContext;
+
+/**
+ * Integration tests for JavaScript components
+ */
+public abstract class AbstractJavaScriptTestCase extends TestCase {
+
+ protected TuscanyRuntime tuscany;
+
+ protected ModuleContext moduleContext;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ tuscany = new TuscanyRuntime("tests", null);
+ tuscany.start();
+ moduleContext = CurrentModuleContext.getContext();
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ tuscany.stop();
+ }
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java
new file mode 100644
index 0000000000..f66f2e1079
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/BasicTestCase.java
@@ -0,0 +1,27 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+/**
+ * Integration tests for JavaScript components
+ */
+public class BasicTestCase extends AbstractJavaScriptTestCase {
+
+ public void testBasicInvocation() throws Exception {
+ HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent1");
+ String response = helloworldService.getGreetings("petra");
+ assertEquals("jsHello petra", response);
+ }
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XServiceRefsTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XServiceRefsTestCase.java
new file mode 100644
index 0000000000..76908b48d1
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XServiceRefsTestCase.java
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+
+/**
+ * Integration tests for JavaScript components and composite contexts
+ *
+ * @version $Rev$ $Date$
+ */
+public class E4XServiceRefsTestCase extends AbstractJavaScriptTestCase {
+
+ public void testE4X() throws Exception {
+ //TODO: E4X serviceRefs don't work yet
+// HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponentE4XProxy");
+// String response = helloworldService.getGreetings("petra");
+// assertEquals("e4xHello proxy:petra", response);
+ }
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java
new file mode 100644
index 0000000000..d6060aea90
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/E4XTestCase.java
@@ -0,0 +1,29 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+/**
+ * Integration tests for JavaScript components and composite contexts
+ *
+ * @version $Rev$ $Date$
+ */
+public class E4XTestCase extends AbstractJavaScriptTestCase {
+
+ public void testE4X() throws Exception {
+ HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponentE4X");
+ String response = helloworldService.getGreetings("petra");
+ assertEquals("e4xHello petra", response);
+ }
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java
new file mode 100644
index 0000000000..3a90be0102
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/HelloWorld.java
@@ -0,0 +1,26 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+/**
+ * This is the business interface of the HelloWorld service component.
+ */
+public interface HelloWorld {
+
+ public String getGreetings(String name);
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java
new file mode 100644
index 0000000000..138d9a8452
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/InitializationTestCase.java
@@ -0,0 +1,33 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+/**
+ * Integration tests for JavaScript components
+ */
+public class InitializationTestCase extends AbstractJavaScriptTestCase {
+
+ public void testInitialization() throws Exception {
+ HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent4");
+ String response = helloworldService.getGreetings("petra");
+ assertEquals("Bonjour petra", response);
+ }
+
+ public void testImports1() throws Exception {
+ HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent5");
+ String response = helloworldService.getGreetings("petra");
+ assertEquals("Kia ora petra", response);
+ }
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java
new file mode 100644
index 0000000000..7b14376dbe
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/PropertiesTestCase.java
@@ -0,0 +1,33 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+/**
+ * Integration tests for JavaScript components
+ */
+public class PropertiesTestCase extends AbstractJavaScriptTestCase {
+
+ public void testDefaultProperty() throws Exception {
+ HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent2a");
+ String response = helloworldService.getGreetings("petra");
+ assertEquals("Hi petra", response);
+ }
+
+ public void testOverrideProperty() throws Exception {
+ HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldComponent2b");
+ String response = helloworldService.getGreetings("petra");
+ assertEquals("Guten Tag petra", response);
+ }
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java
new file mode 100644
index 0000000000..7a6ac040d1
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/ServiceRefsTestCase.java
@@ -0,0 +1,27 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+/**
+ * Integration tests for JavaScript components
+ */
+public class ServiceRefsTestCase extends AbstractJavaScriptTestCase {
+
+ public void testServiceReference() throws Exception {
+ HelloWorld helloworldService = (HelloWorld) moduleContext.locateService("HelloWorldProxyComponent");
+ String response = helloworldService.getGreetings("petra");
+ assertEquals("Hi proxy:petra", response);
+ }
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java
new file mode 100644
index 0000000000..327edd1cbb
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/integration/TestMethods.java
@@ -0,0 +1,30 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.rhino.integration;
+
+public class TestMethods {
+
+ private String salutation = "Kia ora";
+
+ public String getSalutation() {
+ return salutation;
+ }
+
+ public void getSalutation(String s) {
+ salutation = s;
+ }
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/Foo.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/Foo.java
new file mode 100644
index 0000000000..6bcad30c23
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/Foo.java
@@ -0,0 +1,16 @@
+package org.apache.tuscany.container.rhino.rhino;
+
+class Foo {
+ private String s;
+
+ public Foo() {
+ }
+
+ public String getS() {
+ return s;
+ }
+
+ public void setS(String s) {
+ this.s = s;
+ }
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoFunctionInvokerTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoFunctionInvokerTestCase.java
new file mode 100644
index 0000000000..38705841f6
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoFunctionInvokerTestCase.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.rhino.rhino;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.container.rhino.rhino.RhinoFunctionInvoker;
+import org.apache.tuscany.container.rhino.rhino.RhinoScript;
+import org.apache.tuscany.container.rhino.rhino.RhinoScriptInstance;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+
+/**
+ * Tests for the RhinoScript
+ */
+public class RhinoFunctionInvokerTestCase extends TestCase {
+
+ public RhinoFunctionInvokerTestCase() {
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testNoArgsInvoke() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getPetra() {return 'petra';}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getPetra");
+ assertNotNull(invoker);
+ assertEquals("petra", invoker.invoke(null));
+ }
+
+ public void testOneArgInvoke() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getS(s) {return s;}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getS");
+ assertNotNull(invoker);
+ assertEquals("petra", invoker.invoke(new Object[]{"petra"}));
+ }
+
+ public void testMultiArgsInvoke() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function concat(x, y) {return x + y}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("concat");
+ assertNotNull(invoker);
+ assertEquals("petrasue", invoker.invoke(new Object[] { "petra", "sue"}));
+ }
+
+ public void testNoResponseInvoke() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getNull() {}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getNull");
+ assertNotNull(invoker);
+ assertEquals(null, invoker.invoke(new Object[0]));
+ }
+
+ public void testNullResponseInvoke() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getNull() {return null;}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getNull");
+ assertNotNull(invoker);
+ assertEquals(null, invoker.invoke(new Object[0]));
+ }
+
+ public void testResponseTypeDefaultString() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getTrue() {return true;}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getTrue");
+ assertNotNull(invoker);
+ Object o = invoker.invoke(new Object[0]);
+ assertTrue(o instanceof String);
+ assertEquals( "true", o);
+ }
+
+ public void testResponseTypeBoolean() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getTrue() {return true;}");
+ rhinoScript.setResponseClass("getTrue", Boolean.class);
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getTrue");
+ assertNotNull(invoker);
+ assertTrue((Boolean)invoker.invoke(new Object[0]));
+ }
+
+ public void testResponseTypeStringArray() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getAs() {var as = new Array(1);as[0]='petra';return as;}");
+ rhinoScript.setResponseClass("getAs", new String[0].getClass());
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getAs");
+ assertNotNull(invoker);
+ Object o = invoker.invoke(new Object[0]);
+ assertNotNull(o);
+ assertTrue(o.getClass().isArray());
+ assertEquals("petra", ((Object[])o)[0]);
+ }
+
+
+ public void testResponseTypeBooleanArray() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getBs() {var bs = new Array(1);bs[0]=true;return bs;}");
+ rhinoScript.setResponseClass("getBs", new Boolean[0].getClass());
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getBs");
+ assertNotNull(invoker);
+ Object o = invoker.invoke(new Object[0]);
+ assertNotNull(o);
+ assertTrue(o.getClass().isArray());
+ assertTrue(((Boolean[])o)[0]);
+ }
+
+ public void testRequestCustomType() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getFooS(foo) {return foo.getS();}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getFooS");
+ assertNotNull(invoker);
+
+ Foo foo = new Foo();
+ foo.setS("petra");
+ Object o = invoker.invoke(new Object[] {foo});
+ assertEquals(foo.getS(), o);
+ }
+
+ public void testResponseCustomType() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "importClass(Packages.org.apache.tuscany.container.rhino.rhino.Foo);function getFoo(s) {var foo = new Foo(); foo.setS(s);return foo;}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getFoo");
+ assertNotNull(invoker);
+
+ Object o = invoker.invoke(new Object[] {"petra"});
+ assertNotNull(o);
+ assertEquals("petra", ((Foo)o).getS());
+ }
+
+ public void testXMLRequest() throws XmlException, IOException {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function isXML(x) {return 'xml' == (typeof x);}");
+ rhinoScript.setResponseClass("isXML", Boolean.class);
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("isXML");
+ assertNotNull(invoker);
+
+ Object xml = XmlObject.Factory.parse("<a><b/></a>");
+ assertTrue((Boolean) invoker.invoke(new Object[]{xml}));
+
+ Object notXML = "notXML";
+ assertFalse((Boolean) invoker.invoke(new Object[]{notXML}));
+ }
+
+ public void testXMLResponse() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getXML(s) {return <a> { s } </a>;}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getXML");
+ assertNotNull(invoker);
+
+ Object xml = invoker.invoke(new Object[]{"petra"});
+ assertNotNull(xml);
+ assertTrue(xml instanceof XmlObject);
+ assertEquals("<a>petra</a>",((XmlObject)xml).toString());
+ }
+
+}
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptInstanceTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptInstanceTestCase.java
new file mode 100644
index 0000000000..480bbfb2d8
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptInstanceTestCase.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.rhino.rhino;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the RhinoScript
+ */
+public class RhinoScriptInstanceTestCase extends TestCase {
+
+ public RhinoScriptInstanceTestCase() {
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testInvokeFunction() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getPetra() {return 'petra';}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ assertEquals("petra", instance.invokeFunction("getPetra", new Object[0]));
+ }
+
+ public void testCreateRhinoFunctionInvoker() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getPetra() {return 'petra';}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getPetra");
+ assertNotNull(invoker);
+ assertEquals("petra", invoker.invoke(new Object[0]));
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java
new file mode 100644
index 0000000000..05f5624e7c
--- /dev/null
+++ b/sandbox/ant/tuscany-container-rhino/src/test/java/org/apache/tuscany/container/rhino/rhino/RhinoScriptTestCase.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.rhino.rhino;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the RhinoScript
+ */
+public class RhinoScriptTestCase extends TestCase {
+
+ public RhinoScriptTestCase() {
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testSimpleConstructor() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getPetra() {return 'petra';}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ assertEquals("petra", instance.invokeFunction("getPetra", new Object[0]));
+ }
+
+ public void testFullConstructor() {
+ ClassLoader cl = getClass().getClassLoader();
+ Map<String, Object> contexts = new HashMap<String, Object>();
+ contexts.put("name", "petra");
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getName() {return name;}",contexts , cl);
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ assertEquals("petra", instance.invokeFunction("getName", new Object[0]));
+ }
+
+ public void testCreateInstance() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getPetra() {return 'petra';}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ assertNotNull(instance);
+ }
+
+ public void testCreateInstanceWithContext() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getName() {return name;}");
+ Map<String, Object> contexts = new HashMap<String, Object>();
+ contexts.put("name", "petra");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance(contexts);
+ assertEquals("petra", instance.invokeFunction("getName", new Object[0]));
+ }
+
+ public void testDefaultResponseType() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getX() {return 42;}");
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ assertEquals("42", instance.invokeFunction("getX", new Object[0]));
+ }
+
+ public void testSetResponseType() {
+ RhinoScript rhinoScript = new RhinoScript("foo", "function getX() {return 42;}");
+ rhinoScript.setResponseClass("getX", Integer.class);
+ RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance();
+ Object x = instance.invokeFunction("getX", new Object[0]);
+ assertTrue(x instanceof Integer);
+ assertEquals(new Integer(42), x);
+ }
+
+} \ No newline at end of file