More test cleanup: use available port instead of hardcoded

This commit is contained in:
Hadrian Zbarcea 2015-01-06 16:22:48 -05:00
parent a52bfe62a4
commit c5cebd5ec6
4 changed files with 101 additions and 50 deletions

View File

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

View File

@ -16,12 +16,16 @@
*/ */
package org.apache.activemq.web; package org.apache.activemq.web;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.MessageProducer; import javax.jms.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory; import javax.net.SocketFactory;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
@ -36,20 +40,21 @@ import org.junit.Before;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.junit.Assert.*; import static org.junit.Assert.assertTrue;
public class JettyTestSupport { public class JettyTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(JettyTestSupport.class); private static final Logger LOG = LoggerFactory.getLogger(JettyTestSupport.class);
BrokerService broker; protected BrokerService broker;
Server server; protected Session session;
ActiveMQConnectionFactory factory; protected MessageProducer producer;
Connection connection; protected URI tcpUri;
Session session; protected URI stompUri;
MessageProducer producer;
URI tcpUri; private Server server;
URI stompUri; private ActiveMQConnectionFactory factory;
private Connection connection;
private int proxyPort = 0;
protected boolean isPersistent() { protected boolean isPersistent() {
return false; return false;
@ -67,9 +72,10 @@ public class JettyTestSupport {
broker.start(); broker.start();
broker.waitUntilStarted(); broker.waitUntilStarted();
int port = getPort();
server = new Server(); server = new Server();
SelectChannelConnector connector = new SelectChannelConnector(); SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080); connector.setPort(port);
connector.setServer(server); connector.setServer(server);
WebAppContext context = new WebAppContext(); WebAppContext context = new WebAppContext();
@ -81,7 +87,7 @@ public class JettyTestSupport {
connector connector
}); });
server.start(); server.start();
waitForJettySocketToAccept("http://localhost:8080"); waitForJettySocketToAccept("http://localhost:" + port);
factory = new ActiveMQConnectionFactory(tcpUri); factory = new ActiveMQConnectionFactory(tcpUri);
connection = factory.createConnection(); connection = factory.createConnection();
@ -100,6 +106,25 @@ public class JettyTestSupport {
broker.waitUntilStopped(); 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 { public void waitForJettySocketToAccept(String bindLocation) throws Exception {
final URL url = new URL(bindLocation); final URL url = new URL(bindLocation);
assertTrue("Jetty endpoint is available", Wait.waitFor(new Wait.Condition() { assertTrue("Jetty endpoint is available", Wait.waitFor(new Wait.Condition() {

View File

@ -47,9 +47,10 @@ public class RestPersistentTest extends JettyTestSupport {
} }
public void postAndGet(String destinationType) throws Exception { 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 urlGET="http://localhost:" + port + "/message/upcTest?clientId=consumer1&readTimeout=5000&type="+destinationType;
final String urlPOST="http://localhost:8080/message/upcTest?type="+destinationType; final String urlPOST="http://localhost:" + port + "/message/upcTest?type="+destinationType;
final String message1="<itemPolicy><upc>1001</upc></itemPolicy>"; final String message1="<itemPolicy><upc>1001</upc></itemPolicy>";
final String property1="terminalNumber=lane1"; final String property1="terminalNumber=lane1";

View File

@ -37,6 +37,8 @@ public class RestTest extends JettyTestSupport {
@Test(timeout = 60 * 1000) @Test(timeout = 60 * 1000)
public void testConsume() throws Exception { public void testConsume() throws Exception {
int port = getPort();
producer.send(session.createTextMessage("test")); producer.send(session.createTextMessage("test"));
LOG.info("message sent"); LOG.info("message sent");
@ -44,7 +46,7 @@ public class RestTest extends JettyTestSupport {
httpClient.start(); httpClient.start();
ContentExchange contentExchange = new ContentExchange(); ContentExchange contentExchange = new ContentExchange();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); 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); httpClient.send(contentExchange);
contentExchange.waitForDone(); contentExchange.waitForDone();
assertEquals("test", contentExchange.getResponseContent()); assertEquals("test", contentExchange.getResponseContent());
@ -52,11 +54,13 @@ public class RestTest extends JettyTestSupport {
@Test(timeout = 60 * 1000) @Test(timeout = 60 * 1000)
public void testSubscribeFirst() throws Exception { public void testSubscribeFirst() throws Exception {
int port = getPort();
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
ContentExchange contentExchange = new ContentExchange(); ContentExchange contentExchange = new ContentExchange();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); 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); httpClient.send(contentExchange);
Thread.sleep(1000); Thread.sleep(1000);
@ -70,6 +74,8 @@ public class RestTest extends JettyTestSupport {
@Test(timeout = 60 * 1000) @Test(timeout = 60 * 1000)
public void testSelector() throws Exception { public void testSelector() throws Exception {
int port = getPort();
TextMessage msg1 = session.createTextMessage("test1"); TextMessage msg1 = session.createTextMessage("test1");
msg1.setIntProperty("test", 1); msg1.setIntProperty("test", 1);
producer.send(msg1); producer.send(msg1);
@ -84,7 +90,7 @@ public class RestTest extends JettyTestSupport {
httpClient.start(); httpClient.start();
ContentExchange contentExchange = new ContentExchange(); ContentExchange contentExchange = new ContentExchange();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); 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"); contentExchange.setRequestHeader("selector", "test=2");
httpClient.send(contentExchange); httpClient.send(contentExchange);
contentExchange.waitForDone(); contentExchange.waitForDone();
@ -94,6 +100,8 @@ public class RestTest extends JettyTestSupport {
// test for https://issues.apache.org/activemq/browse/AMQ-2827 // test for https://issues.apache.org/activemq/browse/AMQ-2827
@Test(timeout = 15 * 1000) @Test(timeout = 15 * 1000)
public void testCorrelation() throws Exception { public void testCorrelation() throws Exception {
int port = getPort();
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
httpClient.start(); httpClient.start();
@ -109,32 +117,33 @@ public class RestTest extends JettyTestSupport {
producer.send(message); producer.send(message);
ContentExchange contentExchange = new ContentExchange(); 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); httpClient.send(contentExchange);
contentExchange.waitForDone(); contentExchange.waitForDone();
LOG.info("Received: [" + contentExchange.getResponseStatus() + "] " + contentExchange.getResponseContent()); LOG.info("Received: [" + contentExchange.getResponseStatus() + "] " + contentExchange.getResponseContent());
assertEquals(200, contentExchange.getResponseStatus()); assertEquals(200, contentExchange.getResponseStatus());
assertEquals(correlId, contentExchange.getResponseContent()); assertEquals(correlId, contentExchange.getResponseContent());
} }
httpClient.stop(); httpClient.stop();
} }
@Test(timeout = 15 * 1000) @Test(timeout = 15 * 1000)
public void testDisconnect() throws Exception { public void testDisconnect() throws Exception {
int port = getPort();
producer.send(session.createTextMessage("test")); producer.send(session.createTextMessage("test"));
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
ContentExchange contentExchange = new ContentExchange(); ContentExchange contentExchange = new ContentExchange();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); 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); httpClient.send(contentExchange);
contentExchange.waitForDone(); contentExchange.waitForDone();
LOG.info("Received: [" + contentExchange.getResponseStatus() + "] " + contentExchange.getResponseContent()); LOG.info("Received: [" + contentExchange.getResponseStatus() + "] " + contentExchange.getResponseContent());
contentExchange = new ContentExchange(); contentExchange = new ContentExchange();
contentExchange.setMethod("POST"); 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); httpClient.send(contentExchange);
contentExchange.waitForDone(); contentExchange.waitForDone();
@ -147,19 +156,21 @@ public class RestTest extends JettyTestSupport {
@Test(timeout = 15 * 1000) @Test(timeout = 15 * 1000)
public void testPost() throws Exception { public void testPost() throws Exception {
int port = getPort();
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
ContentExchange contentExchange = new ContentExchange(); ContentExchange contentExchange = new ContentExchange();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setMethod("POST"); contentExchange.setMethod("POST");
contentExchange.setURL("http://localhost:8080/message/testPost?type=queue"); contentExchange.setURL("http://localhost:" + port + "/message/testPost?type=queue");
httpClient.send(contentExchange); httpClient.send(contentExchange);
contentExchange.waitForDone(); contentExchange.waitForDone();
assertTrue("success status", HttpStatus.isSuccess(contentExchange.getResponseStatus())); assertTrue("success status", HttpStatus.isSuccess(contentExchange.getResponseStatus()));
ContentExchange contentExchange2 = new ContentExchange(); 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); httpClient.send(contentExchange2);
contentExchange2.waitForDone(); contentExchange2.waitForDone();
assertTrue("success status", HttpStatus.isSuccess(contentExchange2.getResponseStatus())); 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 for https://issues.apache.org/activemq/browse/AMQ-3857
@Test(timeout = 15 * 1000) @Test(timeout = 15 * 1000)
public void testProperties() throws Exception { public void testProperties() throws Exception {
int port = getPort();
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
ContentExchange contentExchange = new ContentExchange(); ContentExchange contentExchange = new ContentExchange();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setMethod("POST"); 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); httpClient.send(contentExchange);
contentExchange.waitForDone(); contentExchange.waitForDone();
assertTrue("success status", HttpStatus.isSuccess(contentExchange.getResponseStatus())); assertTrue("success status", HttpStatus.isSuccess(contentExchange.getResponseStatus()));
ContentExchange contentExchange2 = new ContentExchange(true); 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); httpClient.send(contentExchange2);
contentExchange2.waitForDone(); contentExchange2.waitForDone();
assertTrue("success status", HttpStatus.isSuccess(contentExchange2.getResponseStatus())); assertTrue("success status", HttpStatus.isSuccess(contentExchange2.getResponseStatus()));
@ -193,12 +206,14 @@ public class RestTest extends JettyTestSupport {
@Test(timeout = 15 * 1000) @Test(timeout = 15 * 1000)
public void testAuth() throws Exception { public void testAuth() throws Exception {
int port = getPort();
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
ContentExchange contentExchange = new ContentExchange(); ContentExchange contentExchange = new ContentExchange();
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setMethod("POST"); 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="); contentExchange.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
httpClient.send(contentExchange); httpClient.send(contentExchange);