You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by jo...@apache.org on 2006/01/08 02:03:27 UTC
svn commit: r366969 - in
/webservices/xmlrpc/branches/b20050512_streaming/src/test: java/ java/org/
java/org/apache/ java/org/apache/xmlrpc/ java/org/apache/xmlrpc/test/
resources/ resources/org/ resources/org/apache/
resources/org/apache/xmlrpc/ resou...
Author: jochen
Date: Sat Jan 7 17:03:11 2006
New Revision: 366969
URL: http://svn.apache.org/viewcvs?rev=366969&view=rev
Log:
The latest version of the maven-assembly-plugin is now being used.
Added:
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/BaseTest.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProviderImpl.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/CommonsProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LiteTransportProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalStreamTransportProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalTransportProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SerializerTest.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ServletWebServerProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SunHttpTransportProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/WebServerProvider.java
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/test/
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/test/BaseTest.properties
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/webserver/
webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/BaseTest.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/BaseTest.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/BaseTest.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/BaseTest.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,835 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfig;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.common.XmlRpcExtensionException;
+import org.apache.xmlrpc.server.PropertyHandlerMapping;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import junit.framework.TestCase;
+
+
+/** An abstract test case, to be implemented for the various
+ * transport classes.
+ */
+public class BaseTest extends TestCase {
+ private ClientProvider[] providers;
+
+ public void setUp() throws Exception {
+ if (providers == null) {
+ XmlRpcHandlerMapping mapping = getHandlerMapping();
+ providers = new ClientProvider[]{
+ new LocalTransportProvider(mapping),
+ new LocalStreamTransportProvider(mapping),
+ new LiteTransportProvider(mapping, true),
+ new LiteTransportProvider(mapping, false),
+ new SunHttpTransportProvider(mapping, true),
+ new SunHttpTransportProvider(mapping, false),
+ new CommonsProvider(mapping),
+ new ServletWebServerProvider(mapping, true),
+ new ServletWebServerProvider(mapping, false)
+ };
+ }
+ }
+
+ /** The remote class being invoked by the test case.
+ */
+ public static class Remote {
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public int byteParam(byte pArg) { return pArg*2; }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public byte byteResult(byte pArg) { return (byte) (pArg*2); }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public int shortParam(short pArg) { return pArg*2; }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public short shortResult(short pArg) { return (short) (pArg*2); }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public int intParam(int pArg) { return pArg*2; }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public int longParam(long pArg) { return (int) (pArg*2); }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public long longResult(long pArg) { return pArg*2; }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public double floatParam(float pArg) { return pArg*2; }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public float floatResult(float pArg) { return pArg*2; }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public double doubleParam(double pArg) { return pArg*2; }
+ /** Returns the argument, multiplied by two.
+ * @param pArg The argument being doubled.
+ * @return The argument, multiplied by two.
+ */
+ public double doubleResult(double pArg) { return pArg*2; }
+ /** Returns the argument, concatenated with itself.
+ * @param pArg The argument being concatenated.
+ * @return The argument, concatenated with itself.
+ */
+ public String stringParam(String pArg) { return pArg+pArg; }
+ /** Returns the argument, concatenated with itself.
+ * @param pArg The argument being concatenated.
+ * @return The argument, concatenated with itself.
+ */
+ public String nullableStringParam(String pArg) {
+ if (pArg == null) {
+ pArg = "";
+ }
+ return pArg+pArg;
+ }
+ /** Returns the argument, concatenated with itself.
+ * @param pArg The argument being concatenated.
+ * @return The argument, concatenated with itself.
+ */
+ public String nullableStringResult(String pArg) {
+ if (pArg == null) {
+ return null;
+ }
+ return pArg+pArg;
+ }
+ /** Returns the sum of the bytes in the given byte array.
+ * @param pArg The array of bytes being added.
+ * @return Sum over the bytes in the array.
+ */
+ public int byteArrayParam(byte[] pArg) {
+ int sum = 0;
+ for (int i = 0; i < pArg.length; i++) {
+ sum += pArg[i];
+ }
+ return sum;
+ }
+ /** Returns an array with the bytes 0..pArg.
+ * @param pArg Requestes byte array length.
+ * @return Byte array with 0..pArg.
+ */
+ public byte[] byteArrayResult(int pArg) {
+ byte[] result = new byte[pArg];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = (byte) i;
+ }
+ return result;
+ }
+ /** Returns the sum over the objects in the array.
+ * @param pArg Object array being added
+ * @return Sum over the objects in the array
+ */
+ public int objectArrayParam(Object[] pArg) {
+ int sum = 0;
+ for (int i = 0; i < pArg.length; i++) {
+ if (pArg[i] instanceof Number) {
+ sum += ((Number) pArg[i]).intValue();
+ } else {
+ sum += Integer.parseInt((String) pArg[i]);
+ }
+ }
+ return sum;
+ }
+ /** Returns an array of integers with the values
+ * 0..pArg.
+ * @param pArg Requested array length.
+ * @return Array of integers with the values 0..pArg
+ */
+ public Object[] objectArrayResult(int pArg) {
+ Object[] result = new Object[pArg];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = new Integer(i);
+ }
+ return result;
+ }
+ /** Returns a sum over the entries in the map. Each
+ * key is multiplied with its value.
+ * @param pArg The map being iterated.
+ * @return Sum of keys, multiplied by their values.
+ */
+ public int mapParam(Map pArg) {
+ int sum = 0;
+ for (Iterator iter = pArg.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String key = (String) entry.getKey();
+ Integer value = (Integer) entry.getValue();
+ sum += Integer.parseInt(key) * value.intValue();
+ }
+ return sum;
+ }
+ /** Returns a map with the stringified values 0..pArg as
+ * keys and the corresponding integers as values.
+ * @param pArg Requested map size.
+ * @return Map with the keys "0".."pArg" and
+ * 0..pArg as values.
+ */
+ public Map mapResult(int pArg) {
+ Map result = new HashMap();
+ for (int i = 0; i < pArg; i++) {
+ result.put(Integer.toString(i), new Integer(i));
+ }
+ return result;
+ }
+ /** Returns the sum of all "int" nodes in <code>pNode</code>.
+ * @param pNode The node being counted.
+ * @return The sum of the values of all "int" nodes.
+ */
+ public int nodeParam(Node pNode) {
+ if (pNode.getNodeType() != Node.DOCUMENT_NODE) {
+ throw new IllegalStateException("Expected document node, got " + pNode);
+ }
+ Element e = ((Document) pNode).getDocumentElement();
+ if (!ROOT_TAG.equals(e.getLocalName()) || !INT_URI.equals(e.getNamespaceURI())) {
+ throw new IllegalStateException("Expected root element 'root', got "
+ + new QName(e.getNamespaceURI(), e.getLocalName()));
+ }
+ return count(pNode);
+ }
+ private int count(Node pNode) {
+ if (INT_TAG.equals(pNode.getLocalName()) && INT_URI.equals(pNode.getNamespaceURI())) {
+ StringBuffer sb = new StringBuffer();
+ for (Node child = pNode.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.TEXT_NODE || child.getNodeType() == Node.CDATA_SECTION_NODE) {
+ sb.append(child.getNodeValue());
+ }
+ }
+ return Integer.parseInt(sb.toString());
+ } else {
+ int result = 0;
+ for (Node child = pNode.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ result += count(child);
+ }
+ }
+ return result;
+ }
+ }
+
+ /** Returns the calendar value in milliseconds.
+ * @param pCal Calendar object
+ * @return <code>pCal.getTime().getTime()</code>.
+ */
+ public long serializableParam(Calendar pCal) {
+ return pCal.getTime().getTime();
+ }
+ }
+
+ protected XmlRpcHandlerMapping getHandlerMapping() throws IOException, XmlRpcException {
+ return new PropertyHandlerMapping(getClass().getClassLoader(),
+ getClass().getResource("BaseTest.properties"));
+ }
+
+ protected XmlRpcClientConfigImpl getConfig(ClientProvider pProvider) throws Exception {
+ return pProvider.getConfig();
+ }
+
+ protected XmlRpcClientConfig getExConfig(ClientProvider pProvider) throws Exception {
+ XmlRpcClientConfigImpl config = getConfig(pProvider);
+ config.setEnabledForExtensions(true);
+ return config;
+ }
+
+ /** Test, whether we can invoke a method, passing a byte value.
+ * @throws Exception The test failed.
+ */
+ public void testByteParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testByteParam(providers[i]);
+ }
+ }
+
+ private void testByteParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.byteParam";
+ final Object[] params = new Object[]{new Byte((byte) 3)};
+ XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(6), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, returning a byte.
+ * @throws Exception The test failed.
+ */
+ public void testByteResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testByteResult(providers[i]);
+ }
+ }
+
+ private void testByteResult(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.byteResult";
+ final Object[] params = new Object[]{new Byte((byte) 3)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Byte((byte) 6), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, passing a short value.
+ * @throws Exception The test failed.
+ */
+ public void testShortParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testShortParam(providers[i]);
+ }
+ }
+
+ private void testShortParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.shortParam";
+ final Object[] params = new Object[]{new Short((short) 4)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(8), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, returning a short value.
+ * @throws Exception The test failed.
+ */
+ public void testShortResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testShortResult(providers[i]);
+ }
+ }
+
+ private void testShortResult(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.shortResult";
+ final Object[] params = new Object[]{new Short((short) 4)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Short((short) 8), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, passing an
+ * integer value.
+ * @throws Exception The test failed.
+ */
+ public void testIntParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testIntParam(providers[i]);
+ }
+ }
+
+ private void testIntParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.intParam";
+ final Object[] params = new Object[]{new Integer(5)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals(new Integer(10), result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(10), result);
+ }
+
+ /** Test, whether we can invoke a method, passing a long value.
+ * @throws Exception The test failed.
+ */
+ public void testLongParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testLongParam(providers[i]);
+ }
+ }
+
+ private void testLongParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.longParam";
+ final Object[] params = new Object[]{new Long(6L)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(12), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, returning a long value.
+ * @throws Exception The test failed.
+ */
+ public void testLongResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testLongResult(providers[i]);
+ }
+ }
+
+ private void testLongResult(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.longResult";
+ final Object[] params = new Object[]{new Long(6L)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Long(12L), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, passing a
+ * string value.
+ * @throws Exception The test failed.
+ */
+ public void testStringParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testStringParam(providers[i]);
+ }
+ }
+
+ private void testStringParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.stringParam";
+ final Object[] params = new Object[]{"abc"};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals("abcabc", result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals("abcabc", result);
+ }
+
+ /** Test, whether we can invoke a method, passing a
+ * string value or null.
+ * @throws Exception The test failed.
+ */
+ public void testNullableStringParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testNullableStringParam(providers[i]);
+ }
+ }
+
+ private void testNullableStringParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.nullableStringParam";
+ final Object[] params = new Object[]{"abc"};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals("abcabc", result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals("abcabc", result);
+ final Object[] nullParams = new Object[]{null};
+ result = client.execute(getExConfig(pProvider), methodName, nullParams);
+ assertEquals("", result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, nullParams);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, returning a
+ * string value or null.
+ * @throws Exception The test failed.
+ */
+ public void testNullableStringResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testNullableStringResult(providers[i]);
+ }
+ }
+
+ private void testNullableStringResult(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.nullableStringResult";
+ final Object[] params = new Object[]{"abc"};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals("abcabc", result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals("abcabc", result);
+ final Object[] nullParams = new Object[]{null};
+ result = client.execute(getExConfig(pProvider), methodName, nullParams);
+ assertEquals(null, result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, nullParams);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, passing a float value.
+ * @throws Exception The test failed.
+ */
+ public void testFloatParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testFloatParam(providers[i]);
+ }
+ }
+
+ private void testFloatParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.floatParam";
+ final Object[] params = new Object[]{new Float(0.4)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(8, Math.round(((Double) result).doubleValue()*10));
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, returning a float value.
+ * @throws Exception The test failed.
+ */
+ public void testFloatResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testFloatResult(providers[i]);
+ }
+ }
+
+ private void testFloatResult(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.floatResult";
+ final Object[] params = new Object[]{new Float(0.4)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Float(0.8), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, passing a
+ * double value.
+ * @throws Exception The test failed.
+ */
+ public void testDoubleParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testDoubleParam(providers[i]);
+ }
+ }
+
+ private void testDoubleParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.doubleParam";
+ final Object[] params = new Object[]{new Double(0.6)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals(new Double(1.2), result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Double(1.2), result);
+ }
+
+ /** Test, whether we can invoke a method, returning a
+ * double value.
+ * @throws Exception The test failed.
+ */
+ public void testDoubleResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testDoubleResult(providers[i]);
+ }
+ }
+
+ private void testDoubleResult(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.doubleResult";
+ final Object[] params = new Object[]{new Double(0.6)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals(new Double(1.2), result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Double(1.2), result);
+ }
+
+ /** Test, whether we can invoke a method, passing a
+ * byte array.
+ * @throws Exception The test failed.
+ */
+ public void testByteArrayParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testByteArrayParam(providers[i]);
+ }
+ }
+
+ private void testByteArrayParam(ClientProvider pProvider) throws Exception {
+ final byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ final String methodName = "Remote.byteArrayParam";
+ final Object[] params = new Object[]{bytes};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals(new Integer(0+1+2+3+4+5+6+7+8+9), result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(0+1+2+3+4+5+6+7+8+9), result);
+ }
+
+ /** Test, whether we can invoke a method, returning a
+ * byte array.
+ * @throws Exception The test failed.
+ */
+ public void testByteArrayResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testByteArrayResult(providers[i]);
+ }
+ }
+
+ private void testByteArrayResult(ClientProvider pProvider) throws Exception {
+ final byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7};
+ final String methodName = "Remote.byteArrayResult";
+ final Object[] params = new Object[]{new Integer(8)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertTrue(Arrays.equals(bytes, (byte[]) result));
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertTrue(Arrays.equals(bytes, (byte[]) result));
+ }
+
+ /** Test, whether we can invoke a method, passing an
+ * object array.
+ * @throws Exception The test failed.
+ */
+ public void testObjectArrayParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testObjectArrayParam(providers[i]);
+ }
+ }
+
+ private void testObjectArrayParam(ClientProvider pProvider) throws Exception {
+ final Object[] objects = new Object[]{new Byte((byte) 1), new Short((short) 2),
+ new Integer(3), new Long(4), "5"};
+ final String methodName = "Remote.objectArrayParam";
+ final Object[] params = new Object[]{objects};
+ final XmlRpcClient client = pProvider.getClient();
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(15), result);
+ }
+
+ /** Test, whether we can invoke a method, returning an
+ * object array.
+ * @throws Exception The test failed.
+ */
+ public void testObjectArrayResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testObjectArrayResult(providers[i]);
+ }
+ }
+
+ private void testObjectArrayResult(ClientProvider pProvider) throws Exception {
+ final Object[] objects = new Object[]{new Integer(0), new Integer(1),
+ new Integer(2), new Integer(3)};
+ final String methodName = "Remote.objectArrayResult";
+ final Object[] params = new Object[]{new Integer(4)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertTrue(Arrays.equals(objects, (Object[]) result));
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertTrue(Arrays.equals(objects, (Object[]) result));
+ }
+
+ /** Test, whether we can invoke a method, passing a map.
+ * @throws Exception The test failed.
+ */
+ public void testMapParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testMapParam(providers[i]);
+ }
+ }
+
+ private void testMapParam(ClientProvider pProvider) throws Exception {
+ final Map map = new HashMap();
+ map.put("2", new Integer(3));
+ map.put("3", new Integer(5));
+ final String methodName = "Remote.mapParam";
+ final Object[] params = new Object[]{map};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ assertEquals(new Integer(21), result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(21), result);
+ }
+
+ private void checkMap(Map pResult) {
+ assertEquals(4, pResult.size());
+ assertEquals(new Integer(0), pResult.get("0"));
+ assertEquals(new Integer(1), pResult.get("1"));
+ assertEquals(new Integer(2), pResult.get("2"));
+ assertEquals(new Integer(3), pResult.get("3"));
+ }
+
+ /** Test, whether we can invoke a method, returning a map.
+ * @throws Exception The test failed.
+ */
+ public void testMapResult() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testMapResult(providers[i]);
+ }
+ }
+
+ private void testMapResult(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.mapResult";
+ final Object[] params = new Object[]{new Integer(4)};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getConfig(pProvider), methodName, params);
+ checkMap((Map) result);
+ result = client.execute(getExConfig(pProvider), methodName, params);
+ checkMap((Map) result);
+ }
+
+ /** Test, whether we can invoke a method, passing a DOM
+ * node as parameter.
+ * @throws Exception The test failed.
+ */
+ public void testNodeParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testNodeParam(providers[i]);
+ }
+ }
+
+ private static final String ROOT_TAG = "root";
+ private static final String INT_TAG = "int";
+ private static final String INT_URI = "http://ws.apache.org/xmlrpc/namespaces/testNodeParam";
+
+ private void testNodeParam(ClientProvider pProvider) throws Exception {
+ final String xml =
+ "<" + ROOT_TAG + " xmlns='" + INT_URI +"'>" +
+ " <" + INT_TAG + ">1</" + INT_TAG + ">" +
+ " <" + INT_TAG + ">2</" + INT_TAG + ">" +
+ " <" + INT_TAG + ">3</" + INT_TAG + ">" +
+ " <" + INT_TAG + ">4</" + INT_TAG + ">" +
+ " <" + INT_TAG + ">5</" + INT_TAG + ">" +
+ "</" + ROOT_TAG + ">";
+ final String methodName = "Remote.nodeParam";
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(false);
+ dbf.setNamespaceAware(true);
+ Document doc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
+ final Object[] params = new Object[]{doc};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Integer(1+2+3+4+5), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+
+ /** Test, whether we can invoke a method, passing an instance of
+ * {@link java.io.Serializable} as an instance.
+ * @throws Exception The test failed.
+ */
+ public void testSerializableParam() throws Exception {
+ for (int i = 0; i < providers.length; i++) {
+ testSerializableParam(providers[i]);
+ }
+ }
+
+ private void testSerializableParam(ClientProvider pProvider) throws Exception {
+ final String methodName = "Remote.serializableParam";
+ Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ cal.set(Calendar.YEAR, 2005);
+ cal.set(Calendar.MONTH, 5);
+ cal.set(Calendar.DAY_OF_MONTH, 23);
+ cal.set(Calendar.HOUR_OF_DAY, 8);
+ cal.set(Calendar.MINUTE, 4);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 5);
+ final Object[] params = new Object[]{cal};
+ final XmlRpcClient client = pProvider.getClient();
+ Object result = client.execute(getExConfig(pProvider), methodName, params);
+ assertEquals(new Long(cal.getTime().getTime()), result);
+ boolean ok = false;
+ try {
+ client.execute(getConfig(pProvider), methodName, params);
+ } catch (XmlRpcExtensionException e) {
+ ok = true;
+ }
+ assertTrue(ok);
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+
+/** This interface allows to perform a unit test with various
+ * transports. Basically, the implementation creates the client,
+ * including the transport, and the server, if required.
+ */
+public interface ClientProvider {
+ /** Returns the clients default configuration.
+ * @return The clients configuration.
+ * @throws Exception Creating the configuration failed.
+ */
+ XmlRpcClientConfigImpl getConfig() throws Exception;
+
+ /** Returns a new client instance.
+ * @return A client being used for performing the test.
+ */
+ XmlRpcClient getClient();
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProviderImpl.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProviderImpl.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProviderImpl.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ClientProviderImpl.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.apache.xmlrpc.server.XmlRpcServer;
+
+
+/** Abstract base implementation of {@link org.apache.xmlrpc.test.ClientProvider}.
+ */
+public abstract class ClientProviderImpl implements ClientProvider {
+ protected final XmlRpcHandlerMapping mapping;
+
+ protected abstract XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient);
+
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ */
+ protected ClientProviderImpl(XmlRpcHandlerMapping pMapping) {
+ mapping = pMapping;
+ }
+
+ protected XmlRpcServer getXmlRpcServer() throws Exception {
+ XmlRpcServer server = new XmlRpcServer();
+ server.setHandlerMapping(mapping);
+ return server;
+ }
+
+ public XmlRpcClientConfigImpl getConfig() throws Exception {
+ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+ return config;
+ }
+
+ public XmlRpcClient getClient() {
+ XmlRpcClient client = new XmlRpcClient();
+ client.setTransportFactory(getTransportFactory(client));
+ return client;
+ }
+
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/CommonsProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/CommonsProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/CommonsProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/CommonsProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,38 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+
+
+/** Provider for testing the
+ * {@link org.apache.xmlrpc.client.XmlRpcCommonsTransport}.
+ */
+public class CommonsProvider extends WebServerProvider {
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ */
+ public CommonsProvider(XmlRpcHandlerMapping pMapping) {
+ super(pMapping, true);
+ }
+
+ protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
+ return new XmlRpcCommonsTransportFactory(pClient);
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LiteTransportProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LiteTransportProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LiteTransportProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LiteTransportProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,40 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcLiteHttpTransportFactory;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+
+
+/** Provider for testing the
+ * {@link org.apache.xmlrpc.client.XmlRpcLiteHttpTransport}.
+ */
+public class LiteTransportProvider extends WebServerProvider {
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ * @param pContentLength Whether a Content-Length header is required.
+ */
+ public LiteTransportProvider(XmlRpcHandlerMapping pMapping,
+ boolean pContentLength) {
+ super(pMapping, pContentLength);
+ }
+
+ protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
+ return new XmlRpcLiteHttpTransportFactory(pClient);
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalStreamTransportProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalStreamTransportProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalStreamTransportProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalStreamTransportProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,39 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcLocalStreamTransportFactory;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+
+
+/** Implementation of {@link org.apache.xmlrpc.test.BaseTest}
+ * for testing the {@link org.apache.xmlrpc.client.XmlRpcLocalStreamTransport}.
+ */
+public class LocalStreamTransportProvider extends LocalTransportProvider {
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ */
+ public LocalStreamTransportProvider(XmlRpcHandlerMapping pMapping) {
+ super(pMapping);
+ }
+
+ protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
+ XmlRpcLocalStreamTransportFactory factory = new XmlRpcLocalStreamTransportFactory(pClient);
+ return factory;
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalTransportProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalTransportProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalTransportProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/LocalTransportProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcLocalTransportFactory;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+
+
+/** Implementation of {@link org.apache.xmlrpc.test.BaseTest}
+ * for testing the {@link org.apache.xmlrpc.client.XmlRpcLocalTransport}.
+ */
+public class LocalTransportProvider extends ClientProviderImpl {
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ */
+ public LocalTransportProvider(XmlRpcHandlerMapping pMapping) {
+ super(pMapping);
+ }
+
+ protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
+ XmlRpcLocalTransportFactory factory = new XmlRpcLocalTransportFactory(pClient);
+ return factory;
+ }
+
+ public XmlRpcClientConfigImpl getConfig() throws Exception {
+ XmlRpcClientConfigImpl config = super.getConfig();
+ config.setXmlRpcServer(getXmlRpcServer());
+ return config;
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SerializerTest.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SerializerTest.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SerializerTest.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SerializerTest.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,136 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.ws.commons.serialize.XMLWriter;
+import org.apache.ws.commons.serialize.XMLWriterImpl;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcClientRequestImpl;
+import org.apache.xmlrpc.client.XmlRpcSunHttpTransportFactory;
+import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
+import org.apache.xmlrpc.serializer.XmlRpcWriter;
+import org.xml.sax.SAXException;
+
+
+/** A test case for the various serializers.
+ */
+public class SerializerTest extends TestCase {
+ private final XmlRpcClient client;
+
+ /** Creates a new instance.
+ */
+ public SerializerTest() {
+ client = new XmlRpcClient();
+ client.setTransportFactory(new XmlRpcSunHttpTransportFactory(client));
+ }
+
+ protected XmlRpcClientConfigImpl getConfig() {
+ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+ return config;
+ }
+
+ protected XmlRpcStreamRequestConfig getExConfig() {
+ XmlRpcClientConfigImpl config = getConfig();
+ config.setEnabledForExtensions(true);
+ return config;
+ }
+
+ protected String writeRequest(XmlRpcStreamRequestConfig pConfig, XmlRpcRequest pRequest)
+ throws XmlRpcException, SAXException {
+ StringWriter sw = new StringWriter();
+ XMLWriter xw = new XMLWriterImpl();
+ xw.setEncoding("US-ASCII");
+ xw.setDeclarating(true);
+ xw.setIndenting(false);
+ xw.setWriter(sw);
+ XmlRpcWriter xrw = new XmlRpcWriter(pConfig, xw, client.getTypeFactory());
+ xrw.write(pRequest);
+ return sw.toString();
+ }
+
+ /** Test serialization of a byte parameter.
+ * @throws Exception The test failed.
+ */
+ public void testByteParam() throws Exception {
+ XmlRpcStreamRequestConfig config = getExConfig();
+ XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteParam", new Object[]{new Byte((byte)3)});
+ String got = writeRequest(config, request);
+ String expect =
+ "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
+ + "<methodCall xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">"
+ + "<methodName>byteParam</methodName><params><param><value><ex:i1>3</ex:i1></value></param></params></methodCall>";
+ assertEquals(expect, got);
+ }
+
+ /** Test serialization of an integer parameter.
+ * @throws Exception The test failed.
+ */
+ public void testIntParam() throws Exception {
+ XmlRpcStreamRequestConfig config = getConfig();
+ XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "intParam", new Object[]{new Integer(3)});
+ String got = writeRequest(config, request);
+ String expect =
+ "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
+ + "<methodCall>"
+ + "<methodName>intParam</methodName><params><param><value><i4>3</i4></value></param></params></methodCall>";
+ assertEquals(expect, got);
+ }
+
+ /** Test serialization of a byte array.
+ * @throws Exception The test failed.
+ */
+ public void testByteArrayParam() throws Exception {
+ byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ XmlRpcStreamRequestConfig config = getConfig();
+ XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "byteArrayParam", new Object[]{bytes});
+ String got = writeRequest(config, request);
+ String expect =
+ "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
+ + "<methodCall>"
+ + "<methodName>byteArrayParam</methodName><params><param><value><base64>AAECAwQFBgcICQ==</base64></value></param></params></methodCall>";
+ assertEquals(expect, got);
+ }
+
+ /** Test serialization of a map.
+ * @throws Exception The test failed.
+ */
+ public void testMapParam() throws Exception {
+ final Map map = new HashMap();
+ map.put("2", new Integer(3));
+ map.put("3", new Integer(5));
+ final Object[] params = new Object[]{map};
+ XmlRpcStreamRequestConfig config = getConfig();
+ XmlRpcRequest request = new XmlRpcClientRequestImpl(config, "mapParam", params);
+ String got = writeRequest(config, request);
+ String expect =
+ "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>"
+ + "<methodCall><methodName>mapParam</methodName>"
+ + "<params><param><value><struct>"
+ + "<member><name>3</name><value><i4>5</i4></value></member>"
+ + "<member><name>2</name><value><i4>3</i4></value></member>"
+ + "</struct></value></param></params></methodCall>";
+ assertEquals(expect, got);
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ServletWebServerProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ServletWebServerProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ServletWebServerProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/ServletWebServerProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.ServletException;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcSunHttpTransportFactory;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.apache.xmlrpc.server.XmlRpcServer;
+import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
+import org.apache.xmlrpc.webserver.ServletWebServer;
+import org.apache.xmlrpc.webserver.XmlRpcServlet;
+
+
+/** A provider class for testing the {@link ServletWebServer}.
+ */
+public class ServletWebServerProvider extends ClientProviderImpl {
+ protected final ServletWebServer webServer;
+ private final boolean contentLength;
+ private final int port;
+
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ * @throws ServletException
+ * @throws IOException
+ */
+ protected ServletWebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) throws ServletException, IOException {
+ super(pMapping);
+ contentLength = pContentLength;
+ XmlRpcServlet servlet = new XmlRpcServlet();
+ webServer = new ServletWebServer(servlet, 0);
+ XmlRpcServer server = servlet.getXmlRpcServletServer();
+ server.setHandlerMapping(mapping);
+ XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
+ serverConfig.setEnabledForExtensions(true);
+ serverConfig.setContentLengthOptional(!contentLength);
+ webServer.start();
+ port = webServer.getPort();
+ }
+
+ public final XmlRpcClientConfigImpl getConfig() throws Exception {
+ return getConfig(new URL("http://127.0.0.1:" + port + "/"));
+ }
+
+ protected XmlRpcClientConfigImpl getConfig(URL pServerURL) throws Exception {
+ XmlRpcClientConfigImpl config = super.getConfig();
+ config.setServerURL(pServerURL);
+ config.setContentLengthOptional(!contentLength);
+ return config;
+ }
+
+ protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
+ return new XmlRpcSunHttpTransportFactory(pClient);
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SunHttpTransportProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SunHttpTransportProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SunHttpTransportProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/SunHttpTransportProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcSunHttpTransportFactory;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+
+
+
+
+/** Implementation of {@link BaseTest} for testing the
+ * {@link org.apache.xmlrpc.client.XmlRpcSunHttpTransport}.
+ */
+public class SunHttpTransportProvider extends WebServerProvider {
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ * @param pContentLength Number of bytes being transmitted.
+ */
+ public SunHttpTransportProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
+ super(pMapping, pContentLength);
+ }
+
+ protected XmlRpcTransportFactory getTransportFactory(XmlRpcClient pClient) {
+ return new XmlRpcSunHttpTransportFactory(pClient);
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/WebServerProvider.java
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/WebServerProvider.java?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/WebServerProvider.java (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/java/org/apache/xmlrpc/test/WebServerProvider.java Sat Jan 7 17:03:11 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 1999,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.xmlrpc.test;
+
+import java.net.URL;
+
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.apache.xmlrpc.server.XmlRpcServer;
+import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
+import org.apache.xmlrpc.webserver.WebServer;
+
+
+/** Abstract base class for providers, which require a webserver.
+ */
+public abstract class WebServerProvider extends ClientProviderImpl {
+ protected final WebServer webServer = new WebServer(0);
+ private boolean isActive;
+ private final boolean contentLength;
+
+ /** Creates a new instance.
+ * @param pMapping The test servers handler mapping.
+ */
+ protected WebServerProvider(XmlRpcHandlerMapping pMapping, boolean pContentLength) {
+ super(pMapping);
+ contentLength = pContentLength;
+ }
+
+ public final XmlRpcClientConfigImpl getConfig() throws Exception {
+ initWebServer();
+ return getConfig(new URL("http://127.0.0.1:" + webServer.getPort() + "/"));
+ }
+
+ protected XmlRpcClientConfigImpl getConfig(URL pServerURL) throws Exception {
+ XmlRpcClientConfigImpl config = super.getConfig();
+ config.setServerURL(pServerURL);
+ config.setContentLengthOptional(!contentLength);
+ return config;
+ }
+
+ protected void initWebServer() throws Exception {
+ if (!isActive) {
+ XmlRpcServer server = webServer.getXmlRpcServer();
+ server.setHandlerMapping(mapping);
+ XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
+ serverConfig.setEnabledForExtensions(true);
+ serverConfig.setContentLengthOptional(!contentLength);
+ webServer.start();
+ isActive = true;
+ }
+ }
+}
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/test/BaseTest.properties
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/test/BaseTest.properties?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/test/BaseTest.properties (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/test/BaseTest.properties Sat Jan 7 17:03:11 2006
@@ -0,0 +1 @@
+Remote=org.apache.xmlrpc.test.BaseTest$Remote
Added: webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties
URL: http://svn.apache.org/viewcvs/webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties?rev=366969&view=auto
==============================================================================
--- webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties (added)
+++ webservices/xmlrpc/branches/b20050512_streaming/src/test/resources/org/apache/xmlrpc/webserver/XmlRpcServlet.properties Sat Jan 7 17:03:11 2006
@@ -0,0 +1 @@
+Remote=org.apache.xmlrpc.test.BaseTest$Remote