From 6875b2d21d89bbc91b8c1afe7668b08416c788a3 Mon Sep 17 00:00:00 2001 From: Matt Pavlovich Date: Thu, 7 Dec 2023 14:22:33 -0600 Subject: [PATCH] [#70] Convert to junit5 --- openwire-core/pom.xml | 13 ++- .../openwire/codec/BooleanStreamTest.java | 25 ++--- .../NumberRangesWhileMarshallingTest.java | 17 ++-- .../commands/DataStructureTestSupport.java | 31 +++---- .../openwire/commands/MessageTest.java | 63 ++++++------- .../commands/OpenWireBytesMessageTest.java | 8 +- .../commands/OpenWireDestinationTest.java | 11 ++- .../commands/OpenWireMapMessageTest.java | 17 ++-- .../commands/OpenWireMessageTest.java | 20 ++-- .../commands/OpenWireObjectMessageTest.java | 8 +- .../commands/OpenWireStreamMessageTest.java | 14 +-- .../commands/OpenWireTextMessageTest.java | 8 +- .../utils/OpenWireMarshallingSupportTest.java | 6 +- openwire-generator/pom.xml | 8 +- .../generator/OpenWireTypeDescriptor.java | 6 -- .../generator/OpenWireTypeDescriptorTest.java | 6 +- openwire-interop-tests/pom.xml | 14 ++- .../codec/MessageCompressionTest.java | 58 ++++++------ .../codec/OpenWireInteropTestSupport.java | 21 ++--- .../openwire/codec/OpenWireInteropTests.java | 92 ++++++++++--------- .../codec/OpenWireLegacyValidationTest.java | 35 +++---- .../OpenWireUniversalValidationTest.java | 13 ++- .../WireFormatInfoMarshaledSizeTest.java | 12 +-- .../openwire/codec/v1/OpenWireV1Test.java | 7 -- .../openwire/codec/v10/OpenWireV10Test.java | 7 -- .../openwire/codec/v11/OpenWireV11Test.java | 7 -- .../openwire/codec/v2/OpenWireV2Test.java | 7 -- .../openwire/codec/v3/OpenWireV3Test.java | 7 -- .../openwire/codec/v4/OpenWireV4Test.java | 7 -- .../openwire/codec/v5/OpenWireV5Test.java | 7 -- .../openwire/codec/v6/OpenWireV6Test.java | 7 -- .../openwire/codec/v7/OpenWireV7Test.java | 7 -- .../openwire/codec/v8/OpenWireV8Test.java | 7 -- .../openwire/codec/v9/OpenWireV9Test.java | 7 -- pom.xml | 11 ++- 35 files changed, 264 insertions(+), 330 deletions(-) diff --git a/openwire-core/pom.xml b/openwire-core/pom.xml index f6406a9..8292d80 100644 --- a/openwire-core/pom.xml +++ b/openwire-core/pom.xml @@ -50,8 +50,17 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params test diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/codec/BooleanStreamTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/codec/BooleanStreamTest.java index 0bfb4c3..17a6534 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/codec/BooleanStreamTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/codec/BooleanStreamTest.java @@ -16,8 +16,10 @@ */ package org.apache.activemq.openwire.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -25,13 +27,10 @@ import java.io.DataOutputStream; import java.io.IOException; -import junit.framework.AssertionFailedError; - -import org.apache.activemq.openwire.codec.BooleanStream; -import org.apache.activemq.openwire.codec.OpenWireFormat; import org.apache.activemq.openwire.commands.CommandTypes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; /** * Test for the OpenWire BooleanStream class. @@ -123,14 +122,18 @@ protected void assertMarshalBooleans(int count, BooleanValueSet valueSet) throws boolean expected = valueSet.getBooleanValueFor(i, count); try { boolean actual = bs.readBoolean(); - assertEquals("value of object: " + i + " was: " + actual, expected, actual); + if(expected) { + assertTrue(actual, "value of object: " + i + " was: " + actual); + } else { + assertFalse(actual, "value of object: " + i + " was: " + actual); + } } catch (IOException e) { e.printStackTrace(); fail("Failed to parse boolean: " + i + " out of: " + count + " due to: " + e); } } int marker = dis.readInt(); - assertEquals("Marker int when unmarshalling: " + count + " booleans", Integer.toHexString(endOfStreamMarker), Integer.toHexString(marker)); + assertEquals(Integer.toHexString(endOfStreamMarker), Integer.toHexString(marker), "Marker int when unmarshalling: " + count + " booleans"); // lets try read and we should get an exception try { @@ -141,7 +144,7 @@ protected void assertMarshalBooleans(int count, BooleanValueSet valueSet) throws } } - @Before + @BeforeEach public void setUp() throws Exception { openWireformat = createOpenWireFormat(); } diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/codec/NumberRangesWhileMarshallingTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/codec/NumberRangesWhileMarshallingTest.java index 8ce0303..8700a0b 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/codec/NumberRangesWhileMarshallingTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/codec/NumberRangesWhileMarshallingTest.java @@ -16,8 +16,8 @@ */ package org.apache.activemq.openwire.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -25,12 +25,11 @@ import java.io.DataOutputStream; import java.io.IOException; -import org.apache.activemq.openwire.codec.OpenWireFormat; import org.apache.activemq.openwire.commands.CommandTypes; import org.apache.activemq.openwire.commands.OpenWireTextMessage; import org.apache.activemq.openwire.commands.SessionId; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,12 +79,12 @@ public void testLongNumberRanges() throws Exception { LOG.info("Unmarshaling value: " + i + " = " + expected); SessionId command = (SessionId) openWireformat.unmarshal(dis); - assertEquals("connection ID in object: " + i, connectionId, command.getConnectionId()); + assertEquals(connectionId, command.getConnectionId(), "connection ID in object: " + i); String actual = Long.toHexString(command.getValue()); - assertEquals("value of object: " + i + " was: " + actual, expected, actual); + assertEquals(expected, actual, "value of object: " + i + " was: " + actual); } int marker = dis.readInt(); - assertEquals("Marker int", Integer.toHexString(endOfStreamMarker), Integer.toHexString(marker)); + assertEquals(Integer.toHexString(endOfStreamMarker), Integer.toHexString(marker), "Marker int"); // lets try read and we should get an exception try { @@ -127,7 +126,7 @@ public void testDefaultMaxFrameSizeUnlimited() { assertEquals(Long.MAX_VALUE, wf.getMaxFrameSize()); } - @Before + @BeforeEach public void setUp() throws Exception { openWireformat = createOpenWireFormat(); } diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/DataStructureTestSupport.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/DataStructureTestSupport.java index d877415..4f51b51 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/DataStructureTestSupport.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/DataStructureTestSupport.java @@ -16,31 +16,30 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; -import junit.framework.AssertionFailedError; - import org.apache.activemq.openwire.buffer.Buffer; import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.opentest4j.AssertionFailedError; public abstract class DataStructureTestSupport { - protected boolean cacheEnabled; protected OpenWireFormat wireFormat; public void assertBeanMarshalls(Object original) throws IOException { Object o = marshalAndUnmarshall(original, wireFormat); assertNotNull(o); - assertEquals(original, o); + assertEqualsOpenWire(original, o); } - public static void assertEquals(Object expect, Object was) { + public static void assertEqualsOpenWire(Object expect, Object was) { if (expect == null ^ was == null) { throw new AssertionFailedError("Not equals, expected: " + expect + ", was: " + was); } @@ -88,12 +87,12 @@ public static void assertEquals(Object expect, Object was) { throw new AssertionFailedError("Not equals, array lengths don't match. expected: " + expectArray.length + ", was: " + wasArray.length); } for (int i = 0; i < wasArray.length; i++) { - assertEquals(expectArray[i], wasArray[i]); + assertEqualsOpenWire(expectArray[i], wasArray[i]); } } } else if (expect instanceof Command) { - assertEquals(expect.getClass(), was.getClass()); + assertEqualsOpenWire(expect.getClass(), was.getClass()); Method[] methods = expect.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; @@ -112,7 +111,7 @@ public static void assertEquals(Object expect, Object was) { } try { - assertEquals(method.invoke(expect, (Object) null), method.invoke(was, (Object) null)); + assertEqualsOpenWire(method.invoke(expect, (Object) null), method.invoke(was, (Object) null)); } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { @@ -120,19 +119,19 @@ public static void assertEquals(Object expect, Object was) { } } } else { - org.junit.Assert.assertEquals(expect, was); + assertEquals(expect, was); } } - @Before - public void setUp() throws Exception { - wireFormat = createWireFormat(); + @AfterEach + public void afterEach() { + wireFormat = null; } - protected OpenWireFormat createWireFormat() { + protected void createWireFormat(boolean cacheEnabled) { OpenWireFormat answer = new OpenWireFormat(10); answer.setCacheEnabled(cacheEnabled); - return answer; + wireFormat = answer; } protected Object marshalAndUnmarshall(Object original, OpenWireFormat wireFormat) throws IOException { diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/MessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/MessageTest.java index 8e3494a..ba81d3a 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/MessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/MessageTest.java @@ -16,35 +16,20 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import org.apache.activemq.openwire.commands.MessageId; -import org.apache.activemq.openwire.commands.OpenWireMessage; -import org.apache.activemq.openwire.commands.OpenWireQueue; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -@RunWith(value = Parameterized.class) -public class MessageTest extends DataStructureTestSupport { - - public MessageTest(Boolean cacheEnabled) { - this.cacheEnabled = cacheEnabled; - } - @Parameters - public static Collection data() { - Object[][] data = new Object[][] { { Boolean.TRUE }, { Boolean.FALSE } }; - return Arrays.asList(data); - } +public class MessageTest extends DataStructureTestSupport { - @Test - public void testOpenWireMessageMarshaling() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void testOpenWireMessageMarshaling(boolean cacheEnabled) throws IOException { + createWireFormat(cacheEnabled); OpenWireMessage message = new OpenWireMessage(); message.setCommandId((short)1); message.setOriginalDestination(new OpenWireQueue("queue")); @@ -55,8 +40,10 @@ public void testOpenWireMessageMarshaling() throws IOException { assertBeanMarshalls(message); } - @Test - public void testOpenWireMessageMarshalingBigMessageId() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void testOpenWireMessageMarshalingBigMessageId(boolean cacheEnabled) throws IOException { + createWireFormat(cacheEnabled); OpenWireMessage message = new OpenWireMessage(); message.setCommandId((short)1); message.setOriginalDestination(new OpenWireQueue("queue")); @@ -67,8 +54,10 @@ public void testOpenWireMessageMarshalingBigMessageId() throws IOException { assertBeanMarshalls(message); } - @Test - public void testOpenWireMessageMarshalingBiggerMessageId() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void testOpenWireMessageMarshalingBiggerMessageId(boolean cacheEnabled) throws IOException { + createWireFormat(cacheEnabled); OpenWireMessage message = new OpenWireMessage(); message.setCommandId((short)1); message.setOriginalDestination(new OpenWireQueue("queue")); @@ -79,8 +68,10 @@ public void testOpenWireMessageMarshalingBiggerMessageId() throws IOException { assertBeanMarshalls(message); } - @Test - public void testOpenWireMessageMarshalingBiggestMessageId() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void testOpenWireMessageMarshalingBiggestMessageId(boolean cacheEnabled) throws IOException { + createWireFormat(cacheEnabled); OpenWireMessage message = new OpenWireMessage(); message.setCommandId((short)1); message.setOriginalDestination(new OpenWireQueue("queue")); @@ -91,13 +82,17 @@ public void testOpenWireMessageMarshalingBiggestMessageId() throws IOException { assertBeanMarshalls(message); } - @Test - public void testMessageIdMarshaling() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void testMessageIdMarshaling(boolean cacheEnabled) throws IOException { + createWireFormat(cacheEnabled); assertBeanMarshalls(new MessageId("c1:1:1", 1)); } - @Test - public void testPropRemove() throws Exception { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void testPropRemove(boolean cacheEnabled) throws Exception { + createWireFormat(cacheEnabled); OpenWireMessage message = new OpenWireMessage(); message.setProperty("RM","RM"); @@ -107,6 +102,6 @@ public void testPropRemove() throws Exception { unMarshalled.removeProperty("RM"); OpenWireMessage unMarshalledAgain = (OpenWireMessage) marshalAndUnmarshall(unMarshalled, wireFormat); - assertNull("Prop is gone", unMarshalledAgain.getProperty("RM")); + assertNull(unMarshalledAgain.getProperty("RM"), "Prop is gone"); } } diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireBytesMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireBytesMessageTest.java index 88af005..6edd34a 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireBytesMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireBytesMessageTest.java @@ -16,12 +16,10 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.apache.activemq.openwire.commands.CommandTypes; -import org.apache.activemq.openwire.commands.OpenWireBytesMessage; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class OpenWireBytesMessageTest { diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java index ed13440..1399a65 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java @@ -16,9 +16,10 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertIterableEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.ArrayList; @@ -28,7 +29,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test various usages of the OpenWireDestination and its subclasses. @@ -43,7 +44,7 @@ public void testSorting() throws Exception { List expected = Arrays.asList(destinations); set.addAll(expected); List actual = new ArrayList(set); - assertEquals("Sorted order", expected, actual); + assertIterableEquals(expected, actual, "Sorted order"); } class CombyDest { diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java index ba4d2c2..cb1aa5b 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java @@ -16,20 +16,18 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.Collections; import java.util.Enumeration; import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,9 +35,6 @@ public class OpenWireMapMessageTest { private static final Logger LOG = LoggerFactory.getLogger(OpenWireMapMessageTest.class); - @Rule - public TestName name = new TestName(); - @Test public void testBytesConversion() throws Exception { OpenWireMapMessage msg = new OpenWireMapMessage(); diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java index 3cd11c3..56271d9 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java @@ -16,20 +16,20 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.Map; import org.apache.activemq.openwire.buffer.Buffer; import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +51,7 @@ public class OpenWireMessageTest { private long jmsTimestamp; private long[] consumerIDs; - @Before + @BeforeEach public void setUp() throws Exception { this.myMessageID = new MessageId("ID:TEST-ID:0:0:0:1"); this.jmsCorrelationID = "testcorrelationid"; @@ -428,7 +428,7 @@ public void testGetAndSetDeliveryCount() throws Exception { OpenWireMessage msg = new OpenWireMessage(); msg.setRedeliveryCounter(1); int count = msg.getRedeliveryCounter(); - assertTrue("expected delivery count = 1 - got: " + count, count == 1); + assertTrue(count == 1, "expected delivery count = 1 - got: " + count); } @Test diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java index 895aeec..02d2ada 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java @@ -16,13 +16,13 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class OpenWireObjectMessageTest { diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java index a357045..16790ee 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireStreamMessageTest.java @@ -16,10 +16,10 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.Arrays; @@ -27,14 +27,14 @@ import java.util.List; import org.apache.activemq.openwire.buffer.Buffer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class OpenWireStreamMessageTest { private final List elements = new ArrayList(); - @Before + @BeforeEach public void setUp() throws Exception { elements.add(Boolean.TRUE); diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java index 18b7ca2..a722273 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java @@ -16,16 +16,16 @@ */ package org.apache.activemq.openwire.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.activemq.openwire.buffer.Buffer; import org.apache.activemq.openwire.buffer.DataByteArrayOutputStream; import org.apache.activemq.openwire.utils.MarshallingSupport; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class OpenWireTextMessageTest { diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java index 886c7ae..1e24f46 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/utils/OpenWireMarshallingSupportTest.java @@ -16,14 +16,14 @@ */ package org.apache.activemq.openwire.utils; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.DataInputStream; import org.apache.activemq.openwire.buffer.DataByteArrayInputStream; import org.apache.activemq.openwire.buffer.DataByteArrayOutputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class OpenWireMarshallingSupportTest { diff --git a/openwire-generator/pom.xml b/openwire-generator/pom.xml index dc0dfba..dba41d6 100644 --- a/openwire-generator/pom.xml +++ b/openwire-generator/pom.xml @@ -53,8 +53,12 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine test diff --git a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireTypeDescriptor.java b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireTypeDescriptor.java index 31f773b..ce7b4a7 100644 --- a/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireTypeDescriptor.java +++ b/openwire-generator/src/main/java/org/apache/activemq/openwire/generator/OpenWireTypeDescriptor.java @@ -16,15 +16,9 @@ */ package org.apache.activemq.openwire.generator; -import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; import org.apache.activemq.openwire.annotations.OpenWireType; /** diff --git a/openwire-generator/src/test/java/org/apache/activenq/openwire/generator/OpenWireTypeDescriptorTest.java b/openwire-generator/src/test/java/org/apache/activenq/openwire/generator/OpenWireTypeDescriptorTest.java index d4037a2..6bd64e0 100644 --- a/openwire-generator/src/test/java/org/apache/activenq/openwire/generator/OpenWireTypeDescriptorTest.java +++ b/openwire-generator/src/test/java/org/apache/activenq/openwire/generator/OpenWireTypeDescriptorTest.java @@ -16,13 +16,13 @@ */ package org.apache.activenq.openwire.generator; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.apache.activemq.openwire.annotations.OpenWireProperty; import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.generator.OpenWireTypeDescriptor; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class OpenWireTypeDescriptorTest { diff --git a/openwire-interop-tests/pom.xml b/openwire-interop-tests/pom.xml index cfd129b..45bdf31 100644 --- a/openwire-interop-tests/pom.xml +++ b/openwire-interop-tests/pom.xml @@ -53,11 +53,19 @@ test - junit - junit + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params test - org.apache.activemq diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java index 2bee6fd..f66d36b 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/MessageCompressionTest.java @@ -16,8 +16,8 @@ */ package org.apache.activemq.openwire.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.concurrent.TimeUnit; @@ -45,7 +45,7 @@ import org.apache.activemq.openwire.utils.OpenWireConsumer; import org.apache.activemq.openwire.utils.OpenWireProducer; import org.apache.activemq.openwire.utils.OpenWireSession; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MessageCompressionTest extends OpenWireInteropTestSupport { @@ -61,11 +61,11 @@ public class MessageCompressionTest extends OpenWireInteropTestSupport { + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "; public OpenWireQueue getOpenWireQueue() { - return new OpenWireQueue(name.getMethodName()); + return new OpenWireQueue(testMethodName); } public Queue getActiveMQQueue() { - return new ActiveMQQueue(name.getMethodName()); + return new ActiveMQQueue(testMethodName); } @Test @@ -78,8 +78,8 @@ public void testTextMessageCompressionActiveMQ() throws Exception { message = receiveAMQTextMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } @Test @@ -92,8 +92,8 @@ public void testOpenWireTextMessageCompression() throws Exception { message = receiveOpenWireTextMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } @Test @@ -106,8 +106,8 @@ public void testTextMessageCompressionActiveMQtoOpenWire() throws Exception { message = receiveOpenWireTextMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } @Test @@ -120,8 +120,8 @@ public void testTextMessageCompressionOpenWireToActiveMQ() throws Exception { message = receiveAMQTextMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } @Test @@ -140,8 +140,8 @@ public void testBytesMessageCompressionActiveMQ() throws Exception { message = receiveAMQBytesMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } @Test @@ -158,8 +158,8 @@ public void testBytesMessageCompressionOpenWire() throws Exception { message = receiveOpenWireBytesMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } @Test @@ -176,8 +176,8 @@ public void testBytesMessageCompressionActiveMQtoOpenWire() throws Exception { message = receiveOpenWireBytesMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } @Test @@ -194,8 +194,8 @@ public void testBytesMessageCompressionOpenWiretoActiveMQ() throws Exception { message = receiveOpenWireBytesMessage(); int unCompressedSize = message.getContent().getLength(); - assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", - compressedSize < unCompressedSize); + assertTrue(compressedSize < unCompressedSize, + "expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'"); } //---------- Sends and Receives Message Via ActiveMQ Objects -------------// @@ -263,7 +263,7 @@ private void sendOpenWireTextMessage(String payload, boolean useCompression) thr assertTrue(awaitConnected(10, TimeUnit.SECONDS)); OpenWireConnection connection = new OpenWireConnection(); ConnectionInfo connectionInfo = connection.createConnectionInfo(); - connectionInfo.setClientId(name.getMethodName()); + connectionInfo.setClientId(testMethodName); assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount()); @@ -302,7 +302,7 @@ private void sendOpenWireBytesMessage(String payload, boolean useCompression) th assertTrue(awaitConnected(10, TimeUnit.SECONDS)); OpenWireConnection connection = new OpenWireConnection(); ConnectionInfo connectionInfo = connection.createConnectionInfo(); - connectionInfo.setClientId(name.getMethodName()); + connectionInfo.setClientId(testMethodName); assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount()); @@ -337,7 +337,7 @@ public OpenWireTextMessage receiveOpenWireTextMessage() throws Exception { assertTrue(awaitConnected(10, TimeUnit.SECONDS)); OpenWireConnection connection = new OpenWireConnection(); ConnectionInfo connectionInfo = connection.createConnectionInfo(); - connectionInfo.setClientId(name.getMethodName()); + connectionInfo.setClientId(testMethodName); assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount()); @@ -352,12 +352,12 @@ public OpenWireTextMessage receiveOpenWireTextMessage() throws Exception { assertTrue(request(consumerInfo, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getQueueSubscribers().length); - assertTrue("Should have received a message", Wait.waitFor(new Wait.Condition() { + assertTrue(Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return messages.size() == 1; } - })); + }), "Should have received a message"); Message incoming = messages.poll(); assertTrue(incoming instanceof OpenWireTextMessage); @@ -384,7 +384,7 @@ public OpenWireBytesMessage receiveOpenWireBytesMessage() throws Exception { assertTrue(awaitConnected(10, TimeUnit.SECONDS)); OpenWireConnection connection = new OpenWireConnection(); ConnectionInfo connectionInfo = connection.createConnectionInfo(); - connectionInfo.setClientId(name.getMethodName()); + connectionInfo.setClientId(testMethodName); assertTrue(request(connectionInfo, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount()); @@ -399,12 +399,12 @@ public OpenWireBytesMessage receiveOpenWireBytesMessage() throws Exception { assertTrue(request(consumerInfo, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getQueueSubscribers().length); - assertTrue("Should have received a message", Wait.waitFor(new Wait.Condition() { + assertTrue(Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return messages.size() == 1; } - })); + }),"Should have received a message"); Message incoming = messages.poll(); assertTrue(incoming instanceof OpenWireBytesMessage); diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTestSupport.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTestSupport.java index cd4a664..97604ad 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTestSupport.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTestSupport.java @@ -33,8 +33,6 @@ import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.jmx.QueueViewMBean; -import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.apache.activemq.openwire.codec.OpenWireFormatFactory; import org.apache.activemq.openwire.commands.BrokerInfo; import org.apache.activemq.openwire.commands.Command; import org.apache.activemq.openwire.commands.KeepAliveInfo; @@ -45,10 +43,9 @@ import org.apache.activemq.openwire.commands.WireFormatInfo; import org.apache.activemq.openwire.util.TcpTransport; import org.apache.activemq.openwire.util.TransportListener; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +57,7 @@ public abstract class OpenWireInteropTestSupport implements TransportListener { private static final Logger LOG = LoggerFactory.getLogger(OpenWireInteropTestSupport.class); - @Rule public TestName name = new TestName(); + protected String testMethodName; protected BrokerService brokerService; @@ -83,8 +80,8 @@ public abstract class OpenWireInteropTestSupport implements TransportListener { protected Command latest; protected final Queue messages = new LinkedList(); - @Before - public void setUp() throws Exception { + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { brokerService = createBroker(); brokerService.start(); brokerService.waitUntilStarted(); @@ -95,9 +92,11 @@ public void setUp() throws Exception { factory.setTightEncodingEnabled(isTightEncodingEnabled()); wireFormat = factory.createWireFormat(); + + testMethodName = testInfo.getTestMethod().get().getName(); } - @After + @AfterEach public void tearDown() throws Exception { disconnect(); @@ -134,7 +133,7 @@ protected boolean request(Command command, long timeout, TimeUnit units) throws command.setCommandId(requestIdGenerator.getAndIncrement()); command.setResponseRequired(true); CountDownLatch complete = new CountDownLatch(1); - requestMap.put(new Integer(command.getCommandId()), complete); + requestMap.put(Integer.valueOf(command.getCommandId()), complete); transport.oneway(command); return complete.await(timeout, units); } diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTests.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTests.java index f4e2951..4c2bfa3 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTests.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireInteropTests.java @@ -16,12 +16,10 @@ */ package org.apache.activemq.openwire.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.Arrays; -import java.util.Collection; import java.util.concurrent.TimeUnit; import org.apache.activemq.openwire.commands.ConnectionInfo; @@ -36,15 +34,15 @@ import org.apache.activemq.openwire.utils.OpenWireConsumer; import org.apache.activemq.openwire.utils.OpenWireProducer; import org.apache.activemq.openwire.utils.OpenWireSession; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@RunWith(Parameterized.class) public abstract class OpenWireInteropTests extends OpenWireInteropTestSupport { private static final Logger LOG = LoggerFactory.getLogger(OpenWireInteropTests.class); @@ -52,29 +50,23 @@ public abstract class OpenWireInteropTests extends OpenWireInteropTestSupport { protected OpenWireConnection connectionId; protected boolean tightEncodingEnabled; - public OpenWireInteropTests(boolean tightEncodingEnabled) { - this.tightEncodingEnabled = tightEncodingEnabled; - } - - @Parameters - public static Collection data() { - return Arrays.asList(new Object[][] { { Boolean.FALSE }, { Boolean.TRUE } }); - } - @Override protected boolean isTightEncodingEnabled() { return tightEncodingEnabled; } @Override - @Before - public void setUp() throws Exception { - super.setUp(); + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { + super.setUp(testInfo); connectionId = new OpenWireConnection(); } - @Test(timeout = 60000) - public void testCanConnect() throws Exception { + @ParameterizedTest + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) + @ValueSource(booleans = {true, false}) + public void testCanConnect(boolean tightEncodingEnabled) throws Exception { + this.tightEncodingEnabled = tightEncodingEnabled; connect(); assertTrue(awaitConnected(10, TimeUnit.SECONDS)); assertEquals(getOpenWireVersion(), getRemoteWireFormatInfo().getVersion()); @@ -88,16 +80,20 @@ public void testCanConnect() throws Exception { } } - @Test(timeout = 60000) - public void testCreateConnection() throws Exception { + @ParameterizedTest + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) + @ValueSource(booleans = {true, false}) + public void testCreateConnection(boolean tightEncodingEnabled) throws Exception { connect(); assertTrue(awaitConnected(10, TimeUnit.SECONDS)); assertTrue(request(createConnectionInfo(), 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getCurrentConnectionsCount()); } - @Test(timeout = 60000) - public void testCreateSession() throws Exception { + @ParameterizedTest + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) + @ValueSource(booleans = {true, false}) + public void testCreateSession(boolean tightEncodingEnabled) throws Exception { connect(); assertTrue(awaitConnected(10, TimeUnit.SECONDS)); assertTrue(request(createConnectionInfo(), 10, TimeUnit.SECONDS)); @@ -106,8 +102,10 @@ public void testCreateSession() throws Exception { assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS)); } - @Test(timeout = 60000) - public void testCreateProducer() throws Exception { + @ParameterizedTest + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) + @ValueSource(booleans = {true, false}) + public void testCreateProducer(boolean tightEncodingEnabled) throws Exception { connect(); assertTrue(awaitConnected(10, TimeUnit.SECONDS)); assertTrue(request(createConnectionInfo(), 10, TimeUnit.SECONDS)); @@ -117,7 +115,7 @@ public void testCreateProducer() throws Exception { assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS)); OpenWireProducer producerId = sessionId.createOpenWireProducer(); - ProducerInfo info = producerId.createProducerInfo(new OpenWireTopic(name.getMethodName() + "-Topic")); + ProducerInfo info = producerId.createProducerInfo(new OpenWireTopic(testMethodName + "-Topic")); info.setDispatchAsync(false); assertTrue(request(info, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getTopicProducers().length); @@ -126,8 +124,10 @@ public void testCreateProducer() throws Exception { assertEquals(0, brokerService.getAdminView().getTopicProducers().length); } - @Test(timeout = 60000) - public void testCreateConsumer() throws Exception { + @ParameterizedTest + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) + @ValueSource(booleans = {true, false}) + public void testCreateConsumer(boolean tightEncodingEnabled) throws Exception { connect(); assertTrue(awaitConnected(10, TimeUnit.SECONDS)); assertTrue(request(createConnectionInfo(), 10, TimeUnit.SECONDS)); @@ -137,7 +137,7 @@ public void testCreateConsumer() throws Exception { assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS)); OpenWireConsumer consumerId = sessionId.createOpenWireConsumer(); - ConsumerInfo info = consumerId.createConsumerInfo(new OpenWireTopic(name.getMethodName() + "-Topic")); + ConsumerInfo info = consumerId.createConsumerInfo(new OpenWireTopic(testMethodName + "-Topic")); info.setDispatchAsync(false); assertTrue(request(info, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getTopicSubscribers().length); @@ -146,8 +146,10 @@ public void testCreateConsumer() throws Exception { assertEquals(0, brokerService.getAdminView().getTopicSubscribers().length); } - @Test(timeout = 60000) - public void testSendMessageToQueue() throws Exception { + @ParameterizedTest + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) + @ValueSource(booleans = {true, false}) + public void testSendMessageToQueue(boolean tightEncodingEnabled) throws Exception { connect(); assertTrue(awaitConnected(10, TimeUnit.SECONDS)); assertTrue(request(createConnectionInfo(), 10, TimeUnit.SECONDS)); @@ -157,7 +159,7 @@ public void testSendMessageToQueue() throws Exception { assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS)); OpenWireProducer producerId = sessionId.createOpenWireProducer(); - OpenWireQueue queue = new OpenWireQueue(name.getMethodName() + "-Queue"); + OpenWireQueue queue = new OpenWireQueue(testMethodName + "-Queue"); ProducerInfo info = producerId.createProducerInfo(queue); info.setDispatchAsync(false); @@ -179,8 +181,10 @@ public void testSendMessageToQueue() throws Exception { assertEquals(0, brokerService.getAdminView().getQueueProducers().length); } - @Test(timeout = 60000) - public void testConsumeMessageFromQueue() throws Exception { + @ParameterizedTest + @Timeout(value = 60000, unit = TimeUnit.MILLISECONDS) + @ValueSource(booleans = {true, false}) + public void testConsumeMessageFromQueue(boolean tightEncodingEnabled) throws Exception { connect(); assertTrue(awaitConnected(10, TimeUnit.SECONDS)); assertTrue(request(createConnectionInfo(), 10, TimeUnit.SECONDS)); @@ -190,7 +194,7 @@ public void testConsumeMessageFromQueue() throws Exception { assertTrue(request(sessionId.createSessionInfo(), 10, TimeUnit.SECONDS)); OpenWireProducer producerId = sessionId.createOpenWireProducer(); - OpenWireQueue queue = new OpenWireQueue(name.getMethodName() + "-Queue"); + OpenWireQueue queue = new OpenWireQueue(testMethodName + "-Queue"); ProducerInfo producerInfo = producerId.createProducerInfo(queue); producerInfo.setDispatchAsync(false); @@ -215,12 +219,12 @@ public void testConsumeMessageFromQueue() throws Exception { assertTrue(request(consumerInfo, 10, TimeUnit.SECONDS)); assertEquals(1, brokerService.getAdminView().getQueueSubscribers().length); - assertTrue("Should have received a message", Wait.waitFor(new Wait.Condition() { + assertTrue(Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return messages.size() == 1; } - })); + }), "Should have received a message"); Message incoming = messages.poll(); assertTrue(incoming instanceof OpenWireTextMessage); @@ -235,7 +239,7 @@ protected ConnectionInfo createConnectionInfo() { ConnectionInfo info = new ConnectionInfo(connectionId.getConnectionId()); info.setManageable(false); info.setFaultTolerant(false); - info.setClientId(name.getMethodName()); + info.setClientId(testMethodName); return info; } } diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireLegacyValidationTest.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireLegacyValidationTest.java index f206a92..9cb97d0 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireLegacyValidationTest.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireLegacyValidationTest.java @@ -18,30 +18,30 @@ import java.io.DataOutput; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import java.util.Arrays; +import java.util.stream.Stream; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Test that Openwire marshalling for legacy versions will validate Throwable types during * unmarshalling commands that contain a Throwable */ -@RunWith(Parameterized.class) public class OpenWireLegacyValidationTest extends OpenWireUniversalValidationTest { - private final int version; + private int version; // Run through version 1 - 12 which are legacy // Newly generated will be universal and convered by the parent test - @Parameters(name = "version={0}") - public static Collection data() { - List versions = new ArrayList<>(); - for (int i = 1; i <= 11; i++) { - versions.add(new Object[]{i}); - } - return versions; + + public static Stream versions() { + return Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).stream(); + } + + @AfterEach + public void afterEach() { + this.version = Integer.MIN_VALUE; } @Override @@ -54,8 +54,11 @@ protected int getVersion() { return version; } - public OpenWireLegacyValidationTest(int version) { + @ParameterizedTest + @MethodSource("versions") + public void testOpenwireThrowableValidation(int version) throws Exception { this.version = version; + super.testOpenwireThrowableValidation(); } protected Class getMarshallerFactory() throws ClassNotFoundException { diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireUniversalValidationTest.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireUniversalValidationTest.java index 24c2e3e..fb8fe19 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireUniversalValidationTest.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/OpenWireUniversalValidationTest.java @@ -16,10 +16,9 @@ */ package org.apache.activemq.openwire.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.DataOutput; import java.io.IOException; @@ -29,8 +28,8 @@ import org.apache.activemq.openwire.codec.universal.MarshallerFactory; import org.apache.activemq.openwire.commands.CommandTypes; import org.apache.activemq.openwire.commands.ExceptionResponse; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test that Openwire marshalling will validate Throwable types during @@ -40,7 +39,7 @@ public class OpenWireUniversalValidationTest { private static final AtomicBoolean initialized = new AtomicBoolean(false); - @Before + @BeforeEach public void before() { initialized.set(false); } diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/WireFormatInfoMarshaledSizeTest.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/WireFormatInfoMarshaledSizeTest.java index ff1a57c..bb168f2 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/WireFormatInfoMarshaledSizeTest.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/WireFormatInfoMarshaledSizeTest.java @@ -16,9 +16,9 @@ */ package org.apache.activemq.openwire.codec; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -28,8 +28,8 @@ import org.apache.activemq.openwire.buffer.Buffer; import org.apache.activemq.openwire.commands.WireFormatInfo; import org.apache.activemq.util.ByteSequence; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +48,7 @@ public int getExpectedMarshaledSize() { public abstract int getVersion(); - @Before + @BeforeEach public void setUp() throws Exception { OpenWireFormatFactory factory = new OpenWireFormatFactory(); factory.setVersion(getVersion()); diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v1/OpenWireV1Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v1/OpenWireV1Test.java index c185561..bb05873 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v1/OpenWireV1Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v1/OpenWireV1Test.java @@ -20,13 +20,6 @@ public class OpenWireV1Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV1Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 1; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v10/OpenWireV10Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v10/OpenWireV10Test.java index 5f2eb19..e908ce8 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v10/OpenWireV10Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v10/OpenWireV10Test.java @@ -20,13 +20,6 @@ public class OpenWireV10Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV10Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 10; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v11/OpenWireV11Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v11/OpenWireV11Test.java index 736747d..7d5bd21 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v11/OpenWireV11Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v11/OpenWireV11Test.java @@ -20,13 +20,6 @@ public class OpenWireV11Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV11Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 11; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v2/OpenWireV2Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v2/OpenWireV2Test.java index 14e1fae..30c2841 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v2/OpenWireV2Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v2/OpenWireV2Test.java @@ -20,13 +20,6 @@ public class OpenWireV2Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV2Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 2; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v3/OpenWireV3Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v3/OpenWireV3Test.java index de32688..e8210b3 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v3/OpenWireV3Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v3/OpenWireV3Test.java @@ -20,13 +20,6 @@ public class OpenWireV3Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV3Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 3; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v4/OpenWireV4Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v4/OpenWireV4Test.java index 6cde172..214d93c 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v4/OpenWireV4Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v4/OpenWireV4Test.java @@ -20,13 +20,6 @@ public class OpenWireV4Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV4Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 4; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v5/OpenWireV5Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v5/OpenWireV5Test.java index 3331c5b..1a62702 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v5/OpenWireV5Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v5/OpenWireV5Test.java @@ -20,13 +20,6 @@ public class OpenWireV5Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV5Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 5; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v6/OpenWireV6Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v6/OpenWireV6Test.java index d33a5b8..95b7927 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v6/OpenWireV6Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v6/OpenWireV6Test.java @@ -20,13 +20,6 @@ public class OpenWireV6Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV6Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 6; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v7/OpenWireV7Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v7/OpenWireV7Test.java index 3cdabda..0dcb626 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v7/OpenWireV7Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v7/OpenWireV7Test.java @@ -20,13 +20,6 @@ public class OpenWireV7Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV7Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 7; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v8/OpenWireV8Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v8/OpenWireV8Test.java index acb8930..7c1e9ea 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v8/OpenWireV8Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v8/OpenWireV8Test.java @@ -20,13 +20,6 @@ public class OpenWireV8Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV8Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 8; diff --git a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v9/OpenWireV9Test.java b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v9/OpenWireV9Test.java index b91c699..684e221 100644 --- a/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v9/OpenWireV9Test.java +++ b/openwire-interop-tests/src/test/java/org/apache/activemq/openwire/codec/v9/OpenWireV9Test.java @@ -20,13 +20,6 @@ public class OpenWireV9Test extends OpenWireInteropTests { - /** - * @param tightEncodingEnabled - */ - public OpenWireV9Test(boolean tightEncodingEnabled) { - super(tightEncodingEnabled); - } - @Override protected int getOpenWireVersion() { return 9; diff --git a/pom.xml b/pom.xml index 4d8b2f8..e801837 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 1.10.14 - 4.13.1 + 5.10.1 2.0.9 2.22.0 6.0.1 @@ -158,10 +158,11 @@ ${reflections-version} - junit - junit + org.junit + junit-bom ${junit-version} - test + pom + import org.mockito @@ -246,4 +247,4 @@ - \ No newline at end of file +