From f394abe6a74b4c2b0ffb904e585f8066f6456835 Mon Sep 17 00:00:00 2001 From: rfeng Date: Sat, 28 Jun 2008 16:54:56 +0000 Subject: Clean up the test case to use the embedded tnameserv for testing git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@672548 13f79535-47bb-0310-9956-ffa450edef68 --- java/sca/modules/binding-corba-runtime/pom.xml | 11 ++- .../corba/testing/CorbaServantTestCase.java | 66 +++++++++++---- .../binding/corba/testing/CorbaTypesTestCase.java | 96 ++++++++++++++++------ .../sca/binding/corba/testing/TestConstants.java | 3 +- 4 files changed, 134 insertions(+), 42 deletions(-) (limited to 'java/sca/modules') diff --git a/java/sca/modules/binding-corba-runtime/pom.xml b/java/sca/modules/binding-corba-runtime/pom.xml index 5bdeb4d9c2..a54ddc1444 100644 --- a/java/sca/modules/binding-corba-runtime/pom.xml +++ b/java/sca/modules/binding-corba-runtime/pom.xml @@ -34,12 +34,19 @@ tuscany-binding-corba 1.4-SNAPSHOT - + org.apache.tuscany.sca tuscany-host-corba 1.4-SNAPSHOT - + + + + org.apache.tuscany.sca + tuscany-host-corba-jdk + 1.4-SNAPSHOT + test + cglib diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java index 2b269c94e9..796047a8b4 100644 --- a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java +++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java @@ -19,12 +19,14 @@ package org.apache.tuscany.sca.binding.corba.testing; +import static junit.framework.Assert.fail; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.IOException; import java.lang.reflect.Array; +import junit.framework.Assert; + import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException; import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; @@ -55,6 +57,9 @@ import org.apache.tuscany.sca.binding.corba.testing.servants.NonCorbaServant; import org.apache.tuscany.sca.binding.corba.testing.servants.PrimitivesSetterServant; import org.apache.tuscany.sca.binding.corba.testing.servants.TestObjectServant; import org.apache.tuscany.sca.binding.corba.testing.service.mocks.TestRuntimeComponentService; +import org.apache.tuscany.sca.host.corba.naming.TransientNameServer; +import org.apache.tuscany.sca.host.corba.naming.TransientNameService; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.omg.CORBA.BAD_OPERATION; @@ -64,7 +69,7 @@ import org.omg.CosNaming.NameComponent; import org.omg.CosNaming.NamingContext; import org.omg.CosNaming.NamingContextHelper; -public class CorbaServantTestCase { +public class CorbaServantTestCase { private static Process process; private static ORB orb; @@ -72,9 +77,9 @@ public class CorbaServantTestCase { /** * Spawns tnamserv an initiates ORB */ - @BeforeClass + // @BeforeClass public static void setUp() throws IOException { - String[] args = {"-ORBInitialPort", "" + TestConstants.ORB_INITIAL_PORT}; + String[] args = {"-ORBInitialPort", "" + TestConstants.DEFAULT_PORT}; process = Runtime.getRuntime().exec("tnameserv " + args[0] + " " + args[1]); try { // let the tnameserv have time to start @@ -88,7 +93,7 @@ public class CorbaServantTestCase { /** * Kills tnameserv */ - @BeforeClass + // @BeforeClass public static void tearDown() { try { if (process != null) { @@ -101,6 +106,30 @@ public class CorbaServantTestCase { } } + private static TransientNameServer server; + + @BeforeClass + public static void start() { + try { + server = + new TransientNameServer(TestConstants.DEFAULT_HOST, TestConstants.DEFAULT_PORT, + TransientNameService.DEFAULT_SERVICE_NAME); + Thread t = server.start(); + if (t == null) { + Assert.fail("The naming server cannot be started"); + } + orb = server.getORB(); + } catch (Throwable e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + } + + @AfterClass + public static void stop() { + server.stop(); + } + /** * Binds servant implementation to name */ @@ -139,7 +168,8 @@ public class CorbaServantTestCase { /** * Tests primitives (arguments, return types) */ - @Test public void test_primitivesSetter() { + @Test + public void test_primitivesSetter() { try { PrimitivesSetter primitivesSetter = new PrimitivesSetterServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(primitivesSetter); @@ -187,7 +217,8 @@ public class CorbaServantTestCase { /** * Tests arrays (arguments, return types) */ - @Test public void test_arraysSetter() { + @Test + public void test_arraysSetter() { try { ArraysSetter arraysSetter = new ArraysSetterServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(arraysSetter); @@ -243,7 +274,8 @@ public class CorbaServantTestCase { /** * Tests structures (arguments, return types) */ - @Test public void test_TestObject_setStruct() { + @Test + public void test_TestObject_setStruct() { try { TestObject to = new TestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(to); @@ -277,7 +309,8 @@ public class CorbaServantTestCase { /** * Tests handling BAD_OPERATION system exception */ - @Test public void test_systemException_BAD_OPERATION() { + @Test + public void test_systemException_BAD_OPERATION() { try { TestObjectServant tos = new TestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(tos); @@ -324,7 +357,8 @@ public class CorbaServantTestCase { /** * Tests handling user exceptions */ - @Test public void test_userExceptions() { + @Test + public void test_userExceptions() { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); @@ -367,7 +401,8 @@ public class CorbaServantTestCase { /** * Tests enums (arguments, return types) */ - @Test public void test_enums() { + @Test + public void test_enums() { try { EnumManagerServant ems = new EnumManagerServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ems); @@ -384,7 +419,8 @@ public class CorbaServantTestCase { } } - @Test public void test_nonCorbaServants() { + @Test + public void test_nonCorbaServants() { try { NonCorbaServant ncs = new NonCorbaServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ncs); @@ -424,7 +460,8 @@ public class CorbaServantTestCase { /** * Tests handling BAD_PARAM system exception */ - @Test public void test_systemException_BAD_PARAM() { + @Test + public void test_systemException_BAD_PARAM() { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); @@ -450,7 +487,8 @@ public class CorbaServantTestCase { /** * Tests handling BAD_PARAM system exception */ - @Test public void test_invalidServantConfiguraion() { + @Test + public void test_invalidServantConfiguraion() { try { InvalidTypesServant its = new InvalidTypesServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(its); diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java index 150115517b..0aa9f858d3 100644 --- a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java +++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java @@ -24,8 +24,11 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.IOException; import java.lang.reflect.Array; +import junit.framework.Assert; + import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException; import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; @@ -48,6 +51,8 @@ import org.apache.tuscany.sca.binding.corba.testing.servants.EnumManagerServant; import org.apache.tuscany.sca.binding.corba.testing.servants.ObjectManagerServant; import org.apache.tuscany.sca.binding.corba.testing.servants.PrimitivesSetterServant; import org.apache.tuscany.sca.binding.corba.testing.servants.TestObjectServant; +import org.apache.tuscany.sca.host.corba.naming.TransientNameServer; +import org.apache.tuscany.sca.host.corba.naming.TransientNameService; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -63,6 +68,8 @@ import org.omg.CosNaming.NamingContextHelper; * @version $Rev$ $Date$ */ public class CorbaTypesTestCase { + private static TransientNameServer server; + private static ORB orb; private static Process tnameservProcess; private static Object refPrimitivesSetter; @@ -79,18 +86,20 @@ public class CorbaTypesTestCase { @BeforeClass public static void setUp() { try { - String[] args = {"-ORBInitialPort", "11100"}; - - tnameservProcess = Runtime.getRuntime().exec("tnameserv " + args[0] + " " + args[1]); - try { - // let the tnameserv have time to start - Thread.sleep(TestConstants.TNAMESERV_SPAWN_WAIT); - } catch (Exception e) { + server = + new TransientNameServer(TestConstants.DEFAULT_HOST, TestConstants.DEFAULT_PORT, + TransientNameService.DEFAULT_SERVICE_NAME); + Thread t = server.start(); + if (t == null) { + Assert.fail("The naming server cannot be started"); + } + orb = server.getORB(); + } catch (Throwable e) { e.printStackTrace(); + Assert.fail(e.getMessage()); } - ORB orb = ORB.init(args, null); Object nameService = orb.resolve_initial_references("NameService"); NamingContext namingContext = NamingContextHelper.narrow(nameService); @@ -145,10 +154,26 @@ public class CorbaTypesTestCase { } } + private static ORB createORB() throws IOException { + String[] args = {"-ORBInitialPort", "11100"}; + + tnameservProcess = Runtime.getRuntime().exec("tnameserv " + args[0] + " " + args[1]); + + try { + // let the tnameserv have time to start + Thread.sleep(TestConstants.TNAMESERV_SPAWN_WAIT); + } catch (Exception e) { + e.printStackTrace(); + } + + ORB orb = ORB.init(args, null); + return orb; + } + /** * Kills previously spawned tnameserv process. */ - @AfterClass + // @AfterClass public static void tearDown() { tnameservProcess.destroy(); try { @@ -159,6 +184,11 @@ public class CorbaTypesTestCase { } } + @AfterClass + public static void stop() { + server.stop(); + } + /** * Tests remote operation, basing on given reference, operation name, * arguments, expected return type and content @@ -206,7 +236,8 @@ public class CorbaTypesTestCase { /** * Tests passing (and getting as result) varied primitives */ - @Test public void test_setPrimitives() { + @Test + public void test_setPrimitives() { dynaTestInvoker(refPrimitivesSetter, "setBoolean", Boolean.class, new Boolean[] {true}, true); dynaTestInvoker(refPrimitivesSetter, "setOctet", Byte.class, new Byte[] {1}, (byte)1); @@ -223,7 +254,8 @@ public class CorbaTypesTestCase { /** * Tests passing (and getting as result) varied types sequences */ - @Test public void test_setArrays() { + @Test + public void test_setArrays() { dynaTestInvoker(refArraysSetter, "setBoolean", @@ -277,7 +309,8 @@ public class CorbaTypesTestCase { /** * Tests passing (and getting as result) complex structure */ - @Test public void test_TestObject_setStruct() { + @Test + public void test_TestObject_setStruct() { DynaCorbaRequest request = new DynaCorbaRequest(refTestObject, "setStruct"); SomeStruct struct = new SomeStruct(); @@ -311,7 +344,8 @@ public class CorbaTypesTestCase { /** * Test passing (and getting as result) simple two-field structure */ - @Test public void test_TestObject_setSimpleStruct() { + @Test + public void test_TestObject_setSimpleStruct() { SimpleStruct struct = new SimpleStruct(); struct.field1 = TestConstants.STR_1; struct.field2 = TestConstants.INT_1; @@ -331,7 +365,8 @@ public class CorbaTypesTestCase { /** * Tests passing (and getting as result) two dim. sequence of long. */ - @Test public void test_TestObject_setLongSeq2() { + @Test + public void test_TestObject_setLongSeq2() { int[][] arr1 = new int[2][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { @@ -358,7 +393,8 @@ public class CorbaTypesTestCase { /** * Tests passing multiple complex attributes. */ - @Test public void test_TestObject_pickStructFromArgs() { + @Test + public void test_TestObject_pickStructFromArgs() { SomeStruct arg1 = new SomeStruct(); SomeStruct arg2 = new SomeStruct(); SomeStruct arg3 = new SomeStruct(); @@ -410,7 +446,8 @@ public class CorbaTypesTestCase { /** * Tests handling user defined remote exception (single declared) */ - @Test public void test_singleException() { + @Test + public void test_singleException() { DynaCorbaRequest request1 = new DynaCorbaRequest(refCalcObject, "div"); try { request1.addArgument(2d); @@ -440,7 +477,8 @@ public class CorbaTypesTestCase { /** * Tests handling user defined multiple exceptions */ - @Test public void test_multipleExceptions() { + @Test + public void test_multipleExceptions() { DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "divForSmallArgs"); try { request.addArgument(101d); @@ -457,7 +495,8 @@ public class CorbaTypesTestCase { /** * Tests handling exceptions while user defined no exceptions */ - @Test public void test_noExceptionsDeclared() { + @Test + public void test_noExceptionsDeclared() { DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "div"); try { request.addArgument(1d); @@ -473,7 +512,8 @@ public class CorbaTypesTestCase { /** * Tests handling exceptions while user defined no such exception */ - @Test public void test_noSuchExceptionDeclared() { + @Test + public void test_noSuchExceptionDeclared() { DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "div"); try { request.addArgument(1d); @@ -490,7 +530,8 @@ public class CorbaTypesTestCase { /** * Tests handling non existing operation situation */ - @Test public void test_systemException_BAD_OPERATION() { + @Test + public void test_systemException_BAD_OPERATION() { DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "thisOperationSurelyDoesNotExist"); try { request.invoke(); @@ -504,7 +545,8 @@ public class CorbaTypesTestCase { * Tests obtaining references to other objects and using them with specified * user interface */ - @Test public void test_enchancedReferences() { + @Test + public void test_enchancedReferences() { try { DynaCorbaRequest request = new DynaCorbaRequest(refObjectManager, "getDummyObject"); request.setOutputType(DummyObject.class); @@ -521,7 +563,8 @@ public class CorbaTypesTestCase { /** * Test passing enums as arguments and retrieving them as a result */ - @Test public void test_enums() { + @Test + public void test_enums() { try { DynaCorbaRequest request = new DynaCorbaRequest(refEnumManager, "getColor"); Color color = Color.green; @@ -539,7 +582,8 @@ public class CorbaTypesTestCase { /** * Tests recognizing structures */ - @Test public void test_structValidation() { + @Test + public void test_structValidation() { try { DynaCorbaRequest request = new DynaCorbaRequest(refArraysSetter, "whatever"); request.setOutputType(InvalidStruct1.class); @@ -572,7 +616,8 @@ public class CorbaTypesTestCase { /** * Tests recognizing enums */ - @Test public void test_enumValidation() { + @Test + public void test_enumValidation() { try { DynaCorbaRequest request = new DynaCorbaRequest(refArraysSetter, "whatever"); request.setOutputType(InvalidEnum1.class); @@ -605,7 +650,8 @@ public class CorbaTypesTestCase { /** * Tests hanlding passing wrong params */ - @Test public void test_systemException_BAD_PARAM() { + @Test + public void test_systemException_BAD_PARAM() { try { DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "div"); request.setOutputType(Double.class); diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.java index 2151e09090..65abc081a4 100644 --- a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.java +++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/TestConstants.java @@ -32,7 +32,8 @@ public class TestConstants { public static final String[] STR_ARR_2 = {"Another", "string", "array"}; public static final int INT_1 = 0; - public static final int ORB_INITIAL_PORT = 11100; + public static final int DEFAULT_PORT = 11100; + public static final String DEFAULT_HOST = "localhost"; public static final int[][] INT_ARRAY_2_DIM = { {1, 2}, {3, 4}}; public static final int[][][] INT_ARRAY_3_DIM = { { {1, 2}, {3, 4}}, { {5, 6}, {7, 8}}}; -- cgit v1.2.3