Author: ron.sigal(a)jboss.com
Date: 2009-08-26 15:47:33 -0400 (Wed, 26 Aug 2009)
New Revision: 5394
Modified:
remoting2/branches/2.2/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.2/src/tests/org/jboss/test/remoting/transport/http/marshal/HttpContentTypeTestCase.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/marshal/HttpContentTypeTestCase.java 2009-08-26
19:46:43 UTC (rev 5393)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/marshal/HttpContentTypeTestCase.java 2009-08-26
19:47:33 UTC (rev 5394)
@@ -103,28 +103,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 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 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();
@@ -132,19 +213,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");
@@ -155,7 +235,7 @@
log.info("connection is good");
// Check remoting content type handling.
- validateRawStringMessage();
+ validateRawStringMessage(client);
client.disconnect();
shutdownServer();
@@ -163,8 +243,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);
@@ -174,7 +314,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);
@@ -195,7 +335,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);
@@ -206,6 +346,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();