summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-10-10 05:01:22 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-10-10 05:01:22 +0000
commit5edad53664c23e540bea5ed336bbfa3948bb1035 (patch)
tree9d7254c29826912db0c03e111958ae895c28c438 /sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca
parentfc7cb9fac15928f69dc89adbadd4ef24c1cc3340 (diff)
Fix test case and update license
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1180782 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java27
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java42
2 files changed, 63 insertions, 6 deletions
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 3d817354bc..a83adb4a1b 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
@@ -31,9 +31,6 @@ import org.junit.Test;
import echo.Echo;
public class JSONRPCReferenceTestCase {
- private static final String SERVICE_PATH = "/EchoService";
- private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
-
private static Node nodeServer;
private static Node node;
@@ -82,5 +79,29 @@ public class JSONRPCReferenceTestCase {
throw e;
}
}
+
+ @Test
+ public void testInvokeReference20() throws Exception {
+ Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference20");
+ String result = echoComponent.echo("ABC");
+ Assert.assertEquals("echo: ABC", result);
+ }
+
+ @Test
+ public void testInvokeReferenceVoidOperation20() throws Exception {
+ Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference20");
+ echoComponent.echoVoid();
+ }
+
+ @Test(expected = Exception.class)
+ public void testInvokeReferenceException20() throws Exception {
+ Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20");
+ 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/JSONRPCServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
index a0e7af8172..bbf8d4cee7 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
@@ -28,6 +28,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.JSONArray;
import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -44,9 +45,8 @@ import com.meterware.httpunit.WebResponse;
*/
public class JSONRPCServiceTestCase {
- private static final String SERVICE_PATH = "/EchoService";
-
- private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
+ private static String SERVICE_URL;
+ private static String SERVICE20_URL;
private static Node node;
@@ -56,6 +56,8 @@ public class JSONRPCServiceTestCase {
String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCServiceTestCase.class);
node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
node.start();
+ SERVICE_URL = node.getEndpointAddress("EchoComponent/Echo/Echo");
+ SERVICE20_URL = node.getEndpointAddress("EchoComponent/Echo/jsonrpc20");
} catch (Exception e) {
e.printStackTrace();
}
@@ -79,6 +81,40 @@ public class JSONRPCServiceTestCase {
JSONObject jsonResp = new JSONObject(response.getText());
Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result"));
}
+
+ @Test
+ public void testEchoWithJSONRPC20Binding() throws Exception {
+ JSONObject jsonRequest = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}");
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest( SERVICE20_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
+ WebResponse response = wc.getResource(request);
+
+ Assert.assertEquals(200, response.getResponseCode());
+
+ JSONObject jsonResp = new JSONObject(response.getText());
+ Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result"));
+ }
+
+
+ @Test
+ public void testEchoWithJSONRPC20BindingBatch() throws Exception {
+ JSONObject jsonRequest1 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}");
+ JSONObject jsonRequest2 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC 2.0\"], \"id\": 2}");
+ JSONArray batchReq = new JSONArray();
+ batchReq.put(jsonRequest1);
+ batchReq.put(jsonRequest2);
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest( SERVICE20_URL, new ByteArrayInputStream(batchReq.toString().getBytes("UTF-8")),"application/json");
+ WebResponse response = wc.getResource(request);
+
+ Assert.assertEquals(200, response.getResponseCode());
+
+ JSONArray jsonResp = new JSONArray(response.getText());
+ Assert.assertEquals("echo: Hello JSON-RPC", ((JSONObject) jsonResp.get(0)).getString("result"));
+ Assert.assertEquals("echo: Hello JSON-RPC 2.0", ((JSONObject) jsonResp.get(1)).getString("result"));
+ }
@Test
public void testJSONRPCBindingGET() throws Exception {