Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions openwire-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@
<!-- =================================== -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@
*/
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;
import java.io.DataInputStream;
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.
Expand Down Expand Up @@ -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 {
Expand All @@ -141,7 +144,7 @@ protected void assertMarshalBooleans(int count, BooleanValueSet valueSet) throws
}
}

@Before
@BeforeEach
public void setUp() throws Exception {
openWireformat = createOpenWireFormat();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
*/
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;
import java.io.DataInputStream;
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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -127,7 +126,7 @@ public void testDefaultMaxFrameSizeUnlimited() {
assertEquals(Long.MAX_VALUE, wf.getMaxFrameSize());
}

@Before
@BeforeEach
public void setUp() throws Exception {
openWireformat = createOpenWireFormat();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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];
Expand All @@ -112,27 +111,27 @@ 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) {
}
}
}
} 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object[]> 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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -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");

Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -43,7 +44,7 @@ public void testSorting() throws Exception {
List<OpenWireDestination> expected = Arrays.asList(destinations);
set.addAll(expected);
List<OpenWireDestination> actual = new ArrayList<OpenWireDestination>(set);
assertEquals("Sorted order", expected, actual);
assertIterableEquals(expected, actual, "Sorted order");
}

class CombyDest {
Expand Down
Loading