diff options
Diffstat (limited to 'sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany')
8 files changed, 650 insertions, 392 deletions
diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java index 61e814b740..b5d5e67b00 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxListener.java @@ -27,39 +27,31 @@ import com.ericsson.otp.erlang.OtpMsg; public class MboxListener implements Runnable { - private static final long TEST_TIMEOUT = 500; - - private OtpMbox mbox; - private OtpMsg msg; - private Object response; - - public MboxListener(OtpMbox mbox, Object response) { - this.mbox = mbox; - this.response = response; - } - - public void run() { - try { - try { - msg = mbox.receiveMsg(TEST_TIMEOUT); - - if (response != null) { - Object[] args = new Object[1]; - args[0] = response; - mbox.send(msg.getSenderPid(), TypeHelpersProxy.toErlang(args)); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } catch (OtpErlangExit e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public OtpMsg getMsg() { - return msg; - } + private OtpMbox mbox; + private OtpMsg msg; + private Object response; + + public MboxListener(OtpMbox mbox, Object response) { + this.mbox = mbox; + this.response = response; + } + + public void run() { + try { + msg = mbox.receiveMsg(); + + if (response != null) { + Object[] args = new Object[1]; + args[0] = response; + mbox.send(msg.getSenderPid(), TypeHelpersProxy.toErlang(args)); + } + } catch (OtpErlangExit e) { + e.printStackTrace(); + } + } + + public OtpMsg getMsg() { + return msg; + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java index ff6f5c3b4f..04adb60adb 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java @@ -24,9 +24,15 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import org.apache.tuscany.sca.binding.erlang.impl.TypeMismatchException; +import org.apache.tuscany.sca.binding.erlang.impl.exceptions.ErlangException; +import org.apache.tuscany.sca.binding.erlang.testing.dynaignore.IgnorableRunner; +import org.apache.tuscany.sca.binding.erlang.testing.dynaignore.IgnoreTest; import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; import com.ericsson.otp.erlang.OtpErlangAtom; import com.ericsson.otp.erlang.OtpErlangDouble; @@ -37,360 +43,439 @@ import com.ericsson.otp.erlang.OtpErlangTuple; import com.ericsson.otp.erlang.OtpMbox; import com.ericsson.otp.erlang.OtpNode; +@RunWith(IgnorableRunner.class) public class ReferenceServiceTestCase { - private static MboxInterface mboxReference; - private static ServiceTestComponent moduleReference; - private static OtpNode node; - private static OtpMbox mbox; - - @BeforeClass - public static void init() throws IOException { - SCADomain domain = SCADomain.newInstance("ErlangReference.composite"); - SCADomain.newInstance("ErlangService.composite"); - ReferenceTestComponentImpl component = domain.getService(ReferenceTestComponentImpl.class, "ReferenceTest"); - mboxReference = component.getMboxReference(); - moduleReference = component.getModuleReference(); - node = new OtpNode("MboxServer"); - mbox = node.createMbox("sendArgs"); - } - - @Test - public void testStrings() throws Exception { - String strArg = "Test message"; - String strResult = "OK"; - MboxListener mboxListener = new MboxListener(mbox, strResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String testResult = mboxReference.sendArgs(strArg); - assertEquals(strArg, ((OtpErlangString)mboxListener.getMsg().getMsg()).stringValue()); - assertEquals(strResult, testResult); - } - - @Test - public void testBooleans() throws Exception { - boolean booleanArg = true; - boolean booleanResult = false; - MboxListener mboxListener = new MboxListener(mbox, booleanResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - boolean testResult = mboxReference.sendArgs(booleanArg); - assertEquals(booleanArg, ((OtpErlangAtom)mboxListener.getMsg().getMsg()).booleanValue()); - assertEquals(booleanResult, testResult); - } - - @Test - public void testFloats() throws Exception { - float floatArg = 1.0f; - float floatResult = 2.0f; - MboxListener mboxListener = new MboxListener(mbox, floatResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - float testResult = mboxReference.sendArgs(floatArg); - assertEquals(floatArg, ((OtpErlangDouble)mboxListener.getMsg().getMsg()).doubleValue(), 0); - assertEquals(floatResult, testResult, 0); - } - - @Test - public void testDoubles() throws Exception { - double doubleArg = 1.0f; - double doubleResult = 2.0f; - MboxListener mboxListener = new MboxListener(mbox, doubleResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - double testResult = mboxReference.sendArgs(doubleArg); - assertEquals(doubleArg, ((OtpErlangDouble)mboxListener.getMsg().getMsg()).doubleValue(), 0); - assertEquals(doubleResult, testResult, 0); - } - - @Test - public void testLongs() throws Exception { - long longArg = 1; - long longResult = 2; - MboxListener mboxListener = new MboxListener(mbox, longResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - long testResult = mboxReference.sendArgs(longArg); - assertEquals(longArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).longValue(), 0); - assertEquals(longResult, testResult, 0); - } - - @Test - public void testInts() throws Exception { - int intArg = 1; - int intResult = 2; - MboxListener mboxListener = new MboxListener(mbox, intResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - int testResult = mboxReference.sendArgs(intArg); - assertEquals(intArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).intValue(), 0); - assertEquals(intResult, testResult, 0); - } - - @Test - public void testChars() throws Exception { - char charArg = 1; - char charResult = 2; - MboxListener mboxListener = new MboxListener(mbox, charResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - char testResult = mboxReference.sendArgs(charArg); - assertEquals(charArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).charValue(), 0); - assertEquals(charResult, testResult, 0); - } - - @Test - public void testShorts() throws Exception { - short shortArg = 1; - short shortResult = 2; - MboxListener mboxListener = new MboxListener(mbox, shortResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - short testResult = mboxReference.sendArgs(shortArg); - assertEquals(shortArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).shortValue(), 0); - assertEquals(shortResult, testResult, 0); - } - - @Test - public void testBytes() throws Exception { - byte byteArg = 1; - byte byteResult = 2; - MboxListener mboxListener = new MboxListener(mbox, byteResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - byte testResult = mboxReference.sendArgs(byteArg); - assertEquals(byteArg, ((OtpErlangLong)mboxListener.getMsg().getMsg()).byteValue(), 0); - assertEquals(byteResult, testResult, 0); - } - - @Test - public void testMultipleArguments() throws Exception { - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String testString = "TupleString"; - int testInt = 10; - mboxReference.sendArgs(testInt, testString); - assertEquals(testInt, ((OtpErlangLong)((OtpErlangTuple)mboxListener.getMsg().getMsg()).elementAt(0)) - .longValue()); - assertEquals(testString, ((OtpErlangString)((OtpErlangTuple)mboxListener.getMsg().getMsg()).elementAt(1)) - .stringValue()); - } - - @Test - public void testTuples() throws Exception { - StructuredTuple tupleResult = new StructuredTuple(); - tupleResult.arg1.arg1 = 1; - tupleResult.arg1.arg2 = "Tuple inside tuple"; - tupleResult.arg2 = "Tuple!"; - tupleResult.arg3 = true; - MboxListener mboxListener = new MboxListener(mbox, tupleResult); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - StructuredTuple testArg = new StructuredTuple(); - testArg.arg2 = "Arg2a"; - testArg.arg3 = true; - testArg.arg1.arg1 = 10; - testArg.arg1.arg2 = "Arg2b"; - StructuredTuple testResult = mboxReference.sendArgs(testArg); - assertEquals(tupleResult, testResult); - OtpErlangTuple received = (OtpErlangTuple)mboxListener.getMsg().getMsg(); - assertEquals(testArg.arg1.arg1, ((OtpErlangLong)((OtpErlangTuple)received.elementAt(0)).elementAt(0)) - .longValue()); - assertEquals(testArg.arg1.arg2, ((OtpErlangString)((OtpErlangTuple)received.elementAt(0)).elementAt(1)) - .stringValue()); - assertEquals(testArg.arg2, ((OtpErlangString)received.elementAt(1)).stringValue()); - assertEquals(testArg.arg3, ((OtpErlangAtom)received.elementAt(2)).booleanValue()); - } - - @Test - public void testLists() throws Exception { - String[] testArg = new String[] {"One", "Two", "Three"}; - MboxListener mboxListener = new MboxListener(mbox, testArg); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String[] testResult = mboxReference.sendArgs(testArg); - assertEquals(testArg.length, testResult.length); - for (int i = 0; i < testArg.length; i++) { - assertEquals(testArg[i], testResult[i]); - } - OtpErlangList received = (OtpErlangList)mboxListener.getMsg().getMsg(); - assertEquals(testArg.length, received.arity()); - for (int i = 0; i < testArg.length; i++) { - assertEquals(testArg[i], ((OtpErlangString)received.elementAt(i)).stringValue()); - } - } - - @Test - public void testMultiDimLists() throws Exception { - String[][] testArg = new String[][] { {"One", "Two"}, {"Three", "Four", "Five"}, {"Six"}}; - MboxListener mboxListener = new MboxListener(mbox, testArg); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - String[][] testResult = mboxReference.sendArgs(testArg); - assertEquals(testArg.length, testResult.length); - for (int i = 0; i < testArg.length; i++) { - for (int j = 0; j < testArg[i].length; j++) { - assertEquals(testArg[i][j], testResult[i][j]); - } - } - OtpErlangList received = (OtpErlangList)mboxListener.getMsg().getMsg(); - assertEquals(testArg.length, received.arity()); - for (int i = 0; i < testArg.length; i++) { - for (int j = 0; j < testArg[i].length; j++) { - assertEquals(testArg[i][j], (((OtpErlangString)((OtpErlangList)received.elementAt(i)).elementAt(j)) - .stringValue())); - } - } - } - - @Test - public void typeMismatch() throws Exception { - try { - StructuredTuple arg = new StructuredTuple(); - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - String[] arg = new String[] {"test"}; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - long arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - int arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - short arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - char arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - byte arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - double arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - float arg = 1; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - String arg = "1"; - MboxListener mboxListener = new MboxListener(mbox, true); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - - try { - boolean arg = true; - MboxListener mboxListener = new MboxListener(mbox, 1); - Thread mboxThread = new Thread(mboxListener); - mboxThread.start(); - mboxReference.sendArgs(arg); - } catch (Exception e) { - assertEquals(TypeMismatchException.class, e.getClass()); - System.out.println(e.getMessage()); - } - } - - @Test - public void testRPC() throws Exception { - String[] result = moduleReference.sayHellos(); - assertEquals(2, result.length); - assertEquals("1", result[0]); - assertEquals("2", result[1]); - } - - @Test - public void testRPCWithArgs() throws Exception { - String arg1 = "One"; - String arg2 = "Two"; - String testResult = moduleReference.sayHello(arg1, arg2); - assertEquals("Hello " + arg1 + " " + arg2, testResult); - } - - @Test - public void testRPCWithComplexArgs() throws Exception { - StructuredTuple arg = new StructuredTuple(); - arg.arg1.arg2 = "Not empty"; - arg.arg2 = "Not empty"; - StructuredTuple testResult = moduleReference.passComplexArgs(arg, new String[]{"some", "array"}); - assertEquals(arg, testResult); - } + private static final String EPMD_COMMAND = "epmd"; + + private static MboxInterface mboxReference; + private static ServiceInterface moduleReference; + private static OtpNode node; + private static OtpMbox mbox; + private static Process epmdProcess; + + @BeforeClass + public static void init() throws IOException { + try { + epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); + SCADomain domain = SCADomain + .newInstance("ErlangReference.composite"); + SCADomain.newInstance("ErlangService.composite"); + ReferenceTestComponentImpl component = domain.getService( + ReferenceTestComponentImpl.class, "ReferenceTest"); + mboxReference = component.getMboxReference(); + moduleReference = component.getModuleReference(); + node = new OtpNode("MboxServer"); + mbox = node.createMbox("sendArgs"); + } catch (IOException e) { + System.out.println("Problem executing " + EPMD_COMMAND + ": " + + e.getLocalizedMessage() + ". Tests will be IGNORED."); + } + } + + @AfterClass + public static void clean() { + if (epmdProcess != null) { + epmdProcess.destroy(); + } + } + + @Before + public void before() { + if (epmdProcess == null) { + throw new IgnoreTest(); + } + } + + @Test(timeout = 1000) + public void testStrings() throws Exception { + String strArg = "Test message"; + String strResult = "OK"; + MboxListener mboxListener = new MboxListener(mbox, strResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String testResult = mboxReference.sendArgs(strArg); + assertEquals(strArg, ((OtpErlangString) mboxListener.getMsg().getMsg()) + .stringValue()); + assertEquals(strResult, testResult); + } + + @Test(timeout = 1000) + public void testBooleans() throws Exception { + boolean booleanArg = true; + boolean booleanResult = false; + MboxListener mboxListener = new MboxListener(mbox, booleanResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + boolean testResult = mboxReference.sendArgs(booleanArg); + assertEquals(booleanArg, ((OtpErlangAtom) mboxListener.getMsg() + .getMsg()).booleanValue()); + assertEquals(booleanResult, testResult); + } + + @Test(timeout = 1000) + public void testFloats() throws Exception { + float floatArg = 1.0f; + float floatResult = 2.0f; + MboxListener mboxListener = new MboxListener(mbox, floatResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + float testResult = mboxReference.sendArgs(floatArg); + assertEquals(floatArg, ((OtpErlangDouble) mboxListener.getMsg() + .getMsg()).doubleValue(), 0); + assertEquals(floatResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testDoubles() throws Exception { + double doubleArg = 1.0f; + double doubleResult = 2.0f; + MboxListener mboxListener = new MboxListener(mbox, doubleResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + double testResult = mboxReference.sendArgs(doubleArg); + assertEquals(doubleArg, ((OtpErlangDouble) mboxListener.getMsg() + .getMsg()).doubleValue(), 0); + assertEquals(doubleResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testLongs() throws Exception { + long longArg = 1; + long longResult = 2; + MboxListener mboxListener = new MboxListener(mbox, longResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + long testResult = mboxReference.sendArgs(longArg); + assertEquals(longArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .longValue(), 0); + assertEquals(longResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testInts() throws Exception { + int intArg = 1; + int intResult = 2; + MboxListener mboxListener = new MboxListener(mbox, intResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + int testResult = mboxReference.sendArgs(intArg); + assertEquals(intArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .intValue(), 0); + assertEquals(intResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testChars() throws Exception { + char charArg = 1; + char charResult = 2; + MboxListener mboxListener = new MboxListener(mbox, charResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + char testResult = mboxReference.sendArgs(charArg); + assertEquals(charArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .charValue(), 0); + assertEquals(charResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testShorts() throws Exception { + short shortArg = 1; + short shortResult = 2; + MboxListener mboxListener = new MboxListener(mbox, shortResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + short testResult = mboxReference.sendArgs(shortArg); + assertEquals(shortArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .shortValue(), 0); + assertEquals(shortResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testBytes() throws Exception { + byte byteArg = 1; + byte byteResult = 2; + MboxListener mboxListener = new MboxListener(mbox, byteResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + byte testResult = mboxReference.sendArgs(byteArg); + assertEquals(byteArg, ((OtpErlangLong) mboxListener.getMsg().getMsg()) + .byteValue(), 0); + assertEquals(byteResult, testResult, 0); + } + + @Test(timeout = 1000) + public void testMultipleArguments() throws Exception { + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String testString = "TupleString"; + int testInt = 10; + mboxReference.sendArgs(testInt, testString); + assertEquals(testInt, ((OtpErlangLong) ((OtpErlangTuple) mboxListener + .getMsg().getMsg()).elementAt(0)).longValue()); + assertEquals(testString, + ((OtpErlangString) ((OtpErlangTuple) mboxListener.getMsg() + .getMsg()).elementAt(1)).stringValue()); + } + + @Test(timeout = 1000) + public void testTuples() throws Exception { + StructuredTuple tupleResult = new StructuredTuple(); + tupleResult.arg1.arg1 = 1; + tupleResult.arg1.arg2 = "Tuple inside tuple"; + tupleResult.arg2 = "Tuple!"; + tupleResult.arg3 = true; + MboxListener mboxListener = new MboxListener(mbox, tupleResult); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + StructuredTuple testArg = new StructuredTuple(); + testArg.arg2 = "Arg2a"; + testArg.arg3 = true; + testArg.arg1.arg1 = 10; + testArg.arg1.arg2 = "Arg2b"; + StructuredTuple testResult = mboxReference.sendArgs(testArg); + assertEquals(tupleResult, testResult); + OtpErlangTuple received = (OtpErlangTuple) mboxListener.getMsg() + .getMsg(); + assertEquals(testArg.arg1.arg1, + ((OtpErlangLong) ((OtpErlangTuple) received.elementAt(0)) + .elementAt(0)).longValue()); + assertEquals(testArg.arg1.arg2, + ((OtpErlangString) ((OtpErlangTuple) received.elementAt(0)) + .elementAt(1)).stringValue()); + assertEquals(testArg.arg2, ((OtpErlangString) received.elementAt(1)) + .stringValue()); + assertEquals(testArg.arg3, ((OtpErlangAtom) received.elementAt(2)) + .booleanValue()); + } + + @Test(timeout = 1000) + public void testLists() throws Exception { + String[] testArg = new String[] { "One", "Two", "Three" }; + MboxListener mboxListener = new MboxListener(mbox, testArg); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[] testResult = mboxReference.sendArgs(testArg); + assertEquals(testArg.length, testResult.length); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], testResult[i]); + } + OtpErlangList received = (OtpErlangList) mboxListener.getMsg().getMsg(); + assertEquals(testArg.length, received.arity()); + for (int i = 0; i < testArg.length; i++) { + assertEquals(testArg[i], ((OtpErlangString) received.elementAt(i)) + .stringValue()); + } + } + + @Test(timeout = 1000) + public void testMultiDimLists() throws Exception { + String[][] testArg = new String[][] { { "One", "Two" }, + { "Three", "Four", "Five" }, { "Six" } }; + MboxListener mboxListener = new MboxListener(mbox, testArg); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + String[][] testResult = mboxReference.sendArgs(testArg); + assertEquals(testArg.length, testResult.length); + for (int i = 0; i < testArg.length; i++) { + for (int j = 0; j < testArg[i].length; j++) { + assertEquals(testArg[i][j], testResult[i][j]); + } + } + OtpErlangList received = (OtpErlangList) mboxListener.getMsg().getMsg(); + assertEquals(testArg.length, received.arity()); + for (int i = 0; i < testArg.length; i++) { + for (int j = 0; j < testArg[i].length; j++) { + assertEquals(testArg[i][j], + (((OtpErlangString) ((OtpErlangList) received + .elementAt(i)).elementAt(j)).stringValue())); + } + } + } + + @Test(timeout = 1000) + public void typeMismatch() throws Exception { + try { + StructuredTuple arg = new StructuredTuple(); + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + String[] arg = new String[] { "test" }; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + long arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + int arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + short arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + char arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + byte arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + double arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + float arg = 1; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + String arg = "1"; + MboxListener mboxListener = new MboxListener(mbox, true); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + + try { + boolean arg = true; + MboxListener mboxListener = new MboxListener(mbox, 1); + Thread mboxThread = new Thread(mboxListener); + mboxThread.start(); + mboxReference.sendArgs(arg); + } catch (Exception e) { + assertEquals(TypeMismatchException.class, e.getClass()); + System.out.println(e.getMessage()); + } + } + + @Test(timeout = 1000) + public void testRPC() throws Exception { + String[] result = moduleReference.sayHellos(); + assertEquals(2, result.length); + assertEquals("1", result[0]); + assertEquals("2", result[1]); + } + + @Test(timeout = 1000) + public void testRPCWithArgs() throws Exception { + String arg1 = "One"; + String arg2 = "Two"; + String testResult = moduleReference.sayHello(arg1, arg2); + assertEquals("Hello " + arg1 + " " + arg2, testResult); + } + + @Test(timeout = 1000) + public void testRPCWithComplexArgs() throws Exception { + StructuredTuple arg = new StructuredTuple(); + arg.arg1.arg2 = "Not empty"; + arg.arg2 = "Not empty"; + StructuredTuple testResult = moduleReference.passComplexArgs(arg, + new String[] { "some", "array" }); + assertEquals(arg, testResult); + } + + @Test(timeout = 1000) + public void testUnknownFunction() throws Exception { + + //following functions differs by parameters + + try { + moduleReference.sayHello(); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + try { + moduleReference.sayHello("1"); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + try { + moduleReference.sayHello(1, 2); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + + //for following ones name not exists + + moduleReference.notExist(); + + try { + moduleReference.notExistWithException(); + } catch (Exception e) { + assertEquals(ErlangException.class, e.getClass()); + } + } } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java index 49a06a9256..f9f9a99054 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceTestComponentImpl.java @@ -5,7 +5,7 @@ import org.osoa.sca.annotations.Reference; public class ReferenceTestComponentImpl implements ReferenceTestComponent { private MboxInterface mboxReference; - private ServiceTestComponent moduleReference; + private ServiceInterface moduleReference; @Reference public void setMboxReference(MboxInterface mboxReference) { @@ -13,7 +13,7 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent { } @Reference - public void setModuleReference(ServiceTestComponent moduleReference) { + public void setModuleReference(ServiceInterface moduleReference) { this.moduleReference = moduleReference; } @@ -21,7 +21,7 @@ public class ReferenceTestComponentImpl implements ReferenceTestComponent { return mboxReference; } - public ServiceTestComponent getModuleReference() { + public ServiceInterface getModuleReference() { return moduleReference; } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java new file mode 100644 index 0000000000..33afcfb53d --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java @@ -0,0 +1,20 @@ +package org.apache.tuscany.sca.binding.erlang.testing; + +public interface ServiceInterface { + + String sayHello(String arg1, String arg2); + + String[] sayHellos() throws Exception; + + StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); + + String sayHello() throws Exception; + + String sayHello(String arg) throws Exception; + + String sayHello(int arg1, int arg2); + + void notExistWithException() throws Exception; + + void notExist(); +} diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java index f286627192..f5c03ef281 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java @@ -4,7 +4,7 @@ public interface ServiceTestComponent { String sayHello(String arg1, String arg2); - String[] sayHellos(); + String[] sayHellos() throws Exception; StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2); diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java index 11b7ace284..4d79005938 100644 --- a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java @@ -16,5 +16,4 @@ public class ServiceTestComponentImpl implements ServiceTestComponent { return arg1; } - } diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java new file mode 100644 index 0000000000..81a17ff9dd --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnorableRunner.java @@ -0,0 +1,136 @@ +/* + * 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.sca.binding.erlang.testing.dynaignore; + +import org.junit.runner.Description; +import org.junit.runner.Result; +import org.junit.runner.Runner; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; +import org.junit.runner.notification.RunNotifier; +import org.junit.runner.notification.StoppedByUserException; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +public class IgnorableRunner extends Runner { + + private static final class Notifier extends RunNotifier { + private final RunNotifier notifier; + + public Notifier(final RunNotifier notifier) { + this.notifier = notifier; + } + + public void addFirstListener(final RunListener listener) { + notifier.addFirstListener(listener); + } + + public void addListener(final RunListener listener) { + notifier.addListener(listener); + } + + @Override + public boolean equals(final Object obj) { + return notifier.equals(obj); + } + + @Override + public void fireTestFailure(final Failure failure) { + if (failure.getException().getClass() == IgnoreTest.class) { + notifier.fireTestIgnored(failure.getDescription()); + } else { + notifier.fireTestFailure(failure); + } + } + + @Override + public void fireTestFinished(final Description description) { + notifier.fireTestFinished(description); + } + + @Override + public void fireTestIgnored(final Description description) { + notifier.fireTestIgnored(description); + } + + @Override + public void fireTestRunFinished(final Result result) { + notifier.fireTestRunFinished(result); + } + + @Override + public void fireTestRunStarted(final Description description) { + notifier.fireTestRunStarted(description); + } + + @Override + public void fireTestStarted(final Description description) + throws StoppedByUserException { + notifier.fireTestStarted(description); + } + + @Override + public int hashCode() { + return notifier.hashCode(); + } + + @Override + public void pleaseStop() { + notifier.pleaseStop(); + } + + @Override + public void removeListener(final RunListener listener) { + notifier.removeListener(listener); + } + + public void testAborted(final Description description, + final Throwable cause) { + ((Notifier) notifier).testAborted(description, cause); + } + + @Override + public String toString() { + return notifier.toString(); + } + + } + + Runner runner = null; + + public IgnorableRunner(Class<?> testClass) { + try { + runner = new BlockJUnit4ClassRunner(testClass); + } catch (InitializationError e) { + e.printStackTrace(); + } + } + + @Override + public Description getDescription() { + return runner.getDescription(); + } + + @Override + public void run(RunNotifier notifier) { + runner.run(new Notifier(notifier)); + } + +} diff --git a/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java new file mode 100644 index 0000000000..9a8372051c --- /dev/null +++ b/sandbox/wjaniszewski/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/dynaignore/IgnoreTest.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.erlang.testing.dynaignore; + +public final class IgnoreTest extends Error { + + private static final long serialVersionUID = 1L; + +} |