From 9d627fbdaa4ae300843644dfbae874457b3731e2 Mon Sep 17 00:00:00 2001 From: lresende Date: Fri, 29 Aug 2008 03:19:47 +0000 Subject: TUSCANY-2565 - Fixing issues when passing array parameter using json-rpc binding git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@690089 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/echo/Echo.java | 4 ++- .../src/test/java/echo/EchoComponentImpl.java | 6 ++++- .../binding/jsonrpc/JSONRPCDataTypeTestCase.java | 30 +++++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'java/sca/modules/binding-jsonrpc-runtime/src') diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java index 3017861b99..ba87f22cf6 100644 --- a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java +++ b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/Echo.java @@ -53,7 +53,9 @@ public interface Echo { List echoList(ArrayList list); - String [] echoArray(String[] stringArray); + String [] echoArrayString(String[] stringArray); + + int [] echoArrayInt(int[] intArray); Set echoSet(HashSet set); diff --git a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java index aead6e2959..3e7b848221 100644 --- a/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java +++ b/java/sca/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java @@ -81,10 +81,14 @@ public class EchoComponentImpl implements Echo { return list; } - public String[] echoArray(String[] stringArray) { + public String[] echoArrayString(String[] stringArray) { return stringArray; } + public int[] echoArrayInt(int[] intArray) { + return intArray; + } + public Set echoSet(HashSet param){ Set set = new HashSet(); set = param; 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 c4c3151739..6d156fcdf5 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 @@ -138,11 +138,10 @@ public class JSONRPCDataTypeTestCase { Assert.assertEquals(0, jsonResp.getJSONObject("result").getJSONArray("list").get(0)); } - //@Test - @Ignore("TUSCANY-2565") - public void testArray() throws Exception { + @Test + public void testArrayString() throws Exception { JSONObject jsonRequest = new JSONObject( - "{\"params\":[\"1\",\"2\"],\"method\":\"echoArray\",\"id\":9}"); + "{\"params\":[[\"1\",\"2\"]],\"method\":\"echoArrayString\",\"id\":9}"); WebConversation wc = new WebConversation(); WebRequest request = new PostMethodWebRequest(SERVICE_URL, @@ -153,13 +152,32 @@ public class JSONRPCDataTypeTestCase { JSONObject jsonResp = new JSONObject(response.getText()); - Assert.assertEquals(0, jsonResp.getJSONObject("result").getJSONArray("list").get(0)); + 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\": 10}"); + "{ \"method\": \"echoSet\", \"params\": [ {\"javaClass\": \"java.util.HashSet\", \"set\": {\"1\": \"red\", \"2\": \"blue\"}}],\"id\": 11}"); WebConversation wc = new WebConversation(); WebRequest request = new PostMethodWebRequest(SERVICE_URL, -- cgit v1.2.3