Author: veithen Date: Sun Jun 24 14:39:30 2012 New Revision: 1353277 URL: http://svn.apache.org/viewvc?rev=1353277&view=rev Log: Some unit test improvements.
Modified: axis/axis2/java/core/trunk/modules/jibx/pom.xml axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/Test.java axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/UtilServer.java axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java Modified: axis/axis2/java/core/trunk/modules/jibx/pom.xml URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/pom.xml?rev=1353277&r1=1353276&r2=1353277&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/jibx/pom.xml (original) +++ axis/axis2/java/core/trunk/modules/jibx/pom.xml Sun Jun 24 14:39:30 2012 @@ -66,6 +66,12 @@ <artifactId>ant</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>axis2-testutils</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> </dependencies> <url>http://axis.apache.org/axis2/java/core/</url> <scm> Modified: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/Test.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/Test.java?rev=1353277&r1=1353276&r2=1353277&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/Test.java (original) +++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/Test.java Sun Jun 24 14:39:30 2012 @@ -63,7 +63,7 @@ public class Test extends TestCase { Customer customer = new Customer("Redmond", person, "+14258858080", "WA", "14619 NE 80th Pl.", new Integer(98052)); EchoCustomerServiceStub stub = new EchoCustomerServiceStub(UtilServer.getConfigurationContext(), - "http://127.0.0.1:5555/axis2/services/EchoCustomerService/echo"); + "http://127.0.0.1:" + UtilServer.TESTING_PORT + "/axis2/services/EchoCustomerService/echo"); Customer result = stub.echo(customer); stopServer(); assertEquals("Result object does not match request object", Modified: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/UtilServer.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/UtilServer.java?rev=1353277&r1=1353276&r2=1353277&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/UtilServer.java (original) +++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/UtilServer.java Sun Jun 24 14:39:30 2012 @@ -24,20 +24,16 @@ import org.apache.axis2.context.Configur import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.description.AxisService; import org.apache.axis2.engine.ListenerManager; +import org.apache.axis2.testutils.PortAllocator; import org.apache.axis2.transport.http.SimpleHTTPServer; import javax.xml.namespace.QName; import java.io.File; public class UtilServer { - private static int count = 0; - private static SimpleHTTPServer receiver; - public static final int TESTING_PORT = 5555; - - public static final String FAILURE_MESSAGE = "Intentional Failure"; - + public static final int TESTING_PORT = PortAllocator.allocatePort(); public static synchronized void deployService(AxisService service) throws AxisFault { @@ -52,64 +48,20 @@ public class UtilServer { } public static synchronized void start(String repository) throws Exception { - if (count == 0) { - ConfigurationContext er = getNewConfigurationContext(repository); - - receiver = new SimpleHTTPServer(er, TESTING_PORT); - - try { - receiver.start(); - System.out.print("Server started on port " - + TESTING_PORT + "....."); - } finally { - - } - - try { - Thread.sleep(2000); - } catch (InterruptedException e1) { - throw new AxisFault("Thread interuptted", e1); - } - - } - count++; + start(repository, null); } public static synchronized void start(String repository, String axis2xml) throws Exception { - if (count == 0) { - ConfigurationContext er = getNewConfigurationContext(repository, axis2xml); - - receiver = new SimpleHTTPServer(er, TESTING_PORT); - - try { - receiver.start(); - System.out.print("Server started on port " - + TESTING_PORT + "....."); - } finally { - - } - - try { - Thread.sleep(2000); - } catch (InterruptedException e1) { - throw new AxisFault("Thread interuptted", e1); - } - + if (receiver != null) { + throw new IllegalStateException("Server already started"); } - count++; - } + ConfigurationContext er = getNewConfigurationContext(repository, axis2xml); - public static ConfigurationContext getNewConfigurationContext( - String repository) throws Exception { - File file = new File(repository); - if (!file.exists()) { - throw new Exception("repository directory " - + file.getAbsolutePath() + " does not exists"); - } - return ConfigurationContextFactory - .createConfigurationContextFromFileSystem(file.getAbsolutePath(), - file.getAbsolutePath() + - "/conf/axis2.xml"); + receiver = new SimpleHTTPServer(er, TESTING_PORT); + + receiver.start(); + System.out.print("Server started on port " + + TESTING_PORT + "....."); } public static ConfigurationContext getNewConfigurationContext( @@ -119,31 +71,33 @@ public class UtilServer { throw new Exception("repository directory " + file.getAbsolutePath() + " does not exists"); } + if (axis2xml == null) { + axis2xml = file.getAbsolutePath() + "/conf/axis2.xml"; + } return ConfigurationContextFactory .createConfigurationContextFromFileSystem(file.getAbsolutePath(), axis2xml); } public static synchronized void stop() throws AxisFault { - if (count == 1) { - receiver.stop(); - while (receiver.isRunning()) { - try { - Thread.sleep(1000); - } catch (InterruptedException e1) { - } + if (receiver == null) { + throw new IllegalStateException("Server not started"); + } + receiver.stop(); + while (receiver.isRunning()) { + try { + Thread.sleep(1000); + } catch (InterruptedException e1) { } - count = 0; - // tp.doStop(); - System.out.print("Server stopped ....."); - } else { - count--; } + // tp.doStop(); + System.out.print("Server stopped ....."); ListenerManager listenerManager = receiver.getConfigurationContext().getListenerManager(); if (listenerManager != null) { listenerManager.stop(); } + receiver = null; } public static ConfigurationContext getConfigurationContext() { Modified: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java?rev=1353277&r1=1353276&r2=1353277&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java (original) +++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/unwrapped/LibraryTest.java Sun Jun 24 14:39:30 2012 @@ -49,7 +49,7 @@ public class LibraryTest { @Test public void test1() throws Exception { - LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:5555/axis2/services/library"); + LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:" + UtilServer.TESTING_PORT + "/axis2/services/library"); stub.addBook("Paperback", "0618918248", new String[] { "Richard Dawkins" }, "The God Delusion"); @@ -69,7 +69,7 @@ public class LibraryTest { @Test public void test2() throws Exception { - LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:5555/axis2/services/library"); + LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:" + UtilServer.TESTING_PORT + "/axis2/services/library"); stub.addBookInstance(new Book("Hardcover", "8854401765", "The Voyage of the Beagle", new String[] { "Charles Darwin" })); Book book = stub.getBook("8854401765"); Modified: axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java?rev=1353277&r1=1353276&r2=1353277&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java (original) +++ axis/axis2/java/core/trunk/modules/jibx/src/test/java/org/apache/axis2/jibx/library/wrapped/LibraryTest.java Sun Jun 24 14:39:30 2012 @@ -47,7 +47,7 @@ public class LibraryTest { @Test public void test() throws Exception { - LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:5555/axis2/services/library"); + LibraryStub stub = new LibraryStub(UtilServer.getConfigurationContext(), "http://127.0.0.1:" + UtilServer.TESTING_PORT + "/axis2/services/library"); stub.addBook(new AddBookRequest(new Book("Paperback", "0618918248", "The God Delusion", new String[] { "Richard Dawkins" }))); }