Repository: activemq
Updated Branches:
  refs/heads/trunk a52bfe62a -> c5cebd5ec


More test cleanup: use available port instead of hardcoded


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/c5cebd5e
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/c5cebd5e
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/c5cebd5e

Branch: refs/heads/trunk
Commit: c5cebd5ec660a40025317270ac0400a8c1ab4b8f
Parents: a52bfe6
Author: Hadrian Zbarcea <hadr...@apache.org>
Authored: Tue Jan 6 16:22:48 2015 -0500
Committer: Hadrian Zbarcea <hadr...@apache.org>
Committed: Tue Jan 6 16:22:56 2015 -0500

----------------------------------------------------------------------
 .../java/org/apache/activemq/web/AjaxTest.java  | 60 ++++++++++++--------
 .../apache/activemq/web/JettyTestSupport.java   | 47 +++++++++++----
 .../apache/activemq/web/RestPersistentTest.java |  5 +-
 .../java/org/apache/activemq/web/RestTest.java  | 39 +++++++++----
 4 files changed, 101 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/c5cebd5e/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java
----------------------------------------------------------------------
diff --git 
a/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java 
b/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java
index d229367..8763299 100644
--- a/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java
+++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/AjaxTest.java
@@ -76,6 +76,7 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void 
testAjaxClientReceivesMessagesWhichAreSentToQueueWhileClientIsPolling() throws 
Exception {
         LOG.debug( "*** 
testAjaxClientReceivesMessagesWhichAreSentToQueueWhileClientIsPolling ***" );
+        int port = getPort();
 
         HttpClient httpClient = new HttpClient();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
@@ -85,7 +86,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN" );
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new 
ByteArrayBuffer("destination=queue://test&type=listen&message=handler") );
         contentExchange.setRequestContentType( 
"application/x-www-form-urlencoded; charset=UTF-8" );
         httpClient.send(contentExchange);
@@ -96,7 +97,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING POLL" );
         AjaxTestContentExchange poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
 
@@ -104,7 +105,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING MESSAGES" );
         contentExchange = new AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new ByteArrayBuffer(
             "destination=queue://test&type=send&message=msg1&"+
             "d1=queue://test&t1=send&m1=msg2&"+
@@ -122,7 +123,7 @@ public class AjaxTest extends JettyTestSupport {
         // messages might not all be delivered during the 1st poll.  We need 
to check again.
         poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
         poll.waitForDone();
@@ -140,6 +141,7 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void 
testAjaxClientReceivesMessagesWhichAreSentToTopicWhileClientIsPolling() throws 
Exception {
         LOG.debug( "*** 
testAjaxClientReceivesMessagesWhichAreSentToTopicWhileClientIsPolling ***" );
+        int port = getPort();
 
         HttpClient httpClient = new HttpClient();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
@@ -149,7 +151,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN" );
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new 
ByteArrayBuffer("destination=topic://test&type=listen&message=handler") );
         contentExchange.setRequestContentType( 
"application/x-www-form-urlencoded; charset=UTF-8" );
         httpClient.send(contentExchange);
@@ -160,7 +162,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING POLL" );
         AjaxTestContentExchange poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
 
@@ -168,7 +170,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING MESSAGES" );
         contentExchange = new AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new ByteArrayBuffer(
             "destination=topic://test&type=send&message=msg1&"+
             "d1=topic://test&t1=send&m1=msg2&"+
@@ -186,7 +188,7 @@ public class AjaxTest extends JettyTestSupport {
         // not all messages might be delivered during the 1st poll.  We need 
to check again.
         poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
         poll.waitForDone();
@@ -205,6 +207,8 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void 
testAjaxClientReceivesMessagesWhichAreQueuedBeforeClientSubscribes() throws 
Exception {
         LOG.debug( "*** 
testAjaxClientReceivesMessagesWhichAreQueuedBeforeClientSubscribes ***" );
+        int port = getPort();
+
         // send messages to queue://test
         producer.send( session.createTextMessage("test one") );
         producer.send( session.createTextMessage("test two") );
@@ -218,7 +222,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN" );
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new 
ByteArrayBuffer("destination=queue://test&type=listen&message=handler") );
         contentExchange.setRequestContentType( 
"application/x-www-form-urlencoded; charset=UTF-8" );
         httpClient.send(contentExchange);
@@ -229,7 +233,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING POLL" );
         AjaxTestContentExchange poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
 
@@ -248,6 +252,7 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void testStompMessagesAreReceivedByAjaxClient() throws Exception {
         LOG.debug( "*** testStompMessagesAreRecievedByAjaxClient ***" );
+        int port = getPort();
 
         HttpClient httpClient = new HttpClient();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
@@ -257,7 +262,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN" );
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new 
ByteArrayBuffer("destination=queue://test&type=listen&message=handler") );
         contentExchange.setRequestContentType( 
"application/x-www-form-urlencoded; charset=UTF-8" );
         httpClient.send(contentExchange);
@@ -268,7 +273,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING POLL" );
         AjaxTestContentExchange poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
 
@@ -299,7 +304,7 @@ public class AjaxTest extends JettyTestSupport {
         // not all messages might be delivered during the 1st poll.  We need 
to check again.
         poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
         poll.waitForDone();
@@ -319,6 +324,7 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void testAjaxMessagesAreReceivedByStompClient() throws Exception {
         LOG.debug( "*** testAjaxMessagesAreReceivedByStompClient ***" );
+        int port = getPort();
 
         HttpClient httpClient = new HttpClient();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
@@ -326,7 +332,7 @@ public class AjaxTest extends JettyTestSupport {
 
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new ByteArrayBuffer(
             "destination=queue://test&type=send&message=msg1&"+
             "d1=queue://test&t1=send&m1=msg2&"+
@@ -363,6 +369,7 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void testAjaxClientMayUseSelectors() throws Exception {
         LOG.debug( "*** testAjaxClientMayUseSelectors ***" );
+        int port = getPort();
 
         // send 2 messages to the same queue w/ different 'filter' values.
         Message msg = session.createTextMessage("test one");
@@ -380,7 +387,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN" );
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new 
ByteArrayBuffer("destination=queue://test&type=listen&message=handler") );
         contentExchange.setRequestContentType( 
"application/x-www-form-urlencoded; charset=UTF-8" );
         // SELECTOR
@@ -393,7 +400,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING POLL" );
         AjaxTestContentExchange poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
         poll.waitForDone();
@@ -409,6 +416,7 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void testMultipleAjaxClientsMayExistInTheSameSession() throws 
Exception {
         LOG.debug( "*** testMultipleAjaxClientsMayExistInTheSameSession ***" );
+        int port = getPort();
 
         // send messages to queues testA and testB.
         MessageProducer producerA = 
session.createProducer(session.createQueue("testA"));
@@ -426,7 +434,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN" );
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new ByteArrayBuffer(
             "destination=queue://testA&"+
             "type=listen&"+
@@ -441,7 +449,7 @@ public class AjaxTest extends JettyTestSupport {
         // clientB subscribes to /queue/testB using the same JSESSIONID.
         contentExchange = new AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestHeader( "Cookie", jsessionid );
         contentExchange.setRequestContent( new ByteArrayBuffer(
             "destination=queue://testB&"+
@@ -456,7 +464,7 @@ public class AjaxTest extends JettyTestSupport {
         // clientA polls for messages
         AjaxTestContentExchange poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000&clientId=clientA";);
+        poll.setURL("http://localhost:"; + port + 
"/amq?timeout=5000&clientId=clientA");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
         poll.waitForDone();
@@ -471,7 +479,7 @@ public class AjaxTest extends JettyTestSupport {
         // clientB polls for messages
         poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000&clientId=clientB";);
+        poll.setURL("http://localhost:"; + port + 
"/amq?timeout=5000&clientId=clientB");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
         poll.waitForDone();
@@ -488,6 +496,8 @@ public class AjaxTest extends JettyTestSupport {
     @Test(timeout = 15 * 1000)
     public void testAjaxClientReceivesMessagesForMultipleTopics() throws 
Exception {
         LOG.debug( "*** testAjaxClientReceivesMessagesForMultipleTopics ***" );
+        int port = getPort();
+
         HttpClient httpClient = new HttpClient();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
         httpClient.start();
@@ -495,7 +505,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN FOR /topic/topicA" );
         AjaxTestContentExchange contentExchange = new 
AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new 
ByteArrayBuffer("destination=topic://topicA&type=listen&message=handlerA") );
         contentExchange.setRequestContentType( 
"application/x-www-form-urlencoded; charset=UTF-8" );
         httpClient.send(contentExchange);
@@ -505,7 +515,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING LISTEN FOR /topic/topicB" );
         contentExchange = new AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new 
ByteArrayBuffer("destination=topic://topicB&type=listen&message=handlerB") );
         contentExchange.setRequestContentType( 
"application/x-www-form-urlencoded; charset=UTF-8" );
         contentExchange.setRequestHeader( "Cookie", jsessionid );
@@ -516,7 +526,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING POLL" );
         AjaxTestContentExchange poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
 
@@ -524,7 +534,7 @@ public class AjaxTest extends JettyTestSupport {
         LOG.debug( "SENDING MESSAGES" );
         contentExchange = new AjaxTestContentExchange();
         contentExchange.setMethod( "POST" );
-        contentExchange.setURL("http://localhost:8080/amq";);
+        contentExchange.setURL("http://localhost:"; + port + "/amq");
         contentExchange.setRequestContent( new ByteArrayBuffer(
             "destination=topic://topicA&type=send&message=A1&"+
             "d1=topic://topicB&t1=send&m1=B1&"+
@@ -543,7 +553,7 @@ public class AjaxTest extends JettyTestSupport {
         // not all messages might be delivered during the 1st poll.  We need 
to check again.
         poll = new AjaxTestContentExchange();
         poll.setMethod( "GET" );
-        poll.setURL("http://localhost:8080/amq?timeout=5000";);
+        poll.setURL("http://localhost:"; + port + "/amq?timeout=5000");
         poll.setRequestHeader( "Cookie", jsessionid );
         httpClient.send( poll );
         poll.waitForDone();

http://git-wip-us.apache.org/repos/asf/activemq/blob/c5cebd5e/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java
----------------------------------------------------------------------
diff --git 
a/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java 
b/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java
index e1f565d..3581af4 100644
--- 
a/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java
+++ 
b/activemq-web-demo/src/test/java/org/apache/activemq/web/JettyTestSupport.java
@@ -16,12 +16,16 @@
  */
 package org.apache.activemq.web;
 
+import java.io.IOException;
+import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URI;
 import java.net.URL;
+
 import javax.jms.Connection;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
+import javax.net.ServerSocketFactory;
 import javax.net.SocketFactory;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
@@ -36,20 +40,21 @@ import org.junit.Before;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
 
 public class JettyTestSupport {
     private static final Logger LOG = 
LoggerFactory.getLogger(JettyTestSupport.class);
 
-    BrokerService broker;
-    Server server;
-    ActiveMQConnectionFactory factory;
-    Connection connection;
-    Session session;
-    MessageProducer producer;
+    protected BrokerService broker;
+    protected Session session;
+    protected MessageProducer producer;
+    protected URI tcpUri;
+    protected URI stompUri;
 
-    URI tcpUri;
-    URI stompUri;
+    private Server server;
+    private ActiveMQConnectionFactory factory;
+    private Connection connection;
+    private int proxyPort = 0;
 
     protected boolean isPersistent() {
         return false;
@@ -67,9 +72,10 @@ public class JettyTestSupport {
         broker.start();
         broker.waitUntilStarted();
 
+        int port = getPort();
         server = new Server();
         SelectChannelConnector connector = new SelectChannelConnector();
-        connector.setPort(8080);
+        connector.setPort(port);
         connector.setServer(server);
         WebAppContext context = new WebAppContext();
 
@@ -81,7 +87,7 @@ public class JettyTestSupport {
             connector
         });
         server.start();
-        waitForJettySocketToAccept("http://localhost:8080";);
+        waitForJettySocketToAccept("http://localhost:"; + port);
 
         factory = new ActiveMQConnectionFactory(tcpUri);
         connection = factory.createConnection();
@@ -100,6 +106,25 @@ public class JettyTestSupport {
         broker.waitUntilStopped();
     }
 
+    protected int getPort() {
+        if (proxyPort == 0) {
+            ServerSocket ss = null;
+            try {
+                ss = ServerSocketFactory.getDefault().createServerSocket(0);
+                proxyPort = ss.getLocalPort();
+            } catch (IOException e) { // ignore
+            } finally {
+                try {
+                    if (ss != null ) {
+                        ss.close();
+                    }
+                } catch (IOException e) { // ignore
+                }
+            }
+        }
+        return proxyPort;
+    }
+
     public void waitForJettySocketToAccept(String bindLocation) throws 
Exception {
         final URL url = new URL(bindLocation);
         assertTrue("Jetty endpoint is available", Wait.waitFor(new 
Wait.Condition() {

http://git-wip-us.apache.org/repos/asf/activemq/blob/c5cebd5e/activemq-web-demo/src/test/java/org/apache/activemq/web/RestPersistentTest.java
----------------------------------------------------------------------
diff --git 
a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestPersistentTest.java
 
b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestPersistentTest.java
index 9eb6df9..f971cd2 100644
--- 
a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestPersistentTest.java
+++ 
b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestPersistentTest.java
@@ -47,9 +47,10 @@ public class RestPersistentTest extends JettyTestSupport {
     }
 
     public void postAndGet(String destinationType) throws Exception {
+        int port = getPort();
 
-        final String 
urlGET="http://localhost:8080/message/upcTest?clientId=consumer1&readTimeout=5000&type="+destinationType;
-        final String 
urlPOST="http://localhost:8080/message/upcTest?type="+destinationType;
+        final String urlGET="http://localhost:"; + port + 
"/message/upcTest?clientId=consumer1&readTimeout=5000&type="+destinationType;
+        final String urlPOST="http://localhost:"; + port + 
"/message/upcTest?type="+destinationType;
 
         final String message1="<itemPolicy><upc>1001</upc></itemPolicy>";
         final String property1="terminalNumber=lane1";

http://git-wip-us.apache.org/repos/asf/activemq/blob/c5cebd5e/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java
----------------------------------------------------------------------
diff --git 
a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java 
b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java
index 13488f0..0057153 100644
--- a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java
+++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java
@@ -37,6 +37,8 @@ public class RestTest extends JettyTestSupport {
 
     @Test(timeout = 60 * 1000)
     public void testConsume() throws Exception {
+        int port = getPort();
+
         producer.send(session.createTextMessage("test"));
         LOG.info("message sent");
 
@@ -44,7 +46,7 @@ public class RestTest extends JettyTestSupport {
         httpClient.start();
         ContentExchange contentExchange = new ContentExchange();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
-        
contentExchange.setURL("http://localhost:8080/message/test?readTimeout=1000&type=queue";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/test?readTimeout=1000&type=queue");
         httpClient.send(contentExchange);
         contentExchange.waitForDone();
         assertEquals("test", contentExchange.getResponseContent());
@@ -52,11 +54,13 @@ public class RestTest extends JettyTestSupport {
 
     @Test(timeout = 60 * 1000)
     public void testSubscribeFirst() throws Exception {
+        int port = getPort();
+
         HttpClient httpClient = new HttpClient();
         httpClient.start();
         ContentExchange contentExchange = new ContentExchange();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
-        
contentExchange.setURL("http://localhost:8080/message/test?readTimeout=5000&type=queue";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/test?readTimeout=5000&type=queue");
         httpClient.send(contentExchange);
 
         Thread.sleep(1000);
@@ -70,6 +74,8 @@ public class RestTest extends JettyTestSupport {
 
     @Test(timeout = 60 * 1000)
     public void testSelector() throws Exception {
+        int port = getPort();
+
         TextMessage msg1 = session.createTextMessage("test1");
         msg1.setIntProperty("test", 1);
         producer.send(msg1);
@@ -84,7 +90,7 @@ public class RestTest extends JettyTestSupport {
         httpClient.start();
         ContentExchange contentExchange = new ContentExchange();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
-        
contentExchange.setURL("http://localhost:8080/message/test?readTimeout=1000&type=queue";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/test?readTimeout=1000&type=queue");
         contentExchange.setRequestHeader("selector", "test=2");
         httpClient.send(contentExchange);
         contentExchange.waitForDone();
@@ -94,6 +100,8 @@ public class RestTest extends JettyTestSupport {
     // test for https://issues.apache.org/activemq/browse/AMQ-2827
     @Test(timeout = 15 * 1000)
     public void testCorrelation() throws Exception {
+        int port = getPort();
+
         HttpClient httpClient = new HttpClient();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
         httpClient.start();
@@ -109,32 +117,33 @@ public class RestTest extends JettyTestSupport {
             producer.send(message);
 
             ContentExchange contentExchange = new ContentExchange();
-            
contentExchange.setURL("http://localhost:8080/message/test?readTimeout=1000&type=queue&clientId=test";);
+            contentExchange.setURL("http://localhost:"; + port + 
"/message/test?readTimeout=1000&type=queue&clientId=test");
             httpClient.send(contentExchange);
             contentExchange.waitForDone();
             LOG.info("Received: [" + contentExchange.getResponseStatus() + "] 
" + contentExchange.getResponseContent());
             assertEquals(200, contentExchange.getResponseStatus());
             assertEquals(correlId, contentExchange.getResponseContent());
         }
-       httpClient.stop();
+        httpClient.stop();
     }
 
     @Test(timeout = 15 * 1000)
     public void testDisconnect() throws Exception {
+        int port = getPort();
 
         producer.send(session.createTextMessage("test"));
         HttpClient httpClient = new HttpClient();
         httpClient.start();
         ContentExchange contentExchange = new ContentExchange();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
-        
contentExchange.setURL("http://localhost:8080/message/test?readTimeout=1000&type=queue&clientId=test";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/test?readTimeout=1000&type=queue&clientId=test");
         httpClient.send(contentExchange);
         contentExchange.waitForDone();
         LOG.info("Received: [" + contentExchange.getResponseStatus() + "] " + 
contentExchange.getResponseContent());
 
         contentExchange = new ContentExchange();
         contentExchange.setMethod("POST");
-        
contentExchange.setURL("http://localhost:8080/message/test?clientId=test&action=unsubscribe";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/test?clientId=test&action=unsubscribe");
         httpClient.send(contentExchange);
         contentExchange.waitForDone();
 
@@ -147,19 +156,21 @@ public class RestTest extends JettyTestSupport {
 
     @Test(timeout = 15 * 1000)
     public void testPost() throws Exception {
+        int port = getPort();
+
         HttpClient httpClient = new HttpClient();
         httpClient.start();
         ContentExchange contentExchange = new ContentExchange();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
         contentExchange.setMethod("POST");
-        
contentExchange.setURL("http://localhost:8080/message/testPost?type=queue";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/testPost?type=queue");
         httpClient.send(contentExchange);
 
         contentExchange.waitForDone();
         assertTrue("success status", 
HttpStatus.isSuccess(contentExchange.getResponseStatus()));
 
         ContentExchange contentExchange2 = new ContentExchange();
-        
contentExchange2.setURL("http://localhost:8080/message/testPost?readTimeout=1000&type=Queue";);
+        contentExchange2.setURL("http://localhost:"; + port + 
"/message/testPost?readTimeout=1000&type=Queue");
         httpClient.send(contentExchange2);
         contentExchange2.waitForDone();
         assertTrue("success status", 
HttpStatus.isSuccess(contentExchange2.getResponseStatus()));
@@ -168,19 +179,21 @@ public class RestTest extends JettyTestSupport {
     // test for https://issues.apache.org/activemq/browse/AMQ-3857
     @Test(timeout = 15 * 1000)
     public void testProperties() throws Exception {
+        int port = getPort();
+
         HttpClient httpClient = new HttpClient();
         httpClient.start();
         ContentExchange contentExchange = new ContentExchange();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
         contentExchange.setMethod("POST");
-        
contentExchange.setURL("http://localhost:8080/message/testPost?type=queue&property=value";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/testPost?type=queue&property=value");
         httpClient.send(contentExchange);
 
         contentExchange.waitForDone();
         assertTrue("success status", 
HttpStatus.isSuccess(contentExchange.getResponseStatus()));
 
         ContentExchange contentExchange2 = new ContentExchange(true);
-        
contentExchange2.setURL("http://localhost:8080/message/testPost?readTimeout=1000&type=Queue";);
+        contentExchange2.setURL("http://localhost:"; + port + 
"/message/testPost?readTimeout=1000&type=Queue");
         httpClient.send(contentExchange2);
         contentExchange2.waitForDone();
         assertTrue("success status", 
HttpStatus.isSuccess(contentExchange2.getResponseStatus()));
@@ -193,12 +206,14 @@ public class RestTest extends JettyTestSupport {
 
     @Test(timeout = 15 * 1000)
     public void testAuth() throws Exception {
+        int port = getPort();
+
         HttpClient httpClient = new HttpClient();
         httpClient.start();
         ContentExchange contentExchange = new ContentExchange();
         httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
         contentExchange.setMethod("POST");
-        
contentExchange.setURL("http://localhost:8080/message/testPost?type=queue";);
+        contentExchange.setURL("http://localhost:"; + port + 
"/message/testPost?type=queue");
         contentExchange.setRequestHeader("Authorization", "Basic 
YWRtaW46YWRtaW4=");
         httpClient.send(contentExchange);
 

Reply via email to