From jboss-remoting-commits at lists.jboss.org Fri Dec 24 19:12:10 2010 Content-Type: multipart/mixed; boundary="===============6119065402740925188==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r6194 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http. Date: Fri, 24 Dec 2010 19:12:09 -0500 Message-ID: <201012250012.oBP0C9nK021002@svn01.web.mwc.hst.phx2.redhat.com> --===============6119065402740925188== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2010-12-24 19:12:09 -0500 (Fri, 24 Dec 2010) New Revision: 6194 Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/= IgnoreResponseMessageTestCase.java Log: JBREM-1248: New unit tests. Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/h= ttp/IgnoreResponseMessageTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http= /IgnoreResponseMessageTestCase.java (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http= /IgnoreResponseMessageTestCase.java 2010-12-25 00:12:09 UTC (rev 6194) @@ -0,0 +1,321 @@ +/* +* 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.remoting.util.SecurityUtility; +import org.jboss.test.remoting.classloader.RemoteClassloaderTestCase; + + +/** + * JBREM-1248. + * = + * @author Ron Sigal + * @version $Rev$ + *
+ * Copyright Dec 24, 2010 + *
+ */ +public class IgnoreResponseMessageTestCase extends TestCase +{ + private static Logger log =3D Logger.getLogger(IgnoreResponseMessageTes= tCase.class); + = + protected String host; + protected int port; + protected String locatorURI; + protected ByteArrayOutputStream baos; + protected PrintStream originalPrintStream; + + = + public void setUp() throws Exception + { + originalPrintStream =3D System.out; + baos =3D new ByteArrayOutputStream(); + PrintStream ps =3D new PrintStream(baos); + setOut(ps); + = + Logger.getLogger("org.jboss.remoting").setLevel(Level.DEBUG); + Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO); + String pattern =3D "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n"; + PatternLayout layout =3D new PatternLayout(pattern); + ConsoleAppender consoleAppender =3D new ConsoleAppender(layout); + Logger.getRootLogger().addAppender(consoleAppender); = + log =3D 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 =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraClientConfig(clientConfig); + Client client =3D 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()); + } + = + setOut(originalPrintStream); + String s =3D 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 Throwab= le + { + log.info("entering " + getName()); + + // Create client. + setupLocator(); + locatorURI +=3D "&ignoreErrorResponseMessage=3Dfalse"; + log.info(this + " locator: " + locatorURI); + InvokerLocator clientLocator =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraClientConfig(clientConfig); + Client client =3D 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()); + } + = + setOut(originalPrintStream); + String s =3D 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 +=3D "&" + HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAG= E + "=3Dtrue"; + log.info(this + " locator: " + locatorURI); + InvokerLocator clientLocator =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraClientConfig(clientConfig); + Client client =3D 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()); + } + = + setOut(originalPrintStream); + String s =3D new String(baos.toByteArray()); + System.out.println(s); + assertTrue(s.indexOf("Unable to retrieve response message") =3D=3D -= 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 =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + clientConfig.put(HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAGE, "f= alse"); + addExtraClientConfig(clientConfig); + Client client =3D 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()); + } + = + setOut(originalPrintStream); + String s =3D 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 +=3D "&" + HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAG= E + "=3Dtrue"; + log.info(this + " locator: " + locatorURI); + InvokerLocator clientLocator =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + clientConfig.put(HTTPClientInvoker.IGNORE_ERROR_RESPONSE_MESSAGE, "t= rue"); + addExtraClientConfig(clientConfig); + Client client =3D 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()); + } + = + setOut(originalPrintStream); + String s =3D new String(baos.toByteArray()); + System.out.println(s); + assertTrue(s.indexOf("Unable to retrieve response message") =3D=3D -= 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 =3D InetAddress.getLocalHost().getHostAddress(); + port =3D PortUtil.findFreePort(host); + locatorURI =3D getTransport() + "://" + host + ":" + port + "/?a=3Db= "; + String metadata =3D System.getProperty("remoting.metadata"); + if (metadata !=3D null) + { + locatorURI +=3D "&" + metadata; + } + } + = + = + static private void setOut(final PrintStream ps) + { + if (SecurityUtility.skipAccessControl()) + { + System.setOut(ps); + return; + } + = + try + { + AccessController.doPrivileged( new PrivilegedExceptionAction() + { + public Object run() throws Exception + { + System.setOut(ps); + return null; + } + }); + } + catch (PrivilegedActionException e) + { + throw (RuntimeException) e.getCause(); + } + } +} \ No newline at end of file --===============6119065402740925188==--