Author: ron.sigal(a)jboss.com
Date: 2009-08-26 15:44:41 -0400 (Wed, 26 Aug 2009)
New Revision: 5392
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/marshal/HttpContentTypeTestCase.java
Log:
JBREM-1145: Added new tests to account for making new content type test optional.
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/marshal/HttpContentTypeTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/marshal/HttpContentTypeTestCase.java 2009-08-26
19:41:52 UTC (rev 5391)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/marshal/HttpContentTypeTestCase.java 2009-08-26
19:44:41 UTC (rev 5392)
@@ -102,28 +102,109 @@
}
- public void testOrdinaryInvocation() throws Throwable
+ public void testOrdinaryInvocationDefault() throws Throwable
{
log.info("entering " + getName());
// Start server.
- setupServer();
+ setupServer(false, false);
// Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
HashMap clientConfig = new HashMap();
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
+ Client client = new Client(serverLocator, clientConfig);
client.connect();
log.info("client is connected");
+ // Do invocation.
+ Object o = client.invoke("abc");
+ assertTrue(o instanceof String);
+ String result = (String) o;
+
+ // Show that an InvocationResponse was incorrectly returned as a String, starting
with
+ // the ObjectInputStream header bytes.
+ byte[] bytes = result.getBytes();
+ System.out.print("bytes: ");
+ for (int i = 0; i < bytes.length; i++)
+ System.out.print(bytes[i] + " ");
+ System.out.println("");
+ assertEquals(-84, bytes[0]);
+ assertEquals(-19, bytes[1]);
+ assertEquals(0, bytes[2]);
+ assertEquals(5, bytes[3]);
+
+ // Check remoting content type handling.
+ validateOrdinaryInvocation(client);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testOrdinaryInvocationRemotingContentTypeFalse() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, false);
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Do invocation.
+ Object o = client.invoke("abc");
+ assertTrue(o instanceof String);
+ String result = (String) o;
+
+ // Show that an InvocationResponse was incorrectly returned as a String, starting
with
+ // the ObjectInputStream header bytes.
+ byte[] bytes = result.getBytes();
+ System.out.print("bytes: ");
+ for (int i = 0; i < bytes.length; i++)
+ System.out.print(bytes[i] + " ");
+ System.out.println("");
+ assertEquals(-84, bytes[0]);
+ assertEquals(-19, bytes[1]);
+ assertEquals(0, bytes[2]);
+ assertEquals(5, bytes[3]);
+
+ // Check remoting content type handling.
+ validateOrdinaryInvocation(client);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testOrdinaryInvocationRemotingContentTypeTrue() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, true);
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
// Test connections.
assertEquals("abc", client.invoke("abc"));
log.info("connection is good");
// Check remoting content type handling.
- validateOrdinaryInvocation();
+ validateOrdinaryInvocation(client);
client.disconnect();
shutdownServer();
@@ -131,19 +212,18 @@
}
- public void testRawStringMessage() throws Throwable
+ public void testRawStringMessageDefault() throws Throwable
{
log.info("entering " + getName());
// Start server.
- setupServer();
+ setupServer(false, false);
// Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
HashMap clientConfig = new HashMap();
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
+ Client client = new Client(serverLocator, clientConfig);
client.connect();
log.info("client is connected");
@@ -154,7 +234,7 @@
log.info("connection is good");
// Check remoting content type handling.
- validateRawStringMessage();
+ validateRawStringMessage(client);
client.disconnect();
shutdownServer();
@@ -162,8 +242,68 @@
}
- protected void validateOrdinaryInvocation()
+ public void testRawStringMessageRemotingContentTypeFalse() throws Throwable
{
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, false);
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ Map metadata = new HashMap();
+ metadata.put(Client.RAW, "true");
+ assertEquals("abc", client.invoke("abc", metadata));
+ log.info("connection is good");
+
+ // Check remoting content type handling.
+ validateRawStringMessage(client);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testRawStringMessageRemotingContentTypeTrue() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, true);
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ Map metadata = new HashMap();
+ metadata.put(Client.RAW, "true");
+ assertEquals("abc", client.invoke("abc", metadata));
+ log.info("connection is good");
+
+ // Check remoting content type handling.
+ validateRawStringMessage(client);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected void validateOrdinaryInvocation(Client client) throws Throwable
+ {
assertEquals(6, TestMarshaller.marshallers.size());
assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING,
((TestMarshaller)TestMarshaller.marshallers.get(3)).type);
assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING,
((TestMarshaller)TestMarshaller.marshallers.get(5)).type);
@@ -173,7 +313,7 @@
}
- protected void validateRawStringMessage()
+ protected void validateRawStringMessage(Client client) throws Throwable
{
assertEquals(6, TestMarshaller.marshallers.size());
assertEquals(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_STRING,
((TestMarshaller)TestMarshaller.marshallers.get(3)).type);
@@ -194,7 +334,7 @@
protected void addExtraServerConfig(Map config) {}
- protected void setupServer() throws Exception
+ protected void setupServer(boolean addUseRemotingContentType, boolean
useRemotingContentType) throws Exception
{
host = InetAddress.getLocalHost().getHostAddress();
port = PortUtil.findFreePort(host);
@@ -205,6 +345,10 @@
{
locatorURI += "&" + metadata;
}
+ if (addUseRemotingContentType)
+ {
+ locatorURI += "&useRemotingContentType=" +
useRemotingContentType;
+ }
serverLocator = new InvokerLocator(locatorURI);
log.info("Starting remoting server with locator uri of: " + locatorURI);
HashMap config = new HashMap();