summaryrefslogtreecommitdiffstats
path: root/sandbox/ant/container.python/src/test/java/org
diff options
context:
space:
mode:
authordims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
committerdims <dims@13f79535-47bb-0310-9956-ffa450edef68>2008-06-17 00:23:01 +0000
commitbdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch)
tree38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/ant/container.python/src/test/java/org
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/ant/container.python/src/test/java/org')
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/HelloWorldService.java25
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentBuilderTestCase.java23
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTestCase.java94
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeLoaderTestCase.java87
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeTestCase.java36
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationLoaderTestCase.java110
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationTestCase.java33
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonInvokerTestCase.java62
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonScriptTestCase.java82
-rw-r--r--sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/function/HelloWorldTestCase.java46
10 files changed, 598 insertions, 0 deletions
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/HelloWorldService.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/HelloWorldService.java
new file mode 100644
index 0000000000..50ba1c3695
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/HelloWorldService.java
@@ -0,0 +1,25 @@
+/*
+ * 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.python;
+
+public interface HelloWorldService {
+
+ String sayHello(String s);
+
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentBuilderTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentBuilderTestCase.java
new file mode 100644
index 0000000000..86e77920dc
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentBuilderTestCase.java
@@ -0,0 +1,23 @@
+package org.apache.tuscany.container.python;
+
+import junit.framework.TestCase;
+
+public class PythonComponentBuilderTestCase extends TestCase {
+
+ public void testGetImplementationType() {
+ PythonComponentBuilder builder = new PythonComponentBuilder();
+ assertEquals(PythonImplementation.class, builder.getImplementationType());
+ }
+
+ public void testBuild() {
+// PythonComponentBuilder builder = new PythonComponentBuilder();
+// CompositeComponent parent = createMock(CompositeComponent.class);
+// Component component = builder.build(parent, componentDefinition, deploymentContext);
+// assertNotNull(component);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTestCase.java
new file mode 100644
index 0000000000..3a1f6081ba
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTestCase.java
@@ -0,0 +1,94 @@
+package org.apache.tuscany.container.python;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.easymock.IAnswer;
+
+public class PythonComponentTestCase extends TestCase {
+
+ private ScopeContainer scopeContainer;
+
+ @SuppressWarnings("unchecked")
+ public void testCreateTargetInvoker() {
+ PythonComponent pc = new PythonComponent(null,null,null, null, scopeContainer, null, null);
+
+ Operation operation = new Operation("hashCode", null,null,null,false,null);
+ ServiceContract contract = new ServiceContract(List.class){};
+ operation.setServiceContract(contract);
+ TargetInvoker invoker = pc.createTargetInvoker("hashCode", operation);
+
+ assertNotNull(invoker);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testCreateInstance() throws IOException {
+ PythonComponent pc = new PythonComponent(null,createPythonScript(),null, null, scopeContainer, null, null);
+ Object o = pc.createInstance();
+ assertNotNull(o);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetServiceInstance() {
+ PythonComponent pc = new PythonComponent(null,null,null, null, scopeContainer, null, null);
+ try {
+ pc.getServiceInstance();
+ fail();
+ } catch (TargetException e) {
+ // expected
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetproperties() {
+ PythonComponent pc = new PythonComponent(null,null,null, null, scopeContainer, null, null);
+ assertNotNull(pc.getProperties());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetServiceInterfaces() {
+ List services = new ArrayList();
+ PythonComponent pc = new PythonComponent(null,null,services, null, scopeContainer, null,null);
+ assertEquals(services, pc.getServiceInterfaces());
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() {
+ this.scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+ }
+
+ public PythonScript createPythonScript() throws IOException {
+ URL scriptURL = getClass().getResource("PythonScriptTestCase.py");
+ InputStream is = scriptURL.openStream();
+ StringBuilder sb = new StringBuilder();
+ int i = 0;
+ while ((i = is.read()) != -1) {
+ sb.append((char) i);
+ }
+ is.close();
+ String script = sb.toString();
+ PythonScript pythonScript = new PythonScript("PythonScriptTestCase", "hello", script, null);
+ pythonScript.setServiceInterface(HelloWorldService.class);
+ return pythonScript;
+ }
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeLoaderTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeLoaderTestCase.java
new file mode 100644
index 0000000000..73a6e9b849
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeLoaderTestCase.java
@@ -0,0 +1,87 @@
+/*
+ * 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.python;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+/**
+ *
+ */
+public class PythonComponentTypeLoaderTestCase extends TestCase {
+
+ private String script;
+
+ public void testGetSideFileName() {
+ PythonScript pythonScript = new PythonScript("PythonScriptTestCase", "hello", script, null);
+ PythonComponentTypeLoader loader = new PythonComponentTypeLoader();
+ PythonImplementation implementation = new PythonImplementation();
+ implementation.setPythonScript(pythonScript);
+ assertEquals("PythonScriptTestCase.componentType", loader.getSideFileName(implementation));
+ }
+
+ public void testLoadFromSideFile() throws MalformedURLException, LoaderException, XMLStreamException {
+// PythonComponentTypeLoader loader = new PythonComponentTypeLoader();
+// LoaderRegistry loaderRegistry = createMock(LoaderRegistry.class);
+// expect(loaderRegistry.load(isA(CompositeComponent.class),isA(URL.class),isA(Class.class),isA(DeploymentContext.class))).andStubAnswer(new IAnswer() {
+// public Object answer() throws Throwable {
+// return new ComponentType();
+// }
+// });
+// loader.setLoaderRegistry(loaderRegistry);
+//
+// URL url = new URL("http://foo");
+// DeploymentContext deploymentContext = createMock(DeploymentContext.class);
+// loader.loadFromSidefile(url, deploymentContext);
+ }
+
+ public void testGetImplementationClass() {
+ PythonComponentTypeLoader loader = new PythonComponentTypeLoader();
+ assertEquals(PythonImplementation.class, loader.getImplementationClass());
+ }
+
+ public void testGetResourceName() {
+ PythonComponentTypeLoader loader = new PythonComponentTypeLoader();
+ PythonImplementation implementation = new PythonImplementation();
+ PythonScript pythonScript = new PythonScript("PythonScriptTestCase", "hello", script, null);
+ implementation.setPythonScript(pythonScript);
+ assertEquals("PythonScriptTestCase", loader.getResourceName(implementation));
+ }
+
+ @Override
+ public void setUp() throws IOException {
+ URL scriptURL = getClass().getResource("PythonScriptTestCase.py");
+ InputStream is = scriptURL.openStream();
+ StringBuilder sb = new StringBuilder();
+ int i = 0;
+ while ((i = is.read()) != -1) {
+ sb.append((char) i);
+ }
+ is.close();
+ script = sb.toString();
+ }
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeTestCase.java
new file mode 100644
index 0000000000..3ae4b73e60
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTypeTestCase.java
@@ -0,0 +1,36 @@
+package org.apache.tuscany.container.python;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+public class PythonComponentTypeTestCase extends TestCase {
+
+ public void testLifecycleScope() {
+ PythonComponentType ct = new PythonComponentType();
+ assertEquals(Scope.MODULE, ct.getLifecycleScope());
+ ct.setLifecycleScope(Scope.COMPOSITE);
+ assertEquals(Scope.COMPOSITE, ct.getLifecycleScope());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testComponentTypeConstructor() {
+ ComponentType ct = new ComponentType();
+ Property property = new Property();
+ ct.add(property);
+ ReferenceDefinition reference = new ReferenceDefinition();
+ ct.add(reference);
+ ServiceDefinition service = new ServiceDefinition();
+ ct.add(service);
+
+ PythonComponentType pct = new PythonComponentType(ct);
+
+ assertEquals(property, pct.getProperties().values().iterator().next());
+ assertEquals(reference, pct.getReferences().values().iterator().next());
+ assertEquals(service, pct.getServices().values().iterator().next());
+ }
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationLoaderTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationLoaderTestCase.java
new file mode 100644
index 0000000000..f84d217334
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationLoaderTestCase.java
@@ -0,0 +1,110 @@
+/*
+ * 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.python;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+
+/**
+ *
+ */
+public class PythonImplementationLoaderTestCase extends TestCase {
+ private CompositeComponent parent;
+
+ private XMLStreamReader reader;
+
+ private DeploymentContext deploymentContext;
+
+ private ClassLoader classLoader;
+
+ private LoaderRegistry registry;
+
+ private PythonImplementationLoader loader;
+
+ public void testNoModuleAttribute() throws LoaderException, XMLStreamException {
+ expect(reader.getAttributeValue(null, "module")).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, "module")).andReturn("foo.py");
+ expect(reader.getAttributeValue(null, "class")).andReturn(null);
+ expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ expect(deploymentContext.getClassLoader()).andReturn(classLoader);
+
+ replay(reader);
+ replay(deploymentContext);
+
+ PythonImplementationLoader mockLoader = new PythonImplementationLoader(registry) {
+ protected String loadSource(ClassLoader cl, String resource) throws LoaderException {
+ assertSame(classLoader, cl);
+ assertEquals("foo.py", resource);
+ throw new MissingResourceException(resource);
+ }
+ };
+ try {
+ mockLoader.load(parent, reader, deploymentContext);
+ fail();
+ } catch (MissingResourceException e) {
+ assertEquals("foo.py", e.getMessage());
+ }
+ verify(reader);
+ verify(deploymentContext);
+ }
+
+ public void testLoadScript() throws LoaderException {
+ String script = loader.loadSource(getClass().getClassLoader(), "org/apache/tuscany/container/python/PythonScriptTestCase.py");
+ assertTrue(script.startsWith("from org.apache.tuscany.container.python"));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ loader = new PythonImplementationLoader(registry);
+
+ parent = createMock(CompositeComponent.class);
+ reader = createMock(XMLStreamReader.class);
+ deploymentContext = createMock(DeploymentContext.class);
+ classLoader = createMock(ClassLoader.class);
+ }
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationTestCase.java
new file mode 100644
index 0000000000..a2af619795
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonImplementationTestCase.java
@@ -0,0 +1,33 @@
+package org.apache.tuscany.container.python;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class PythonImplementationTestCase extends TestCase {
+
+ private PythonScript pythonScript;
+
+ public void testGetPythonScript() {
+ PythonImplementation impl = new PythonImplementation();
+ impl.setPythonScript(pythonScript);
+ assertEquals(pythonScript, impl.getJythonScript());
+ }
+
+ public void setUp() throws IOException {
+ URL scriptURL = getClass().getResource("PythonScriptTestCase.py");
+ assert scriptURL != null;
+ InputStream is = scriptURL.openStream();
+ StringBuilder sb = new StringBuilder();
+ int i = 0;
+ while ((i = is.read()) != -1) {
+ sb.append((char) i);
+ }
+ is.close();
+ String script = sb.toString();
+ pythonScript = new PythonScript("PythonScriptTestCase", "hello", script, null);
+ }
+
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonInvokerTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonInvokerTestCase.java
new file mode 100644
index 0000000000..03a9151a47
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonInvokerTestCase.java
@@ -0,0 +1,62 @@
+package org.apache.tuscany.container.python;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.model.Scope;
+import org.easymock.IAnswer;
+
+public class PythonInvokerTestCase extends TestCase {
+
+ private PythonComponent context;
+
+ private Method method;
+
+ private ScopeContainer scopeContainer;
+
+ public void testInvokeTarget() throws InvocationTargetException {
+ PythonInvoker invoker = new PythonInvoker(method, context);
+ Object o = invoker.invokeTarget(new Object[] { "petra" });
+ assertEquals("hello petra", o);
+ }
+
+ public void testInvokeTargetException() throws InvocationTargetException, SecurityException, NoSuchMethodException {
+ PythonInvoker invoker = new PythonInvoker(method, context);
+ try {
+ invoker.invokeTarget(null);
+ fail();
+ } catch (InvocationTargetException e) {
+ // expected
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ scopeContainer = createMock(ScopeContainer.class);
+ expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return "hello ";
+ }
+ });
+ expect(scopeContainer.getScope()).andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return Scope.MODULE;
+ }
+ });
+ replay(scopeContainer);
+
+ context = new PythonComponent(null, null, null, null, scopeContainer, null, null);
+ method = String.class.getDeclaredMethod("concat", new Class[] { String.class });
+ }
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonScriptTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonScriptTestCase.java
new file mode 100644
index 0000000000..560b623e9a
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonScriptTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * 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.python;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class PythonScriptTestCase extends TestCase {
+
+ protected String script;
+
+ public void testCreateInstance() {
+ PythonScript pythonScript = new PythonScript("PythonScriptTestCase", "hello", script, null);
+ pythonScript.setServiceInterface(HelloWorldService.class);
+ HelloWorldService helloworld = (HelloWorldService) pythonScript.createInstance(null);
+
+ assertEquals("Hello petra", helloworld.sayHello("petra"));
+ }
+
+ public void testCreateInstanceBadIface() {
+ PythonScript pythonScript = new PythonScript("PythonScriptTestCase", "hello", script, null);
+ pythonScript.setServiceInterface(String.class);
+ try {
+ pythonScript.createInstance(null);
+ fail();
+ } catch (RuntimeException e) {
+ // expected
+ }
+ }
+
+ public void testCreateInstanceBadClassName() {
+ PythonScript pythonScript = new PythonScript("PythonScriptTestCase", "badClass", script, null);
+ pythonScript.setServiceInterface(String.class);
+ try {
+ pythonScript.createInstance(null);
+ assertTrue("expecting bad class exception", false);
+ } catch (RuntimeException e) {
+ // expected
+ }
+ }
+
+ public void testGetters() {
+ PythonScript pythonScript = new PythonScript("PythonScriptTestCase", "hello", script, null);
+ assertEquals(null, pythonScript.getClassLoader());
+ assertEquals("hello", pythonScript.getClassName());
+ assertEquals(script, pythonScript.getScript());
+ }
+
+ @Override
+ public void setUp() throws IOException {
+ URL scriptURL = getClass().getResource("PythonScriptTestCase.py");
+ InputStream is = scriptURL.openStream();
+ StringBuilder sb = new StringBuilder();
+ int i = 0;
+ while ((i = is.read()) != -1) {
+ sb.append((char) i);
+ }
+ is.close();
+ script = sb.toString();
+
+ }
+
+}
diff --git a/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/function/HelloWorldTestCase.java b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/function/HelloWorldTestCase.java
new file mode 100644
index 0000000000..38f15adafd
--- /dev/null
+++ b/sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/function/HelloWorldTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.container.python.function;
+
+
+import org.apache.tuscany.container.python.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;
+
+ protected void setUp() throws Exception {
+ addExtension("PythonContainer", getClass().getClassLoader().getResource("META-INF/sca/py.system.scdl"));
+ setApplicationSCDL("org/apache/tuscany/container/python/function/helloworld.scdl");
+ super.setUp();
+
+ CompositeContext context = CurrentCompositeContext.getContext();
+ helloWorldService = context.locateService(HelloWorldService.class, "HelloWorldComponent");
+ }
+
+ public void testHelloWorld() throws Exception {
+ assertEquals(helloWorldService.sayHello("petra"), "Hello petra");
+ }
+}