Converted to JUnit 4 and added timeouts. See AMQ-5013

This commit is contained in:
Kevin Earls 2014-02-03 14:29:25 +01:00
parent da3775302c
commit bdf7aa4823
4 changed files with 39 additions and 4 deletions

View File

@ -31,9 +31,12 @@ import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayBuffer;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.junit.Assert.*;
public class AjaxTest extends JettyTestSupport { public class AjaxTest extends JettyTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(AjaxTest.class); private static final Logger LOG = LoggerFactory.getLogger(AjaxTest.class);
@ -70,6 +73,7 @@ public class AjaxTest extends JettyTestSupport {
assertEquals( "Expected number of <response> elements is not correct.", expected, occurrences ); assertEquals( "Expected number of <response> elements is not correct.", expected, occurrences );
} }
@Test(timeout = 60 * 1000)
public void testAjaxClientReceivesMessagesWhichAreSentToQueueWhileClientIsPolling() throws Exception { public void testAjaxClientReceivesMessagesWhichAreSentToQueueWhileClientIsPolling() throws Exception {
LOG.debug( "*** testAjaxClientReceivesMessagesWhichAreSentToQueueWhileClientIsPolling ***" ); LOG.debug( "*** testAjaxClientReceivesMessagesWhichAreSentToQueueWhileClientIsPolling ***" );
@ -132,6 +136,7 @@ public class AjaxTest extends JettyTestSupport {
assertResponseCount( 3, fullResponse ); assertResponseCount( 3, fullResponse );
} }
@Test(timeout = 60 * 1000)
public void testAjaxClientReceivesMessagesWhichAreSentToTopicWhileClientIsPolling() throws Exception { public void testAjaxClientReceivesMessagesWhichAreSentToTopicWhileClientIsPolling() throws Exception {
LOG.debug( "*** testAjaxClientReceivesMessagesWhichAreSentToTopicWhileClientIsPolling ***" ); LOG.debug( "*** testAjaxClientReceivesMessagesWhichAreSentToTopicWhileClientIsPolling ***" );
@ -194,6 +199,7 @@ public class AjaxTest extends JettyTestSupport {
assertResponseCount( 3, fullResponse ); assertResponseCount( 3, fullResponse );
} }
@Test(timeout = 60 * 1000)
public void testAjaxClientReceivesMessagesWhichAreQueuedBeforeClientSubscribes() throws Exception { public void testAjaxClientReceivesMessagesWhichAreQueuedBeforeClientSubscribes() throws Exception {
LOG.debug( "*** testAjaxClientReceivesMessagesWhichAreQueuedBeforeClientSubscribes ***" ); LOG.debug( "*** testAjaxClientReceivesMessagesWhichAreQueuedBeforeClientSubscribes ***" );
// send messages to queue://test // send messages to queue://test
@ -234,6 +240,7 @@ public class AjaxTest extends JettyTestSupport {
assertResponseCount( 3, response ); assertResponseCount( 3, response );
} }
@Test(timeout = 60 * 1000)
public void testStompMessagesAreReceivedByAjaxClient() throws Exception { public void testStompMessagesAreReceivedByAjaxClient() throws Exception {
LOG.debug( "*** testStompMessagesAreRecievedByAjaxClient ***" ); LOG.debug( "*** testStompMessagesAreRecievedByAjaxClient ***" );
@ -302,6 +309,7 @@ public class AjaxTest extends JettyTestSupport {
assertResponseCount( 5, fullResponse ); assertResponseCount( 5, fullResponse );
} }
@Test(timeout = 60 * 1000)
public void testAjaxMessagesAreReceivedByStompClient() throws Exception { public void testAjaxMessagesAreReceivedByStompClient() throws Exception {
LOG.debug( "*** testAjaxMessagesAreReceivedByStompClient ***" ); LOG.debug( "*** testAjaxMessagesAreReceivedByStompClient ***" );
@ -343,6 +351,7 @@ public class AjaxTest extends JettyTestSupport {
assertContains( "msg4", allMessageBodies ); assertContains( "msg4", allMessageBodies );
} }
@Test(timeout = 60 * 1000)
public void testAjaxClientMayUseSelectors() throws Exception { public void testAjaxClientMayUseSelectors() throws Exception {
LOG.debug( "*** testAjaxClientMayUseSelectors ***" ); LOG.debug( "*** testAjaxClientMayUseSelectors ***" );
@ -388,6 +397,7 @@ public class AjaxTest extends JettyTestSupport {
} }
@Test(timeout = 60 * 1000)
public void testMultipleAjaxClientsMayExistInTheSameSession() throws Exception { public void testMultipleAjaxClientsMayExistInTheSameSession() throws Exception {
LOG.debug( "*** testMultipleAjaxClientsMayExistInTheSameSession ***" ); LOG.debug( "*** testMultipleAjaxClientsMayExistInTheSameSession ***" );
@ -465,6 +475,7 @@ public class AjaxTest extends JettyTestSupport {
assertContains( expected2, poll.getResponseContent() ); assertContains( expected2, poll.getResponseContent() );
} }
@Test(timeout = 60 * 1000)
public void testAjaxClientReceivesMessagesForMultipleTopics() throws Exception { public void testAjaxClientReceivesMessagesForMultipleTopics() throws Exception {
LOG.debug( "*** testAjaxClientReceivesMessagesForMultipleTopics ***" ); LOG.debug( "*** testAjaxClientReceivesMessagesForMultipleTopics ***" );
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();

View File

@ -24,7 +24,6 @@ import javax.jms.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
import javax.net.SocketFactory; import javax.net.SocketFactory;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
@ -32,10 +31,14 @@ import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class JettyTestSupport extends TestCase { import static org.junit.Assert.*;
public class JettyTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(JettyTestSupport.class); private static final Logger LOG = LoggerFactory.getLogger(JettyTestSupport.class);
BrokerService broker; BrokerService broker;
@ -52,7 +55,8 @@ public class JettyTestSupport extends TestCase {
return false; return false;
} }
protected void setUp() throws Exception { @Before
public void setUp() throws Exception {
broker = new BrokerService(); broker = new BrokerService();
broker.setBrokerName("amq-broker"); broker.setBrokerName("amq-broker");
broker.setPersistent(isPersistent()); broker.setPersistent(isPersistent());
@ -86,7 +90,9 @@ public class JettyTestSupport extends TestCase {
producer = session.createProducer(session.createQueue("test")); producer = session.createProducer(session.createQueue("test"));
} }
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
session.close(); session.close();
connection.close(); connection.close();
server.stop(); server.stop();

View File

@ -22,6 +22,9 @@ import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
public class RestPersistentTest extends JettyTestSupport { public class RestPersistentTest extends JettyTestSupport {
@ -31,10 +34,13 @@ public class RestPersistentTest extends JettyTestSupport {
return true; return true;
} }
@Test(timeout = 60 * 1000)
public void testPostAndGetWithQueue() throws Exception { public void testPostAndGetWithQueue() throws Exception {
postAndGet("queue"); postAndGet("queue");
} }
@Test(timeout = 60 * 1000)
@Ignore("Needs a JIRA")
public void testPostAndGetWithTopic() throws Exception { public void testPostAndGetWithTopic() throws Exception {
// TODO: problems with topics // TODO: problems with topics
// postAndGet("topic"); // postAndGet("topic");

View File

@ -26,12 +26,16 @@ import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static org.junit.Assert.*;
public class RestTest extends JettyTestSupport { public class RestTest extends JettyTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(RestTest.class); private static final Logger LOG = LoggerFactory.getLogger(RestTest.class);
@Test(timeout = 60 * 1000)
public void testConsume() throws Exception { public void testConsume() throws Exception {
producer.send(session.createTextMessage("test")); producer.send(session.createTextMessage("test"));
LOG.info("message sent"); LOG.info("message sent");
@ -46,6 +50,7 @@ public class RestTest extends JettyTestSupport {
assertEquals("test", contentExchange.getResponseContent()); assertEquals("test", contentExchange.getResponseContent());
} }
@Test(timeout = 60 * 1000)
public void testSubscribeFirst() throws Exception { public void testSubscribeFirst() throws Exception {
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
@ -63,6 +68,7 @@ public class RestTest extends JettyTestSupport {
assertEquals("test", contentExchange.getResponseContent()); assertEquals("test", contentExchange.getResponseContent());
} }
@Test(timeout = 60 * 1000)
public void testSelector() throws Exception { public void testSelector() throws Exception {
TextMessage msg1 = session.createTextMessage("test1"); TextMessage msg1 = session.createTextMessage("test1");
msg1.setIntProperty("test", 1); msg1.setIntProperty("test", 1);
@ -86,6 +92,7 @@ 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 = 60 * 1000)
public void testCorrelation() throws Exception { public void testCorrelation() throws Exception {
for (int i = 0; i < 200; i++) { for (int i = 0; i < 200; i++) {
String correlId = "RESTY" + RandomStringUtils.randomNumeric(10); String correlId = "RESTY" + RandomStringUtils.randomNumeric(10);
@ -111,6 +118,7 @@ public class RestTest extends JettyTestSupport {
} }
} }
@Test(timeout = 60 * 1000)
public void testDisconnect() throws Exception { public void testDisconnect() throws Exception {
producer.send(session.createTextMessage("test")); producer.send(session.createTextMessage("test"));
@ -136,6 +144,7 @@ public class RestTest extends JettyTestSupport {
assertEquals("Consumers not closed", 0 , subs.size()); assertEquals("Consumers not closed", 0 , subs.size());
} }
@Test(timeout = 60 * 1000)
public void testPost() throws Exception { public void testPost() throws Exception {
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
@ -156,6 +165,7 @@ 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 = 60 * 1000)
public void testProperties() throws Exception { public void testProperties() throws Exception {
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();
@ -179,6 +189,8 @@ public class RestTest extends JettyTestSupport {
assertEquals("header value", "value", fields.getStringField("property")); assertEquals("header value", "value", fields.getStringField("property"));
} }
@Test(timeout = 60 * 1000)
public void testAuth() throws Exception { public void testAuth() throws Exception {
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
httpClient.start(); httpClient.start();