Author: ron.sigal(a)jboss.com
Date: 2009-08-29 20:45:44 -0400 (Sat, 29 Aug 2009)
New Revision: 5405
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/ContentTypeTestClient.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestInvocationHandler.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestMarshaller.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestUnMarshaller.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/remoting-servlet-service.xml
Log:
JBREM-1145: Added unit tests for servlet transport.
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/ContentTypeTestClient.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/ContentTypeTestClient.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/ContentTypeTestClient.java 2009-08-30
00:45:44 UTC (rev 5405)
@@ -0,0 +1,132 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.servlet.marshal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+import org.jboss.test.remoting.transport.http.marshal.HttpContentTypeTestCase;
+
+
+/**
+ * Unit tests for JBREM-1145.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright August 17, 2009
+ * </p>
+ */
+public class ContentTypeTestClient extends HttpContentTypeTestCase
+{
+ private static Logger log = Logger.getLogger(ContentTypeTestClient.class);
+
+
+ protected void validateOrdinaryInvocation(Client client) throws Throwable
+ {
+ // Local tests
+ log.info("TestMarshaller.marshallers.size(): " +
TestMarshaller.marshallers.size());
+ log.info("TestMarshaller.unmarshallers.size(): " +
TestUnMarshaller.unmarshallers.size());
+ assertEquals(2, TestMarshaller.marshallers.size());
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING,
((TestMarshaller)TestMarshaller.marshallers.get(1)).type);
+ assertEquals(2, TestUnMarshaller.unmarshallers.size());
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING,
((TestUnMarshaller)TestUnMarshaller.unmarshallers.get(1)).type);
+
+ // Remote tests
+ int serverMarshallerCount = ((Integer)
client.invoke(TestInvocationHandler.GET_NUMBER_OF_MARSHALLERS)).intValue();
+ log.info("server side marshallers: " + serverMarshallerCount);
+ int serverUnmarshallerCount = ((Integer)
client.invoke(TestInvocationHandler.GET_NUMBER_OF_UNMARSHALLERS)).intValue();
+ log.info("server side unmarshallers: " + serverUnmarshallerCount);
+ Map metadata = new HashMap();
+ metadata.put(TestInvocationHandler.N, Integer.toString(serverMarshallerCount -
1));
+ String type = (String) client.invoke(TestInvocationHandler.GET_NTH_MARSHALLER_TYPE,
metadata);
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING, type);
+ metadata.put(TestInvocationHandler.N, Integer.toString(serverUnmarshallerCount -
1));
+ type = (String) client.invoke(TestInvocationHandler.GET_NTH_UNMARSHALLER_TYPE,
metadata);
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING, type);
+ client.invoke(TestInvocationHandler.RESET);
+ }
+
+
+ protected void validateRawStringMessage(Client client) throws Throwable
+ {
+ // Local tests
+ log.info("TestMarshaller.marshallers.size(): " +
TestMarshaller.marshallers.size());
+ log.info("TestMarshaller.unmarshallers.size(): " +
TestUnMarshaller.unmarshallers.size());
+ assertEquals(2, TestMarshaller.marshallers.size());
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_STRING,
((TestMarshaller)TestMarshaller.marshallers.get(1)).type);
+ assertEquals(2, TestUnMarshaller.unmarshallers.size());
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_STRING,
((TestUnMarshaller)TestUnMarshaller.unmarshallers.get(1)).type);
+
+ // Remote tests
+ int serverMarshallerCount = ((Integer)
client.invoke(TestInvocationHandler.GET_NUMBER_OF_MARSHALLERS)).intValue();
+ log.info("server side marshallers: " + serverMarshallerCount);
+ int serverUnmarshallerCount = ((Integer)
client.invoke(TestInvocationHandler.GET_NUMBER_OF_UNMARSHALLERS)).intValue();
+ log.info("server side unmarshallers: " + serverUnmarshallerCount);
+ assertEquals(4, serverMarshallerCount);
+ assertEquals(6, serverUnmarshallerCount);
+ Map metadata = new HashMap();
+ metadata.put(TestInvocationHandler.N, "3");
+ String type = (String) client.invoke(TestInvocationHandler.GET_NTH_MARSHALLER_TYPE,
metadata);
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_STRING, type);
+ metadata.put(TestInvocationHandler.N, "1");
+ type = (String) client.invoke(TestInvocationHandler.GET_NTH_UNMARSHALLER_TYPE,
metadata);
+ assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_STRING, type);
+ client.invoke(TestInvocationHandler.RESET);
+ }
+
+ protected String getTransport()
+ {
+ return "servlet";
+ }
+
+ protected void setupServer(boolean addUseRemotingContentType, boolean
useRemotingContentType) throws Exception
+ {
+ String path = null;
+ String useRemotingContentTypeAttribute = null;
+ if (addUseRemotingContentType)
+ {
+ if (useRemotingContentType)
+ {
+ path = "servlet-invoker/ServerInvokerServlet/true";
+ useRemotingContentTypeAttribute =
"&useRemotingContentType=true";
+ }
+ else
+ {
+ path = "servlet-invoker/ServerInvokerServlet/false";
+ useRemotingContentTypeAttribute =
"&useRemotingContentType=false";
+ }
+ }
+ else
+ {
+ path = "servlet-invoker/ServerInvokerServlet/default";
+ useRemotingContentTypeAttribute = "";
+ }
+
+ String locatorURI = "servlet://localhost:8080/" + path +
"/?datatype=test&marshaller=org.jboss.test.remoting.marshall.TestMarshaller&unmarshaller=org.jboss.test.remoting.marshall.TestUnmarshaller"
+ useRemotingContentTypeAttribute;
+ serverLocator = new InvokerLocator(locatorURI);
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestInvocationHandler.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestInvocationHandler.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestInvocationHandler.java 2009-08-30
00:45:44 UTC (rev 5405)
@@ -0,0 +1,114 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.test.remoting.transport.servlet.marshal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.marshal.MarshalFactory;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+
+
+/**
+ * For JBREM-1145.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright August 17, 2009
+ * </p>
+ */
+public class TestInvocationHandler implements ServerInvocationHandler
+{
+ public static String GET_NUMBER_OF_MARSHALLERS = "getNumberOfMarshallers";
+ public static String GET_NUMBER_OF_UNMARSHALLERS =
"getNumberOfUnmarshallers";
+ public static String GET_NTH_MARSHALLER_TYPE = "getNthMarshallerType";
+ public static String GET_NTH_UNMARSHALLER_TYPE = "getNthUnarshallerType";
+ public static String RESET = "reset";
+ public static String N = "n";
+
+ private static Logger log = Logger.getLogger(TestInvocationHandler.class);
+
+ static
+ {
+ MarshalFactory.addMarshaller("test", new TestMarshaller(), new
TestUnMarshaller());
+ }
+
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ String s = (String) invocation.getParameter();
+ log.info("command: " + s);
+ if (RESET.equals(s))
+ {
+ log.info("doing reset");
+ TestMarshaller.marshallers.clear();
+ TestUnMarshaller.unmarshallers.clear();
+ log.info("TestMarshaller.marshallers: " +
TestMarshaller.marshallers);
+ log.info("TestUnMarshaller.unmarshallers: " +
TestUnMarshaller.unmarshallers);
+ }
+ else if (GET_NUMBER_OF_MARSHALLERS.equals(s))
+ {
+ return new Integer(TestMarshaller.marshallers.size());
+ }
+ else if (GET_NUMBER_OF_UNMARSHALLERS.equals(s))
+ {
+ return new Integer(TestUnMarshaller.unmarshallers.size());
+ }
+ else if (GET_NTH_MARSHALLER_TYPE.equals(s))
+ {
+ int n =
Integer.valueOf((String)invocation.getRequestPayload().get(N)).intValue();
+ return ((TestMarshaller)TestMarshaller.marshallers.get(n)).type;
+ }
+ else if (GET_NTH_UNMARSHALLER_TYPE.equals(s))
+ {
+ int n =
Integer.valueOf((String)invocation.getRequestPayload().get(N)).intValue();
+ return ((TestUnMarshaller)TestUnMarshaller.unmarshallers.get(n)).type;
+ }
+ else if ("abc".equals(s))
+ {
+ Map responseMap = invocation.getReturnPayload();
+ if (responseMap == null)
+ {
+ responseMap = new HashMap();
+ invocation.setReturnPayload(responseMap);
+ }
+ responseMap.put(HTTPMetadataConstants.CONTENTTYPE, "text/html");
+ return invocation.getParameter();
+ }
+
+ return invocation.getParameter();
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestMarshaller.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestMarshaller.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestMarshaller.java 2009-08-30
00:45:44 UTC (rev 5405)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.test.remoting.transport.servlet.marshal;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.remoting.marshal.http.HTTPMarshaller;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+
+
+/**
+ * Part of unit tests for JBREM-1145
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Aug 20, 2009
+ * </p>
+ */
+public class TestMarshaller extends HTTPMarshaller
+{
+ private static Logger log = Logger.getLogger(TestMarshaller.class);
+
+ public static ArrayList marshallers = new ArrayList();
+ private static final long serialVersionUID = -7528137229006015488L;
+ public String type;
+
+ public void write(Object dataObject, OutputStream output, int version) throws
IOException
+ {
+ log.info(this + " writing " + dataObject);
+ type = (dataObject instanceof String) ?
HTTPMetadataConstants.REMOTING_CONTENT_TYPE_STRING :
HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING;
+ super.write(dataObject, output, version);
+ }
+
+ public Marshaller cloneMarshaller() throws CloneNotSupportedException
+ {
+ TestMarshaller marshaller = new TestMarshaller();
+ marshallers.add(marshaller);
+ log.info("returning " + marshaller);
+ return marshaller;
+ }
+}
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestUnMarshaller.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestUnMarshaller.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/TestUnMarshaller.java 2009-08-30
00:45:44 UTC (rev 5405)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.test.remoting.transport.servlet.marshal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.marshal.http.HTTPUnMarshaller;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+
+
+/**
+ * Part of unit tests for JBREM-1145.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Aug 20, 2009
+ * </p>
+ */
+public class TestUnMarshaller extends HTTPUnMarshaller
+{
+ public static ArrayList unmarshallers = new ArrayList();
+ private static final long serialVersionUID = -6422222480047910351L;
+ public String type;
+
+ public Object read(InputStream inputStream, Map metadata, int version) throws
IOException, ClassNotFoundException
+ {
+ Object o = metadata.get(HTTPMetadataConstants.REMOTING_CONTENT_TYPE);
+ if (o instanceof List)
+ {
+ type = (String) ((List) o).get(0);
+ }
+ else if (o instanceof String)
+ {
+ type = (String) o;
+ }
+ else
+ {
+ o = metadata.get(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_LC);
+ log.info("remotingcontenttype: " + o);
+ if (o instanceof List)
+ {
+ type = (String) ((List) o).get(0);
+ }
+ else if (o instanceof String)
+ {
+ type = (String) o;
+ }
+ else
+ {
+ log.warn(this + " unrecognized remotingContentType: " + o);
+ }
+ }
+
+ o = super.read(inputStream, metadata, version);
+ log.info(this + " read " + o);
+ return o;
+ }
+
+ public UnMarshaller cloneUnMarshaller() throws CloneNotSupportedException
+ {
+ TestUnMarshaller unmarshaller = new TestUnMarshaller();
+ unmarshallers.add(unmarshaller);
+ unmarshaller.setClassLoader(this.customClassLoader);
+ log.info("returning " + unmarshaller, new Exception());
+ return unmarshaller;
+ }
+}
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/remoting-servlet-service.xml
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/remoting-servlet-service.xml
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/servlet/marshal/remoting-servlet-service.xml 2009-08-30
00:45:44 UTC (rev 5405)
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+ <mbean code="org.jboss.remoting.transport.Connector"
+
name="jboss.remoting:service=Connector,transport=Servlet,useRemotingContentType=default"
+ display-name="Servlet transport Connector (default)">
+
+ <attribute name="Configuration">
+ <config>
+ <invoker transport="servlet">
+ <attribute
name="serverBindAddress">127.0.0.1</attribute>
+ <attribute name="serverBindPort">8080</attribute>
+ <attribute
name="path">servlet-invoker/ServerInvokerServlet/default</attribute>
+ <attribute name="datatype"
isParam="true">test</attribute>
+ <attribute name="marshaller"
isParam="true">org.jboss.test.remoting.transport.servlet.marshal.TestMarshaller</attribute>
+ <attribute name="unmarshaller"
isParam="true">org.jboss.test.remoting.transport.servlet.marshal.TestUnMarshaller</attribute>
+ </invoker>
+ <handlers>
+ <handler
subsystem="test">org.jboss.test.remoting.transport.servlet.marshal.TestInvocationHandler</handler>
+ </handlers>
+ </config>
+ </attribute>
+ </mbean>
+ <mbean code="org.jboss.remoting.transport.Connector"
+
name="jboss.remoting:service=Connector,transport=Servlet,useRemotingContentType=false"
+ display-name="Servlet transport Connector (false)">
+
+ <attribute name="Configuration">
+ <config>
+ <invoker transport="servlet">
+ <attribute
name="serverBindAddress">127.0.0.1</attribute>
+ <attribute name="serverBindPort">8080</attribute>
+ <attribute
name="path">servlet-invoker/ServerInvokerServlet/false</attribute>
+ <attribute name="datatype"
isParam="true">test</attribute>
+ <attribute name="marshaller"
isParam="true">org.jboss.test.remoting.transport.servlet.marshal.TestMarshaller</attribute>
+ <attribute name="unmarshaller"
isParam="true">org.jboss.test.remoting.transport.servlet.marshal.TestUnMarshaller</attribute>
+ <attribute name="useRemotingContentType"
isParam="true">false</attribute>
+ </invoker>
+ <handlers>
+ <handler
subsystem="test">org.jboss.test.remoting.transport.servlet.marshal.TestInvocationHandler</handler>
+ </handlers>
+ </config>
+ </attribute>
+ </mbean>
+ <mbean code="org.jboss.remoting.transport.Connector"
+
name="jboss.remoting:service=Connector,transport=Servlet,useRemotingContentType=true"
+ display-name="Servlet transport Connector (true)">
+
+ <attribute name="Configuration">
+ <config>
+ <invoker transport="servlet">
+ <attribute
name="serverBindAddress">127.0.0.1</attribute>
+ <attribute name="serverBindPort">8080</attribute>
+ <attribute
name="path">servlet-invoker/ServerInvokerServlet/true</attribute>
+ <attribute name="datatype"
isParam="true">test</attribute>
+ <attribute name="marshaller"
isParam="true">org.jboss.test.remoting.transport.servlet.marshal.TestMarshaller</attribute>
+ <attribute name="unmarshaller"
isParam="true">org.jboss.test.remoting.transport.servlet.marshal.TestUnMarshaller</attribute>
+ <attribute name="useRemotingContentType"
isParam="true">true</attribute>
+ </invoker>
+ <handlers>
+ <handler
subsystem="test">org.jboss.test.remoting.transport.servlet.marshal.TestInvocationHandler</handler>
+ </handlers>
+ </config>
+ </attribute>
+ </mbean>
+</server>