You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2007/11/24 00:02:41 UTC
svn commit: r597754 - in /incubator/cxf/trunk/rt/javascript/src:
main/java/org/apache/cxf/javascript/service/
main/java/org/apache/cxf/javascript/types/
test/java/org/apache/cxf/javascript/
test/java/org/apache/cxf/javascript/fortest/ test/java/org/apa...
Author: bimargulies
Date: Fri Nov 23 15:02:40 2007
New Revision: 597754
URL: http://svn.apache.org/viewvc?rev=597754&view=rev
Log:
Work in progress to exercise more of the Javascript code. The main test case is commented out; this checkin is a checkpoint so that I can get back if the next
thing I try to code turnes out to be a really bad idea.
Added:
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/BeanRequestWrapper.java
Modified:
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitWrappedClientTest.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrapped.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrappedImpl.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean2.java
incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
incubator/cxf/trunk/rt/javascript/src/test/resources/DocLitWrappedClientTestBeans.xml
incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties
incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/DocLitWrappedTests.js
Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java Fri Nov 23 15:02:40 2007
@@ -487,6 +487,10 @@
@Override
public void begin(ServiceInfo service) {
+
+ code.append("//\n");
+ code.append("// Definitions for service: " + service.toString() + "\n");
+ code.append("//\n");
BindingInfo xml = null;
// assume only one soap binding.
Modified: incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java Fri Nov 23 15:02:40 2007
@@ -201,7 +201,7 @@
utils.appendExpression("elementName");
utils.appendString(">");
utils.endBlock();
- code.append("return xml;\n");
+ utils.appendLine("return xml;");
code.append("}\n");
code.append(nameManager.getJavascriptName(type) + ".prototype.serialize = " + functionName + ";\n");
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitWrappedClientTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitWrappedClientTest.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitWrappedClientTest.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/DocLitWrappedClientTest.java Fri Nov 23 15:02:40 2007
@@ -29,6 +29,9 @@
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.javascript.JavascriptTestUtilities.JSRunnable;
import org.apache.cxf.javascript.JavascriptTestUtilities.Notifier;
+import org.apache.cxf.javascript.fortest.SimpleDocLitWrappedImpl;
+import org.apache.cxf.javascript.fortest.TestBean1;
+import org.apache.cxf.javascript.fortest.TestBean2;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.service.model.ServiceInfo;
@@ -39,6 +42,7 @@
import org.mozilla.javascript.Scriptable;
import org.springframework.context.support.GenericApplicationContext;
+@org.junit.Ignore
public class DocLitWrappedClientTest extends AbstractCXFSpringTest {
private static final Logger LOG = LogUtils.getL7dLogger(DocLitWrappedClientTest.class);
@@ -46,15 +50,30 @@
// shadow declaration from base class.
private JavascriptTestUtilities testUtilities;
private JaxWsProxyFactoryBean clientProxyFactory;
+ private EndpointImpl endpoint;
public DocLitWrappedClientTest() throws Exception {
testUtilities = new JavascriptTestUtilities(getClass());
testUtilities.addDefaultNamespaces();
}
- @Override
- protected String[] getConfigLocations() {
- return new String[] {"classpath:DocLitWrappedClientTestBeans.xml"};
+ public String getStaticResourceURL() throws Exception {
+ File staticFile = new File(this.getClass().getResource("test.html").toURI());
+ staticFile = staticFile.getParentFile();
+ staticFile = staticFile.getAbsoluteFile();
+ URL furl = staticFile.toURL();
+ return furl.toString();
+ }
+
+ // just one test function to avoid muddles with engine startup/shutdown
+ @Test
+ public void runTests() throws Exception {
+ endpoint = getBean(EndpointImpl.class, "dlw-service-endpoint");
+ callMethodWithWrappers();
+ callMethodWithoutWrappers();
+ callTest2WithNullString();
+ callIntReturnMethod();
+ callFunctionWithBeans();
}
@Before
@@ -71,19 +90,104 @@
testUtilities.loadJavascriptForService(serviceInfo);
testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/DocLitWrappedTests.js");
}
+
+ @Override
+ protected void additionalSpringConfiguration(GenericApplicationContext context) throws Exception {
+ }
+
+ @Override
+ protected String[] getConfigLocations() {
+ return new String[] {"classpath:DocLitWrappedClientTestBeans.xml"};
+ }
- // just one test function to avoid muddles with engine startup/shutdown
- @Test
- public void runTests() throws Exception {
- callMethodWithWrappers();
+ private Void beanFunctionCaller(Context context) {
+ TestBean1 b1 = new TestBean1();
+ b1.stringItem = "strung";
+ TestBean1[] beans = new TestBean1[3];
+ beans[0] = new TestBean1();
+ beans[0].beanTwoNotRequiredItem = new TestBean2("bean2");
+ beans[1] = null;
+ beans[2] = new TestBean1();
+ beans[2].optionalIntArrayItem = new int[2];
+ beans[2].optionalIntArrayItem[0] = 4;
+ beans[2].optionalIntArrayItem[1] = 6;
- callMethodWithoutWrappers();
+ Object[] jsBeans = new Object[3];
+ jsBeans[0] = testBean1ToJS(testUtilities, context, beans[0]);
+ jsBeans[1] = testBean1ToJS(testUtilities, context, beans[1]);
+ jsBeans[2] = testBean1ToJS(testUtilities, context, beans[2]);
+
+ Scriptable jsBean1 = testBean1ToJS(testUtilities, context, b1);
+ Scriptable jsBeanArray = context.newArray(testUtilities.getRhinoScope(), jsBeans);
+
+ LOG.info("About to call test4 " + endpoint.getAddress());
+ Notifier notifier =
+ testUtilities.rhinoCallConvert("test4", Notifier.class,
+ testUtilities.javaToJS(endpoint.getAddress()),
+ jsBean1,
+ jsBeanArray);
+ boolean notified = notifier.waitForJavascript(1000 * 10);
+ assertTrue(notified);
+ Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
+ assertNull(errorStatus);
+ String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
+ assertNull(errorText);
+
+ // this method returns void, which translated into a Javascript object with no properties.
+ Scriptable responseObject = (Scriptable)testUtilities.rhinoEvaluate("globalResponseObject");
+ assertNotNull(responseObject);
+ SimpleDocLitWrappedImpl impl = getBean(SimpleDocLitWrappedImpl.class, "dlw-service");
+ TestBean1 b1returned = impl.getLastBean1();
+ assertEquals(b1, b1returned);
+ TestBean1[] beansReturned = impl.getLastBean1Array();
+ assertArrayEquals(beans, beansReturned);
+ return null;
+ }
+
+ private void callFunctionWithBeans() {
+ LOG.info("about to call test4/beanFunction");
+ testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
+ public Void run(Context context) {
+ return beanFunctionCaller(context);
+ }
+ });
+ }
+
+ private void callIntReturnMethod() {
+ testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
+ public Void run(Context context) {
+ LOG.info("About to call test3/IntFunction" + endpoint.getAddress());
+ Notifier notifier =
+ testUtilities.rhinoCallConvert("test3", Notifier.class,
+ testUtilities.javaToJS(endpoint.getAddress()),
+ testUtilities.javaToJS(Double.valueOf(17.0)),
+ testUtilities.javaToJS(Float.valueOf((float)111.0)),
+ testUtilities.javaToJS(Integer.valueOf(142)),
+ testUtilities.javaToJS(Long.valueOf(1240000)),
+ null);
+ boolean notified = notifier.waitForJavascript(1000 * 10);
+ assertTrue(notified);
+ Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
+ assertNull(errorStatus);
+ String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
+ assertNull(errorText);
+
+ Scriptable responseObject = (Scriptable)testUtilities.rhinoEvaluate("globalResponseObject");
+ assertNotNull(responseObject);
+ // by default, for doc/lit/wrapped, we end up with a part object with a slot named
+ // 'return'.
+ Integer returnValue = testUtilities.rhinoCallMethodInContext(Integer.class, responseObject,
+ "getReturn");
+ assertEquals(42, returnValue);
+
+ return null; // well, null AND void.
+ }
+ });
}
private void callMethodWithoutWrappers() {
testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
public Void run(Context context) {
- EndpointImpl endpoint = getBean(EndpointImpl.class, "dlw-service-endpoint");
LOG.info("About to call test2 " + endpoint.getAddress());
Notifier notifier =
testUtilities.rhinoCallConvert("test2", Notifier.class,
@@ -116,7 +220,6 @@
private void callMethodWithWrappers() {
testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
public Void run(Context context) {
- EndpointImpl endpoint = getBean(EndpointImpl.class, "dlw-service-endpoint");
LOG.info("About to call test1 " + endpoint.getAddress());
Notifier notifier = testUtilities.rhinoCallConvert("test1", Notifier.class, testUtilities
@@ -144,15 +247,69 @@
});
}
- public String getStaticResourceURL() throws Exception {
- File staticFile = new File(this.getClass().getResource("test.html").toURI());
- staticFile = staticFile.getParentFile();
- staticFile = staticFile.getAbsoluteFile();
- URL furl = staticFile.toURL();
- return furl.toString();
+ private void callTest2WithNullString() {
+ testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
+ public Void run(Context context) {
+ LOG.info("About to call test2 with null string" + endpoint.getAddress());
+ Notifier notifier =
+ testUtilities.rhinoCallConvert("test2", Notifier.class,
+ testUtilities.javaToJS(endpoint.getAddress()),
+ testUtilities.javaToJS(Double.valueOf(17.0)),
+ testUtilities.javaToJS(Float.valueOf((float)111.0)),
+ testUtilities.javaToJS(Integer.valueOf(142)),
+ testUtilities.javaToJS(Long.valueOf(1240000)),
+ null);
+ boolean notified = notifier.waitForJavascript(1000 * 10);
+ assertTrue(notified);
+ Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
+ assertNull(errorStatus);
+ String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);
+ assertNull(errorText);
+
+ Scriptable responseObject = (Scriptable)testUtilities.rhinoEvaluate("globalResponseObject");
+ assertNotNull(responseObject);
+ // by default, for doc/lit/wrapped, we end up with a part object with a slot named
+ // 'return'.
+ String returnString = testUtilities.rhinoCallMethodInContext(String.class, responseObject,
+ "getReturn");
+ assertEquals("cetaceans", returnString);
+
+ return null; // well, null AND void.
+ }
+ });
}
- @Override
- protected void additionalSpringConfiguration(GenericApplicationContext context) throws Exception {
+ public static Scriptable testBean1ToJS(JavascriptTestUtilities testUtilities,
+ Context context,
+ TestBean1 b1) {
+ if (b1 == null) {
+ return null; // black is always in fashion. (Really, we can be called with a null).
+ }
+ Scriptable rv = context.newObject(testUtilities.getRhinoScope(),
+ "org_apache_cxf_javascript_testns_testBean1");
+ testUtilities.rhinoCallMethod(rv, "setStringItem", testUtilities.javaToJS(b1.stringItem));
+ testUtilities.rhinoCallMethod(rv, "setIntItem", testUtilities.javaToJS(b1.intItem));
+ testUtilities.rhinoCallMethod(rv, "setLongItem", testUtilities.javaToJS(b1.longItem));
+ testUtilities.rhinoCallMethod(rv, "setBase64Item", testUtilities.javaToJS(b1.base64Item));
+ testUtilities.rhinoCallMethod(rv, "setOptionalIntItem", testUtilities.javaToJS(b1.optionalIntItem));
+ testUtilities.rhinoCallMethod(rv, "setOptionalIntArrayItem",
+ testUtilities.javaToJS(b1.optionalIntArrayItem));
+ testUtilities.rhinoCallMethod(rv, "setDoubleItem", testUtilities.javaToJS(b1.doubleItem));
+ testUtilities.rhinoCallMethod(rv, "setBeanTwoItem", testBean2ToJS(testUtilities,
+ context, b1.beanTwoItem));
+ testUtilities.rhinoCallMethod(rv, "setBeanTwoNotRequiredItem",
+ testBean2ToJS(testUtilities, context, b1.beanTwoNotRequiredItem));
+ return rv;
+ }
+
+ public static Object testBean2ToJS(JavascriptTestUtilities testUtilities,
+ Context context, TestBean2 beanTwoItem) {
+ if (beanTwoItem == null) {
+ return null;
+ }
+ Scriptable rv = context.newObject(testUtilities.getRhinoScope(),
+ "org_apache_cxf_javascript_testns3_testBean2");
+ testUtilities.rhinoCallMethod(rv, "setStringItem", beanTwoItem.stringItem);
+ return rv;
}
}
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java Fri Nov 23 15:02:40 2007
@@ -236,7 +236,8 @@
}
/**
- * Call a method on a Javascript object and convert result to specified class.
+ * Call a method on a Javascript object and convert result to specified class. Convert to the
+ * requested class.
* @param <T> type
* @param clazz class object.
* @param that Javascript object.
@@ -245,7 +246,7 @@
* @return return value.
*/
public <T> T rhinoCallMethodConvert(Class<T> clazz, Scriptable that, String methodName, Object... args) {
- return clazz.cast(rhinoCallMethod(that, methodName, args));
+ return clazz.cast(Context.jsToJava(rhinoCallMethod(that, methodName, args), clazz));
}
/**
@@ -263,7 +264,7 @@
// we end up performing the cast twice to make the compiler happy.
return runInsideContext(clazz, new JSRunnable<T>() {
public T run(Context context) {
- return clazz.cast(rhinoCallMethod(that, methodName, args));
+ return rhinoCallMethodConvert(clazz, that, methodName, args);
}
});
}
@@ -362,5 +363,18 @@
serviceBuilder.walk();
String serviceJavascript = serviceBuilder.getCode();
readStringIntoRhino(serviceJavascript, serviceInfo.getName() + ".js");
+ }
+
+ public static String scriptableToString(Scriptable scriptable) {
+ StringBuilder builder = new StringBuilder();
+ for (Object propid : scriptable.getIds()) {
+ String propIdString = Context.toString(propid);
+ String propValue = Context.toString(scriptable.get(propIdString, scriptable));
+ builder.append(propIdString);
+ builder.append(": ");
+ builder.append(propValue);
+ builder.append("; ");
+ }
+ return builder.toString();
}
}
Added: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/BeanRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/BeanRequestWrapper.java?rev=597754&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/BeanRequestWrapper.java (added)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/BeanRequestWrapper.java Fri Nov 23 15:02:40 2007
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.javascript.fortest;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Wrapper class.
+ */
+@XmlRootElement(namespace = "uri:org.apache.cxf.javascript.testns")
+// specify alphabetical order explicitly to remind us that there is JavaScript code that knows this order!
+@XmlType(namespace = "uri:org.apache.cxf.javascript.testns",
+ propOrder = {"bean1", "beanArray" })
+public class BeanRequestWrapper {
+ private TestBean1 bean1;
+ private TestBean1[] beanArray;
+
+ public TestBean1 getBean1() {
+ return bean1;
+ }
+ public void setBean1(TestBean1 bean1) {
+ this.bean1 = bean1;
+ }
+ public TestBean1[] getBeanArray() {
+ return beanArray;
+ }
+ public void setBeanArray(TestBean1[] beanArray) {
+ this.beanArray = beanArray;
+ }
+}
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrapped.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrapped.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrapped.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrapped.java Fri Nov 23 15:02:40 2007
@@ -34,12 +34,14 @@
@RequestWrapper(className = "org.apache.cxf.javascript.fortest.BasicTypeFunctionReturnStringWrapper")
@ResponseWrapper(className = "org.apache.cxf.javascript.fortest.StringWrapper")
@WebResult(name = "returnValue", targetNamespace = "uri:org.apache.cxf.javascript.testns")
+ @WebMethod
String basicTypeFunctionReturnString(@WebParam(name = "s") String s,
@WebParam(name = "i") int i,
@WebParam(name = "l") long l,
@WebParam(name = "f") float f,
@WebParam(name = "d") double d);
+ @WebMethod
String basicTypeFunctionReturnStringNoWrappers(@WebParam(name = "s") String s,
@WebParam(name = "i") int i,
@WebParam(name = "l") long l,
@@ -48,11 +50,19 @@
@WebMethod
TestBean1 functionReturnTestBean1();
+
+ @WebMethod
int basicTypeFunctionReturnInt(@WebParam(name = "s") String s,
@WebParam(name = "i") int i,
@WebParam(name = "l") long l,
@WebParam(name = "f") float f,
@WebParam(name = "d") double d);
+
+ @RequestWrapper(className = "org.apache.cxf.javascript.fortest.BeanRequestWrapper")
+ @WebMethod
+ void beanFunctionWithWrapper(@WebParam(name = "bean1") TestBean1 bean,
+ @WebParam(name = "beanArray") TestBean1[] beans);
+
@WebMethod
void beanFunction(@WebParam(name = "bean1") TestBean1 bean,
@WebParam(name = "beanArray") TestBean1[] beans);
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrappedImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrappedImpl.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrappedImpl.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/SimpleDocLitWrappedImpl.java Fri Nov 23 15:02:40 2007
@@ -72,6 +72,12 @@
}
/** {@inheritDoc}*/
+ public void beanFunctionWithWrapper(TestBean1 bean, TestBean1[] beans) {
+ lastBean1 = bean;
+ lastBean1Array = beans;
+ }
+
+ /** {@inheritDoc}*/
public TestBean1 functionReturnTestBean1() {
TestBean1 bean1 = new TestBean1();
bean1.intItem = 42;
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean1.java Fri Nov 23 15:02:40 2007
@@ -31,6 +31,8 @@
public class TestBean1 {
public TestBean1() {
+ intItem = 43;
+ doubleItem = -1.0;
beanTwoItem = new TestBean2("required=true");
beanTwoNotRequiredItem = null;
}
@@ -55,4 +57,28 @@
@XmlElement(required = false)
public TestBean2 beanTwoNotRequiredItem;
//CHECKSTYLE:ON
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof TestBean1)) {
+ return false;
+ }
+ TestBean1 other = (TestBean1) obj;
+ return stringItem.equals(other.stringItem)
+ && intItem == other.intItem
+ && longItem == other.longItem
+ && base64Item == other.base64Item
+ && optionalIntItem == other.optionalIntItem
+ && optionalIntArrayItem == other.optionalIntArrayItem
+ && doubleItem == other.doubleItem
+ && beanTwoItem.equals(other.beanTwoItem)
+ && beanTwoNotRequiredItem.equals(other.beanTwoNotRequiredItem);
+ }
+
+ @Override
+ public int hashCode() {
+ // intentionally stupid. We don't use this object in collections.
+ return super.hashCode();
+ }
+
}
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean2.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean2.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean2.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/fortest/TestBean2.java Fri Nov 23 15:02:40 2007
@@ -36,4 +36,20 @@
//CHECKSTYLE:OFF
public String stringItem;
//CHECKSTYLE:ON
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof TestBean2)) {
+ return false;
+ }
+ TestBean2 other = (TestBean2) obj;
+ return stringItem.equals(other.stringItem);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return stringItem.hashCode();
+ }
+
+
}
Modified: incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/service/DocLitWrappedTest.java Fri Nov 23 15:02:40 2007
@@ -29,6 +29,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.w3c.dom.Document;
@@ -41,11 +42,14 @@
import org.apache.cxf.databinding.DataReader;
import org.apache.cxf.databinding.DataWriter;
import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.javascript.DocLitWrappedClientTest;
import org.apache.cxf.javascript.JavascriptTestUtilities;
import org.apache.cxf.javascript.JavascriptTestUtilities.JSRunnable;
import org.apache.cxf.javascript.JsSimpleDomNode;
import org.apache.cxf.javascript.fortest.BasicTypeFunctionReturnStringWrapper;
import org.apache.cxf.javascript.fortest.StringWrapper;
+import org.apache.cxf.javascript.fortest.TestBean1;
+import org.apache.cxf.javascript.fortest.TestBean2;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.service.model.MessageInfo;
import org.apache.cxf.service.model.MessagePartInfo;
@@ -65,6 +69,8 @@
private static final Logger LOG = LogUtils.getL7dLogger(DocLitWrappedTest.class);
private static final String BASIC_TYPE_FUNCTION_RETURN_STRING_SERIALIZER_NAME
= "org_apache_cxf_javascript_fortest_basicTypeFunctionReturnString_serializeInput";
+ private static final String BEAN_FUNCTION_SERIALIZER_NAME
+ = "org_apache_cxf_javascript_fortest_beanFunctionWithWrapper_serializeInput";
private JavascriptTestUtilities testUtilities;
private Client client;
@@ -139,6 +145,21 @@
assertEquals(params[4], wrapper.getS());
}
+ @Test
+ public void testBeanFunctionSerialization() throws Exception {
+ setupClientAndRhino("simple-dlwu-proxy-factory");
+ final DataBinding dataBinding = clientProxyFactory.getServiceFactory().getDataBinding();
+ assertNotNull(dataBinding);
+
+ testUtilities.runInsideContext(Void.class, new JSRunnable<Void>() {
+ public Void run(Context context) {
+ return runBeanSerializationTest(dataBinding, context);
+ }
+ }
+ );
+ }
+
+
@Test
public void testResponseDeserialization() throws Exception {
setupClientAndRhino("simple-dlwu-proxy-factory");
@@ -187,5 +208,65 @@
@Override
protected void additionalSpringConfiguration(GenericApplicationContext context) throws Exception {
+ }
+
+ private Void runBeanSerializationTest(final DataBinding dataBinding, Context context) {
+
+ TestBean1 b1 = new TestBean1();
+ b1.stringItem = "strung";
+ TestBean1[] beans = new TestBean1[3];
+ beans[0] = new TestBean1();
+ beans[0].beanTwoNotRequiredItem = new TestBean2("bean2");
+ beans[1] = null;
+ beans[2] = new TestBean1();
+ beans[2].optionalIntArrayItem = new int[2];
+ beans[2].optionalIntArrayItem[0] = 4;
+ beans[2].optionalIntArrayItem[1] = 6;
+
+ Object[] jsBeans = new Object[3];
+ jsBeans[0] = DocLitWrappedClientTest.testBean1ToJS(testUtilities, context, beans[0]);
+ jsBeans[1] = DocLitWrappedClientTest.testBean1ToJS(testUtilities, context, beans[1]);
+ jsBeans[2] = DocLitWrappedClientTest.testBean1ToJS(testUtilities, context, beans[2]);
+
+ Scriptable jsBean1 = DocLitWrappedClientTest.testBean1ToJS(testUtilities, context, b1);
+ Scriptable jsBeanArray = context.newArray(testUtilities.getRhinoScope(), jsBeans);
+ Scriptable paramsArray = context.newArray(testUtilities.getRhinoScope(),
+ new Object[] {jsBean1, jsBeanArray });
+
+ String xmlString = testUtilities.rhinoCallConvert(BEAN_FUNCTION_SERIALIZER_NAME,
+ String.class,
+ paramsArray);
+ DataReader<XMLStreamReader> reader = dataBinding.createReader(XMLStreamReader.class);
+ ServiceInfo serviceInfo = serviceInfos.get(0); // assume we only have one.
+ QName messageName = new QName("uri:org.apache.cxf.javascript.fortest",
+ "beanFunctionWithWrapper");
+ MessageInfo inputMessage = serviceInfo.getMessage(messageName);
+ assertNotNull(inputMessage);
+ MessagePartInfo part = inputMessage.getMessagePartByIndex(0); // has only one part.
+ LOG.info(part.getConcreteName().toString());
+ // Read into the full message to find the part.
+ StringReader stringReader = new StringReader(xmlString);
+ XMLStreamReader xmlStreamReader;
+ boolean gotToPart = false;
+ Object messageObject = null;
+ try {
+ xmlStreamReader = xmlInputFactory.createXMLStreamReader(stringReader);
+ gotToPart = false;
+ do {
+ int item = xmlStreamReader.next();
+ if (item == XMLStreamReader.START_ELEMENT) {
+ LOG.finest(xmlStreamReader.getName().toString());
+ if (xmlStreamReader.getName().equals(part.getConcreteName())) {
+ gotToPart = true;
+ }
+ }
+ } while (!gotToPart && xmlStreamReader.hasNext());
+ assertTrue("Found element " + part.getConcreteName().toString(), gotToPart);
+ messageObject = reader.read(part, xmlStreamReader);
+ } catch (XMLStreamException e) {
+ throw new RuntimeException(e);
+ }
+ assertNotNull(messageObject);
+ return null;
}
}
Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/DocLitWrappedClientTestBeans.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/DocLitWrappedClientTestBeans.xml?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/DocLitWrappedClientTestBeans.xml (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/DocLitWrappedClientTestBeans.xml Fri Nov 23 15:02:40 2007
@@ -30,16 +30,19 @@
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
-
- <jaxws:endpoint id="dlw-service-endpoint"
- implementor="org.apache.cxf.javascript.fortest.SimpleDocLitWrappedImpl"
+
+ <bean id='dlw-service' class='org.apache.cxf.javascript.fortest.SimpleDocLitWrappedImpl'/>
+
+ <!-- use # so that we can pull state out of the service object in the tests. -->
+ <jaxws:endpoint id="dlw-service-endpoint"
+ implementor="#dlw-service"
address="http://localhost:8808/SimpleDocLitWrapped" >
- </jaxws:endpoint>
+ </jaxws:endpoint>
- <bean id="dlw-proxy-factory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean" >
+ <bean id="dlw-proxy-factory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean" >
<property name="serviceClass" value="org.apache.cxf.javascript.fortest.SimpleDocLitWrapped"/>
<property name="address" value="http://localhost:8808/SimpleDocLitWrapped"/>
- </bean>
+ </bean>
</beans>
Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/logging.properties Fri Nov 23 15:02:40 2007
@@ -23,7 +23,9 @@
.level= INFO
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
-#org.apache.cxf.javascript.service.ServiceJavascriptBuilder.level=FINE
-#org.apache.cxf.javascript.JavascriptTestUtilities.level=FINE
-#org.apache.cxf.javascript.JsXMLHttpRequest.level = FINE
+org.apache.cxf.javascript.service.ServiceJavascriptBuilder.level=WARNING
+org.apache.cxf.javascript.types.SchemaJavascriptBuilder.level=WARNING
+org.apache.cxf.javascript.JavascriptTestUtilities.level=FINE
+org.apache.cxf.javascript.JsXMLHttpRequest.level = WARNING
+org.apache.cxf.javascript.service.DocLitWrappedTest.level=FINE
Modified: incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/DocLitWrappedTests.js
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/DocLitWrappedTests.js?rev=597754&r1=597753&r2=597754&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/DocLitWrappedTests.js (original)
+++ incubator/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/DocLitWrappedTests.js Fri Nov 23 15:02:40 2007
@@ -27,9 +27,16 @@
var globalErrorStatusText = null;
var globalResponseObject = null;
+function resetGlobals() {
+ globalNotifier = null;
+ globalErrorStatus = null;
+ globalErrorStatusText = null;
+ globalResponseObject = null;
+}
+
function test1ErrorCallback(httpStatus, httpStatusText)
{
- org_apache_cxf_trace.trace("test1/2 error");
+ org_apache_cxf_trace.trace("test1/2/3 error");
globalErrorStatus = httpStatus;
globalStatusText = httpStatusText;
globalNotifier.notify();
@@ -40,7 +47,7 @@
// from Java, I think.
function test1SuccessCallback(responseObject)
{
- org_apache_cxf_trace.trace("test1/2 success");
+ org_apache_cxf_trace.trace("test1/2/3 success");
globalResponseObject = responseObject;
globalNotifier.notify();
}
@@ -48,6 +55,7 @@
function test1(url, doubleArg, floatArg, intArg, longArg, stringArg)
{
org_apache_cxf_trace.trace("Enter test1.");
+ resetGlobals();
globalNotifier = new org_apache_cxf_notifier();
var intf = new org_apache_cxf_javascript_fortest_SimpleDocLitWrapped();
@@ -63,6 +71,7 @@
function test2(url, doubleArg, floatArg, intArg, longArg, stringArg)
{
org_apache_cxf_trace.trace("Enter test2.");
+ resetGlobals();
globalNotifier = new org_apache_cxf_notifier();
var intf = new org_apache_cxf_javascript_fortest_SimpleDocLitWrapped();
@@ -73,3 +82,32 @@
// Return the notifier as a convenience to the Java code.
return globalNotifier;
}
+
+function test3(url, doubleArg, floatArg, intArg, longArg, stringArg)
+{
+ org_apache_cxf_trace.trace("Enter test3.");
+ resetGlobals();
+ globalNotifier = new org_apache_cxf_notifier();
+
+ var intf = new org_apache_cxf_javascript_fortest_SimpleDocLitWrapped();
+ intf.url = url;
+ // param order from the interface
+ intf.basicTypeFunctionReturnInt(test1SuccessCallback, test1ErrorCallback,
+ stringArg, intArg, longArg, floatArg, doubleArg);
+ // Return the notifier as a convenience to the Java code.
+ return globalNotifier;
+}
+
+function test4(url, beanArg, beansArg)
+{
+ org_apache_cxf_trace.trace("Enter test4.");
+ resetGlobals();
+ globalNotifier = new org_apache_cxf_notifier();
+
+ var intf = new org_apache_cxf_javascript_fortest_SimpleDocLitWrapped();
+ intf.url = url;
+ // param order from the interface
+ intf.beanFunction(test1SuccessCallback, test1ErrorCallback, beanArg, beansArg);
+ // Return the notifier as a convenience to the Java code.
+ return globalNotifier;
+}
\ No newline at end of file