From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../JavaScriptImplementationLoaderTestCase.java | 107 +++++++++++++ .../container/javascript/PropertyTestCase.java | 56 +++++++ .../RhinoScriptIntrospectorTestCase.java | 114 ++++++++++++++ .../container/javascript/ScriptInvokeTestCase.java | 54 +++++++ .../tuscany/container/javascript/WireTestCase.java | 166 ++++++++++++++++++++ .../javascript/function/HelloWorldTestCase.java | 104 ++++++++++++ .../javascript/function/ScopeTestCase.java | 65 ++++++++ .../container/javascript/mock/Greeting.java | 26 +++ .../tuscany/container/javascript/rhino/Foo.java | 34 ++++ .../rhino/RhinoFunctionInvokerTestCase.java | 174 +++++++++++++++++++++ .../javascript/rhino/RhinoSCAConfigTestCase.java | 116 ++++++++++++++ .../rhino/RhinoScriptInstanceTestCase.java | 50 ++++++ .../javascript/rhino/RhinoScriptTestCase.java | 83 ++++++++++ .../xmlfromxsd/XMLfromXSDGeneratorTestCase.java | 129 +++++++++++++++ 14 files changed, 1278 insertions(+) create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/ScopeTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoSCAConfigTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java create mode 100644 sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/XMLfromXSDGeneratorTestCase.java (limited to 'sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container') diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java new file mode 100644 index 0000000000..de62afc327 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java @@ -0,0 +1,107 @@ +/* + * 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.javascript; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.MissingResourceException; + +import junit.framework.TestCase; +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; + +/** + * Tests for JavaScriptImplementationLoader + */ +public class JavaScriptImplementationLoaderTestCase extends TestCase { + private CompositeComponent parent; + + private XMLStreamReader reader; + + private DeploymentContext deploymentContext; + + private ClassLoader classLoader; + + private LoaderRegistry registry; + + private JavaScriptImplementationLoader loader; + + public void testNoScriptAttribute() 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 testNoScriptPresent() throws LoaderException, XMLStreamException { + expect(reader.getAttributeValue(null, "script")).andReturn("foo.groovy"); + expect(deploymentContext.getClassLoader()).andReturn(classLoader); + + replay(reader); + replay(deploymentContext); + + JavaScriptImplementationLoader mockLoader = new JavaScriptImplementationLoader(registry) { + protected String loadSource(ClassLoader cl, String resource) throws LoaderException { + assertSame(classLoader, cl); + assertEquals("foo.groovy", resource); + throw new MissingResourceException(resource); + } + }; + try { + mockLoader.load(parent, null, reader, deploymentContext); + fail(); + } catch (MissingResourceException e) { + assertEquals("foo.groovy", e.getIdentifier()); + } + verify(reader); + verify(deploymentContext); + } + + public void testLoadScript() throws LoaderException { + String script = + loader.loadSource(getClass().getClassLoader(), "org/apache/tuscany/container/javascript/mock/test.js"); + assertEquals("//Test Script", script); + } + + protected void setUp() throws Exception { + super.setUp(); + registry = createMock(LoaderRegistry.class); + loader = new JavaScriptImplementationLoader(registry); + + parent = createMock(CompositeComponent.class); + reader = createMock(XMLStreamReader.class); + deploymentContext = createMock(DeploymentContext.class); + classLoader = createMock(ClassLoader.class); + } +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java new file mode 100644 index 0000000000..9318d9c125 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.javascript; + +import junit.framework.TestCase; + +import org.apache.tuscany.container.javascript.rhino.RhinoScript; + +/** + * Tests for component properties + */ +public class PropertyTestCase extends TestCase { + + private static final String SCRIPT = "function greet(name){ return property; }"; + + private RhinoScript implClass; + + /** + * Tests injecting a simple property type on a Javascript implementation instance + */ + public void testPropertyInjection() throws Exception { + /*CompositeScopeContainer scope = new CompositeScopeContainer(null); + scope.start(); + List> serviceBindings = new ArrayList>(); + serviceBindings.add(Greeting.class); + Map properties = new HashMap(); + properties.put("property", "bar"); + WireService wireService = ArtifactFactory.createWireService(); + JavaScriptComponent context = new JavaScriptComponent("source", implClass, serviceBindings, properties, null, scope, wireService, null); + scope.register(context); + Greeting greeting = context.getServiceInstance(); + assertEquals("bar", greeting.greet("foo")); + scope.stop();*/ + } + + protected void setUp() throws Exception { + super.setUp(); + implClass = new RhinoScript("test", SCRIPT); + } +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java new file mode 100644 index 0000000000..3b1b3de5e5 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/RhinoScriptIntrospectorTestCase.java @@ -0,0 +1,114 @@ +/* + * 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.javascript; + +import java.io.IOException; +import java.net.URL; +import java.util.Map; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.idl.java.JavaServiceContract; +import org.apache.tuscany.spi.loader.MissingResourceException; +import org.apache.tuscany.spi.model.ComponentType; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.ServiceDefinition; + +import helloworld.HelloWorldService; +import junit.framework.TestCase; +import org.apache.tuscany.container.javascript.rhino.RhinoSCAConfig; +import org.apache.tuscany.container.javascript.rhino.RhinoScript; +import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; +import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl; +import org.apache.tuscany.idl.wsdl.WSDLServiceContract; +import org.apache.tuscany.idl.wsdl.XMLSchemaRegistryImpl; + +public class RhinoScriptIntrospectorTestCase extends TestCase { + + private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { + public void readingWSDL(String namespace, URL location) { + } + + public void cachingDefinition(String namespace, URL location) { + } + }; + + public void testJavaInterface() throws MissingResourceException, InvalidServiceContractException { + RhinoScript rs = + new RhinoScript("javaInterfaceTest", "SCA = { javaInterface : 'helloworld.HelloWorldService',};", + null, getClass().getClassLoader()); + RhinoSCAConfig scaConfig = new RhinoSCAConfig(rs.getScriptScope()); + JavaScriptIntrospector introspector = + new JavaScriptIntrospector(null, new JavaInterfaceProcessorRegistryImpl()); + ComponentType comonentType = introspector.introspectScript(scaConfig, rs.getClassLoader()); + assertNotNull(comonentType); + Map services = comonentType.getServices(); + assertEquals(1, services.size()); + ServiceDefinition serviceDefinition = (ServiceDefinition) services.values().iterator().next(); + ServiceContract serviceContract = serviceDefinition.getServiceContract(); + assertTrue(serviceContract instanceof JavaServiceContract); + JavaServiceContract javaServiceContract = (JavaServiceContract) serviceContract; + assertEquals(HelloWorldService.class, javaServiceContract.getInterfaceClass()); + } + + public void testWSDLLocation() throws WSDLException { +// RhinoScript rs = new RhinoScript("wsdlLocation", +// "SCA = { wsdlLocation : 'src/test/resources/org/apache/tuscany/container/javascript/rhino/helloworld.wsdl',};", null, getClass() +// .getClassLoader()); +// RhinoSCAConfig scaConfig = new RhinoSCAConfig(rs.getScriptScope()); +// JavaScriptIntrospector introspector = new JavaScriptIntrospector(null); +// ComponentType comonentType = introspector.introspectScript(scaConfig, rs.getClassLoader()); +// assertNotNull(comonentType); +// Map serviceBindings = comonentType.getServices(); +// assertEquals(1, serviceBindings.size()); +// ServiceDefinition serviceDefinition = (ServiceDefinition) serviceBindings.values().iterator().next(); +// ServiceContract serviceContract = serviceDefinition.getServiceContract(); +// assertTrue(serviceContract instanceof WSDLServiceContract); +// WSDLServiceContract wsdlServiceContract = (WSDLServiceContract) serviceContract; +// assertEquals(new QName("http://helloworld", "HelloWorld"), wsdlServiceContract.getPortType().getQName()); + } + + public void testWSDLPortType() throws WSDLException, IOException, MissingResourceException, + InvalidServiceContractException { + RhinoScript rs = new RhinoScript("wsdlPortType", + "SCA = { wsdlPortType : 'HelloWorld', wsdlNamespace : 'http://helloworld',};", null, + getClass().getClassLoader()); + RhinoSCAConfig scaConfig = new RhinoSCAConfig(rs.getScriptScope()); + + WSDLDefinitionRegistryImpl wsdlReg = new WSDLDefinitionRegistryImpl(); + wsdlReg.setSchemaRegistry(new XMLSchemaRegistryImpl()); + wsdlReg.setMonitor(NULL_MONITOR); + URL wsdlURL = + getClass().getClassLoader().getResource("org/apache/tuscany/container/javascript/rhino/helloworld.wsdl"); + wsdlReg.loadDefinition("http://helloworld", wsdlURL); + + JavaScriptIntrospector introspector = + new JavaScriptIntrospector(wsdlReg, new JavaInterfaceProcessorRegistryImpl()); + ComponentType comonentType = introspector.introspectScript(scaConfig, rs.getClassLoader()); + assertNotNull(comonentType); + Map services = comonentType.getServices(); + assertEquals(1, services.size()); + ServiceDefinition serviceDefinition = (ServiceDefinition) services.values().iterator().next(); + ServiceContract serviceContract = serviceDefinition.getServiceContract(); + assertTrue(serviceContract instanceof WSDLServiceContract); + WSDLServiceContract wsdlServiceContract = (WSDLServiceContract) serviceContract; + assertEquals(new QName("http://helloworld", "HelloWorld"), wsdlServiceContract.getPortType().getQName()); + } +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java new file mode 100644 index 0000000000..e852625bd9 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java @@ -0,0 +1,54 @@ +/* + * 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.javascript; + +import junit.framework.TestCase; + +import org.apache.tuscany.container.javascript.rhino.RhinoScript; + +/** + * Tests for invoker JavaScriptComponents + */ +public class ScriptInvokeTestCase extends TestCase { + + private static final String SCRIPT = "function greet(name) { return name }"; + + private RhinoScript rhinoScript; + + /** + * Tests the invocation of a Groovy "script" as opposed to a class + */ + public void testBasicScriptInvocation() throws Exception { +// CompositeScopeContainer scope = new CompositeScopeContainer(null); +// scope.start(); +// List> serviceBindings = new ArrayList>(); +// serviceBindings.add(Greeting.class); +// JavaScriptComponent context = new JavaScriptComponent("source", rhinoScript, serviceBindings, new HashMap(), +// null, scope, ArtifactFactory.createWireService(), null); +// scope.register(context); +// Greeting object = (Greeting) context.getServiceInstance(); +// assertEquals("foo", object.greet("foo")); +// scope.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + rhinoScript = new RhinoScript("test", SCRIPT); + } +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java new file mode 100644 index 0000000000..58a831f66a --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java @@ -0,0 +1,166 @@ +/* + * 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.javascript; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.tuscany.spi.model.Operation; +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; +import org.apache.tuscany.spi.wire.InboundInvocationChain; +import org.apache.tuscany.spi.wire.InboundWire; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.WireService; + +import junit.framework.TestCase; +import org.apache.tuscany.container.javascript.mock.Greeting; +import org.apache.tuscany.container.javascript.rhino.RhinoScript; +import org.apache.tuscany.core.component.scope.CompositeScopeContainer; +import org.apache.tuscany.test.ArtifactFactory; +import static org.easymock.EasyMock.reportMatcher; +import org.easymock.IArgumentMatcher; + +/** + * Tests for JavaScript component wiring + */ +public class WireTestCase extends TestCase { + + private static final String SCRIPT = + " function setWire(ref){" + + " wire = ref;" + " }" + + " " + + " function greet(name){" + + " return wire.greet(name); " + + " }"; + + private static final String SCRIPT2 = + " function greet(name){" + + " return name; " + + " }"; + + private RhinoScript implClass1; + + private RhinoScript implClass2; + private WireService wireService; + + /** + * Tests a basic invocation down a source wire + */ + public void testReferenceWireInvocation() throws Exception { +// CompositeScopeContainer scope = new CompositeScopeContainer(null); +// scope.start(); +// +// List> serviceBindings = new ArrayList>(); +// serviceBindings.add(Greeting.class); +// JavaScriptComponent context = new JavaScriptComponent("source", implClass1, serviceBindings, properties, null, scope, +// ArtifactFactory.createWireService(), null); +// OutboundWire wire = ArtifactFactory.createOutboundWire("wire", Greeting.class); +// ArtifactFactory.terminateWire(wire); +// +// TargetInvoker invoker = createMock(TargetInvoker.class); +// expect(invoker.isCacheable()).andReturn(false); +// Message response = new MessageImpl(); +// response.setBody("foo"); +// expect(invoker.invoke(eqMessage())).andReturn(response); +// replay(invoker); +// +// for (OutboundInvocationChain chain : wire.getInvocationChains().values()) { +// chain.setTargetInvoker(invoker); +// } +// scope.register(context); +// context.addOutboundWire(wire); +// Greeting greeting = context.getServiceInstance(); +// assertEquals("foo", greeting.greet("foo")); +// verify(invoker); +// +// scope.stop(); + } + + // todo this could be generalized and moved to test module + public static Message eqMessage() { + reportMatcher(new IArgumentMatcher() { + public boolean matches(Object object) { + if (!(object instanceof Message)) { + return false; + } + final Message msg = (Message) object; + Object[] body = (Object[]) msg.getBody(); + return "foo".equals(body[0]); + } + + public void appendTo(StringBuffer stringBuffer) { + } + }); + return null; + } + + /** + * Tests a basic invocation to a target + */ + public void testTargetInvocation() throws Exception { + CompositeScopeContainer scope = new CompositeScopeContainer(null); + scope.start(); + List> services = new ArrayList>(); + services.add(Greeting.class); + JavaScriptComponent context = + new JavaScriptComponent("source", implClass2, new HashMap(), null, + ArtifactFactory.createWireService(), null, null); + context.setScopeContainer(scope); + scope.register(context); + Operation operation = new Operation("greet", null, null, null, false, null, NO_CONVERSATION); + TargetInvoker invoker = context.createTargetInvoker(null, operation, null); + assertEquals("foo", invoker.invokeTarget(new String[]{"foo"}, TargetInvoker.NONE)); + scope.stop(); + } + + /** + * Tests a basic invocation down a target wire + */ + public void testTargetWireInvocation() throws Exception { + CompositeScopeContainer scope = new CompositeScopeContainer(null); + scope.start(); + List> services = new ArrayList>(); + services.add(Greeting.class); + JavaScriptComponent context = + new JavaScriptComponent("source", implClass2, new HashMap(), null, + ArtifactFactory.createWireService(), null, null); + context.setScopeContainer(scope); + scope.register(context); + + InboundWire wire = ArtifactFactory.createLocalInboundWire("Greeting", Greeting.class); + ArtifactFactory.terminateWire(wire); + for (InboundInvocationChain chain : wire.getInvocationChains().values()) { + chain.setTargetInvoker(context.createTargetInvoker(null, chain.getOperation(), null)); + } + context.addInboundWire(wire); + Greeting greeting = wireService.createProxy(Greeting.class, context.getInboundWire("Greeting")); + assertEquals("foo", greeting.greet("foo")); + scope.stop(); + } + + protected void setUp() throws Exception { + super.setUp(); + wireService = ArtifactFactory.createWireService(); + implClass1 = new RhinoScript("script1", SCRIPT); + implClass2 = new RhinoScript("script2", SCRIPT2); + } +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java new file mode 100644 index 0000000000..3db49618e2 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java @@ -0,0 +1,104 @@ +/* + * 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.javascript.function; + +import helloworld.HelloWorldService; + +import java.io.ByteArrayInputStream; +import java.net.URL; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.om.util.StAXUtils; +import org.apache.tuscany.test.SCATestCase; +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +/** + * This shows how to test the HelloWorld service component. + */ +public class HelloWorldTestCase extends SCATestCase { + + private CompositeContext context; + + protected void setUp() throws Exception { + URL base = getClass().getResource("/META-INF/sca/js.system.scdl"); + addExtension("JavaScriptContainer", new URL(base, "default.scdl")); + setApplicationSCDL(getClass().getResource("helloworld.scdl")); + super.setUp(); + + context = CurrentCompositeContext.getContext(); + } + + public void testHelloWorld() throws Exception { + HelloWorldService helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponent"); + assertEquals(helloWorldService.sayHello("petra"), "Hello petra"); + } + + public void testIntrospectedHelloWorld() throws Exception { + HelloWorldService introspectableService = context.locateService(HelloWorldService.class, "IntrospectableHelloWorldComponent"); + assertEquals(introspectableService.sayHello("petra"), "Hello petra"); + } + + public void testE4XImplInvocation() throws Exception { + HelloWorldService e4xHelloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponentE4X"); + String xmlInput = " " + + "TuscanyWorld " + + ""; + + XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader( + new ByteArrayInputStream(xmlInput.getBytes())); + StAXOMBuilder staxOMBuilder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), xmlReader); + Object response = e4xHelloWorldService.sayE4XHello(staxOMBuilder.getDocumentElement()); + assertNotNull(response); + assertTrue(response instanceof OMElement); + assertEquals("e4xHello TuscanyWorld", ((OMElement)response).getFirstElement().getText()); + //System.out.println(response); + } + + public void testE4XRefInvocation() throws Exception + { + HelloWorldService e4xHelloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponentE4X"); + + String initialInput = "JavaClient"; + String jsAddition = " thro e4x reference"; + String endSvcImplResponse = "Hello from Java Implementation to "; + + Object response = e4xHelloWorldService.sayHello(initialInput); + assertNotNull(response); + assertTrue(response instanceof String); + assertEquals(endSvcImplResponse + initialInput + jsAddition, response.toString()); + //System.out.println(response); + } + + public void testHelloWorldProperty() throws Exception { + HelloWorldService helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldProperty"); + assertEquals(helloWorldService.sayHello("petra"), "Kia ora petra"); + System.out.println(helloWorldService.sayHello("petra")); + } + + public void testHelloWorldPropertyDefault() throws Exception { + HelloWorldService helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldPropertyDefault"); + assertEquals(helloWorldService.sayHello("petra"), "Hi petra"); + } + +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/ScopeTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/ScopeTestCase.java new file mode 100644 index 0000000000..b823939e6c --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/function/ScopeTestCase.java @@ -0,0 +1,65 @@ +/* + * 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.javascript.function; + +import java.net.URL; + +import helloworld.HelloWorldService; + +import org.apache.tuscany.test.SCATestCase; +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +/** + * This shows how to test the HelloWorld service component. + */ +public class ScopeTestCase extends SCATestCase { + + private CompositeContext context; + + protected void setUp() throws Exception { + URL base = getClass().getResource("/META-INF/sca/js.system.scdl"); + addExtension("JavaScriptContainer", new URL(base, "default.scdl")); + setApplicationSCDL(getClass().getResource("scopeTest.scdl")); + super.setUp(); + + context = CurrentCompositeContext.getContext(); + } + +// Composite scope not implemented in core yet +// public void testComposite() throws Exception { +// HelloWorldService composoteScopeService = context.locateService(HelloWorldService.class, "ComposoteScopeService"); +// assertEquals("1", composoteScopeService.sayHello("")); +// assertEquals("2", composoteScopeService.sayHello("")); +// } + + public void testStateless() throws Exception { + HelloWorldService statelessService = context.locateService(HelloWorldService.class, "StatelessComponent"); + assertEquals("1", statelessService.sayHello("")); + // stateless gives a new instance for each request + assertEquals("1", statelessService.sayHello("")); + } + +// Request scope not implemented in core yet +// public void testRequestState() throws Exception { +// HelloWorldService requestService = context.locateService(HelloWorldService.class, "RequestComponent"); +// assertEquals("1", requestService.sayHello("")); +// assertEquals("1", requestService.sayHello("")); +// } +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java new file mode 100644 index 0000000000..e300f73469 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.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.javascript.mock; + +public interface Greeting { + + String setWire(Greeting ref); + + String greet(String name); +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java new file mode 100644 index 0000000000..397501a23b --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.javascript.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/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java new file mode 100644 index 0000000000..dad61659f3 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java @@ -0,0 +1,174 @@ +/* + * 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.javascript.rhino; + +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; + +/** + * Tests for the RhinoFunctionInvoker + */ +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", Boolean.class); + 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", new String[0].getClass()); + 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", new Boolean[0].getClass()); + 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.javascript.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", Boolean.class); + assertNotNull(invoker); + + Object xml = XmlObject.Factory.parse(""); + 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 { s } ;}"); + RhinoScriptInstance instance = rhinoScript.createRhinoScriptInstance(); + RhinoFunctionInvoker invoker = instance.createRhinoFunctionInvoker("getXML"); + assertNotNull(invoker); + + Object xml = invoker.invoke(new Object[] { "petra" }); + assertNotNull(xml); + assertTrue(xml instanceof OMElement); + assertEquals("petra", ((OMElement) xml).toString()); + } + +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoSCAConfigTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoSCAConfigTestCase.java new file mode 100644 index 0000000000..8975dbaeac --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoSCAConfigTestCase.java @@ -0,0 +1,116 @@ +/* + * 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.javascript.rhino; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.model.Scope; + +public class RhinoSCAConfigTestCase extends TestCase { + + public void testJavaInteface() { + RhinoScript rs = new RhinoScript("javaInterface", "SCA = { javaInterface : 'Test' }"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals("Test", scaConfig.getJavaInterface()); + } + + public void testWSDLLocation() { + RhinoScript rs = new RhinoScript("wsdlLocation", "SCA = { wsdlLocation : 'Test' }"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals("Test", scaConfig.getWSDLLocation()); + } + + public void testWSDLNamespace() { + RhinoScript rs = new RhinoScript("wsdlNamespace", "SCA = { wsdlNamespace : 'Test' }"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals("Test", scaConfig.getWSDLNamespace()); + } + + public void testWSDLPortType() { + RhinoScript rs = new RhinoScript("wsdlPortType", "SCA = { wsdlPortType : 'Test' }"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals("Test", scaConfig.getWSDLPortType()); + } + + public void testScopeStateless() { + RhinoScript rs = new RhinoScript("testScopeStateless", "SCA = { scope : 'stateless', javaInterface : 'helloworld.HelloWorldService'}"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals(Scope.STATELESS, scaConfig.getScope()); + } + + public void testScopeComposite() { + RhinoScript rs = new RhinoScript("testScopeComposite", "SCA = { scope : 'composite', javaInterface : 'helloworld.HelloWorldService'}"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals(Scope.COMPOSITE, scaConfig.getScope()); // TODO + } + + public void testScopeConversational() { + RhinoScript rs = new RhinoScript("testScopeConversational", "SCA = { scope : 'conversational', javaInterface : 'helloworld.HelloWorldService'}"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals(Scope.SESSION, scaConfig.getScope()); + } + + public void testScopeRequest() { + RhinoScript rs = new RhinoScript("testScopeRequest", "SCA = { scope : 'request', javaInterface : 'helloworld.HelloWorldService'}"); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(scaConfig.hasSCAConfig()); + assertEquals(Scope.REQUEST, scaConfig.getScope()); + } + + public void testBadScope() { + RhinoScript rs = new RhinoScript("testScopeStateless", "SCA = { scope : 'rubbish', javaInterface : 'helloworld.HelloWorldService'}"); + try { + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + fail("expecting bad scope exception: " + scaConfig); + } catch (IllegalArgumentException e) { + } + } + + public void testNoConfig() { + RhinoScript rs = new RhinoScript("javaInterface", ""); + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + assertTrue(!scaConfig.hasSCAConfig()); + } + + public void testNoService() { + RhinoScript rs = new RhinoScript("javaInterface", "SCA = {}"); + try { + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + fail("expecting no service exception: " + scaConfig); + } catch (IllegalArgumentException e) { + } + } + + public void testDupicateInteface() { + RhinoScript rs = new RhinoScript("javaInterface", "SCA = { javaInterface : 'Test', wsdlLocation : 'Test' }"); + try { + RhinoSCAConfig scaConfig = rs.getSCAConfig(); + fail("expecting multiple service exception: " + scaConfig); + } catch (IllegalArgumentException e) { + } + } + +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java new file mode 100644 index 0000000000..76d6c7c49d --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.javascript.rhino; + +import junit.framework.TestCase; + +/** + * Tests for the RhinoScriptInstance + */ +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])); + } + +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java new file mode 100644 index 0000000000..ab684c39ce --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java @@ -0,0 +1,83 @@ +/* + * 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.javascript.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 contexts = new HashMap(); + 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 contexts = new HashMap(); + 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], Integer.class); + assertTrue(x instanceof Integer); + assertEquals(new Integer(42), x); + } + +} diff --git a/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/XMLfromXSDGeneratorTestCase.java b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/XMLfromXSDGeneratorTestCase.java new file mode 100644 index 0000000000..15752bdaa1 --- /dev/null +++ b/sandbox/old/contrib/implementation-javascript/container/src/test/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/XMLfromXSDGeneratorTestCase.java @@ -0,0 +1,129 @@ +/* + * 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.javascript.utils.xmlfromxsd; + +import junit.framework.TestCase; + +public class XMLfromXSDGeneratorTestCase extends TestCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /*public void testXMLInstance_SDO_based_1() + { + String[] arguments = new String[] { "-xsd", "sequences.xsd", + "-st", "MixedQuote", + "-stn", "http://www.example.com/sequences", + "-o", "target/xmlFromxsd-source", + "-of", "sequences_sdo.xml" + }; + + XMLfromXSDGenerator.main(arguments); + //File file = new File("target/java2wsdl-source/CustomerValue.wsdl"); + //assertTrue(file.exists() && file.isFile()); + } + + public void testXMLInstance_SDO_based_2() + { + try + { + XMLfromXSDConfiguration config = new XMLfromXSDConfiguration(); + config.setXsdFileName("interopdoc.wsdl"); + config.setSchemaTypeName("ComplexDocument"); + config.setSchemaTypeNamespaceURI("http://soapinterop.org/"); + config.setXmlOutputLocation("target/xmlFromxsd-source"); + config.setXmlFileName("interopdoc_sdo.xml"); + + XMLGeneratorFactory.getInstance().createGenerator(XMLGenerator.SDO_BASED).generateXML(config); + //XMLGeneratorFactory.getInstance().createGenerator(XMLGenerator.XMLBEANS_BASED).generateXML(config); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + + public void testXMLInstance_SDO_based_3() + { + try + { + XMLfromXSDConfiguration config = new XMLfromXSDConfiguration(); + config.setXsdFileName("helloworld.wsdl"); + //config.setSchemaTypeName("getGreetings"); + config.setSchemaTypeName("ComplexGreetings"); + config.setSchemaTypeNamespaceURI("http://helloworldaxis.samples.tuscany.apache.org"); + config.setXmlOutputLocation("target/xmlFromxsd-source"); + config.setXmlFileName("helloworld_sdo.xml"); + + XMLGeneratorFactory.getInstance().createGenerator(XMLGenerator.SDO_BASED).generateXML(config); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + }*/ + + public void testXMLInstance_XB_based_1() { + String[] arguments = new String[] { "-xsd", "src/test/resources/sequences.xsd", "-st", "mixedStockQuote", "-stn", + "http://www.example.com/sequences", "-o", "target/xmlFromxsd-source", "-of", "sequences_xb.xml" }; + + XMLfromXSDGenerator.generatorType = XMLGenerator.XMLBEANS_BASED; + XMLfromXSDGenerator.main(arguments); + /* + * File file = new File("target/java2wsdl-source/CustomerValue.wsdl"); assertTrue(file.exists() && file.isFile()); + */ + } + + public void testXMLInstance_XB_based_2() { + try { + XMLfromXSDConfiguration config = new XMLfromXSDConfiguration(); + config.setXsdFileName("interopdoc.wsdl"); + config.setSchemaTypeName("ComplexDocument"); + config.setSchemaTypeNamespaceURI("http://soapinterop.org/"); + config.setXmlOutputLocation("target/xmlFromxsd-source"); + config.setXmlFileName("interopdoc_xb.xml"); + + XMLGeneratorFactory.getInstance().createGenerator(XMLGenerator.XMLBEANS_BASED).generateXML(config); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testXMLInstance_XB_based_3() { + try { + XMLfromXSDConfiguration config = new XMLfromXSDConfiguration(); + config.setXsdFileName("org/apache/tuscany/container/javascript/rhino/helloworld.wsdl"); + // config.setXsdFileName("helloworld.wsdl"); + config.setSchemaTypeName("getGreetings"); + // config.setSchemaTypeName("ComplexGreetings"); + config.setSchemaTypeNamespaceURI("http://helloworld"); + config.setXmlOutputLocation("target/xmlFromxsd-source"); + config.setXmlFileName("helloworld_xb.xml"); + + XMLGeneratorFactory.getInstance().createGenerator(XMLGenerator.XMLBEANS_BASED).generateXML(config); + } catch (Exception e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3