diff options
Diffstat (limited to 'sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTestCase.java')
-rw-r--r-- | sandbox/ant/container.python/src/test/java/org/apache/tuscany/container/python/PythonComponentTestCase.java | 94 |
1 files changed, 94 insertions, 0 deletions
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; + } +} |