summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-02 16:47:48 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-02 16:47:48 +0000
commit801a2949b2661e8bc050f5206d33105c0a3a236d (patch)
tree8814206fb7b9451900209cd059ccb9bc2f8913c9
parentd3e4a0e00eea07246c593636d5228d75ddfc1900 (diff)
Formatting JSONRPC tests
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@821092 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java262
-rw-r--r--java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java60
-rw-r--r--java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java34
-rw-r--r--java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java36
4 files changed, 196 insertions, 196 deletions
diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
index 80694484d9..96dea057e8 100644
--- a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
+++ b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
@@ -41,163 +41,163 @@ import com.meterware.httpunit.WebResponse;
*/
public class JSONRPCDataTypeTestCase {
- private static final String SERVICE_PATH = "/EchoService";
- private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
-
- private static Node node;
-
- @BeforeClass
- public static void setUp() throws Exception {
- try {
- String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCDataTypeTestCase.class);
- node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
- node.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- node.stop();
- node.destroy();
- }
-
- @Test
- public void testInt() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{ \"method\": \"echoInt\", \"params\": [12345], \"id\": 4}");
-
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_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(12345, jsonResp.getInt("result"));
- }
+ private static final String SERVICE_PATH = "/EchoService";
+ private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
- @Test
- public void testBoolean() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{ \"method\": \"echoBoolean\", \"params\": [true], \"id\": 5}");
-
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_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(true, jsonResp.getBoolean("result"));
- }
-
- @Test
- public void testMap() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{ \"method\": \"echoMap\", \"params\": [ {\"javaClass\": \"java.util.HashMap\", \"map\": { \"Binding\": \"JSON-RPC\"}}], \"id\": 6}");
+ private static Node node;
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_URL,
- new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
- WebResponse response = wc.getResource(request);
+ @BeforeClass
+ public static void setUp() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCDataTypeTestCase.class);
+ node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
+ node.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
- Assert.assertEquals(200, response.getResponseCode());
+ @AfterClass
+ public static void tearDown() throws Exception {
+ node.stop();
+ node.destroy();
+ }
- JSONObject jsonResp = new JSONObject(response.getText());
+ @Test
+ public void testInt() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{ \"method\": \"echoInt\", \"params\": [12345], \"id\": 4}");
- Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getJSONObject("map").getString("Binding"));
- }
-
- @Test
- public void testBean() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{ \"method\": \"echoBean\", \"params\": [ {\"javaClass\": \"bean.TestBean\", \"testString\": \"JSON-RPC\", \"testInt\":1234}], \"id\": 7}");
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_URL,
+ new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
+ WebResponse response = wc.getResource(request);
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_URL,
- new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
- WebResponse response = wc.getResource(request);
+ Assert.assertEquals(200, response.getResponseCode());
- Assert.assertEquals(200, response.getResponseCode());
+ JSONObject jsonResp = new JSONObject(response.getText());
- JSONObject jsonResp = new JSONObject(response.getText());
+ Assert.assertEquals(12345, jsonResp.getInt("result"));
+ }
- Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getString("testString"));
- }
+ @Test
+ public void testBoolean() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{ \"method\": \"echoBoolean\", \"params\": [true], \"id\": 5}");
- @Test
- public void testList() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{ \"method\": \"echoList\", \"params\": [ {\"javaClass\": \"java.util.ArrayList\", \"list\": [0,1,2,3,4]}], \"id\": 8}");
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_URL,
+ new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
+ WebResponse response = wc.getResource(request);
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_URL,
- new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
- WebResponse response = wc.getResource(request);
+ Assert.assertEquals(200, response.getResponseCode());
- Assert.assertEquals(200, response.getResponseCode());
+ JSONObject jsonResp = new JSONObject(response.getText());
- JSONObject jsonResp = new JSONObject(response.getText());
+ Assert.assertEquals(true, jsonResp.getBoolean("result"));
+ }
- Assert.assertEquals(0, jsonResp.getJSONObject("result").getJSONArray("list").get(0));
- }
-
- @Test
- public void testArrayString() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{\"params\":[[\"1\",\"2\"]],\"method\":\"echoArrayString\",\"id\":9}");
+ @Test
+ public void testMap() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{ \"method\": \"echoMap\", \"params\": [ {\"javaClass\": \"java.util.HashMap\", \"map\": { \"Binding\": \"JSON-RPC\"}}], \"id\": 6}");
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_URL,
- new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
- WebResponse response = wc.getResource(request);
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_URL,
+ new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
+ WebResponse response = wc.getResource(request);
- Assert.assertEquals(200, response.getResponseCode());
+ Assert.assertEquals(200, response.getResponseCode());
- JSONObject jsonResp = new JSONObject(response.getText());
+ JSONObject jsonResp = new JSONObject(response.getText());
- Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0));
- }
+ Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getJSONObject("map").getString("Binding"));
+ }
-
- @Test
- public void testArrayInt() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{\"params\":[[1,2]],\"method\":\"echoArrayInt\",\"id\":10}");
+ @Test
+ public void testBean() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{ \"method\": \"echoBean\", \"params\": [ {\"javaClass\": \"bean.TestBean\", \"testString\": \"JSON-RPC\", \"testInt\":1234}], \"id\": 7}");
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_URL,
- new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
- WebResponse response = wc.getResource(request);
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_URL,
+ new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
+ WebResponse response = wc.getResource(request);
- Assert.assertEquals(200, response.getResponseCode());
+ Assert.assertEquals(200, response.getResponseCode());
- JSONObject jsonResp = new JSONObject(response.getText());
+ JSONObject jsonResp = new JSONObject(response.getText());
- Assert.assertEquals(1, jsonResp.getJSONArray("result").getInt(0));
- }
+ Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getString("testString"));
+ }
-
- @Test
- public void testSet() throws Exception {
- JSONObject jsonRequest = new JSONObject(
- "{ \"method\": \"echoSet\", \"params\": [ {\"javaClass\": \"java.util.HashSet\", \"set\": {\"1\": \"red\", \"2\": \"blue\"}}],\"id\": 11}");
+ @Test
+ public void testList() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{ \"method\": \"echoList\", \"params\": [ {\"javaClass\": \"java.util.ArrayList\", \"list\": [0,1,2,3,4]}], \"id\": 8}");
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest(SERVICE_URL,
- new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
- WebResponse response = wc.getResource(request);
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_URL,
+ new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
+ WebResponse response = wc.getResource(request);
- Assert.assertEquals(200, response.getResponseCode());
+ Assert.assertEquals(200, response.getResponseCode());
- JSONObject jsonResp = new JSONObject(response.getText());
+ JSONObject jsonResp = new JSONObject(response.getText());
- Assert.assertEquals("red", jsonResp.getJSONObject("result").getJSONObject("set").getString("red"));
- }
+ Assert.assertEquals(0, jsonResp.getJSONObject("result").getJSONArray("list").get(0));
+ }
+
+ @Test
+ public void testArrayString() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{\"params\":[[\"1\",\"2\"]],\"method\":\"echoArrayString\",\"id\":9}");
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_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(1, jsonResp.getJSONArray("result").getInt(0));
+ }
+
+
+ @Test
+ public void testArrayInt() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{\"params\":[[1,2]],\"method\":\"echoArrayInt\",\"id\":10}");
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_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(1, jsonResp.getJSONArray("result").getInt(0));
+ }
+
+
+ @Test
+ public void testSet() throws Exception {
+ JSONObject jsonRequest = new JSONObject(
+ "{ \"method\": \"echoSet\", \"params\": [ {\"javaClass\": \"java.util.HashSet\", \"set\": {\"1\": \"red\", \"2\": \"blue\"}}],\"id\": 11}");
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest(SERVICE_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("red", jsonResp.getJSONObject("result").getJSONObject("set").getString("red"));
+ }
} \ No newline at end of file
diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java
index 42fb446aee..635c99a462 100644
--- a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java
+++ b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java
@@ -45,52 +45,52 @@ public class JSONRPCExceptionTestCase{
private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
- private static Node node;
-
- @BeforeClass
- public static void setUp() throws Exception {
- try {
- String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCExceptionTestCase.class);
- node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
- node.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- node.stop();
- node.destroy();
- }
-
+ private static Node node;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCExceptionTestCase.class);
+ node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
+ node.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ node.stop();
+ node.destroy();
+ }
+
@Test
public void testRuntimeException() throws Exception{
- JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoRuntimeException\", \"params\": [], \"id\": 2}");
-
- WebConversation wc = new WebConversation();
+ JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoRuntimeException\", \"params\": [], \"id\": 2}");
+
+ WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals(200, response.getResponseCode());
-
+
JSONObject jsonErr = new JSONObject(response.getText()).getJSONObject("error");
-
+
Assert.assertEquals("Runtime Exception", jsonErr.getString("msg"));
}
-
+
@Test
public void testBusinessException() throws Exception{
- JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoBusinessException\", \"params\": [], \"id\": 3}");
-
- WebConversation wc = new WebConversation();
+ JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoBusinessException\", \"params\": [], \"id\": 3}");
+
+ WebConversation wc = new WebConversation();
WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
WebResponse response = wc.getResource(request);
Assert.assertEquals(200, response.getResponseCode());
-
+
JSONObject jsonErr = new JSONObject(response.getText()).getJSONObject("error");
-
+
Assert.assertEquals("Business Exception", jsonErr.getString("msg"));
}
} \ No newline at end of file
diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
index e0c8acd120..502b2c2862 100644
--- a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
+++ b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
@@ -45,24 +45,24 @@ public class JSONRPCServiceTestCase{
private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
- private static Node node;
+ private static Node node;
- @BeforeClass
- public static void setUp() throws Exception {
- try {
- String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCServiceTestCase.class);
- node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
- node.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ @BeforeClass
+ public static void setUp() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCServiceTestCase.class);
+ node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
+ node.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
- @AfterClass
- public static void tearDown() throws Exception {
- node.stop();
- node.destroy();
- }
+ @AfterClass
+ public static void tearDown() throws Exception {
+ node.stop();
+ node.destroy();
+ }
@Test
public void testJSONRPCBinding() throws Exception {
@@ -73,7 +73,7 @@ public class JSONRPCServiceTestCase{
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"));
}
diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java
index bbaddb5fbb..6a13a7d951 100644
--- a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java
+++ b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java
@@ -42,27 +42,27 @@ public class JSONRPCSmdTestCase {
private static final String SERVICE_PATH = "/EchoService";
private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
-
+
private static final String SMD_URL = SERVICE_URL + "?smd";
- private static Node node;
+ private static Node node;
- @BeforeClass
- public static void setUp() throws Exception {
- try {
- String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCSmdTestCase.class);
- node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
- node.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ @BeforeClass
+ public static void setUp() throws Exception {
+ try {
+ String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCSmdTestCase.class);
+ node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test", contribution));
+ node.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
- @AfterClass
- public static void tearDown() throws Exception {
- node.stop();
- node.destroy();
- }
+ @AfterClass
+ public static void tearDown() throws Exception {
+ node.stop();
+ node.destroy();
+ }
@Test
/**
@@ -75,7 +75,7 @@ public class JSONRPCSmdTestCase {
Assert.assertEquals(200, response.getResponseCode());
Assert.assertNotNull(response.getText());
-
+
//System.out.println(">>>SMD:" + response.getText());
}
}