You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/08/12 00:56:56 UTC
svn commit: r430912 [15/17] - in /incubator/tuscany/java: samples/sca/
samples/sca/bigbank/src/main/resources/META-INF/
samples/sca/bigbank/src/main/resources/META-INF/sca/
samples/sca/calculator/src/main/resources/META-INF/
samples/sca/calculator/src/...
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,105 +1,105 @@
-/*
- *
- * Copyright 2006 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.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, 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, reader, deploymentContext);
- fail();
- } catch (MissingResourceException e) {
- assertEquals("foo.groovy", e.getMessage());
- }
- 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);
- }
-}
+/*
+ *
+ * Copyright 2006 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.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, 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, reader, deploymentContext);
+ fail();
+ } catch (MissingResourceException e) {
+ assertEquals("foo.groovy", e.getMessage());
+ }
+ 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);
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/JavaScriptImplementationLoaderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,47 +1,47 @@
-package org.apache.tuscany.container.javascript;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-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.ModuleScopeContainer;
-import org.apache.tuscany.spi.wire.WireService;
-import org.apache.tuscany.test.ArtifactFactory;
-
-/**
- * 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 Groovy implementation instance
- */
- public void testPropertyInjection() throws Exception {
- ModuleScopeContainer scope = new ModuleScopeContainer(null);
- scope.start();
- List<Class<?>> services = new ArrayList<Class<?>>();
- services.add(Greeting.class);
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put("property", "bar");
- WireService wireService = ArtifactFactory.createWireService();
- JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass, services, 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);
- }
-}
+package org.apache.tuscany.container.javascript;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.ModuleScopeContainer;
+import org.apache.tuscany.spi.wire.WireService;
+import org.apache.tuscany.test.ArtifactFactory;
+
+/**
+ * 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 Groovy implementation instance
+ */
+ public void testPropertyInjection() throws Exception {
+ ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ scope.start();
+ List<Class<?>> services = new ArrayList<Class<?>>();
+ services.add(Greeting.class);
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("property", "bar");
+ WireService wireService = ArtifactFactory.createWireService();
+ JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass, services, 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);
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/PropertyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,43 +1,43 @@
-package org.apache.tuscany.container.javascript;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-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.ModuleScopeContainer;
-import org.apache.tuscany.test.ArtifactFactory;
-
-/**
- * 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 {
- ModuleScopeContainer scope = new ModuleScopeContainer(null);
- scope.start();
- List<Class<?>> services = new ArrayList<Class<?>>();
- services.add(Greeting.class);
- JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", rhinoScript, services, new HashMap<String, Object>(),
- 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);
- }
-}
+package org.apache.tuscany.container.javascript;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+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.ModuleScopeContainer;
+import org.apache.tuscany.test.ArtifactFactory;
+
+/**
+ * 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 {
+ ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ scope.start();
+ List<Class<?>> services = new ArrayList<Class<?>>();
+ services.add(Greeting.class);
+ JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", rhinoScript, services, new HashMap<String, Object>(),
+ 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);
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/ScriptInvokeTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,148 +1,148 @@
-package org.apache.tuscany.container.javascript;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reportMatcher;
-import static org.easymock.EasyMock.verify;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-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.ModuleScopeContainer;
-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.MessageImpl;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.test.ArtifactFactory;
-import org.easymock.IArgumentMatcher;
-
-/**
- * Tests for JavaScript component wiring
- */
-public class WireTestCase extends TestCase {
- private static final Map<String, Object> properties = new HashMap<String, Object>();
-
- 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;
-
- /**
- * Tests a basic invocation down a source wire
- */
- public void testReferenceWireInvocation() throws Exception {
- ModuleScopeContainer scope = new ModuleScopeContainer(null);
- scope.start();
-
- List<Class<?>> services = new ArrayList<Class<?>>();
- services.add(Greeting.class);
- JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass1, services, 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 {
- ModuleScopeContainer scope = new ModuleScopeContainer(null);
- scope.start();
- List<Class<?>> services = new ArrayList<Class<?>>();
- services.add(Greeting.class);
- JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass2, services, properties, null, scope,
- ArtifactFactory.createWireService(), null);
- scope.register(context);
- TargetInvoker invoker = context.createTargetInvoker("greeting", Greeting.class.getMethod("greet", String.class)
- );
- assertEquals("foo", invoker.invokeTarget(new String[] { "foo" }));
- scope.stop();
- }
-
- /**
- * Tests a basic invocation down a target wire
- */
- public void testTargetWireInvocation() throws Exception {
- ModuleScopeContainer scope = new ModuleScopeContainer(null);
- scope.start();
- List<Class<?>> services = new ArrayList<Class<?>>();
- services.add(Greeting.class);
- JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass2, services, properties, null, scope,
- ArtifactFactory.createWireService(), null);
- scope.register(context);
-
- InboundWire<?> wire = ArtifactFactory.createInboundWire("Greeting", Greeting.class);
- ArtifactFactory.terminateWire(wire);
- for (InboundInvocationChain chain : wire.getInvocationChains().values()) {
- chain.setTargetInvoker(context.createTargetInvoker("Greeting", chain.getMethod()));
- }
- context.addInboundWire(wire);
- Greeting greeting = (Greeting) context.getServiceInstance("Greeting");
- assertEquals("foo", greeting.greet("foo"));
- scope.stop();
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- implClass1 = new RhinoScript("script1", SCRIPT);
- implClass2 = new RhinoScript("script2", SCRIPT2);
- }
-}
+package org.apache.tuscany.container.javascript;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reportMatcher;
+import static org.easymock.EasyMock.verify;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.ModuleScopeContainer;
+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.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.test.ArtifactFactory;
+import org.easymock.IArgumentMatcher;
+
+/**
+ * Tests for JavaScript component wiring
+ */
+public class WireTestCase extends TestCase {
+ private static final Map<String, Object> properties = new HashMap<String, Object>();
+
+ 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;
+
+ /**
+ * Tests a basic invocation down a source wire
+ */
+ public void testReferenceWireInvocation() throws Exception {
+ ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ scope.start();
+
+ List<Class<?>> services = new ArrayList<Class<?>>();
+ services.add(Greeting.class);
+ JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass1, services, 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 {
+ ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ scope.start();
+ List<Class<?>> services = new ArrayList<Class<?>>();
+ services.add(Greeting.class);
+ JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass2, services, properties, null, scope,
+ ArtifactFactory.createWireService(), null);
+ scope.register(context);
+ TargetInvoker invoker = context.createTargetInvoker("greeting", Greeting.class.getMethod("greet", String.class)
+ );
+ assertEquals("foo", invoker.invokeTarget(new String[] { "foo" }));
+ scope.stop();
+ }
+
+ /**
+ * Tests a basic invocation down a target wire
+ */
+ public void testTargetWireInvocation() throws Exception {
+ ModuleScopeContainer scope = new ModuleScopeContainer(null);
+ scope.start();
+ List<Class<?>> services = new ArrayList<Class<?>>();
+ services.add(Greeting.class);
+ JavaScriptComponent<Greeting> context = new JavaScriptComponent<Greeting>("source", implClass2, services, properties, null, scope,
+ ArtifactFactory.createWireService(), null);
+ scope.register(context);
+
+ InboundWire<?> wire = ArtifactFactory.createInboundWire("Greeting", Greeting.class);
+ ArtifactFactory.terminateWire(wire);
+ for (InboundInvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(context.createTargetInvoker("Greeting", chain.getMethod()));
+ }
+ context.addInboundWire(wire);
+ Greeting greeting = (Greeting) context.getServiceInstance("Greeting");
+ assertEquals("foo", greeting.greet("foo"));
+ scope.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ implClass1 = new RhinoScript("script1", SCRIPT);
+ implClass2 = new RhinoScript("script2", SCRIPT2);
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/WireTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,51 +1,51 @@
-/**
- *
- * 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.javascript.function;
-
-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 HelloWorldTestCase extends SCATestCase {
-
- private HelloWorldService helloWorldService;
-
- private HelloWorldService introspectableService;
-
- protected void setUp() throws Exception {
- addExtension("JavaScriptContainer", getClass().getClassLoader().getResource("META-INF/sca/default.scdl"));
- setApplicationSCDL("org/apache/tuscany/container/javascript/function/helloworld.scdl");
- super.setUp();
-
- CompositeContext context = CurrentCompositeContext.getContext();
- helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponent");
- introspectableService = context.locateService(HelloWorldService.class, "IntrospectableHelloWorldComponent");
- }
-
- public void testHelloWorld() throws Exception {
- assertEquals(helloWorldService.sayHello("petra"), "Hello petra");
- }
-
- public void testIntrospectedHelloWorld() throws Exception {
- assertEquals(introspectableService.sayHello("petra"), "Hello petra");
- }
-}
+/**
+ *
+ * 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.javascript.function;
+
+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 HelloWorldTestCase extends SCATestCase {
+
+ private HelloWorldService helloWorldService;
+
+ private HelloWorldService introspectableService;
+
+ protected void setUp() throws Exception {
+ addExtension("JavaScriptContainer", getClass().getClassLoader().getResource("META-INF/sca/default.scdl"));
+ setApplicationSCDL("org/apache/tuscany/container/javascript/function/helloworld.scdl");
+ super.setUp();
+
+ CompositeContext context = CurrentCompositeContext.getContext();
+ helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponent");
+ introspectableService = context.locateService(HelloWorldService.class, "IntrospectableHelloWorldComponent");
+ }
+
+ public void testHelloWorld() throws Exception {
+ assertEquals(helloWorldService.sayHello("petra"), "Hello petra");
+ }
+
+ public void testIntrospectedHelloWorld() throws Exception {
+ assertEquals(introspectableService.sayHello("petra"), "Hello petra");
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/function/HelloWorldTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java Fri Aug 11 15:56:46 2006
@@ -1,8 +1,8 @@
-package org.apache.tuscany.container.javascript.mock;
-
-public interface Greeting {
-
- String setWire(Greeting ref);
-
- String greet(String name);
-}
+package org.apache.tuscany.container.javascript.mock;
+
+public interface Greeting {
+
+ String setWire(Greeting ref);
+
+ String greet(String name);
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/mock/Greeting.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java Fri Aug 11 15:56:46 2006
@@ -1,16 +1,16 @@
-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;
- }
-}
+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;
+ }
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/Foo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,170 +1,170 @@
-/*
- * 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.javascript.rhino;
-
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-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");
- 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.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");
- 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());
- }
-
-}
+/*
+ * 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.javascript.rhino;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+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");
+ 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.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");
+ 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());
+ }
+
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoFunctionInvokerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,47 +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.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]));
- }
-
-}
\ No newline at end of file
+/*
+ * 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.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]));
+ }
+
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptInstanceTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java Fri Aug 11 15:56:46 2006
@@ -1,80 +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.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<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
+/*
+ * 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.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<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);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/rhino/RhinoScriptTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.componentType
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.componentType?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.componentType (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.componentType Fri Aug 11 15:56:46 2006
@@ -1,9 +1,9 @@
-<?xml version="1.0" encoding="ASCII"?>
-
-<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
- <service name="HelloWorldService">
- <interface.java interface="helloworld.HelloWorldService"/>
- </service>
-
-</componentType>
\ No newline at end of file
+<?xml version="1.0" encoding="ASCII"?>
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <service name="HelloWorldService">
+ <interface.java interface="helloworld.HelloWorldService"/>
+ </service>
+
+</componentType>
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.componentType
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.js
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.js?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.js (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.js Fri Aug 11 15:56:46 2006
@@ -1,3 +1,3 @@
-function sayHello(s) {
- return "Hello " + s;
-}
+function sayHello(s) {
+ return "Hello " + s;
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/HelloWorld.js
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/IntrospectableHelloWorld.js
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/IntrospectableHelloWorld.js?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/IntrospectableHelloWorld.js (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/IntrospectableHelloWorld.js Fri Aug 11 15:56:46 2006
@@ -1,7 +1,7 @@
-SCA = {
- 'serviceClass' : 'helloworld.HelloWorldService'
-}
-
-function sayHello(s) {
- return "Hello " + s;
-}
+SCA = {
+ 'serviceClass' : 'helloworld.HelloWorldService'
+}
+
+function sayHello(s) {
+ return "Hello " + s;
+}
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/IntrospectableHelloWorld.js
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl?rev=430912&r1=430911&r2=430912&view=diff
==============================================================================
--- incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl (original)
+++ incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl Fri Aug 11 15:56:46 2006
@@ -1,30 +1,30 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- * Copyright (c) 2006 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.
- -->
-<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
- xmlns:js="http://tuscany.apache.org/xmlns/js/1.0"
-
- name="HelloWorldComposite">
-
- <component name="HelloWorldComponent">
- <js:implementation.js script="org/apache/tuscany/container/javascript/function/HelloWorld.js"/>
- </component>
-
- <component name="IntrospectableHelloWorldComponent">
- <js:implementation.js script="org/apache/tuscany/container/javascript/function/IntrospectableHelloWorld.js"/>
- </component>
-
-</composite>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright (c) 2006 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.
+ -->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:js="http://tuscany.apache.org/xmlns/js/1.0"
+
+ name="HelloWorldComposite">
+
+ <component name="HelloWorldComponent">
+ <js:implementation.js script="org/apache/tuscany/container/javascript/function/HelloWorld.js"/>
+ </component>
+
+ <component name="IntrospectableHelloWorldComponent">
+ <js:implementation.js script="org/apache/tuscany/container/javascript/function/IntrospectableHelloWorld.js"/>
+ </component>
+
+</composite>
Propchange: incubator/tuscany/java/sca/containers/container.javascript/src/test/resources/org/apache/tuscany/container/javascript/function/helloworld.scdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/containers/container.spring/.ruleset
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org