diff options
| author | Stephen Vinoski <vinoski@apache.org> | 2006-11-19 04:14:42 +0000 |
|---|---|---|
| committer | Stephen Vinoski <vinoski@apache.org> | 2006-11-19 04:14:42 +0000 |
| commit | 26f3bd59751462922e4c3268392a526a60ef7b2f (patch) | |
| tree | 33d4dcf6804551948e3c78233494e29fbba95c4e /java/client/src/test | |
| parent | be9f473e274d6cfe4cf8d8b04dd3f5a171ba9de4 (diff) | |
| download | qpid-python-26f3bd59751462922e4c3268392a526a60ef7b2f.tar.gz | |
convert tests to junit3
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@476701 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src/test')
42 files changed, 1070 insertions, 1639 deletions
diff --git a/java/client/src/test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java b/java/client/src/test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java index 836727df5d..5f328a4107 100644 --- a/java/client/src/test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java +++ b/java/client/src/test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java @@ -26,7 +26,6 @@ import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.AMQQueue; import org.apache.log4j.Logger; import org.apache.log4j.Level; -import org.junit.Assert; import javax.naming.Context; import javax.naming.InitialContext; diff --git a/java/client/src/test/java/org/apache/qpid/framing/FieldTableTest.java b/java/client/src/test/java/org/apache/qpid/framing/FieldTableTest.java index a75fff68e1..49e1630f15 100644 --- a/java/client/src/test/java/org/apache/qpid/framing/FieldTableTest.java +++ b/java/client/src/test/java/org/apache/qpid/framing/FieldTableTest.java @@ -20,10 +20,7 @@ */ package org.apache.qpid.framing; -import junit.framework.JUnit4TestAdapter; import org.apache.mina.common.ByteBuffer; -import static org.junit.Assert.assertEquals; -import org.junit.Test; import java.io.BufferedReader; import java.io.IOException; @@ -32,10 +29,11 @@ import java.io.Reader; import java.util.Enumeration; import java.util.Properties; -public class FieldTableTest +import junit.framework.TestCase; + +public class FieldTableTest extends TestCase { - @Test - public void dataDump() throws IOException, AMQFrameDecodingException + public void testDataDump() throws IOException, AMQFrameDecodingException { byte[] data = readBase64("content.txt"); System.out.println("Got " + data.length + " bytes of data"); @@ -52,19 +50,17 @@ public class FieldTableTest } /* - @Test - public void case1() throws AMQFrameDecodingException, IOException + public void testCase1() throws AMQFrameDecodingException, IOException { - testEncoding(load("FieldTableTest.properties")); + doTestEncoding(load("FieldTableTest.properties")); } - @Test - public void case2() throws AMQFrameDecodingException, IOException + public void testCase2() throws AMQFrameDecodingException, IOException { - testEncoding(load("FieldTableTest2.properties")); + doTestEncoding(load("FieldTableTest2.properties")); } */ - void testEncoding(FieldTable table) throws AMQFrameDecodingException + void doTestEncoding(FieldTable table) throws AMQFrameDecodingException { assertEquivalent(table, encodeThenDecode(table)); } @@ -157,6 +153,6 @@ public class FieldTableTest public static junit.framework.Test suite() { - return new JUnit4TestAdapter(FieldTableTest.class); + return new junit.framework.TestSuite(FieldTableTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/mina/AcceptorTest.java b/java/client/src/test/java/org/apache/qpid/mina/AcceptorTest.java index bae3a60675..de3d558f7c 100644 --- a/java/client/src/test/java/org/apache/qpid/mina/AcceptorTest.java +++ b/java/client/src/test/java/org/apache/qpid/mina/AcceptorTest.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.mina; -import junit.framework.JUnit4TestAdapter; import org.apache.log4j.Logger; import org.apache.mina.common.ByteBuffer; import org.apache.mina.common.IoAcceptor; @@ -29,17 +28,18 @@ import org.apache.mina.common.IoSession; import org.apache.mina.transport.socket.nio.SocketAcceptor; import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; import org.apache.mina.transport.socket.nio.SocketSessionConfig; -import org.junit.Test; import org.apache.qpid.pool.ReadWriteThreadModel; import java.io.IOException; import java.net.InetSocketAddress; +import junit.framework.TestCase; + /** * Tests MINA socket performance. This acceptor simply reads data from the network and writes it back again. * */ -public class AcceptorTest +public class AcceptorTest extends TestCase { private static final Logger _logger = Logger.getLogger(AcceptorTest.class); @@ -71,8 +71,7 @@ public class AcceptorTest } } - @Test - public void startAcceptor() throws IOException + public void testStartAcceptor() throws IOException { IoAcceptor acceptor = null; acceptor = new SocketAcceptor(); @@ -90,14 +89,14 @@ public class AcceptorTest _logger.info("Bound on port " + PORT); } - public static junit.framework.Test suite() + public static void main(String[] args) throws IOException { - return new JUnit4TestAdapter(AcceptorTest.class); + AcceptorTest a = new AcceptorTest(); + a.testStartAcceptor(); } - public static void main(String[] args) throws IOException + public static junit.framework.Test suite() { - AcceptorTest a = new AcceptorTest(); - a.startAcceptor(); + return new junit.framework.TestSuite(AcceptorTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/mina/BlockingAcceptorTest.java b/java/client/src/test/java/org/apache/qpid/mina/BlockingAcceptorTest.java index 79dba32e47..bfe29c47e6 100644 --- a/java/client/src/test/java/org/apache/qpid/mina/BlockingAcceptorTest.java +++ b/java/client/src/test/java/org/apache/qpid/mina/BlockingAcceptorTest.java @@ -20,9 +20,7 @@ */ package org.apache.qpid.mina; -import junit.framework.JUnit4TestAdapter; import org.apache.log4j.Logger; -import org.junit.Test; import java.io.IOException; import java.io.InputStream; @@ -30,19 +28,15 @@ import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; -public class BlockingAcceptorTest +import junit.framework.TestCase; + +public class BlockingAcceptorTest extends TestCase { private static final Logger _logger = Logger.getLogger(BlockingAcceptorTest.class); public static int PORT = 9999; - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(AcceptorTest.class); - } - - @Test - public void startAcceptor() throws IOException + public void testStartAcceptor() throws IOException { ServerSocket sock = new ServerSocket(PORT); @@ -89,6 +83,11 @@ public class BlockingAcceptorTest public static void main(String[] args) throws IOException { BlockingAcceptorTest a = new BlockingAcceptorTest(); - a.startAcceptor(); + a.testStartAcceptor(); + } + + public static junit.framework.Test suite() + { + return new junit.framework.TestSuite(AcceptorTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/mina/WriterTest.java b/java/client/src/test/java/org/apache/qpid/mina/WriterTest.java index dc29861c87..910345624f 100644 --- a/java/client/src/test/java/org/apache/qpid/mina/WriterTest.java +++ b/java/client/src/test/java/org/apache/qpid/mina/WriterTest.java @@ -20,240 +20,237 @@ */ package org.apache.qpid.mina; -import junit.framework.JUnit4TestAdapter; import org.apache.log4j.Logger; import org.apache.mina.common.*; import org.apache.mina.transport.socket.nio.SocketConnector; import org.apache.mina.transport.socket.nio.SocketConnectorConfig; import org.apache.mina.transport.socket.nio.SocketSessionConfig; -import org.junit.Test; import java.io.IOException; import java.net.InetSocketAddress; import java.util.concurrent.CountDownLatch; -public class WriterTest implements Runnable +import junit.framework.TestCase; + +public class WriterTest extends TestCase { private static final Logger _logger = Logger.getLogger(WriterTest.class); - private IoSession _session; + private static class RunnableWriterTest implements Runnable + { + private Logger _logger; - private long _startTime; + private IoSession _session; - private long[] _chunkTimes; + private long _startTime; - private int _chunkCount = 500000; + private long[] _chunkTimes; - private int _chunkSize = 1024; + private int _chunkCount = 500000; - private CountDownLatch _notifier; + private int _chunkSize = 1024; - public void run() - { - _startTime = System.currentTimeMillis(); - _notifier = new CountDownLatch(1); - for (int i = 0; i < _chunkCount; i++) - { - ByteBuffer buf = ByteBuffer.allocate(_chunkSize, false); - byte check = (byte) (i % 128); - buf.put(check); - buf.fill((byte)88, buf.remaining()); - buf.flip(); - _session.write(buf); - } + private CountDownLatch _notifier; - try + public RunnableWriterTest(Logger logger) { - _logger.info("All buffers sent; waiting for receipt from server"); - _notifier.await(); + _logger = logger; } - catch (InterruptedException e) - { - } - _logger.info("Completed"); - long totalTime = System.currentTimeMillis() - _startTime; - _logger.info("Total time: " + totalTime); - _logger.info("MB per second: " + (_chunkSize * _chunkCount)/totalTime); - long lastChunkTime = _startTime; - double average = 0; - for (int i = 0; i < _chunkTimes.length; i++) + + public void run() { - if (i == 0) + _startTime = System.currentTimeMillis(); + _notifier = new CountDownLatch(1); + for (int i = 0; i < _chunkCount; i++) + { + ByteBuffer buf = ByteBuffer.allocate(_chunkSize, false); + byte check = (byte) (i % 128); + buf.put(check); + buf.fill((byte)88, buf.remaining()); + buf.flip(); + _session.write(buf); + } + + try { - average = _chunkTimes[i] - _startTime; + _logger.info("All buffers sent; waiting for receipt from server"); + _notifier.await(); } - else + catch (InterruptedException e) { - long delta = _chunkTimes[i] - lastChunkTime; - if (delta != 0) + } + _logger.info("Completed"); + long totalTime = System.currentTimeMillis() - _startTime; + _logger.info("Total time: " + totalTime); + _logger.info("MB per second: " + (_chunkSize * _chunkCount)/totalTime); + long lastChunkTime = _startTime; + double average = 0; + for (int i = 0; i < _chunkTimes.length; i++) + { + if (i == 0) + { + average = _chunkTimes[i] - _startTime; + } + else { - average = (average + delta)/2; + long delta = _chunkTimes[i] - lastChunkTime; + if (delta != 0) + { + average = (average + delta)/2; + } } + lastChunkTime = _chunkTimes[i]; } - lastChunkTime = _chunkTimes[i]; + _logger.info("Average chunk time: " + average + "ms"); + CloseFuture cf = _session.close(); + cf.join(); } - _logger.info("Average chunk time: " + average + "ms"); - CloseFuture cf = _session.close(); - cf.join(); - } - private class WriterHandler extends IoHandlerAdapter - { - private int _chunksReceived = 0; + private class WriterHandler extends IoHandlerAdapter + { + private int _chunksReceived = 0; - private int _partialBytesRead = 0; + private int _partialBytesRead = 0; - private byte _partialCheckNumber; + private byte _partialCheckNumber; - private int _totalBytesReceived = 0; + private int _totalBytesReceived = 0; - public void messageReceived(IoSession session, Object message) throws Exception - { - ByteBuffer result = (ByteBuffer) message; - _totalBytesReceived += result.remaining(); - int size = result.remaining(); - long now = System.currentTimeMillis(); - if (_partialBytesRead > 0) + public void messageReceived(IoSession session, Object message) throws Exception { - int offset = _chunkSize - _partialBytesRead; - if (size >= offset) - { - _chunkTimes[_chunksReceived++] = now; - result.position(offset); - } - else + ByteBuffer result = (ByteBuffer) message; + _totalBytesReceived += result.remaining(); + int size = result.remaining(); + long now = System.currentTimeMillis(); + if (_partialBytesRead > 0) { - // have not read even one chunk, including the previous partial bytes - _partialBytesRead += size; - return; + int offset = _chunkSize - _partialBytesRead; + if (size >= offset) + { + _chunkTimes[_chunksReceived++] = now; + result.position(offset); + } + else + { + // have not read even one chunk, including the previous partial bytes + _partialBytesRead += size; + return; + } } - } - int chunkCount = result.remaining()/_chunkSize; + int chunkCount = result.remaining()/_chunkSize; - for (int i = 0; i < chunkCount; i++) - { - _chunkTimes[_chunksReceived++] = now; - byte check = result.get(); - _logger.debug("Check number " + check + " read"); - if (check != (byte)((_chunksReceived - 1)%128)) + for (int i = 0; i < chunkCount; i++) { - _logger.error("Check number " + check + " read when expected " + (_chunksReceived%128)); + _chunkTimes[_chunksReceived++] = now; + byte check = result.get(); + _logger.debug("Check number " + check + " read"); + if (check != (byte)((_chunksReceived - 1)%128)) + { + _logger.error("Check number " + check + " read when expected " + (_chunksReceived%128)); + } + _logger.debug("Chunk times recorded"); + + try + { + result.skip(_chunkSize - 1); + } + catch (IllegalArgumentException e) + { + _logger.error("Position was: " + result.position()); + _logger.error("Tried to skip to: " + (_chunkSize * i)); + _logger.error("limit was; " + result.limit()); + } } - _logger.debug("Chunk times recorded"); + _logger.debug("Chunks received now " + _chunksReceived); + _logger.debug("Bytes received: " + _totalBytesReceived); + _partialBytesRead = result.remaining(); - try + if (_partialBytesRead > 0) { - result.skip(_chunkSize - 1); + _partialCheckNumber = result.get(); } - catch (IllegalArgumentException e) + + if (_chunksReceived >= _chunkCount) { - _logger.error("Position was: " + result.position()); - _logger.error("Tried to skip to: " + (_chunkSize * i)); - _logger.error("limit was; " + result.limit()); + _notifier.countDown(); } - } - _logger.debug("Chunks received now " + _chunksReceived); - _logger.debug("Bytes received: " + _totalBytesReceived); - _partialBytesRead = result.remaining(); - if (_partialBytesRead > 0) - { - _partialCheckNumber = result.get(); } - if (_chunksReceived >= _chunkCount) + public void exceptionCaught(IoSession session, Throwable cause) throws Exception { - _notifier.countDown(); + _logger.error("Error: " + cause, cause); } - } - public void exceptionCaught(IoSession session, Throwable cause) throws Exception + public void startWriter(int chunkSize) throws IOException, InterruptedException { - _logger.error("Error: " + cause, cause); - } - } + _chunkSize = chunkSize; - public void startWriter() throws IOException, InterruptedException - { - IoConnector ioConnector = null; + IoConnector ioConnector = null; - ioConnector = new SocketConnector(); + ioConnector = new SocketConnector(); - SocketConnectorConfig cfg = (SocketConnectorConfig) ioConnector.getDefaultConfig(); - cfg.setThreadModel(ThreadModel.MANUAL); - SocketSessionConfig scfg = (SocketSessionConfig) cfg.getSessionConfig(); - scfg.setTcpNoDelay(true); - scfg.setSendBufferSize(32768); - scfg.setReceiveBufferSize(32768); - - final InetSocketAddress address = new InetSocketAddress("localhost", AcceptorTest.PORT); - _logger.info("Attempting connection to " + address); - ConnectFuture future = ioConnector.connect(address, new WriterHandler()); - // wait for connection to complete - future.join(); - _logger.info("Connection completed"); - // we call getSession which throws an IOException if there has been an error connecting - _session = future.getSession(); - _chunkTimes = new long[_chunkCount]; - Thread t = new Thread(this); - t.start(); - t.join(); - _logger.info("Test completed"); + SocketConnectorConfig cfg = (SocketConnectorConfig) ioConnector.getDefaultConfig(); + cfg.setThreadModel(ThreadModel.MANUAL); + SocketSessionConfig scfg = (SocketSessionConfig) cfg.getSessionConfig(); + scfg.setTcpNoDelay(true); + scfg.setSendBufferSize(32768); + scfg.setReceiveBufferSize(32768); + + final InetSocketAddress address = new InetSocketAddress("localhost", AcceptorTest.PORT); + _logger.info("Attempting connection to " + address); + ConnectFuture future = ioConnector.connect(address, new WriterHandler()); + // wait for connection to complete + future.join(); + _logger.info("Connection completed"); + // we call getSession which throws an IOException if there has been an error connecting + _session = future.getSession(); + _chunkTimes = new long[_chunkCount]; + Thread t = new Thread(this); + t.start(); + t.join(); + _logger.info("Test completed"); + } } - @Test + private RunnableWriterTest _runnableWriterTest = new RunnableWriterTest(_logger); + public void test1k() throws IOException, InterruptedException { _logger.info("Starting 1k test"); - _chunkSize = 1024; - startWriter(); + _runnableWriterTest.startWriter(1024); } - @Test public void test2k() throws IOException, InterruptedException { _logger.info("Starting 2k test"); - _chunkSize = 2048; - startWriter(); + _runnableWriterTest.startWriter(2048); } - @Test public void test4k() throws IOException, InterruptedException { _logger.info("Starting 4k test"); - _chunkSize = 4096; - startWriter(); + _runnableWriterTest.startWriter(4096); } - @Test public void test8k() throws IOException, InterruptedException { _logger.info("Starting 8k test"); - _chunkSize = 8192; - startWriter(); + _runnableWriterTest.startWriter(8192); } - @Test public void test16k() throws IOException, InterruptedException { _logger.info("Starting 16k test"); - _chunkSize = 16384; - startWriter(); + _runnableWriterTest.startWriter(16384); } - @Test public void test32k() throws IOException, InterruptedException { _logger.info("Starting 32k test"); - _chunkSize = 32768; - startWriter(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(WriterTest.class); + _runnableWriterTest.startWriter(32768); } public static void main(String[] args) throws IOException, InterruptedException @@ -266,4 +263,9 @@ public class WriterTest implements Runnable //w.test16k(); //w.test32k(); } + + public static junit.framework.Test suite() + { + return new junit.framework.TestSuite(WriterTest.class); + } } diff --git a/java/client/src/test/java/org/apache/qpid/requestreply1/VmRequestReply.java b/java/client/src/test/java/org/apache/qpid/requestreply1/VmRequestReply.java index ada10dcd13..56d1ce9b6d 100644 --- a/java/client/src/test/java/org/apache/qpid/requestreply1/VmRequestReply.java +++ b/java/client/src/test/java/org/apache/qpid/requestreply1/VmRequestReply.java @@ -22,38 +22,16 @@ package org.apache.qpid.requestreply1; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; -import org.junit.Test; -import org.junit.Before; -import org.junit.Assert; -import org.junit.After; +import org.apache.qpid.test.VMBrokerSetup; import org.apache.log4j.Logger; -import junit.framework.JUnit4TestAdapter; -public class VmRequestReply +import junit.framework.TestCase; + +public class VmRequestReply extends TestCase { private static final Logger _logger = Logger.getLogger(VmRequestReply.class); - @Before - public void startVmBrokers() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create VM Broker: " + e.getMessage()); - } - } - - @After - public void stopVmBrokers() - { - TransportConnection.killVMBroker(1); - } - - @Test - public void simpleClient() throws Exception + public void testSimpleClient() throws Exception { ServiceProvidingClient serviceProvider = new ServiceProvidingClient("vm://:1", "guest", "guest", "serviceProvidingClient", "/test", @@ -74,21 +52,21 @@ public class VmRequestReply } } - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(VmRequestReply.class); - } - public static void main(String[] args) { VmRequestReply rr = new VmRequestReply(); try { - rr.simpleClient(); + rr.testSimpleClient(); } catch (Exception e) { _logger.error("Error: " + e, e); } } + + public static junit.framework.Test suite() + { + return new VMBrokerSetup(new junit.framework.TestSuite(VmRequestReply.class)); + } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MessageUnitTests.java b/java/client/src/test/java/org/apache/qpid/test/VMBrokerSetup.java index dfcd80649d..e859fac4af 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MessageUnitTests.java +++ b/java/client/src/test/java/org/apache/qpid/test/VMBrokerSetup.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,19 +17,36 @@ * under the License. * */ -package org.apache.qpid.test.unit.client.message; +package org.apache.qpid.test; +import junit.extensions.TestSetup; +import junit.framework.Test; -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.apache.qpid.client.transport.TransportConnection; -@RunWith(Suite.class) -@Suite.SuiteClasses({BytesMessageTest.class, TextMessageTest.class}) -public class MessageUnitTests +public class VMBrokerSetup extends TestSetup { - public static junit.framework.Test suite() + public VMBrokerSetup(Test t) + { + super(t); + } + + protected void setUp() throws Exception + { + super.setUp(); + try + { + TransportConnection.createVMBroker(1); + } + catch (Exception e) + { + fail("Unable to create broker: " + e); + } + } + + protected void tearDown() throws Exception { - return new JUnit4TestAdapter(MessageUnitTests.class); + TransportConnection.killVMBroker(1); + super.tearDown(); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java index f9b2b15be5..5161705ef2 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/ack/RecoverTest.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,7 +19,6 @@ */ package org.apache.qpid.test.unit.ack; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.AMQSession; @@ -28,14 +26,13 @@ import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.log4j.Logger; import org.apache.log4j.xml.DOMConfigurator; -import org.junit.Assert; -import org.junit.Test; -import org.junit.Before; -import org.junit.After; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.*; -public class RecoverTest +import junit.framework.TestCase; + +public class RecoverTest extends TestCase { private static final Logger _logger = Logger.getLogger(RecoverTest.class); @@ -48,31 +45,10 @@ public class RecoverTest System.out.println("QPID_WORK not set using tmp directory: " + tempdir); System.setProperty("QPID_WORK", tempdir); } - //DOMConfigurator.configure("../etc/log4j.xml"); - DOMConfigurator.configure("broker/etc/log4j.xml"); - } - - @Before - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } + DOMConfigurator.configure("../broker/etc/log4j.xml"); } - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - @Test - public void recoverResendsMsgs() throws Exception + public void testRecoverResendsMsgs() throws Exception { Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); @@ -106,13 +82,13 @@ public class RecoverTest // no ack for last three messages so when I call recover I expect to get three messages back consumerSession.recover(); tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg2", tm.getText()); + assertEquals("msg2", tm.getText()); tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg3", tm.getText()); + assertEquals("msg3", tm.getText()); tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg4", tm.getText()); + assertEquals("msg4", tm.getText()); _logger.info("Received redelivery of three messages. Acknowledging last message"); tm.acknowledge(); @@ -122,16 +98,14 @@ public class RecoverTest consumerSession.recover(); tm = (TextMessage) consumer.receiveNoWait(); - Assert.assertNull(tm); + assertNull(tm); _logger.info("No messages redelivered as is expected"); con.close(); - } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(RecoverTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(RecoverTest.class)); } } - diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/ack/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/ack/UnitTests.java deleted file mode 100644 index a0eec941d5..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/ack/UnitTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.ack; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({RecoverTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java index 8013e9e527..bf97c1918e 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,7 +19,6 @@ */ package org.apache.qpid.test.unit.basic; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQQueue; @@ -28,18 +26,17 @@ import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.message.JMSBytesMessage; +import org.apache.qpid.test.VMBrokerSetup; import org.apache.mina.common.ByteBuffer; -import org.junit.Test; -import org.junit.Before; -import org.junit.Assert; -import org.junit.After; -import javax.jms.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import javax.jms.*; + +import junit.framework.TestCase; -public class BytesMessageTest implements MessageListener +public class BytesMessageTest extends TestCase implements MessageListener { private Connection _connection; private Destination _destination; @@ -49,29 +46,15 @@ public class BytesMessageTest implements MessageListener private int _count = 100; public String _connectionString = "vm://:1"; - @Before - public void init() throws Exception + protected void setUp() throws Exception { - createVMBroker(); - init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); + super.setUp(); + init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); } - public void createVMBroker() + protected void tearDown() throws Exception { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); + super.tearDown(); } void init(AMQConnection connection) throws Exception @@ -90,10 +73,8 @@ public class BytesMessageTest implements MessageListener connection.start(); } - @Test public void test() throws Exception { - try { send(_count); @@ -229,6 +210,6 @@ public class BytesMessageTest implements MessageListener public static junit.framework.Test suite() { - return new JUnit4TestAdapter(BytesMessageTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(BytesMessageTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java index f78014a4b6..079def81d0 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java @@ -20,22 +20,18 @@ */ package org.apache.qpid.test.unit.basic; -import org.junit.Test; -import org.junit.Assert; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.client.message.JMSTextMessage; import org.apache.qpid.client.message.TestMessageHelper; - import java.util.Enumeration; -import junit.framework.JUnit4TestAdapter; - import javax.jms.JMSException; -public class FieldTableKeyEnumeratorTest +import junit.framework.TestCase; + +public class FieldTableKeyEnumeratorTest extends TestCase { - @Test public void testKeyEnumeration() { FieldTable result = new FieldTable(); @@ -47,14 +43,13 @@ public class FieldTableKeyEnumeratorTest Enumeration e = result.keys(); - Assert.assertTrue("one".equals(e.nextElement())); - Assert.assertTrue("two".equals(e.nextElement())); - Assert.assertTrue("three".equals(e.nextElement())); - Assert.assertTrue("four".equals(e.nextElement())); - Assert.assertTrue("five".equals(e.nextElement())); + assertTrue("one".equals(e.nextElement())); + assertTrue("two".equals(e.nextElement())); + assertTrue("three".equals(e.nextElement())); + assertTrue("four".equals(e.nextElement())); + assertTrue("five".equals(e.nextElement())); } - @Test public void testPropertEnu() { try @@ -68,10 +63,10 @@ public class FieldTableKeyEnumeratorTest Enumeration e = text.getPropertyNames(); - Assert.assertTrue("Boolean1".equals(e.nextElement())); - Assert.assertTrue("Boolean2".equals(e.nextElement())); - Assert.assertTrue("Int".equals(e.nextElement())); - Assert.assertTrue("Long".equals(e.nextElement())); + assertTrue("Boolean1".equals(e.nextElement())); + assertTrue("Boolean2".equals(e.nextElement())); + assertTrue("Int".equals(e.nextElement())); + assertTrue("Long".equals(e.nextElement())); } catch (JMSException e) { @@ -81,8 +76,6 @@ public class FieldTableKeyEnumeratorTest public static junit.framework.Test suite() { - return new JUnit4TestAdapter(FieldTableKeyEnumeratorTest.class); + return new junit.framework.TestSuite(FieldTableKeyEnumeratorTest.class); } - - } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java index c04166aa12..b969942128 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.test.unit.basic; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQQueue; @@ -31,17 +30,16 @@ import org.apache.qpid.client.message.JMSBytesMessage; import org.apache.qpid.framing.AMQFrameDecodingException; import org.apache.qpid.framing.FieldTable; import org.apache.qpid.framing.FieldTableTest; +import org.apache.qpid.test.VMBrokerSetup; import org.apache.mina.common.ByteBuffer; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; -import javax.jms.*; import java.io.IOException; import java.util.ArrayList; +import javax.jms.*; + +import junit.framework.TestCase; -public class FieldTableMessageTest implements MessageListener +public class FieldTableMessageTest extends TestCase implements MessageListener { private AMQConnection _connection; private AMQDestination _destination; @@ -51,29 +49,15 @@ public class FieldTableMessageTest implements MessageListener private int _count = 10; public String _connectionString = "vm://:1"; - @Before - public void init() throws Exception + protected void setUp() throws Exception { - createVMBroker(); + super.setUp(); init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); } - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() + protected void tearDown() throws Exception { - TransportConnection.killVMBroker(1); + super.tearDown(); } @@ -108,7 +92,6 @@ public class FieldTableMessageTest implements MessageListener return result; } - @Test public void test() throws Exception { int count = _count; @@ -170,13 +153,13 @@ public class FieldTableMessageTest implements MessageListener { FieldTableMessageTest test = new FieldTableMessageTest(); test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; - test.init(); + test.setUp(); test._count = argv.length > 1 ? Integer.parseInt(argv[1]) : 5; test.test(); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(FieldTableMessageTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(FieldTableMessageTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java index 1b2108b928..a2569a4701 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,24 +19,22 @@ */ package org.apache.qpid.test.unit.basic; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.AMQTopic; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; -import org.junit.Test; -import org.junit.Assert; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.*; +import junit.framework.TestCase; + /** * This is a slow test. */ -public class MultipleConnectionTest +public class MultipleConnectionTest extends TestCase { public static String _connectionString = "vm://:1"; @@ -178,7 +175,6 @@ public class MultipleConnectionTest test.test(); } - @Test public void test() throws Exception { String broker = _connectionString; @@ -220,28 +216,8 @@ public class MultipleConnectionTest } } - @BeforeClass - public static void createVMBroker() throws Exception - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @AfterClass - public static void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(MultipleConnectionTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(MultipleConnectionTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java index a86d756e67..c09369b4b5 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/ObjectMessageTest.java @@ -1,5 +1,4 @@ /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,7 +19,6 @@ */ package org.apache.qpid.test.unit.basic; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQQueue; @@ -28,10 +26,7 @@ import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.message.JMSObjectMessage; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.JMSException; import javax.jms.Message; @@ -42,7 +37,9 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -public class ObjectMessageTest implements MessageListener +import junit.framework.TestCase; + +public class ObjectMessageTest extends TestCase implements MessageListener { private AMQConnection _connection; private AMQDestination _destination; @@ -52,37 +49,22 @@ public class ObjectMessageTest implements MessageListener private int _count = 100; public String _connectionString = "vm://:1"; - @Before - public void init() + protected void setUp() throws Exception { - String broker = _connectionString; - createVMBroker(); + super.setUp(); try - { - init(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path")); + { + init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); } catch (Exception e) { - Assert.fail("Uable to initialise: " + e); - } - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); + fail("Uable to initialise: " + e); } } - @After - public void stopVmBroker() + protected void tearDown() throws Exception { - TransportConnection.killVMBroker(1); + super.tearDown(); } private void init(AMQConnection connection) throws Exception @@ -101,7 +83,6 @@ public class ObjectMessageTest implements MessageListener connection.start(); } - @Test public void test() throws Exception { int count = _count; @@ -225,7 +206,7 @@ public class ObjectMessageTest implements MessageListener { ObjectMessageTest test = new ObjectMessageTest(); test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; - test.init(); + test.setUp(); if (argv.length > 1) { test._count = Integer.parseInt(argv[1]); @@ -235,6 +216,6 @@ public class ObjectMessageTest implements MessageListener public static junit.framework.Test suite() { - return new JUnit4TestAdapter(ObjectMessageTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(ObjectMessageTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/ReceiveTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/ReceiveTest.java index cfa438dfdb..e73479eba0 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/ReceiveTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/ReceiveTest.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.test.unit.basic; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQQueue; @@ -28,14 +27,11 @@ import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; - import javax.jms.MessageConsumer; -public class ReceiveTest +import junit.framework.TestCase; + +public class ReceiveTest extends TestCase { private AMQConnection _connection; private AMQDestination _destination; @@ -45,16 +41,15 @@ public class ReceiveTest private static final String VM_BROKER = "vm://:1"; public String _connectionString = VM_BROKER; - @Before - public void init() throws Exception + protected void setUp() throws Exception { + super.setUp(); if (_connectionString.equals(VM_BROKER)) { createVMBroker(); + String broker = _connectionString; + init(new AMQConnection(broker, "guest", "guest", "ReceiveTestClient", "/test_path")); } - - String broker = _connectionString; - init(new AMQConnection(broker, "guest", "guest", "ReceiveTestClient", "/test_path")); } public void createVMBroker() @@ -63,23 +58,21 @@ public class ReceiveTest { TransportConnection.createVMBroker(1); } - catch ( - AMQVMBrokerCreationException e) + catch (AMQVMBrokerCreationException e) { - Assert.fail("Unable to create broker: " + e); + fail("Unable to create broker: " + e); } } - @After - public void stopVmBroker() + protected void tearDown() throws Exception { if (_connectionString.equals(VM_BROKER)) { TransportConnection.killVMBroker(1); } + super.tearDown(); } - private void init(AMQConnection connection) throws Exception { init(connection, new AMQQueue("ReceiveTest", true)); @@ -94,7 +87,6 @@ public class ReceiveTest _connection.start(); } - @Test public void test() throws Exception { _consumer.receive(5000); @@ -105,12 +97,12 @@ public class ReceiveTest { ReceiveTest test = new ReceiveTest(); test._connectionString = argv.length == 0 ? VM_BROKER : argv[0]; - test.init(); + test.setUp(); test.test(); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(ReceiveTest.class); + return new junit.framework.TestSuite(ReceiveTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java index 436be3c1c9..6fa8ab95bf 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/SessionStartTest.java @@ -20,24 +20,21 @@ */ package org.apache.qpid.test.unit.basic; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; -public class SessionStartTest implements MessageListener +import junit.framework.TestCase; + +public class SessionStartTest extends TestCase implements MessageListener { private AMQConnection _connection; private AMQDestination _destination; @@ -45,36 +42,15 @@ public class SessionStartTest implements MessageListener private int count; public String _connectionString = "vm://:1"; - @Before - public void init() + protected void setUp() throws Exception { - createVMBroker(); - try - { - init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); - } - catch (Exception e) - { - Assert.fail("Unable to initialise connection: " + e); - } - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } + super.setUp(); + init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); } - @After - public void stopVmBroker() + protected void tearDown() throws Exception { - TransportConnection.killVMBroker(1); + super.tearDown(); } private void init(AMQConnection connection) throws Exception @@ -92,7 +68,6 @@ public class SessionStartTest implements MessageListener _session.createConsumer(destination).setMessageListener(this); } - @Test public synchronized void test() throws JMSException, InterruptedException { try @@ -131,12 +106,12 @@ public class SessionStartTest implements MessageListener { SessionStartTest test = new SessionStartTest(); test._connectionString = argv.length == 0 ? "localhost:5672" : argv[0]; - test.init(); + test.setUp(); test.test(); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(SessionStartTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(SessionStartTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java index ddd8c0865d..11f511449f 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.test.unit.basic; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQQueue; @@ -28,17 +27,16 @@ import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.message.JMSTextMessage; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; +import org.apache.qpid.test.VMBrokerSetup; -import javax.jms.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import javax.jms.*; + +import junit.framework.TestCase; -public class TextMessageTest implements MessageListener +public class TextMessageTest extends TestCase implements MessageListener { private AMQConnection _connection; private Destination _destination; @@ -48,37 +46,22 @@ public class TextMessageTest implements MessageListener private int _count = 100; public String _connectionString = "vm://:1"; - @Before - public void init() + protected void setUp() throws Exception { - createVMBroker(); - + super.setUp(); try { init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); } catch (Exception e) { - Assert.fail("Unable to initialilse connection: " + e); - } - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); + fail("Unable to initialilse connection: " + e); } } - @After - public void stopVmBroker() + protected void tearDown() throws Exception { - TransportConnection.killVMBroker(1); + super.tearDown(); } private void init(AMQConnection connection) throws Exception @@ -98,7 +81,6 @@ public class TextMessageTest implements MessageListener connection.start(); } - @Test public void test() throws Exception { int count = _count; @@ -197,7 +179,7 @@ public class TextMessageTest implements MessageListener { TextMessageTest test = new TextMessageTest(); test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; - test.init(); + test.setUp(); if (argv.length > 1) { test._count = Integer.parseInt(argv[1]); @@ -207,6 +189,6 @@ public class TextMessageTest implements MessageListener public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TextMessageTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(TextMessageTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/basic/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/basic/UnitTests.java deleted file mode 100644 index 89bb00edd9..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/basic/UnitTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.basic; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - BytesMessageTest.class, - FieldTableMessageTest.class, - FieldTableKeyEnumeratorTest.class, - MultipleConnectionTest.class, - ObjectMessageTest.class, - SessionStartTest.class, - TextMessageTest.class - }) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java index 7086d21a81..9b46c5b18a 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.test.unit.client; -import org.junit.*; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.AMQTopic; @@ -29,44 +28,30 @@ import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.AMQSession; import org.apache.qpid.AMQException; import org.apache.qpid.url.URLSyntaxException; -import junit.framework.JUnit4TestAdapter; +import org.apache.qpid.test.VMBrokerSetup; +import java.lang.reflect.Method; import javax.jms.*; -public class AMQConnectionTest -{ +import junit.framework.TestCase; +public class AMQConnectionTest extends TestCase +{ private static AMQConnection _connection; private static AMQTopic _topic; private static AMQQueue _queue; private static QueueSession _queueSession; private static TopicSession _topicSession; - - @Before - public void setUp() throws AMQException, URLSyntaxException, JMSException + protected void setUp() throws Exception { - createVMBroker(); - //initialise the variables we need for testing + super.setUp(); _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", "/test"); _topic = new AMQTopic("mytopic"); _queue = new AMQQueue("myqueue"); } - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() + protected void tearDown() throws Exception { try { @@ -76,7 +61,7 @@ public class AMQConnectionTest { //ignore } - TransportConnection.killVMBroker(1); + super.tearDown(); } /** @@ -84,62 +69,137 @@ public class AMQConnectionTest * And that they throw exceptions where appropriate as per JMS spec */ - @Test public void testCreateQueueSession() throws JMSException { _queueSession = _connection.createQueueSession(false, AMQSession.NO_ACKNOWLEDGE); } - @Test public void testCreateTopicSession() throws JMSException { _topicSession = _connection.createTopicSession(false, AMQSession.NO_ACKNOWLEDGE); } - @Test(expected = javax.jms.IllegalStateException.class) public void testTopicSessionCreateBrowser() throws JMSException { - _topicSession.createBrowser(_queue); + try + { + _topicSession.createBrowser(_queue); + fail("expected exception did not occur"); + } + catch (javax.jms.IllegalStateException s) + { + // ok + } + catch (Exception e) + { + fail("expected javax.jms.IllegalStateException, got " + e); + } } - @Test(expected = javax.jms.IllegalStateException.class) public void testTopicSessionCreateQueue() throws JMSException { - _topicSession.createQueue("abc"); + try + { + _topicSession.createQueue("abc"); + fail("expected exception did not occur"); + } + catch (javax.jms.IllegalStateException s) + { + // ok + } + catch (Exception e) + { + fail("expected javax.jms.IllegalStateException, got " + e); + } } - @Test(expected = javax.jms.IllegalStateException.class) public void testTopicSessionCreateTemporaryQueue() throws JMSException { - _topicSession.createTemporaryQueue(); + try + { + _topicSession.createTemporaryQueue(); + fail("expected exception did not occur"); + } + catch (javax.jms.IllegalStateException s) + { + // ok + } + catch (Exception e) + { + fail("expected javax.jms.IllegalStateException, got " + e); + } } - @Test(expected = javax.jms.IllegalStateException.class) public void testQueueSessionCreateTemporaryTopic() throws JMSException { - _queueSession.createTemporaryTopic(); + try + { + _queueSession.createTemporaryTopic(); + fail("expected exception did not occur"); + } + catch (javax.jms.IllegalStateException s) + { + // ok + } + catch (Exception e) + { + fail("expected javax.jms.IllegalStateException, got " + e); + } } - @Test(expected = javax.jms.IllegalStateException.class) public void testQueueSessionCreateTopic() throws JMSException { - _queueSession.createTopic("abc"); + try + { + _queueSession.createTopic("abc"); + fail("expected exception did not occur"); + } + catch (javax.jms.IllegalStateException s) + { + // ok + } + catch (Exception e) + { + fail("expected javax.jms.IllegalStateException, got " + e); + } } - @Test(expected = javax.jms.IllegalStateException.class) public void testQueueSessionDurableSubscriber() throws JMSException { - _queueSession.createDurableSubscriber(_topic, "abc"); + try + { + _queueSession.createDurableSubscriber(_topic, "abc"); + fail("expected exception did not occur"); + } + catch (javax.jms.IllegalStateException s) + { + // ok + } + catch (Exception e) + { + fail("expected javax.jms.IllegalStateException, got " + e); + } } - @Test(expected = javax.jms.IllegalStateException.class) public void testQueueSessionUnsubscribe() throws JMSException { - _queueSession.unsubscribe("abc"); + try + { + _queueSession.unsubscribe("abc"); + fail("expected exception did not occur"); + } + catch (javax.jms.IllegalStateException s) + { + // ok + } + catch (Exception e) + { + fail("expected javax.jms.IllegalStateException, got " + e); + } } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(AMQConnectionTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(AMQConnectionTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java index 871bd41684..af4673856e 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/AMQSessionTest.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.test.unit.client; -import org.junit.*; import org.apache.qpid.AMQException; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; @@ -28,18 +27,19 @@ import org.apache.qpid.client.AMQTopic; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.test.VMBrokerSetup; import org.apache.qpid.url.URLSyntaxException; import javax.jms.JMSException; import javax.jms.TopicSubscriber; import javax.jms.QueueReceiver; -import junit.framework.JUnit4TestAdapter; +import junit.framework.TestCase; /** * Tests for QueueReceiver and TopicSubscriber creation methods on AMQSession */ -public class AMQSessionTest +public class AMQSessionTest extends TestCase { private static AMQSession _session; @@ -47,32 +47,16 @@ public class AMQSessionTest private static AMQQueue _queue; private static AMQConnection _connection; - @Before - public void setUp() throws AMQException, URLSyntaxException, JMSException + protected void setUp() throws Exception { - createVMBroker(); - //initialise the variables we need for testing + super.setUp(); _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", "/test"); _topic = new AMQTopic("mytopic"); _queue = new AMQQueue("myqueue"); _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() + protected void tearDown() throws Exception { try { @@ -82,50 +66,45 @@ public class AMQSessionTest { //just close } - TransportConnection.killVMBroker(1); + super.tearDown(); } - @Test public void testCreateSubscriber() throws JMSException { TopicSubscriber subscriber = _session.createSubscriber(_topic); - Assert.assertEquals("Topic names should match from TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName()); + assertEquals("Topic names should match from TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName()); subscriber = _session.createSubscriber(_topic, "abc", false); - Assert.assertEquals("Topic names should match from TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName()); + assertEquals("Topic names should match from TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName()); } - @Test public void testCreateDurableSubscriber() throws JMSException { TopicSubscriber subscriber = _session.createDurableSubscriber(_topic, "mysubname"); - Assert.assertEquals("Topic names should match from durable TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName()); + assertEquals("Topic names should match from durable TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName()); subscriber = _session.createDurableSubscriber(_topic, "mysubname", "abc", false); - Assert.assertEquals("Topic names should match from durable TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName()); + assertEquals("Topic names should match from durable TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName()); } - @Test public void testCreateQueueReceiver() throws JMSException { QueueReceiver receiver = _session.createQueueReceiver(_queue); - Assert.assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName()); + assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName()); receiver = _session.createQueueReceiver(_queue, "abc"); - Assert.assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName()); + assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName()); } - @Test public void testCreateReceiver() throws JMSException { QueueReceiver receiver = _session.createReceiver(_queue); - Assert.assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName()); + assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName()); receiver = _session.createReceiver(_queue, "abc"); - Assert.assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName()); + assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName()); } - @AfterClass public static void stopVmBrokers() { _queue = null; @@ -135,8 +114,6 @@ public class AMQSessionTest public static junit.framework.Test suite() { - return new JUnit4TestAdapter(AMQSessionTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(AMQSessionTest.class)); } - - } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/AllClientUnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/AllClientUnitTests.java deleted file mode 100644 index b3cb87a171..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/AllClientUnitTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.client; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * All client unit tests - even one in packages like org.apache.qpid.ack. - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ - org.apache.qpid.test.unit.ack.UnitTests.class, - org.apache.qpid.test.unit.basic.UnitTests.class, - org.apache.qpid.test.unit.client.channelclose.UnitTests.class, - org.apache.qpid.test.unit.client.message.MessageUnitTests.class, - org.apache.qpid.test.unit.client.forwardall.UnitTests.class, - org.apache.qpid.test.unit.client.destinationurl.UnitTests.class, - org.apache.qpid.test.unit.jndi.referenceabletest.UnitTests.class, - org.apache.qpid.test.unit.transacted.UnitTests.class, - org.apache.qpid.test.unit.client.protocol.AMQProtocolSessionTest.class, - org.apache.qpid.test.unit.client.AMQConnectionTest.class, - org.apache.qpid.test.unit.client.AMQSessionTest.class - }) -public class AllClientUnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(AllClientUnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java index c90d2cc4d3..d3a05c3d75 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java @@ -20,22 +20,20 @@ */ package org.apache.qpid.test.unit.client.channelclose; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; +import org.apache.qpid.test.VMBrokerSetup; import org.apache.log4j.Logger; -import org.junit.After; -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; import javax.jms.*; import java.util.ArrayList; import java.util.List; +import junit.framework.TestCase; +import junit.textui.TestRunner; + /** * Due to bizarre exception handling all sessions are closed if you get * a channel close request and no exception listener is registered. @@ -50,7 +48,7 @@ import java.util.List; * 3. Since client does not have an exception listener, currently all sessions are * closed. */ -public class ChannelCloseOkTest +public class ChannelCloseOkTest extends TestCase { private Connection _connection; private Destination _destination1; @@ -64,27 +62,9 @@ public class ChannelCloseOkTest public String _connectionString = "vm://:1"; - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - @Before - public void init() throws Exception + protected void setUp() throws Exception { - createVMBroker(); + super.setUp(); _connection = new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"); @@ -133,7 +113,12 @@ public class ChannelCloseOkTest } } - @After + protected void tearDown() throws Exception + { + closeConnection(); + super.tearDown(); + } + public void closeConnection() throws JMSException { if (_connection != null) @@ -141,17 +126,13 @@ public class ChannelCloseOkTest System.out.println(">>>>>>>>>>>>>>.. closing"); _connection.close(); } - - stopVmBroker(); } - @Test public void testWithoutExceptionListener() throws Exception { - test(); + doTest(); } - @Test public void testWithExceptionListener() throws Exception { _connection.setExceptionListener(new ExceptionListener() @@ -162,10 +143,10 @@ public class ChannelCloseOkTest } }); - test(); + doTest(); } - public void test() throws Exception + public void doTest() throws Exception { // Check both sessions are ok. sendAndWait(_session1, _destination1, "first", _received1, 1); @@ -223,16 +204,13 @@ public class ChannelCloseOkTest return in + System.currentTimeMillis(); } - /** - * For Junit 3 compatibility. - */ - public static junit.framework.Test suite() + public static void main(String[] args) { - return new JUnit4TestAdapter(ChannelCloseOkTest.class); + TestRunner.run(ChannelCloseOkTest.class); } - public static void main(String[] args) + public static junit.framework.Test suite() { - org.junit.runner.JUnitCore.main(ChannelCloseOkTest.class.getName()); + return new VMBrokerSetup(new junit.framework.TestSuite(ChannelCloseOkTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/UnitTests.java deleted file mode 100644 index 6daf8e048c..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/UnitTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.client.channelclose; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - ChannelCloseOkTest.class - }) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java index 990a9f3121..d7862d047f 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java @@ -27,44 +27,20 @@ import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.AMQException; import org.apache.qpid.AMQConnectionException; import org.apache.qpid.AMQUnresolvedAddressException; -import org.junit.Test; -import org.junit.Assert; -import org.junit.Before; -import org.junit.After; -import org.junit.Ignore; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.Connection; -import junit.framework.JUnit4TestAdapter; +import junit.framework.TestCase; -public class ConnectionTest +public class ConnectionTest extends TestCase { String _broker = "vm://:1"; String _broker_NotRunning = "vm://:2"; String _broker_BadDNS = "tcp://hg3sgaaw4lgihjs"; - @Before - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - @Test - public void simpleConnection() + public void testSimpleConnection() { try { @@ -73,68 +49,61 @@ public class ConnectionTest } catch (Exception e) { - Assert.fail("Connection to " + _broker + " should succeed. Reason: " + e); + fail("Connection to " + _broker + " should succeed. Reason: " + e); } } - @Ignore("The inVM broker currently has no authentication .. Needs added QPID-70") - @Test + // FIXME The inVM broker currently has no authentication .. Needs added QPID-70 public void passwordFailureConnection() throws Exception { try { new AMQConnection("amqp://guest:rubbishpassword@clientid/testpath?brokerlist='" + _broker + "?retries='1''"); - Assert.fail("Connection should not be established password is wrong."); + fail("Connection should not be established password is wrong."); } catch (AMQException amqe) { if (!(amqe instanceof AMQAuthenticationException)) { - Assert.fail("Correct exception not thrown. Excpected 'AMQAuthenticationException' got: " + amqe); + fail("Correct exception not thrown. Excpected 'AMQAuthenticationException' got: " + amqe); } } } - @Test - public void connectionFailure() throws Exception + public void testConnectionFailure() throws Exception { try { new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='" + _broker_NotRunning + "?retries='0''"); - Assert.fail("Connection should not be established"); + fail("Connection should not be established"); } catch (AMQException amqe) { if (!(amqe instanceof AMQConnectionException)) { - Assert.fail("Correct exception not thrown. Excpected 'AMQConnectionException' got: " + amqe); + fail("Correct exception not thrown. Excpected 'AMQConnectionException' got: " + amqe); } } } - @Test - public void unresolvedHostFailure() throws Exception + public void testUnresolvedHostFailure() throws Exception { try { new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='" + _broker_BadDNS + "?retries='0''"); - Assert.fail("Connection should not be established"); + fail("Connection should not be established"); } catch (AMQException amqe) { if (!(amqe instanceof AMQUnresolvedAddressException)) { - Assert.fail("Correct exception not thrown. Excpected 'AMQUnresolvedAddressException' got: " + amqe); + fail("Correct exception not thrown. Excpected 'AMQUnresolvedAddressException' got: " + amqe); } } } - /** - * For Junit 3 compatibility. - */ public static junit.framework.Test suite() { - return new JUnit4TestAdapter(ConnectionTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(ConnectionTest.class)); } - } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java index 9fbfab7664..d89bc4a771 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java @@ -20,14 +20,14 @@ */ package org.apache.qpid.test.unit.client.connection; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.AMQException; import org.apache.qpid.url.URLSyntaxException; import org.apache.qpid.client.AMQConnection; import org.apache.log4j.Logger; -import org.junit.Test; -public class TestManyConnections +import junit.framework.TestCase; + +public class TestManyConnections extends TestCase { private static final Logger _log = Logger.getLogger(TestManyConnections.class); @@ -53,50 +53,43 @@ public class TestManyConnections "ms"); } - @Test - public void create10Connections() throws AMQException, URLSyntaxException + public void testCreate10Connections() throws AMQException, URLSyntaxException { createConnections(10); } - @Test - public void create50Connections() throws AMQException, URLSyntaxException + public void testCreate50Connections() throws AMQException, URLSyntaxException { createConnections(50); } - @Test - public void create100Connections() throws AMQException, URLSyntaxException + public void testCreate100Connections() throws AMQException, URLSyntaxException { createConnections(100); } - @Test - public void create250Connections() throws AMQException, URLSyntaxException + public void testCreate250Connections() throws AMQException, URLSyntaxException { createConnections(250); } - @Test - public void create500Connections() throws AMQException, URLSyntaxException + public void testCreate500Connections() throws AMQException, URLSyntaxException { createConnections(500); } - @Test - public void create1000Connections() throws AMQException, URLSyntaxException + public void testCreate1000Connections() throws AMQException, URLSyntaxException { createConnections(1000); } - @Test - public void create5000Connections() throws AMQException, URLSyntaxException + public void testCreate5000Connections() throws AMQException, URLSyntaxException { createConnections(5000); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TestManyConnections.class); + return new junit.framework.TestSuite(TestManyConnections.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java index 1a5c6f84f7..13a6d214ba 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java @@ -20,11 +20,6 @@ */ package org.apache.qpid.test.unit.client.connectionurl; -import org.junit.Test; -import org.junit.Assert; -import org.junit.Before; -import org.junit.After; -import org.junit.Ignore; import org.apache.qpid.client.AMQConnectionURL; import org.apache.qpid.client.AMQBrokerDetails; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; @@ -32,280 +27,269 @@ import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.jms.ConnectionURL; import org.apache.qpid.jms.BrokerDetails; import org.apache.qpid.url.URLSyntaxException; -import junit.framework.JUnit4TestAdapter; -public class ConnectionURLTest +import junit.framework.TestCase; + +public class ConnectionURLTest extends TestCase { - @Test - public void failoverURL() throws URLSyntaxException + public void testFailoverURL() throws URLSyntaxException { String url = "amqp://ritchiem:bob@/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("bob")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); + assertTrue(connectionurl.getUsername().equals("ritchiem")); + assertTrue(connectionurl.getPassword().equals("bob")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getBrokerCount() == 2); + assertTrue(connectionurl.getBrokerCount() == 2); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); + assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); service = connectionurl.getBrokerDetails(1); - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("fancyserver")); - Assert.assertTrue(service.getPort() == 3000); + assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getHost().equals("fancyserver")); + assertTrue(service.getPort() == 3000); } - @Test - public void singleTransportUsernamePasswordURL() throws URLSyntaxException + public void testSingleTransportUsernamePasswordURL() throws URLSyntaxException { String url = "amqp://ritchiem:bob@/temp?brokerlist='tcp://localhost:5672'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("bob")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("ritchiem")); + assertTrue(connectionurl.getPassword().equals("bob")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); + assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); } - @Test - public void singleTransportUsernameBlankPasswordURL() throws URLSyntaxException + public void testSingleTransportUsernameBlankPasswordURL() throws URLSyntaxException { String url = "amqp://ritchiem:@/temp?brokerlist='tcp://localhost:5672'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("ritchiem")); + assertTrue(connectionurl.getPassword().equals("")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); + assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); } - @Test - public void failedURLNullPassword() + public void testFailedURLNullPassword() { String url = "amqp://ritchiem@/temp?brokerlist='tcp://localhost:5672'"; try { new AMQConnectionURL(url); - Assert.fail("URL has null password"); + fail("URL has null password"); } catch (URLSyntaxException e) { - Assert.assertTrue(e.getReason().equals("Null password in user information not allowed.")); - Assert.assertTrue(e.getIndex() == 7); + assertTrue(e.getReason().equals("Null password in user information not allowed.")); + assertTrue(e.getIndex() == 7); } } - @Test - public void singleTransportURL() throws URLSyntaxException + public void testSingleTransportURL() throws URLSyntaxException { String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/test")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("guest")); + assertTrue(connectionurl.getPassword().equals("guest")); + assertTrue(connectionurl.getVirtualHost().equals("/test")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); + assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); } - @Test - public void singleTransportWithClientURLURL() throws URLSyntaxException + public void testSingleTransportWithClientURLURL() throws URLSyntaxException { String url = "amqp://guest:guest@clientname/temp?brokerlist='tcp://localhost:5672'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getClientName().equals("clientname")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("guest")); + assertTrue(connectionurl.getPassword().equals("guest")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getClientName().equals("clientname")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); + assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); } - @Test - public void singleTransport1OptionURL() throws URLSyntaxException + public void testSingleTransport1OptionURL() throws URLSyntaxException { String url = "amqp://guest:guest@/temp?brokerlist='tcp://localhost:5672',routingkey='jim'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("guest")); + assertTrue(connectionurl.getPassword().equals("guest")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - Assert.assertTrue(connectionurl.getOption("routingkey").equals("jim")); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); + assertTrue(connectionurl.getOption("routingkey").equals("jim")); } - @Test - public void singleTransportDefaultedBroker() throws URLSyntaxException + public void testSingleTransportDefaultedBroker() throws URLSyntaxException { String url = "amqp://guest:guest@/temp?brokerlist='localhost'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("guest")); + assertTrue(connectionurl.getPassword().equals("guest")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); } - @Test - public void singleTransportMultiOptionURL() throws URLSyntaxException + public void testSingleTransportMultiOptionURL() throws URLSyntaxException { String url = "amqp://guest:guest@/temp?brokerlist='tcp://localhost:5672',routingkey='jim',timeout='200',immediatedelivery='true'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("guest")); + assertTrue(connectionurl.getPassword().equals("guest")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("tcp")); + assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); + assertTrue(service.getHost().equals("localhost")); + assertTrue(service.getPort() == 5672); - Assert.assertTrue(connectionurl.getOption("routingkey").equals("jim")); - Assert.assertTrue(connectionurl.getOption("timeout").equals("200")); - Assert.assertTrue(connectionurl.getOption("immediatedelivery").equals("true")); + assertTrue(connectionurl.getOption("routingkey").equals("jim")); + assertTrue(connectionurl.getOption("timeout").equals("200")); + assertTrue(connectionurl.getOption("immediatedelivery").equals("true")); } - @Test - public void singlevmURL() throws URLSyntaxException + public void testSinglevmURL() throws URLSyntaxException { String url = "amqp://guest:guest@/messages?brokerlist='vm://:2'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/messages")); + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("guest")); + assertTrue(connectionurl.getPassword().equals("guest")); + assertTrue(connectionurl.getVirtualHost().equals("/messages")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("vm")); - Assert.assertTrue(service.getHost().equals("")); - Assert.assertTrue(service.getPort() == 2); + assertTrue(service.getTransport().equals("vm")); + assertTrue(service.getHost().equals("")); + assertTrue(service.getPort() == 2); } - @Test - public void failoverVMURL() throws URLSyntaxException + public void testFailoverVMURL() throws URLSyntaxException { String url = "amqp://ritchiem:bob@/temp?brokerlist='vm://:2;vm://:3',failover='roundrobin'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("bob")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); + assertTrue(connectionurl.getUsername().equals("ritchiem")); + assertTrue(connectionurl.getPassword().equals("bob")); + assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getBrokerCount() == 2); + assertTrue(connectionurl.getBrokerCount() == 2); BrokerDetails service = connectionurl.getBrokerDetails(0); - Assert.assertTrue(service.getTransport().equals("vm")); - Assert.assertTrue(service.getHost().equals("")); - Assert.assertTrue(service.getPort() == 2); + assertTrue(service.getTransport().equals("vm")); + assertTrue(service.getHost().equals("")); + assertTrue(service.getPort() == 2); service = connectionurl.getBrokerDetails(1); - Assert.assertTrue(service.getTransport().equals("vm")); - Assert.assertTrue(service.getHost().equals("")); - Assert.assertTrue(service.getPort() == 3); + assertTrue(service.getTransport().equals("vm")); + assertTrue(service.getHost().equals("")); + assertTrue(service.getPort() == 3); } - @Test - public void noVirtualHostURL() + public void testNoVirtualHostURL() { String url = "amqp://user@?brokerlist='tcp://localhost:5672'"; try { new AMQConnectionURL(url); - Assert.fail("URL has no virtual host should not parse"); + fail("URL has no virtual host should not parse"); } catch (URLSyntaxException e) { @@ -313,23 +297,22 @@ public class ConnectionURLTest } } - @Test - public void noClientID() throws URLSyntaxException + public void testNoClientID() throws URLSyntaxException { String url = "amqp://user:@/test?brokerlist='tcp://localhost:5672'"; ConnectionURL connectionurl = new AMQConnectionURL(url); - Assert.assertTrue(connectionurl.getUsername().equals("user")); - Assert.assertTrue(connectionurl.getPassword().equals("")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/test")); + assertTrue(connectionurl.getUsername().equals("user")); + assertTrue(connectionurl.getPassword().equals("")); + assertTrue(connectionurl.getVirtualHost().equals("/test")); - Assert.assertTrue(connectionurl.getBrokerCount() == 1); + assertTrue(connectionurl.getBrokerCount() == 1); } - @Ignore("Connection now parses but result is wrong QPID-71") - @Test - public void wrongOptionSeperatorInBroker() + // FIXME Connection now parses but result is wrong QPID-71 + /* + public void testWrongOptionSeparatorInBroker() { String url = "amqp://user:@/test?brokerlist='tcp://localhost:5672+option='value''"; @@ -340,103 +323,97 @@ public class ConnectionURLTest Float version = Float.parseFloat(System.getProperty("java.specification.version")); if (version > 1.5) { - Assert.fail("URL Should not parse on Java " + version + " Connection is:" + connection); + fail("URL Should not parse on Java " + version + " Connection is:" + connection); } } catch (URLSyntaxException urise) { - Assert.assertTrue(urise.getReason().equals("Illegal character in port number")); + assertTrue(urise.getReason().equals("Illegal character in port number")); } } + */ - @Test - public void wrongOptionSeperatorInOptions() + public void testWrongOptionSeparatorInOptions() { String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'+failover='roundrobin'"; try { new AMQConnectionURL(url); - Assert.fail("URL Should not parse"); + fail("URL Should not parse"); } catch (URLSyntaxException urise) { - Assert.assertTrue(urise.getReason().equals("Unterminated option. Possible illegal option separator:'+'")); + assertTrue(urise.getReason().equals("Unterminated option. Possible illegal option separator:'+'")); } } - @Test - public void transportsDefaultToTCP() throws URLSyntaxException + public void testTransportsDefaultToTCP() throws URLSyntaxException { String url = "amqp://guest:guest@/test?brokerlist='localhost:5672;myhost:5673'&failover='roundrobin'"; AMQConnectionURL connection = new AMQConnectionURL(url); BrokerDetails broker = connection.getBrokerDetails(0); - Assert.assertTrue(broker.getTransport().equals("tcp")); + assertTrue(broker.getTransport().equals("tcp")); broker = connection.getBrokerDetails(1); - Assert.assertTrue(broker.getTransport().equals("tcp")); + assertTrue(broker.getTransport().equals("tcp")); } - @Test - public void noUserDetailsProvidedWithClientID() + public void testNoUserDetailsProvidedWithClientID() { String url = "amqp://clientID/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; try { new AMQConnectionURL(url); - Assert.fail("URL Should not parse"); + fail("URL Should not parse"); } catch (URLSyntaxException urise) { - Assert.assertTrue(urise.getMessage().startsWith("User information not found on url")); + assertTrue(urise.getMessage().startsWith("User information not found on url")); } } - @Test - public void noUserDetailsProvidedNOClientID() + public void testNoUserDetailsProvidedNOClientID() { String url = "amqp:///test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; try { new AMQConnectionURL(url); - Assert.fail("URL Should not parse"); + fail("URL Should not parse"); } catch (URLSyntaxException urise) { - Assert.assertTrue(urise.getMessage().startsWith("User information not found on url")); + assertTrue(urise.getMessage().startsWith("User information not found on url")); } } - @Test - public void checkVirtualhostFormat() throws URLSyntaxException + public void testCheckVirtualhostFormat() throws URLSyntaxException { String url = "amqp://guest:guest@/t.-_+!=:?brokerlist='tcp://localhost:5672'"; AMQConnectionURL connection = new AMQConnectionURL(url); - Assert.assertTrue(connection.getVirtualHost().equals("/t.-_+!=:")); + assertTrue(connection.getVirtualHost().equals("/t.-_+!=:")); } - @Test - public void checkDefaultPort() throws URLSyntaxException + public void testCheckDefaultPort() throws URLSyntaxException { String url = "amqp://guest:guest@/test=:?brokerlist='tcp://localhost'"; AMQConnectionURL connection = new AMQConnectionURL(url); BrokerDetails broker = connection.getBrokerDetails(0); - Assert.assertTrue(broker.getPort() == AMQBrokerDetails.DEFAULT_PORT); + assertTrue(broker.getPort() == AMQBrokerDetails.DEFAULT_PORT); } - @Test - public void checkMissingFinalQuote() throws URLSyntaxException + public void testCheckMissingFinalQuote() throws URLSyntaxException { String url = "amqp://guest:guest@id/test" + "?brokerlist='tcp://localhost:5672"; @@ -446,15 +423,12 @@ public class ConnectionURLTest } catch (URLSyntaxException e) { - Assert.assertEquals(e.getMessage(), "Unterminated option at index 32: brokerlist='tcp://localhost:5672"); + assertEquals(e.getMessage(), "Unterminated option at index 32: brokerlist='tcp://localhost:5672"); } - - } - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(ConnectionURLTest.class); + return new junit.framework.TestSuite(ConnectionURLTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java deleted file mode 100644 index 6184810880..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.client.connectionurl; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import junit.framework.JUnit4TestAdapter; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ConnectionURLTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(org.apache.qpid.test.unit.client.connectionurl.UnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java index aad5aace65..58a3c8c282 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java @@ -20,134 +20,126 @@ */ package org.apache.qpid.test.unit.client.destinationurl; -import org.junit.Test; -import org.junit.Assert; import org.apache.qpid.url.AMQBindingURL; import org.apache.qpid.url.URLSyntaxException; import org.apache.qpid.exchange.ExchangeDefaults; -import junit.framework.JUnit4TestAdapter; -public class DestinationURLTest +import junit.framework.TestCase; + +public class DestinationURLTest extends TestCase { - @Test - public void fullURL() throws URLSyntaxException + public void testFullURL() throws URLSyntaxException { String url = "exchange.Class://exchangeName/Destination/Queue"; AMQBindingURL dest = new AMQBindingURL(url); - Assert.assertTrue(url.equals(dest.toString())); + assertTrue(url.equals(dest.toString())); - Assert.assertTrue(dest.getExchangeClass().equals("exchange.Class")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("Queue")); + assertTrue(dest.getExchangeClass().equals("exchange.Class")); + assertTrue(dest.getExchangeName().equals("exchangeName")); + assertTrue(dest.getDestinationName().equals("Destination")); + assertTrue(dest.getQueueName().equals("Queue")); } - @Test - public void queue() throws URLSyntaxException + public void testQueue() throws URLSyntaxException { String url = "exchangeClass://exchangeName//Queue"; AMQBindingURL dest = new AMQBindingURL(url); - Assert.assertTrue(url.equals(dest.toString())); + assertTrue(url.equals(dest.toString())); - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("")); - Assert.assertTrue(dest.getQueueName().equals("Queue")); + assertTrue(dest.getExchangeClass().equals("exchangeClass")); + assertTrue(dest.getExchangeName().equals("exchangeName")); + assertTrue(dest.getDestinationName().equals("")); + assertTrue(dest.getQueueName().equals("Queue")); } - @Test - public void queueWithOption() throws URLSyntaxException + public void testQueueWithOption() throws URLSyntaxException { String url = "exchangeClass://exchangeName//Queue?option='value'"; AMQBindingURL dest = new AMQBindingURL(url); - Assert.assertTrue(url.equals(dest.toString())); + assertTrue(url.equals(dest.toString())); - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("")); - Assert.assertTrue(dest.getQueueName().equals("Queue")); - Assert.assertTrue(dest.getOption("option").equals("value")); + assertTrue(dest.getExchangeClass().equals("exchangeClass")); + assertTrue(dest.getExchangeName().equals("exchangeName")); + assertTrue(dest.getDestinationName().equals("")); + assertTrue(dest.getQueueName().equals("Queue")); + assertTrue(dest.getOption("option").equals("value")); } - @Test - public void destination() throws URLSyntaxException + public void testDestination() throws URLSyntaxException { String url = "exchangeClass://exchangeName/Destination/"; AMQBindingURL dest = new AMQBindingURL(url); - Assert.assertTrue(url.equals(dest.toString())); + assertTrue(url.equals(dest.toString())); - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("")); + assertTrue(dest.getExchangeClass().equals("exchangeClass")); + assertTrue(dest.getExchangeName().equals("exchangeName")); + assertTrue(dest.getDestinationName().equals("Destination")); + assertTrue(dest.getQueueName().equals("")); } - @Test - public void destinationWithOption() throws URLSyntaxException + public void testDestinationWithOption() throws URLSyntaxException { String url = "exchangeClass://exchangeName/Destination/?option='value'"; AMQBindingURL dest = new AMQBindingURL(url); - Assert.assertTrue(url.equals(dest.toString())); + assertTrue(url.equals(dest.toString())); - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("")); + assertTrue(dest.getExchangeClass().equals("exchangeClass")); + assertTrue(dest.getExchangeName().equals("exchangeName")); + assertTrue(dest.getDestinationName().equals("Destination")); + assertTrue(dest.getQueueName().equals("")); - Assert.assertTrue(dest.getOption("option").equals("value")); + assertTrue(dest.getOption("option").equals("value")); } - @Test - public void destinationWithMultiOption() throws URLSyntaxException + public void testDestinationWithMultiOption() throws URLSyntaxException { String url = "exchangeClass://exchangeName/Destination/?option='value',option2='value2'"; AMQBindingURL dest = new AMQBindingURL(url); - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("")); + assertTrue(dest.getExchangeClass().equals("exchangeClass")); + assertTrue(dest.getExchangeName().equals("exchangeName")); + assertTrue(dest.getDestinationName().equals("Destination")); + assertTrue(dest.getQueueName().equals("")); - Assert.assertTrue(dest.getOption("option").equals("value")); - Assert.assertTrue(dest.getOption("option2").equals("value2")); + assertTrue(dest.getOption("option").equals("value")); + assertTrue(dest.getOption("option2").equals("value2")); } - @Test - public void destinationWithNoExchangeDefaultsToDirect() throws URLSyntaxException + public void testDestinationWithNoExchangeDefaultsToDirect() throws URLSyntaxException { String url = "IBMPerfQueue1?durable='true'"; AMQBindingURL dest = new AMQBindingURL(url); - Assert.assertTrue(dest.getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)); - Assert.assertTrue(dest.getExchangeName().equals(ExchangeDefaults.DIRECT_EXCHANGE_NAME)); - Assert.assertTrue(dest.getDestinationName().equals("")); - Assert.assertTrue(dest.getQueueName().equals("IBMPerfQueue1")); + assertTrue(dest.getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)); + assertTrue(dest.getExchangeName().equals(ExchangeDefaults.DIRECT_EXCHANGE_NAME)); + assertTrue(dest.getDestinationName().equals("")); + assertTrue(dest.getQueueName().equals("IBMPerfQueue1")); - Assert.assertTrue(dest.getOption("durable").equals("true")); + assertTrue(dest.getOption("durable").equals("true")); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(DestinationURLTest.class); + return new junit.framework.TestSuite(DestinationURLTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java deleted file mode 100644 index db7d9f3f0b..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.client.destinationurl; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import junit.framework.JUnit4TestAdapter; - -@RunWith(Suite.class) -@Suite.SuiteClasses({DestinationURLTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java index be2f85e878..9218424a5e 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java @@ -20,43 +20,31 @@ */ package org.apache.qpid.test.unit.client.forwardall; -import junit.framework.JUnit4TestAdapter; -import org.junit.Test; -import org.junit.Before; -import org.junit.Assert; -import org.junit.After; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; +import org.apache.qpid.test.VMBrokerSetup; + +import junit.framework.TestCase; /** * Runs the Service's and Client parts of the test in the same process * as the broker */ -public class CombinedTest +public class CombinedTest extends TestCase { - @Before - public void createVMBroker() + protected void setUp() throws Exception { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } + super.setUp(); } - @After - public void stopVmBroker() + protected void tearDown() throws Exception { ServiceCreator.closeAll(); - TransportConnection.killVMBroker(1); + super.tearDown(); } - @Test - public void forwardAll() throws Exception + public void testForwardAll() throws Exception { int services = 2; ServiceCreator.start("vm://:1", services); @@ -70,6 +58,6 @@ public class CombinedTest public static junit.framework.Test suite() { - return new JUnit4TestAdapter(CombinedTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(CombinedTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/UnitTests.java deleted file mode 100644 index 6be99bcda9..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/UnitTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.client.forwardall; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - CombinedTest.class -}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/BytesMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/BytesMessageTest.java index fbd32d0783..2a76c920b1 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/BytesMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/BytesMessageTest.java @@ -20,9 +20,6 @@ */ package org.apache.qpid.test.unit.client.message; -import junit.framework.JUnit4TestAdapter; -import org.junit.Test; -import org.junit.Assert; import org.apache.qpid.client.message.JMSBytesMessage; import org.apache.qpid.client.message.TestMessageHelper; @@ -30,29 +27,52 @@ import javax.jms.MessageNotReadableException; import javax.jms.MessageNotWriteableException; import javax.jms.MessageEOFException; -public class BytesMessageTest +import junit.framework.TestCase; + +public class BytesMessageTest extends TestCase { /** * Tests that on creation a call to getBodyLength() throws an exception * if null was passed in during creation */ - @Test(expected=MessageNotReadableException.class) public void testNotReadableOnCreationWithNull() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.getBodyLength(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.getBodyLength(); + fail("expected exception did not occur"); + } + catch (MessageNotReadableException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageNotReadableException, got " + e); + } } - @Test(expected= MessageNotWriteableException.class) public void testResetMakesReadble() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeInt(10); - bm.reset(); - bm.writeInt(12); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeInt(10); + bm.reset(); + bm.writeInt(12); + fail("expected exception did not occur"); + } + catch (MessageNotWriteableException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageNotWriteableException, got " + e); + } } - @Test public void testClearBodyMakesWritable() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); @@ -62,153 +82,271 @@ public class BytesMessageTest bm.writeInt(10); } - @Test public void testWriteInt() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); bm.writeInt(10); bm.reset(); long len = bm.getBodyLength(); - Assert.assertTrue(len == 4); + assertTrue(len == 4); int val = bm.readInt(); - Assert.assertTrue(val == 10); + assertTrue(val == 10); } - @Test public void testWriteString() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); bm.writeUTF("Bananas"); bm.reset(); String res = bm.readUTF(); - Assert.assertEquals("Bananas", res); + assertEquals("Bananas", res); } - @Test(expected=NullPointerException.class) public void testWriteObjectThrowsNPE() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeObject(null); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeObject(null); + fail("expected exception did not occur"); + } + catch (NullPointerException n) + { + // ok + } + catch (Exception e) + { + fail("expected NullPointerException, got " + e); + } } - @Test public void testReadBoolean() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); bm.writeBoolean(true); bm.reset(); boolean result = bm.readBoolean(); - Assert.assertTrue(result); + assertTrue(result); } - @Test(expected=MessageEOFException.class) public void testEOFByte() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)1); - bm.reset(); - bm.readByte(); - // should throw - bm.readByte(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)1); + bm.reset(); + bm.readByte(); + // should throw + bm.readByte(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFUnsignedByte() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)1); - bm.reset(); - bm.readByte(); - // should throw - bm.readUnsignedByte(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)1); + bm.reset(); + bm.readByte(); + // should throw + bm.readUnsignedByte(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFBoolean() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeBoolean(true); - bm.reset(); - bm.readBoolean(); - // should throw - bm.readBoolean(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeBoolean(true); + bm.reset(); + bm.readBoolean(); + // should throw + bm.readBoolean(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFChar() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeChar('A'); - bm.reset(); - bm.readChar(); - // should throw - bm.readChar(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeChar('A'); + bm.reset(); + bm.readChar(); + // should throw + bm.readChar(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFDouble() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeDouble(1.3d); - bm.reset(); - bm.readDouble(); - // should throw - bm.readDouble(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeDouble(1.3d); + bm.reset(); + bm.readDouble(); + // should throw + bm.readDouble(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFFloat() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeFloat(1.3f); - bm.reset(); - bm.readFloat(); - // should throw - bm.readFloat(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeFloat(1.3f); + bm.reset(); + bm.readFloat(); + // should throw + bm.readFloat(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFInt() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeInt(99); - bm.reset(); - bm.readInt(); - // should throw - bm.readInt(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeInt(99); + bm.reset(); + bm.readInt(); + // should throw + bm.readInt(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFLong() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeLong(4L); - bm.reset(); - bm.readLong(); - // should throw - bm.readLong(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeLong(4L); + bm.reset(); + bm.readLong(); + // should throw + bm.readLong(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFShort() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeShort((short)4); - bm.reset(); - bm.readShort(); - // should throw - bm.readShort(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeShort((short)4); + bm.reset(); + bm.readShort(); + // should throw + bm.readShort(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } - @Test(expected=MessageEOFException.class) public void testEOFUnsignedShort() throws Exception { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeShort((short)4); - bm.reset(); - bm.readUnsignedShort(); - // should throw - bm.readUnsignedShort(); + try + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeShort((short)4); + bm.reset(); + bm.readUnsignedShort(); + // should throw + bm.readUnsignedShort(); + fail("expected exception did not occur"); + } + catch (MessageEOFException m) + { + // ok + } + catch (Exception e) + { + fail("expected MessageEOFException, got " + e); + } } /** @@ -216,7 +354,6 @@ public class BytesMessageTest * correctly * @throws Exception */ - @Test public void testReadBytes() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); @@ -225,12 +362,11 @@ public class BytesMessageTest bm.reset(); byte[] result = new byte[2]; int count = bm.readBytes(result); - Assert.assertEquals((byte)3, result[0]); - Assert.assertEquals((byte)4, result[1]); - Assert.assertEquals(2, count); + assertEquals((byte)3, result[0]); + assertEquals((byte)4, result[1]); + assertEquals(2, count); } - @Test public void testReadBytesEOF() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); @@ -240,10 +376,9 @@ public class BytesMessageTest byte[] result = new byte[2]; bm.readBytes(result); int count = bm.readBytes(result); - Assert.assertEquals(-1, count); + assertEquals(-1, count); } - @Test public void testReadBytesWithLargerArray() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); @@ -252,13 +387,12 @@ public class BytesMessageTest bm.reset(); byte[] result = new byte[3]; int count = bm.readBytes(result); - Assert.assertEquals(2, count); - Assert.assertEquals((byte)3, result[0]); - Assert.assertEquals((byte)4, result[1]); - Assert.assertEquals((byte)0, result[2]); + assertEquals(2, count); + assertEquals((byte)3, result[0]); + assertEquals((byte)4, result[1]); + assertEquals((byte)0, result[2]); } - @Test public void testReadBytesWithCount() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); @@ -268,13 +402,12 @@ public class BytesMessageTest bm.reset(); byte[] result = new byte[3]; int count = bm.readBytes(result, 2); - Assert.assertEquals(2, count); - Assert.assertEquals((byte)3, result[0]); - Assert.assertEquals((byte)4, result[1]); - Assert.assertEquals((byte)0, result[2]); + assertEquals(2, count); + assertEquals((byte)3, result[0]); + assertEquals((byte)4, result[1]); + assertEquals((byte)0, result[2]); } - @Test public void testToBodyString() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); @@ -282,20 +415,19 @@ public class BytesMessageTest bm.writeUTF(testText); bm.reset(); String result = bm.toBodyString(); - Assert.assertEquals(testText, result); + assertEquals(testText, result); } - @Test public void testToBodyStringWithNull() throws Exception { JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); bm.reset(); String result = bm.toBodyString(); - Assert.assertNull(result); + assertNull(result); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(BytesMessageTest.class); + return new junit.framework.TestSuite(BytesMessageTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java index 13deeed1fa..9425b7c304 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java @@ -26,11 +26,7 @@ import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.client.transport.TransportConnection; - -import org.junit.Test; -import org.junit.Assert; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.MessageListener; import javax.jms.MessageProducer; @@ -41,58 +37,25 @@ import java.io.Serializable; import java.util.HashMap; import java.util.ArrayList; -import junit.framework.JUnit4TestAdapter; +import junit.framework.TestCase; -public class ObjectMessageTest implements MessageListener +public class ObjectMessageTest extends TestCase implements MessageListener { - private final AMQConnection connection; - private final AMQDestination destination; - private final AMQSession session; - private final Serializable[] data; + private AMQConnection connection; + private AMQDestination destination; + private AMQSession session; + private Serializable[] data; private volatile boolean waiting; private int received; private final ArrayList items = new ArrayList(); + private String _broker = "vm://:1"; - @BeforeClass - public static void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @AfterClass - public static void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - - public ObjectMessageTest() throws Exception - { - this(new AMQConnection("vm://:1", "guest", "guest", randomize("Client"), "/test_path")); - } - - ObjectMessageTest(String broker) throws Exception - { - this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path")); - } - - ObjectMessageTest(AMQConnection connection) throws Exception - { - this(connection, new AMQQueue(randomize("LatencyTest"), true)); - } - - ObjectMessageTest(AMQConnection connection, AMQDestination destination) throws Exception + protected void setUp() throws Exception { - this.connection = connection; - this.destination = destination; + super.setUp(); + connection = new AMQConnection(_broker, "guest", "guest", randomize("Client"), "/test_path"); + destination = new AMQQueue(randomize("LatencyTest"), true); session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); A a1 = new A(1, "A"); A a2 = new A(2, "a"); @@ -106,6 +69,19 @@ public class ObjectMessageTest implements MessageListener data = new Serializable[]{a1, a2, b, c, "Hello World!", new Integer(1001)}; } + protected void tearDown() throws Exception + { + super.tearDown(); + } + + public ObjectMessageTest() + { + } + + ObjectMessageTest(String broker) throws Exception + { + _broker = broker; + } public void test() throws Exception { @@ -116,6 +92,10 @@ public class ObjectMessageTest implements MessageListener check(); System.out.println("All " + data.length + " items matched."); } + catch (Exception e) + { + fail("This Test should succeed but failed due to: " + e); + } finally { close(); @@ -220,19 +200,6 @@ public class ObjectMessageTest implements MessageListener } - @Test - public void doJUnitTest() - { - try - { - new ObjectMessageTest("vm://:1").test(); - } - catch (Exception e) - { - Assert.fail("This Test should succeed but failed due to: " + e); - } - } - public static void main(String[] argv) throws Exception { String broker = argv.length > 0 ? argv[0] : "vm://:1"; @@ -302,6 +269,6 @@ public class ObjectMessageTest implements MessageListener public static junit.framework.Test suite() { - return new JUnit4TestAdapter(ObjectMessageTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(ObjectMessageTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java index a73e0cb6be..337b0f3bbc 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java @@ -20,37 +20,35 @@ */ package org.apache.qpid.test.unit.client.message; -import junit.framework.JUnit4TestAdapter; -import org.junit.Test; -import org.junit.Assert; import org.apache.qpid.client.message.TestMessageHelper; import org.apache.qpid.client.message.JMSTextMessage; -public class TextMessageTest +import junit.framework.TestCase; + +public class TextMessageTest extends TestCase { - @Test public void testTextOnConstruction() throws Exception { JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); tm.setText("pies"); String val = tm.getText(); - Assert.assertEquals(val, "pies"); + assertEquals(val, "pies"); } - @Test public void testClearBody() throws Exception { JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); tm.setText("pies"); tm.clearBody(); String val = tm.getText(); - Assert.assertNull(val); + assertNull(val); tm.setText("Banana"); val = tm.getText(); - Assert.assertEquals(val, "Banana"); + assertEquals(val, "Banana"); } + public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TextMessageTest.class); + return new junit.framework.TestSuite(TextMessageTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java index 417d1baced..98e355b0da 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java @@ -24,14 +24,33 @@ import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.protocol.AMQProtocolHandler; import org.apache.qpid.client.protocol.AMQProtocolSession; import org.apache.mina.common.IoSession; -import org.junit.Before; -import org.junit.Test; -import org.junit.After; -import junit.framework.JUnit4TestAdapter; -import junit.framework.Assert; -public class AMQProtocolSessionTest extends AMQProtocolSession +import junit.framework.TestCase; + +public class AMQProtocolSessionTest extends TestCase { + private static class AMQProtSession extends AMQProtocolSession + { + public AMQProtSession() + { + } + + public AMQProtSession(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection) + { + super(protocolHandler,protocolSession,connection); + } + + public TestIoSession getMinaProtocolSession() + { + return (TestIoSession) _minaProtocolSession; + } + + public String genQueueName() + { + return generateQueueName(); + } + } + //private Strings for test values and expected results private String _brokenAddress; private String _generatedAddress; @@ -40,28 +59,14 @@ public class AMQProtocolSessionTest extends AMQProtocolSession private String _validAddress; private String _generatedAddress_3; private int _port; - private AMQProtocolSessionTest _testSession; - - public AMQProtocolSessionTest() - { - - } - - public AMQProtocolSessionTest(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection) - { - super(protocolHandler,protocolSession,connection); - } + private AMQProtSession _testSession; - public TestIoSession getMinaProtocolSession() + protected void setUp() throws Exception { - return (TestIoSession) _minaProtocolSession; - } + super.setUp(); - @Before - public void setUp() - { //don't care about the values set here apart from the dummy IoSession - _testSession = new AMQProtocolSessionTest(null,new TestIoSession(),null); + _testSession = new AMQProtSession(null,new TestIoSession(),null); //initialise addresses for test and expected results _port = 123; @@ -71,11 +76,9 @@ public class AMQProtocolSessionTest extends AMQProtocolSession _generatedAddress_2 = "tmp_localhost127.0.0.1123_2"; _validAddress = "abc"; _generatedAddress_3 = "tmp_abc123_3"; - } - @Test - public void TestGenerateQueueName() + public void testGenerateQueueName() { String testAddress; @@ -83,30 +86,24 @@ public class AMQProtocolSessionTest extends AMQProtocolSession _testSession.getMinaProtocolSession().setStringLocalAddress(_brokenAddress); _testSession.getMinaProtocolSession().setLocalPort(_port); - testAddress = _testSession.generateQueueName(); - Assert.assertEquals("Failure when generating a queue name from an address with special chars",_generatedAddress,testAddress); + testAddress = _testSession.genQueueName(); + assertEquals("Failure when generating a queue name from an address with special chars",_generatedAddress,testAddress); //test empty address _testSession.getMinaProtocolSession().setStringLocalAddress(_emptyAddress); - testAddress = _testSession.generateQueueName(); - Assert.assertEquals("Failure when generating a queue name from an empty address",_generatedAddress_2,testAddress); + testAddress = _testSession.genQueueName(); + assertEquals("Failure when generating a queue name from an empty address",_generatedAddress_2,testAddress); //test address with no special chars _testSession.getMinaProtocolSession().setStringLocalAddress(_validAddress); - testAddress = _testSession.generateQueueName(); - Assert.assertEquals("Failure when generating a queue name from an address with no special chars",_generatedAddress_3,testAddress); + testAddress = _testSession.genQueueName(); + assertEquals("Failure when generating a queue name from an address with no special chars",_generatedAddress_3,testAddress); } - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(AMQProtocolSessionTest.class); - } - - @After - public void tearDown() + protected void tearDown() throws Exception { _testSession = null; _brokenAddress = null; @@ -115,5 +112,11 @@ public class AMQProtocolSessionTest extends AMQProtocolSession _generatedAddress_2 = null; _validAddress = null; _generatedAddress_3 = null; + super.tearDown(); + } + + public static junit.framework.Test suite() + { + return new junit.framework.TestSuite(AMQProtocolSessionTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java index 6a03035f1e..c8d54cdcc5 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java @@ -20,13 +20,9 @@ */ package org.apache.qpid.test.unit.jndi; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnectionFactory; import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.AMQTopic; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; import javax.naming.Context; import javax.naming.InitialContext; @@ -34,14 +30,16 @@ import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; import java.util.Properties; -public class PropertiesFileInitialContextFactoryTest +import junit.framework.TestCase; + +public class PropertiesFileInitialContextFactoryTest extends TestCase { InitialContextFactory contextFactory; Properties _properties; - @Before - public void setupProperties() + protected void setUp() throws Exception { + super.setUp(); _properties = new Properties(); _properties.put("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"); _properties.put("connectionfactory.local", "amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'"); @@ -50,7 +48,6 @@ public class PropertiesFileInitialContextFactoryTest _properties.put("destination.direct", "direct://amq.direct//directQueue"); } - @Test public void test() { Context ctx = null; @@ -60,54 +57,52 @@ public class PropertiesFileInitialContextFactoryTest } catch (NamingException ne) { - Assert.fail("Error loading context:" + ne); + fail("Error loading context:" + ne); } try { AMQConnectionFactory cf = (AMQConnectionFactory) ctx.lookup("local"); - Assert.assertEquals("amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'", cf.getConnectionURL().toString()); + assertEquals("amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'", cf.getConnectionURL().toString()); } catch (NamingException ne) { - Assert.fail("Unable to create Connection Factory:" + ne); + fail("Unable to create Connection Factory:" + ne); } try { AMQQueue queue = (AMQQueue) ctx.lookup("MyQueue"); - Assert.assertEquals("example.MyQueue", queue.getRoutingKey()); + assertEquals("example.MyQueue", queue.getRoutingKey()); } catch (NamingException ne) { - Assert.fail("Unable to create queue:" + ne); + fail("Unable to create queue:" + ne); } try { AMQTopic topic = (AMQTopic) ctx.lookup("ibmStocks"); - Assert.assertEquals("stocks.nyse.ibm", topic.getTopicName()); + assertEquals("stocks.nyse.ibm", topic.getTopicName()); } catch (Exception ne) { - Assert.fail("Unable to create topic:" + ne); + fail("Unable to create topic:" + ne); } try { AMQQueue direct = (AMQQueue) ctx.lookup("direct"); - Assert.assertEquals("directQueue", direct.getRoutingKey()); + assertEquals("directQueue", direct.getRoutingKey()); } catch (NamingException ne) { - Assert.fail("Unable to create direct destination:" + ne); + fail("Unable to create direct destination:" + ne); } - - } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PropertiesFileInitialContextFactoryTest.class); + return new junit.framework.TestSuite(PropertiesFileInitialContextFactoryTest.class); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java index 083d90d79d..db871281bf 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java @@ -24,7 +24,6 @@ import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionFactory; import org.apache.qpid.client.AMQTopic; import org.apache.qpid.url.URLSyntaxException; -import org.junit.Assert; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -39,6 +38,8 @@ import javax.naming.NoInitialContextException; import java.io.File; import java.util.Hashtable; +import junit.framework.TestCase; + /** * Usage: To run these you need to have the sun JNDI SPI for the FileSystem. * This can be downloaded from sun here: @@ -49,7 +50,7 @@ import java.util.Hashtable; * <p/> * Also you need to create the directory /temp/qpid-jndi-test */ -class Bind +class Bind extends TestCase { public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + "/JNDITest" + System.currentTimeMillis(); public static final String DEFAULT_PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH; @@ -124,11 +125,11 @@ class Bind } catch (JMSException jmsqe) { - Assert.fail("Unable to create Connection:" + jmsqe); + fail("Unable to create Connection:" + jmsqe); } catch (URLSyntaxException urlse) { - Assert.fail("Unable to create Connection:" + urlse); + fail("Unable to create Connection:" + urlse); } try @@ -247,4 +248,3 @@ class Bind new Bind(true); } } - diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java index c8374dead0..4731caca98 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java @@ -20,18 +20,14 @@ */ package org.apache.qpid.test.unit.jndi.referenceabletest; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; -import junit.framework.JUnit4TestAdapter; +import org.apache.qpid.test.VMBrokerSetup; import javax.naming.NameAlreadyBoundException; import javax.naming.NoInitialContextException; +import junit.framework.TestCase; /** * Usage: To run these you need to have the sun JNDI SPI for the FileSystem. @@ -43,31 +39,10 @@ import javax.naming.NoInitialContextException; * <p/> * Also you need to create the directory /temp/qpid-jndi-test */ -public class JNDIReferenceableTest +public class JNDIReferenceableTest extends TestCase { - @Before - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - - @Ignore("FSContext has been removed from repository. This needs redone with the PropertiesFileInitialContextFactory. QPID-84") - @Test - public void referenceable() + // FIXME FSContext has been removed from repository. This needs redone with the PropertiesFileInitialContextFactory. QPID-84 + public void testReferenceable() { Bind b = null; try @@ -86,18 +61,18 @@ public class JNDIReferenceableTest } catch (NameAlreadyBoundException ee) { - Assert.fail("Unable to clear bound objects for test."); + fail("Unable to clear bound objects for test."); } } else { - Assert.fail("Unable to clear bound objects for test."); + fail("Unable to clear bound objects for test."); } } } catch (NoInitialContextException e) { - Assert.fail("You don't have the File System SPI on you class path.\n" + + fail("You don't have the File System SPI on you class path.\n" + "This can be downloaded from sun here:\n" + "http://java.sun.com/products/jndi/downloads/index.html\n" + "Click : Download JNDI 1.2.1 & More button\n" + @@ -105,25 +80,25 @@ public class JNDIReferenceableTest "and add the two jars in the lib dir to your class path."); } - Assert.assertTrue(b.bound()); + assertTrue(b.bound()); Lookup l = new Lookup(b.getProviderURL()); - Assert.assertTrue(l.connectionFactoryValue().equals(b.connectionFactoryValue())); + assertTrue(l.connectionFactoryValue().equals(b.connectionFactoryValue())); - Assert.assertTrue(l.connectionValue().equals(b.connectionValue())); + assertTrue(l.connectionValue().equals(b.connectionValue())); - Assert.assertTrue(l.topicValue().equals(b.topicValue())); + assertTrue(l.topicValue().equals(b.topicValue())); Unbind u = new Unbind(); - Assert.assertTrue(u.unbound()); + assertTrue(u.unbound()); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(JNDIReferenceableTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(JNDIReferenceableTest.class)); } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java deleted file mode 100644 index ff7f04779c..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.jndi.referenceabletest; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import junit.framework.JUnit4TestAdapter; - -@RunWith(Suite.class) -@Suite.SuiteClasses({JNDIReferenceableTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java index 57aafd7719..b20cfa046a 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java @@ -20,11 +20,6 @@ */ package org.apache.qpid.test.unit.topic; -import junit.framework.JUnit4TestAdapter; -import org.junit.Assert; -import org.junit.Test; -import org.junit.Before; -import org.junit.After; import org.apache.qpid.AMQException; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.url.URLSyntaxException; @@ -32,6 +27,7 @@ import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.AMQTopic; import org.apache.qpid.client.transport.TransportConnection; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.JMSException; import javax.jms.Message; @@ -41,30 +37,11 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.TopicSubscriber; -public class DurableSubscriptionTest -{ +import junit.framework.TestCase; - @Before - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - @Test - public void unsubscribe() throws AMQException, JMSException, URLSyntaxException +public class DurableSubscriptionTest extends TestCase +{ + public void testUnsubscribe() throws AMQException, JMSException, URLSyntaxException { AMQTopic topic = new AMQTopic("MyTopic"); AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "test", "/test"); @@ -81,32 +58,31 @@ public class DurableSubscriptionTest Message msg; msg = consumer1.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); + assertEquals("A", ((TextMessage) msg).getText()); msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); msg = consumer2.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); + assertEquals("A", ((TextMessage) msg).getText()); msg = consumer2.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); session2.unsubscribe("MySubscription"); producer.send(session1.createTextMessage("B")); msg = consumer1.receive(); - Assert.assertEquals("B", ((TextMessage) msg).getText()); + assertEquals("B", ((TextMessage) msg).getText()); msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); msg = consumer2.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); con.close(); } - @Test - public void durability() throws AMQException, JMSException, URLSyntaxException + public void testDurability() throws AMQException, JMSException, URLSyntaxException { AMQTopic topic = new AMQTopic("MyTopic"); AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "test", "/test"); @@ -123,14 +99,14 @@ public class DurableSubscriptionTest Message msg; msg = consumer1.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); + assertEquals("A", ((TextMessage) msg).getText()); msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); msg = consumer2.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); + assertEquals("A", ((TextMessage) msg).getText()); msg = consumer2.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); consumer2.close(); @@ -140,21 +116,20 @@ public class DurableSubscriptionTest producer.send(session1.createTextMessage("B")); msg = consumer1.receive(); - Assert.assertEquals("B", ((TextMessage) msg).getText()); + assertEquals("B", ((TextMessage) msg).getText()); msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); msg = consumer3.receive(); - Assert.assertEquals("B", ((TextMessage) msg).getText()); + assertEquals("B", ((TextMessage) msg).getText()); msg = consumer3.receive(1000); - Assert.assertEquals(null, msg); + assertEquals(null, msg); con.close(); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(DurableSubscriptionTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(DurableSubscriptionTest.class)); } - } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java index ecd66d99ce..8918259be3 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/transacted/TransactedTest.java @@ -20,24 +20,18 @@ */ package org.apache.qpid.test.unit.transacted; -import junit.framework.JUnit4TestAdapter; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.AMQSession; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; -import org.junit.After; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.AfterClass; +import org.apache.qpid.test.VMBrokerSetup; import javax.jms.*; -public class TransactedTest +import junit.framework.TestCase; + +public class TransactedTest extends TestCase { private AMQQueue queue1; private AMQQueue queue2; @@ -56,28 +50,9 @@ public class TransactedTest private MessageConsumer testConsumer1; private MessageConsumer testConsumer2; - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - public void stopVmBroker() + protected void setup() throws Exception { - TransportConnection.killVMBroker(1); - } - - @Before - public void setup() throws Exception - { - createVMBroker(); + super.setUp(); queue1 = new AMQQueue("Q1", false); queue2 = new AMQQueue("Q2", false); @@ -108,17 +83,15 @@ public class TransactedTest testCon.start(); } - @After - public void shutdown() throws Exception + protected void tearDown() throws Exception { con.close(); testCon.close(); prepCon.close(); - stopVmBroker(); + super.tearDown(); } - @Test - public void commit() throws Exception + public void testCommit() throws Exception { //send and receive some messages producer2.send(session.createTextMessage("X")); @@ -140,8 +113,7 @@ public class TransactedTest assertTrue(null == testConsumer2.receive(1000)); } - @Test - public void rollback() throws Exception + public void testRollback() throws Exception { producer2.send(session.createTextMessage("X")); producer2.send(session.createTextMessage("Y")); @@ -170,7 +142,6 @@ public class TransactedTest public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TransactedTest.class); + return new VMBrokerSetup(new junit.framework.TestSuite(TransactedTest.class)); } - } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/UnitTests.java b/java/client/src/test/java/org/apache/qpid/test/unit/transacted/UnitTests.java deleted file mode 100644 index 24e6ace366..0000000000 --- a/java/client/src/test/java/org/apache/qpid/test/unit/transacted/UnitTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.test.unit.transacted; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({TransactedTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} |
