Author: lresende
Date: Fri Oct 2 16:47:48 2009
New Revision: 821092
URL: http://svn.apache.org/viewvc?rev=821092&view=rev
Log:
Formatting JSONRPC tests
Modified:
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java
Modified:
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java?rev=821092&r1=821091&r2=821092&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
(original)
+++
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCDataTypeTestCase.java
Fri Oct 2 16:47:48 2009
@@ -41,163 +41,163 @@
*/
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"));
- }
-
- @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}");
-
- 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("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);
-
- Assert.assertEquals(200, response.getResponseCode());
-
- JSONObject jsonResp = new JSONObject(response.getText());
-
- Assert.assertEquals("JSON-RPC",
jsonResp.getJSONObject("result").getString("testString"));
- }
-
- @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);
-
- Assert.assertEquals(200, response.getResponseCode());
-
- JSONObject jsonResp = new JSONObject(response.getText());
-
- 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);
+ private static final String SERVICE_PATH = "/EchoService";
+ private static final String SERVICE_URL =
"http://localhost:8085/SCADomain" + SERVICE_PATH;
- Assert.assertEquals(200, response.getResponseCode());
+ private static Node node;
- JSONObject jsonResp = new JSONObject(response.getText());
+ @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("red",
jsonResp.getJSONObject("result").getJSONObject("set").getString("red"));
- }
+ @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"));
+ }
+
+ @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}");
+
+ 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("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);
+
+ Assert.assertEquals(200, response.getResponseCode());
+
+ JSONObject jsonResp = new JSONObject(response.getText());
+
+ Assert.assertEquals("JSON-RPC",
jsonResp.getJSONObject("result").getString("testString"));
+ }
+
+ @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);
+
+ Assert.assertEquals(200, response.getResponseCode());
+
+ JSONObject jsonResp = new JSONObject(response.getText());
+
+ 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
Modified:
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java?rev=821092&r1=821091&r2=821092&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java
(original)
+++
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCExceptionTestCase.java
Fri Oct 2 16:47:48 2009
@@ -45,52 +45,52 @@
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(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();
+ }
- @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
Modified:
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java?rev=821092&r1=821091&r2=821092&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
(original)
+++
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
Fri Oct 2 16:47:48 2009
@@ -45,24 +45,24 @@
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();
- }
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- node.stop();
- node.destroy();
- }
+ @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();
+ }
@Test
public void testJSONRPCBinding() throws Exception {
@@ -73,7 +73,7 @@
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"));
}
Modified:
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java?rev=821092&r1=821091&r2=821092&view=diff
==============================================================================
---
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java
(original)
+++
tuscany/java/sca/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCSmdTestCase.java
Fri Oct 2 16:47:48 2009
@@ -42,27 +42,27 @@
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();
- }
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- node.stop();
- node.destroy();
- }
+ @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();
+ }
@Test
/**
@@ -75,7 +75,7 @@
Assert.assertEquals(200, response.getResponseCode());
Assert.assertNotNull(response.getText());
-
+
//System.out.println(">>>SMD:" + response.getText());
}
}