summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-10-10 07:07:31 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-10-10 07:07:31 +0000
commitcd0891e54e0e4e9123f029f3a4f9689c15598337 (patch)
tree48c7e5ee175c2cb47adf4aceb619ddf66072bd06 /sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test
parent5edad53664c23e540bea5ed336bbfa3948bb1035 (diff)
Fix the invoker to serialize the objects to json
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1180795 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test')
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java67
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java51
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java4
-rw-r--r--sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java42
4 files changed, 122 insertions, 42 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java
index 4b159fb563..508fc31c08 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/bean/TestBean.java
@@ -18,11 +18,14 @@
*/
package bean;
+import java.util.ArrayList;
+import java.util.List;
+
public class TestBean {
private String testString;
- private String[] testStringArray;
+ // private String[] testStringArray; // Jackson cannot deserilize String[]
+ private List<String> testStringArray = new ArrayList<String>();
private int testInt;
-
public String getTestString() {
return testString;
@@ -32,14 +35,14 @@ public class TestBean {
this.testString = testString;
}
- public String[] getTestStringArray() {
- return testStringArray;
+ public List<String> getTestStringArray() {
+ return testStringArray;
}
- public void setStringArray(String[] stringArray) {
- this.testStringArray = stringArray;
+ public void setStringArray(List<String> stringArray) {
+ this.testStringArray = stringArray;
}
-
+
public int getTestInt() {
return testInt;
}
@@ -48,4 +51,54 @@ public class TestBean {
this.testInt = testInt;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + testInt;
+ result = prime * result + ((testString == null) ? 0 : testString.hashCode());
+ result = prime * result + ((testStringArray == null) ? 0 : testStringArray.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TestBean other = (TestBean)obj;
+ if (testInt != other.testInt) {
+ return false;
+ }
+ if (testString == null) {
+ if (other.testString != null) {
+ return false;
+ }
+ } else if (!testString.equals(other.testString)) {
+ return false;
+ }
+ if (testStringArray == null) {
+ if (other.testStringArray != null) {
+ return false;
+ }
+ } else if (!testStringArray.equals(other.testStringArray)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("TestBean [testString=").append(testString).append(", testStringArray=").append(testStringArray)
+ .append(", testInt=").append(testInt).append("]");
+ return builder.toString();
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
index 49cb2cf0eb..09a4ab183a 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoClientImpl.java
@@ -27,71 +27,76 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.oasisopen.sca.annotation.AllowsPassByReference;
import org.oasisopen.sca.annotation.Reference;
import bean.TestBean;
+@AllowsPassByReference
public class EchoClientImpl implements Echo {
@Reference
+ @AllowsPassByReference
protected Echo echoReference;
public String echo(String msg) {
return echoReference.echo(msg);
}
-
+
public void echoVoid() {
echoReference.echoVoid();
}
- public int[] echoArrayInt(int[] intArray) {
- throw new UnsupportedOperationException("UNsupported !");
+ public void echoRuntimeException() throws RuntimeException {
+ echoReference.echoRuntimeException();
}
- public String[] echoArrayString(String[] stringArray) {
- throw new UnsupportedOperationException("UNsupported !");
+ public void echoBusinessException() throws EchoBusinessException {
+ echoReference.echoBusinessException();
}
- public TestBean echoBean(TestBean testBean) {
- throw new UnsupportedOperationException("UNsupported !");
+ public int echoInt(int param) {
+ return echoReference.echoInt(param);
}
- public boolean echoBoolean(boolean param) {
- throw new UnsupportedOperationException("UNsupported !");
+ public double echoDouble(double param) {
+ return echoReference.echoDouble(param);
}
- public void echoBusinessException() throws EchoBusinessException {
- echoReference.echoBusinessException();
+ public boolean echoBoolean(boolean param) {
+ return echoReference.echoBoolean(param);
}
- public int echoInt(int param) {
- throw new UnsupportedOperationException("UNsupported !");
+ public Map echoMap(HashMap map) {
+ return echoReference.echoMap(map);
}
- public double echoDouble(double param) {
- throw new UnsupportedOperationException("UNsupported !");
+ public TestBean echoBean(TestBean testBean) {
+ return echoReference.echoBean(testBean);
}
public List echoList(ArrayList list) {
- throw new UnsupportedOperationException("UNsupported !");
+ return echoReference.echoList(list);
}
- public Map echoMap(HashMap map) {
- throw new UnsupportedOperationException("UNsupported !");
+ public String[] echoArrayString(String[] stringArray) {
+ return echoReference.echoArrayString(stringArray);
}
- public void echoRuntimeException() throws RuntimeException {
- echoReference.echoRuntimeException();
+ public int[] echoArrayInt(int[] intArray) {
+ return echoReference.echoArrayInt(intArray);
}
public Set echoSet(HashSet set) {
- throw new UnsupportedOperationException("UNsupported !");
+ return echoReference.echoSet(set);
}
public void get\u03a9\u03bb\u03c0() {
- throw new UnsupportedOperationException("UNsupported !");
+ echoReference.get\u03a9\u03bb\u03c0();
}
public BigDecimal echoBigDecimal(BigDecimal param) {
- throw new UnsupportedOperationException("UNsupported !");
+ return echoReference.echoBigDecimal(param);
}
+
+
}
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
index b8b63906b9..bdfa88c65f 100644
--- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/echo/EchoComponentImpl.java
@@ -27,6 +27,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.oasisopen.sca.annotation.AllowsPassByReference;
+
import bean.TestBean;
/**
@@ -34,6 +36,7 @@ import bean.TestBean;
*
* @version $Rev$ $Date$
*/
+@AllowsPassByReference
public class EchoComponentImpl implements Echo {
public String echo(String msg) {
@@ -80,6 +83,7 @@ public class EchoComponentImpl implements Echo {
TestBean testBean = new TestBean();
testBean.setTestString(testBean1.getTestString());
testBean.setTestInt(testBean1.getTestInt());
+ testBean.setStringArray(testBean1.getTestStringArray());
return testBean;
}
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 a83adb4a1b..2c92e33f9a 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
@@ -18,6 +18,8 @@
*/
package org.apache.tuscany.sca.binding.jsonrpc;
+import java.util.Arrays;
+
import junit.framework.Assert;
import org.apache.tuscany.sca.node.Contribution;
@@ -28,6 +30,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import bean.TestBean;
import echo.Echo;
public class JSONRPCReferenceTestCase {
@@ -38,13 +41,17 @@ public class JSONRPCReferenceTestCase {
public static void setUp() throws Exception {
try {
String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCReferenceTestCase.class);
- nodeServer = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("testServer", contribution));
+ 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 =
+ NodeFactory.newInstance().createNode("JSONRPCReference.composite",
+ new Contribution("testClient", contribution));
node.start();
-
+
} catch (Exception e) {
e.printStackTrace();
}
@@ -55,20 +62,31 @@ public class JSONRPCReferenceTestCase {
nodeServer.stop();
node.stop();
}
-
+
@Test
public void testInvokeReference() throws Exception {
- Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference");
+ Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
String result = echoComponent.echo("ABC");
Assert.assertEquals("echo: ABC", result);
}
@Test
+ public void testInvokeBeanReference() throws Exception {
+ Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
+ TestBean bean = new TestBean();
+ bean.setTestInt(1);
+ bean.setTestString("123");
+ bean.setStringArray(Arrays.asList("A", "B"));
+ TestBean result = echoComponent.echoBean(bean);
+ Assert.assertEquals(bean, result);
+ }
+
+ @Test
public void testInvokeReferenceVoidOperation() throws Exception {
- Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference");
+ Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
echoComponent.echoVoid();
}
-
+
@Test(expected = Exception.class)
public void testInvokeReferenceException() throws Exception {
Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference");
@@ -79,20 +97,20 @@ public class JSONRPCReferenceTestCase {
throw e;
}
}
-
+
@Test
public void testInvokeReference20() throws Exception {
- Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference20");
+ 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");
+ 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");