Author: ron.sigal(a)jboss.com
Date: 2010-12-25 00:08:35 -0500 (Sat, 25 Dec 2010)
New Revision: 6196
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/IgnoreResponseMessageTestCase.java
Log:
JBREM-1248: New unit tests.
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/IgnoreResponseMessageTestCase.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/IgnoreResponseMessageTestCase.java
(rev 0)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/IgnoreResponseMessageTestCase.java 2010-12-25
05:08:35 UTC (rev 6196)
@@ -0,0 +1,294 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.http;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.http.HTTPClientInvoker;
+import org.jboss.test.remoting.classloader.RemoteClassloaderTestCase;
+
+
+/**
+ * JBREM-1248.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Dec 24, 2010
+ * </p>
+ */
+public class IgnoreResponseMessageTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(IgnoreResponseMessageTestCase.class);
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected ByteArrayOutputStream baos;
+ protected PrintStream originalPrintStream;
+
+
+ public void setUp() throws Exception
+ {
+ originalPrintStream = System.out;
+ baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ System.setOut(ps);
+
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.DEBUG);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ log = Logger.getLogger(RemoteClassloaderTestCase.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ setupLocator();
+ log.info(this + " locator: " + locatorURI);
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Attempt invocation.
+ try
+ {
+ client.invoke("abc");
+ fail("expected exception");
+ }
+ catch (Exception e)
+ {
+ log.info(this + " got exception: " + e.getMessage());
+ }
+
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("Unable to retrieve response message") > -1);
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIgnoreErrorResponseMessageLocatorFalse() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ setupLocator();
+ locatorURI += "&ignoreErrorResponseMessage=false";
+ log.info(this + " locator: " + locatorURI);
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Attempt invocation.
+ try
+ {
+ client.invoke("abc");
+ fail("expected exception");
+ }
+ catch (Exception e)
+ {
+ log.info(this + " got exception: " + e.getMessage());
+ }
+
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("Unable to retrieve response message") > -1);
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIgnoreErrorResponseMessageLocatorTrue() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ setupLocator();
+ locatorURI += "&" + HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAGE +
"=true";
+ log.info(this + " locator: " + locatorURI);
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Attempt invocation.
+ try
+ {
+ client.invoke("abc");
+ fail("expected exception");
+ }
+ catch (Exception e)
+ {
+ log.info(this + " got exception: " + e.getMessage());
+ }
+
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("Unable to retrieve response message") == -1);
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIgnoreErrorResponseMessageConfigFalse() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ setupLocator();
+ log.info(this + " locator: " + locatorURI);
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAGE,
"false");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Attempt invocation.
+ try
+ {
+ client.invoke("abc");
+ fail("expected exception");
+ }
+ catch (Exception e)
+ {
+ log.info(this + " got exception: " + e.getMessage());
+ }
+
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("Unable to retrieve response message") > -1);
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIgnoreErrorResponseMessageConfigTrue() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ setupLocator();
+ locatorURI += "&" + HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAGE +
"=true";
+ log.info(this + " locator: " + locatorURI);
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAGE,
"true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Attempt invocation.
+ try
+ {
+ client.invoke("abc");
+ fail("expected exception");
+ }
+ catch (Exception e)
+ {
+ log.info(this + " got exception: " + e.getMessage());
+ }
+
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("Unable to retrieve response message") == -1);
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "http";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupLocator() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port +
"/?a=b";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ }
+}
\ No newline at end of file