From 510339785280a70836958a2bf06354f576c7e322 Mon Sep 17 00:00:00 2001 From: rfeng Date: Fri, 16 Sep 2011 17:34:05 +0000 Subject: Improved the SMD and error handling git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1171688 13f79535-47bb-0310-9956-ffa450edef68 --- .../binding/jsonrpc/JSONRPCReferenceTestCase.java | 36 +++++++++++----------- .../sca/binding/jsonrpc/JSONRPCSmdTestCase.java | 14 ++++++--- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany') diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java index c639d3eef7..3d817354bc 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java @@ -35,6 +35,7 @@ public class JSONRPCReferenceTestCase { private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH; private static Node nodeServer; + private static Node node; @BeforeClass public static void setUp() throws Exception { @@ -42,6 +43,11 @@ public class JSONRPCReferenceTestCase { String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTestCase.class); nodeServer = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("testServer", contribution)); nodeServer.start(); + + contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTestCase.class); + node = NodeFactory.newInstance().createNode("JSONRPCReference.composite", new Contribution("testClient", contribution)); + node.start(); + } catch (Exception e) { e.printStackTrace(); } @@ -50,37 +56,31 @@ public class JSONRPCReferenceTestCase { @AfterClass public static void tearDown() throws Exception { nodeServer.stop(); + node.stop(); } @Test public void testInvokeReference() throws Exception { - Node node = null; - - String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTestCase.class); - node = NodeFactory.newInstance().createNode("JSONRPCReference.composite", new Contribution("testClient", contribution)); - node.start(); - Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference"); String result = echoComponent.echo("ABC"); Assert.assertEquals("echo: ABC", result); - if (node != null) { - node.stop(); - } } @Test public void testInvokeReferenceVoidOperation() throws Exception { - Node node = null; - - String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTestCase.class); - node = NodeFactory.newInstance().createNode("JSONRPCReference.composite", new Contribution("testClient", contribution)); - node.start(); - Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference"); echoComponent.echoVoid(); - - if (node != null) { - node.stop(); + } + + @Test(expected = Exception.class) + public void testInvokeReferenceException() throws Exception { + Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference"); + try { + echoComponent.echoBusinessException(); + } catch (Exception e) { + System.err.println(e); + throw e; } } + } diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java index a1b076c0e8..0ee1643243 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java @@ -25,6 +25,7 @@ import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.ContributionLocationHelper; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; +import org.json.JSONObject; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -34,6 +35,8 @@ import com.meterware.httpunit.WebConversation; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; +import echo.Echo; + /** * @version $Rev$ $Date$ */ @@ -51,7 +54,9 @@ public class JSONRPCSmdTestCase { public static void setUp() throws Exception { try { String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCSmdTestCase.class); - node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution)); + node = + NodeFactory.newInstance() + .createNode("JSONRPCBinding.composite", new Contribution("test", contribution)); node.start(); } catch (Exception e) { e.printStackTrace(); @@ -69,12 +74,13 @@ public class JSONRPCSmdTestCase { */ public void testJSONRPCSmdSpecialCharacters() throws Exception { WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest(SMD_URL); + WebRequest request = new GetMethodWebRequest(SMD_URL); WebResponse response = wc.getResource(request); Assert.assertEquals(200, response.getResponseCode()); - Assert.assertNotNull(response.getText()); + JSONObject smd = new JSONObject(response.getText()); + Assert.assertEquals(Echo.class.getMethods().length, smd.getJSONArray("methods").length()); - //System.out.println(">>>SMD:" + response.getText()); + // System.out.println(">>>SMD:\n" + response.getText()); } } -- cgit v1.2.3