From jboss-remoting-commits at lists.jboss.org Wed Feb 17 16:45:01 2010 Content-Type: multipart/mixed; boundary="===============4333120070372348093==" 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: r5719 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator. Date: Wed, 17 Feb 2010 16:45:01 -0500 Message-ID: <201002172145.o1HLj1xV012409@svn01.web.mwc.hst.phx2.redhat.com> --===============4333120070372348093== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2010-02-17 16:45:01 -0500 (Wed, 17 Feb 2010) New Revision: 5719 Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator/Malform= edLocatorTestCase.java Log: JBREM-1180: New unit tests. Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator/Mal= formedLocatorTestCase.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/locator/Malfor= medLocatorTestCase.java (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator/Malfor= medLocatorTestCase.java 2010-02-17 21:45:01 UTC (rev 5719) @@ -0,0 +1,188 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2010, 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.locator; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +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.InvokerLocator; +import org.jboss.remoting.util.SecurityUtility; + + +/** + * Unit tests for JBREM-1180. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 17, 2010 + */ +public class MalformedLocatorTestCase extends TestCase +{ + private ByteArrayOutputStream baos; + private PrintStream originalPrintStream; + private Logger log; + = + 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.INFO); + 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(MalformedLocatorTestCase.class); + } + + = + public void tearDown() + { + } + = + = + public void testMalformedLocatorDefaultLogging() throws Throwable + { + log.info("entering " + getName()); + String locatorURI =3D "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPo= olSize=3D200"; + InvokerLocator locator =3D new InvokerLocator(locatorURI); + System.out.println(locatorURI + " -> " + locator); + setOut(originalPrintStream); + String s =3D new String(baos.toByteArray()); + System.out.println(s); + assertTrue(s.indexOf("WARN") >=3D 0); + assertTrue(s.indexOf("Host resolves to null") >=3D 0); + System.out.println(getName() + " PASSES"); + } + = + = + public void testMalformedLocatorLoggingTurnedOff() throws Throwable + { + log.info("entering " + getName()); + setSystemProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "true"); + String locatorURI =3D "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPo= olSize=3D200"; + InvokerLocator locator =3D new InvokerLocator(locatorURI); + System.out.println(locatorURI + " -> " + locator); + setOut(originalPrintStream); + String s =3D new String(baos.toByteArray()); + System.out.println(s); + assertTrue(s.indexOf("WARN") =3D=3D -1); + assertTrue(s.indexOf("Host resolves to null") =3D=3D -1); + System.out.println(getName() + " PASSES"); + } + = + = + public void testMalformedLocatorLoggingTurnedOn() throws Throwable + { + log.info("entering " + getName()); + setSystemProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "false"); + String locatorURI =3D "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPo= olSize=3D200"; + InvokerLocator locator =3D new InvokerLocator(locatorURI); + System.out.println(locatorURI + " -> " + locator); + setOut(originalPrintStream); + String s =3D new String(baos.toByteArray()); + System.out.println(s); + assertTrue(s.indexOf("WARN") >=3D 0); + assertTrue(s.indexOf("Host resolves to null") >=3D 0); + System.out.println(getName() + " PASSES"); + } + = + = + public void testWellformedLocator() throws Throwable + { + log.info("entering " + getName()); + String locatorURI =3D "bisocket://UNDERSCORE:4457//?JBM_clientMaxPoo= lSize=3D200"; + InvokerLocator locator =3D new InvokerLocator(locatorURI); + System.out.println(locatorURI + " -> " + locator); + setOut(originalPrintStream); + String s =3D new String(baos.toByteArray()); + System.out.println(s); + assertTrue(s.indexOf("WARN") =3D=3D -1); + assertTrue(s.indexOf("Host resolves to null") =3D=3D -1); + System.out.println(getName() + " PASSES"); + } + = + = + static private void setSystemProperty(final String name, final String v= alue) + { + if (SecurityUtility.skipAccessControl()) + { + System.setProperty(name, value); + return; + } + = + try + { + AccessController.doPrivileged( new PrivilegedExceptionAction() + { + public Object run() throws Exception + { + return System.setProperty(name, value); + } + }); + } + catch (PrivilegedActionException e) + { + throw (RuntimeException) e.getCause(); + } + } + = + = + 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 --===============4333120070372348093==--