QPID-8647: [Broker-J] JUnit 5 tests refactoring for broker-plugins/amqp-1-0-protocol (#185)
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0ImplTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0ImplTest.java
index 5c6924f..47e4975 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0ImplTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/AMQPConnection_1_0ImplTest.java
@@ -24,7 +24,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -47,7 +47,7 @@
import org.apache.qpid.server.virtualhost.QueueManagingVirtualHost;
import org.apache.qpid.test.utils.UnitTestBase;
-public class AMQPConnection_1_0ImplTest extends UnitTestBase
+class AMQPConnection_1_0ImplTest extends UnitTestBase
{
private Broker<?> _broker;
private ServerNetworkConnection _network;
@@ -56,7 +56,7 @@
private QueueManagingVirtualHost<?> _virtualHost;
@BeforeAll
- public void setUp() throws Exception
+ void setUp() throws Exception
{
_broker = BrokerTestHelper.createBrokerMock();
final Model model = _broker.getModel();
@@ -72,7 +72,7 @@
}
@Test
- public void testGetOpenTransactions()
+ void getOpenTransactions()
{
final AMQPConnection_1_0Impl connection =
new AMQPConnection_1_0Impl(_broker, _network, _port, Transport.TCP, 0, _aggregateTicket);
@@ -90,7 +90,7 @@
}
@Test
- public void testCreateIdentifiedTransaction()
+ void createIdentifiedTransaction()
{
final AMQPConnection_1_0Impl connection =
new AMQPConnection_1_0Impl(_broker, _network, _port, Transport.TCP, 0, _aggregateTicket);
@@ -105,7 +105,7 @@
}
@Test
- public void testGetTransaction()
+ void getTransaction()
{
final AMQPConnection_1_0Impl connection =
new AMQPConnection_1_0Impl(_broker, _network, _port, Transport.TCP, 0, _aggregateTicket);
@@ -121,26 +121,20 @@
}
@Test
- public void testGetTransactionUnknownId()
+ void getTransactionUnknownId()
{
final AMQPConnection_1_0Impl connection =
new AMQPConnection_1_0Impl(_broker, _network, _port, Transport.TCP, 0, _aggregateTicket);
connection.setAddressSpace(_virtualHost);
final IdentifiedTransaction tx1 = connection.createIdentifiedTransaction();
- try
- {
- connection.getTransaction(tx1.getId() + 1);
- fail("UnknownTransactionException is not thrown");
- }
- catch (UnknownTransactionException e)
- {
- // pass
- }
+ assertThrows(UnknownTransactionException.class,
+ () -> connection.getTransaction(tx1.getId() + 1),
+ "UnknownTransactionException is not thrown");
}
@Test
- public void testRemoveTransaction()
+ void removeTransaction()
{
final AMQPConnection_1_0Impl connection =
new AMQPConnection_1_0Impl(_broker, _network, _port, Transport.TCP, 0, _aggregateTicket);
@@ -148,19 +142,13 @@
final IdentifiedTransaction tx1 = connection.createIdentifiedTransaction();
connection.removeTransaction(tx1.getId());
- try
- {
- connection.getTransaction(tx1.getId());
- fail("UnknownTransactionException is not thrown");
- }
- catch (UnknownTransactionException e)
- {
- // pass
- }
+ assertThrows(UnknownTransactionException.class,
+ () -> connection.getTransaction(tx1.getId()),
+ "UnknownTransactionException is not thrown");
}
@Test
- public void resetStatistics()
+ void resetStatistics()
{
final AMQPConnection_1_0Impl connection =
new AMQPConnection_1_0Impl(_broker, _network, _port, Transport.TCP, 0, _aggregateTicket);
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ConsumerTarget_1_0Test.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ConsumerTarget_1_0Test.java
index 8483f5d..7aafaf0 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ConsumerTarget_1_0Test.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ConsumerTarget_1_0Test.java
@@ -32,8 +32,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.BeforeAll;
@@ -62,19 +62,21 @@
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class ConsumerTarget_1_0Test extends UnitTestBase
+@SuppressWarnings({"rawtypes", "unchecked"})
+class ConsumerTarget_1_0Test extends UnitTestBase
{
- private final AMQPDescribedTypeRegistry _describedTypeRegistry = AMQPDescribedTypeRegistry.newInstance()
- .registerTransportLayer()
- .registerMessagingLayer()
- .registerTransactionLayer()
- .registerSecurityLayer()
- .registerExtensionSoleconnLayer();
+ private static final AMQPDescribedTypeRegistry AMQP_DESCRIBED_TYPE_REGISTRY = AMQPDescribedTypeRegistry.newInstance()
+ .registerTransportLayer()
+ .registerMessagingLayer()
+ .registerTransactionLayer()
+ .registerSecurityLayer()
+ .registerExtensionSoleconnLayer();
+
private ConsumerTarget_1_0 _consumerTarget;
private SendingLinkEndpoint _sendingLinkEndpoint;
@BeforeAll
- public void setUp() throws Exception
+ void setUp()
{
final AMQPConnection_1_0 connection = mock(AMQPConnection_1_0.class);
final Session_1_0 session = mock(Session_1_0.class);
@@ -83,19 +85,19 @@
when(_sendingLinkEndpoint.isAttached()).thenReturn(true);
when(session.getAMQPConnection()).thenReturn(connection);
when(session.getConnection()).thenReturn(connection);
- when(connection.getDescribedTypeRegistry()).thenReturn(_describedTypeRegistry);
+ when(connection.getDescribedTypeRegistry()).thenReturn(AMQP_DESCRIBED_TYPE_REGISTRY);
when(connection.getContextValue(Long.class, Consumer.SUSPEND_NOTIFICATION_PERIOD)).thenReturn(10000L);
_consumerTarget = new ConsumerTarget_1_0(_sendingLinkEndpoint, true);
}
@Test
- public void testTTLAdjustedOnSend() throws Exception
+ void TTLAdjustedOnSend() throws Exception
{
- final MessageInstanceConsumer comsumer = mock(MessageInstanceConsumer.class);
+ final MessageInstanceConsumer consumer = mock(MessageInstanceConsumer.class);
- long ttl = 2000L;
- long arrivalTime = System.currentTimeMillis() - 1000L;
+ final long ttl = 2000L;
+ final long arrivalTime = System.currentTimeMillis() - 1000L;
final Header header = new Header();
header.setTtl(UnsignedInteger.valueOf(ttl));
@@ -103,30 +105,30 @@
final MessageInstance messageInstance = mock(MessageInstance.class);
when(messageInstance.getMessage()).thenReturn(message);
- AtomicReference<QpidByteBuffer> payloadRef = new AtomicReference<>();
+ final AtomicReference<QpidByteBuffer> payloadRef = new AtomicReference<>();
doAnswer(invocation ->
- {
- final Object[] args = invocation.getArguments();
- Transfer transfer = (Transfer) args[0];
+ {
+ final Object[] args = invocation.getArguments();
+ final Transfer transfer = (Transfer) args[0];
- QpidByteBuffer transferPayload = transfer.getPayload();
+ final QpidByteBuffer transferPayload = transfer.getPayload();
- QpidByteBuffer payloadCopy = transferPayload.duplicate();
- payloadRef.set(payloadCopy);
- return null;
- }).when(_sendingLinkEndpoint).transfer(any(Transfer.class), anyBoolean());
+ final QpidByteBuffer payloadCopy = transferPayload.duplicate();
+ payloadRef.set(payloadCopy);
+ return null;
+ }).when(_sendingLinkEndpoint).transfer(any(Transfer.class), anyBoolean());
- _consumerTarget.doSend(comsumer, messageInstance, false);
+ _consumerTarget.doSend(consumer, messageInstance, false);
verify(_sendingLinkEndpoint, times(1)).transfer(any(Transfer.class), anyBoolean());
final List<EncodingRetainingSection<?>> sections;
- try (QpidByteBuffer payload = payloadRef.get())
+ try (final QpidByteBuffer payload = payloadRef.get())
{
- sections = new SectionDecoderImpl(_describedTypeRegistry.getSectionDecoderRegistry()).parseAll(payload);
+ sections = new SectionDecoderImpl(AMQP_DESCRIBED_TYPE_REGISTRY.getSectionDecoderRegistry()).parseAll(payload);
}
Header sentHeader = null;
- for (EncodingRetainingSection<?> section : sections)
+ for (final EncodingRetainingSection<?> section : sections)
{
if (section instanceof HeaderSection)
{
@@ -141,21 +143,21 @@
private Message_1_0 createTestMessage(final Header header, long arrivalTime)
{
- DeliveryAnnotationsSection deliveryAnnotations =
- new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
- MessageAnnotationsSection messageAnnotations =
- new MessageAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
- ApplicationPropertiesSection applicationProperties =
- new ApplicationProperties(Collections.emptyMap()).createEncodingRetainingSection();
- FooterSection footer = new Footer(Collections.emptyMap()).createEncodingRetainingSection();
- MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(),
- deliveryAnnotations,
- messageAnnotations,
- new Properties().createEncodingRetainingSection(),
- applicationProperties,
- footer,
- arrivalTime,
- 0);
+ final DeliveryAnnotationsSection deliveryAnnotations =
+ new DeliveryAnnotations(Map.of()).createEncodingRetainingSection();
+ final MessageAnnotationsSection messageAnnotations =
+ new MessageAnnotations(Map.of()).createEncodingRetainingSection();
+ final ApplicationPropertiesSection applicationProperties =
+ new ApplicationProperties(Map.of()).createEncodingRetainingSection();
+ final FooterSection footer = new Footer(Map.of()).createEncodingRetainingSection();
+ final MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(),
+ deliveryAnnotations,
+ messageAnnotations,
+ new Properties().createEncodingRetainingSection(),
+ applicationProperties,
+ footer,
+ arrivalTime,
+ 0);
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
when(storedMessage.getContent(eq(0), anyInt())).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkImplTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkImplTest.java
index b365b29..8312c91 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkImplTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkImplTest.java
@@ -53,7 +53,7 @@
import org.apache.qpid.server.transport.AMQPConnection;
@SuppressWarnings({"rawtypes", "unchecked"})
-public class LinkImplTest
+class LinkImplTest
{
private final static String REMOTE_CONTAINER_ID = "remote-container-id";
private final static String LINK_NAME = "link-name";
@@ -61,13 +61,13 @@
private LinkRegistry<Source, Target> _linkRegistry;
@BeforeEach
- public void setUp()
+ void setUp()
{
_linkRegistry = mock(LinkRegistry.class);
}
@Test
- public void linkStealing_PublishToQueue() throws Exception
+ void linkStealing_PublishToQueue() throws Exception
{
final Queue<?> queue = mock(Queue.class);
final Session_1_0 session1 = createSession("principal1", queue);
@@ -87,7 +87,7 @@
}
@Test
- public void linkStealing_ConsumeQueue() throws Exception
+ void linkStealing_ConsumeQueue() throws Exception
{
final Queue<?> queue = mock(Queue.class);
final Session_1_0 session1 = createSession("principal1", queue);
@@ -107,7 +107,7 @@
}
@Test
- public void linkStealing_PublishToExchange() throws Exception
+ void linkStealing_PublishToExchange() throws Exception
{
final Exchange<?> exchange = mock(Exchange.class);
final Queue<?> queue = mock(Queue.class);
@@ -128,7 +128,7 @@
}
@Test
- public void linkStealing_ConsumeExchange() throws Exception
+ void linkStealing_ConsumeExchange() throws Exception
{
final Exchange<?> exchange = mock(Exchange.class);
final Queue<?> queue = mock(Queue.class);
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkRegistryTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkRegistryTest.java
index 180a107..c030cb8 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkRegistryTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/LinkRegistryTest.java
@@ -37,142 +37,141 @@
import org.apache.qpid.server.virtualhost.QueueManagingVirtualHost;
import org.apache.qpid.test.utils.UnitTestBase;
-public class LinkRegistryTest extends UnitTestBase
+class LinkRegistryTest extends UnitTestBase
{
- public static final Pattern ANY = Pattern.compile(".*");
- private QueueManagingVirtualHost _virtualHost;
- private LinkRegistryImpl _linkRegistry;
+ static final Pattern ANY = Pattern.compile(".*");
+
+ private QueueManagingVirtualHost<?> _virtualHost;
+ private LinkRegistryImpl<?, ?> _linkRegistry;
@BeforeAll
- public void beforeAll()
+ void beforeAll()
{
_virtualHost = mock(QueueManagingVirtualHost.class);
}
@BeforeEach
- public void beforeEach()
+ void beforeEach()
{
- _linkRegistry = new LinkRegistryImpl(_virtualHost);
+ _linkRegistry = new LinkRegistryImpl<>(_virtualHost);
}
@Test
- public void testGetSendingLink()
+ void getSendingLink()
{
- String remoteContainerId = "testRemoteContainerId";
- String linkName = "testLinkName";
- LinkModel link = _linkRegistry.getSendingLink(remoteContainerId, linkName);
+ final String remoteContainerId = "testRemoteContainerId";
+ final String linkName = "testLinkName";
+ final LinkModel link = _linkRegistry.getSendingLink(remoteContainerId, linkName);
assertNotNull(link, "LinkRegistryModel#getSendingLink should always return an object");
- LinkModel link2 = _linkRegistry.getSendingLink(remoteContainerId, linkName);
+ final LinkModel link2 = _linkRegistry.getSendingLink(remoteContainerId, linkName);
assertNotNull(link2, "LinkRegistryModel#getSendingLink should always return an object");
assertSame(link, link2, "Two calls to LinkRegistryModel#getSendingLink should return the same object");
}
@Test
- public void testGetReceivingLink()
+ void getReceivingLink()
{
- String remoteContainerId = "testRemoteContainerId";
- String linkName = "testLinkName";
- LinkModel link = _linkRegistry.getReceivingLink(remoteContainerId, linkName);
+ final String remoteContainerId = "testRemoteContainerId";
+ final String linkName = "testLinkName";
+ final LinkModel link = _linkRegistry.getReceivingLink(remoteContainerId, linkName);
assertNotNull(link, "LinkRegistryModel#getReceivingLink should always return an object");
- LinkModel link2 = _linkRegistry.getReceivingLink(remoteContainerId, linkName);
+ final LinkModel link2 = _linkRegistry.getReceivingLink(remoteContainerId, linkName);
assertNotNull(link2, "LinkRegistryModel#getReceivingLink should always return an object");
- assertSame(link,
- link2,
- "Two calls to LinkRegistryModel#getReceivingLink should return the same object");
+ assertSame(link, link2, "Two calls to LinkRegistryModel#getReceivingLink should return the same object");
}
@Test
- public void testPurgeSendingLinksFromRegistryWithEmptyRegistry()
+ void purgeSendingLinksFromRegistryWithEmptyRegistry()
{
_linkRegistry.purgeSendingLinks(ANY, ANY);
}
@Test
- public void testPurgeSendingLinksExactMatch()
+ void purgeSendingLinksExactMatch()
{
_linkRegistry.getSendingLink("testContainerId", "testLinkName");
_linkRegistry.purgeSendingLinks(Pattern.compile("testContainerId"), Pattern.compile("testLinkName"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 0);
}
@Test
- public void testPurgeSendingLinksRegEx()
+ void purgeSendingLinksRegEx()
{
_linkRegistry.getSendingLink("testContainerId", "testLinkName");
_linkRegistry.purgeSendingLinks(Pattern.compile("test.*Id"), Pattern.compile("testLink.*"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 0);
}
@Test
- public void testPurgeSendingLinksNotMatchingRegEx()
+ void purgeSendingLinksNotMatchingRegEx()
{
_linkRegistry.getSendingLink("testContainerId", "testLinkName");
_linkRegistry.purgeSendingLinks(Pattern.compile("Foo.*"), Pattern.compile(".*bar"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 1);
}
@Test
- public void testPurgeSendingLinksDoesNotRemoveReceivingLink()
+ void purgeSendingLinksDoesNotRemoveReceivingLink()
{
_linkRegistry.getSendingLink("testContainerId", "testLinkName");
_linkRegistry.getReceivingLink("testContainerId", "testLinkName");
_linkRegistry.purgeSendingLinks(Pattern.compile("testContainerId"), Pattern.compile("testLinkName"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 1);
assertEquals(dump.getContainers().get("testContainerId").getReceivingLinks().size(), (long) 1);
assertEquals(dump.getContainers().get("testContainerId").getSendingLinks().size(), (long) 0);
}
@Test
- public void testPurgeReceivingLinksFromRegistryWithEmptyRegistry()
+ void purgeReceivingLinksFromRegistryWithEmptyRegistry()
{
_linkRegistry.purgeReceivingLinks(ANY, ANY);
}
@Test
- public void testPurgeReceivingLinksExactMatch()
+ void purgeReceivingLinksExactMatch()
{
_linkRegistry.getReceivingLink("testContainerId", "testLinkName");
_linkRegistry.purgeReceivingLinks(Pattern.compile("testContainerId"), Pattern.compile("testLinkName"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 0);
}
@Test
- public void testPurgeReceivingLinksRegEx()
+ void purgeReceivingLinksRegEx()
{
_linkRegistry.getReceivingLink("testContainerId", "testLinkName");
_linkRegistry.purgeReceivingLinks(Pattern.compile("test.*Id"), Pattern.compile("testLink.*"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 0);
}
@Test
- public void testPurgeReceivingLinksNotMatchingRegEx()
+ void purgeReceivingLinksNotMatchingRegEx()
{
_linkRegistry.getReceivingLink("testContainerId", "testLinkName");
_linkRegistry.purgeReceivingLinks(Pattern.compile("Foo.*"), Pattern.compile(".*bar"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 1);
}
@Test
- public void testPurgeReceivingLinksDoesNotRemoveSendingLink()
+ void purgeReceivingLinksDoesNotRemoveSendingLink()
{
_linkRegistry.getSendingLink("testContainerId", "testLinkName");
_linkRegistry.getReceivingLink("testContainerId", "testLinkName");
_linkRegistry.purgeReceivingLinks(Pattern.compile("testContainerId"), Pattern.compile("testLinkName"));
- LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
+ final LinkRegistryImpl.LinkRegistryDump dump = _linkRegistry.dump();
assertEquals(dump.getContainers().size(), (long) 1);
assertEquals(dump.getContainers().get("testContainerId").getReceivingLinks().size(), (long) 0);
assertEquals(dump.getContainers().get("testContainerId").getSendingLinks().size(), (long) 1);
}
@Test
- public void testDump()
+ void dump()
{
_linkRegistry.getSendingLink("testContainerId1", "testLinkName");
_linkRegistry.getReceivingLink("testContainerId2", "testLinkName");
@@ -206,7 +205,7 @@
}
@Test
- public void testDumpIsSerializable() throws Exception
+ void dumpIsSerializable() throws Exception
{
_linkRegistry.getSendingLink("testContainerId1", "testLinkName");
_linkRegistry.getReceivingLink("testContainerId2", "testLinkName");
@@ -216,5 +215,4 @@
assertNotNull(data);
}
-
}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_Internal_to_1_0Test.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_Internal_to_1_0Test.java
index f97bb19..6c3f24b 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_Internal_to_1_0Test.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_Internal_to_1_0Test.java
@@ -31,7 +31,6 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -63,23 +62,23 @@
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class MessageConverter_Internal_to_1_0Test extends UnitTestBase
+class MessageConverter_Internal_to_1_0Test extends UnitTestBase
{
- private final MessageConverter_Internal_to_v1_0 _converter = new MessageConverter_Internal_to_v1_0();
- private final AMQPDescribedTypeRegistry _typeRegistry = AMQPDescribedTypeRegistry.newInstance()
- .registerTransportLayer()
- .registerMessagingLayer()
- .registerTransactionLayer()
- .registerSecurityLayer();
+ private static final MessageConverter_Internal_to_v1_0 CONVERTER = new MessageConverter_Internal_to_v1_0();
+ private static final AMQPDescribedTypeRegistry TYPE_REGISTRY = AMQPDescribedTypeRegistry.newInstance()
+ .registerTransportLayer()
+ .registerMessagingLayer()
+ .registerTransactionLayer()
+ .registerSecurityLayer();
- private final StoredMessage<InternalMessageMetaData> _handle = mock(StoredMessage.class);
+ private static final StoredMessage<InternalMessageMetaData> HANDLE = mock(StoredMessage.class);
- private final AMQMessageHeader _amqpHeader = mock(AMQMessageHeader.class);
+ private static final AMQMessageHeader AMQP_HEADER = mock(AMQMessageHeader.class);
@Test
- public void testStringMessage() throws Exception
+ void stringMessage() throws Exception
{
- String content = "testContent";
+ final String content = "testContent";
final String mimeType = "text/plain";
doTest(content,
mimeType,
@@ -90,9 +89,9 @@
}
@Test
- public void testStringMessageWithUnknownMimeType() throws Exception
+ void stringMessageWithUnknownMimeType() throws Exception
{
- String content = "testContent";
+ final String content = "testContent";
final String mimeType = "foo/bar";
doTest(content,
mimeType,
@@ -103,9 +102,9 @@
}
@Test
- public void testStringMessageWithoutMimeType() throws Exception
+ void stringMessageWithoutMimeType() throws Exception
{
- String content = "testContent";
+ final String content = "testContent";
doTest(content,
null,
AmqpValueSection.class,
@@ -115,9 +114,9 @@
}
@Test
- public void testListMessageWithMimeType() throws Exception
+ void listMessageWithMimeType() throws Exception
{
- ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
+ final ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
doTest(content,
"text/plain",
AmqpSequenceSection.class,
@@ -127,9 +126,9 @@
}
@Test
- public void testListMessageWithoutMimeType() throws Exception
+ void listMessageWithoutMimeType() throws Exception
{
- ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
+ final ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
doTest(content,
null,
AmqpSequenceSection.class,
@@ -139,9 +138,9 @@
}
@Test
- public void testListMessageWithoutMimeTypeWithNonJmsContent() throws Exception
+ void listMessageWithoutMimeTypeWithNonJmsContent() throws Exception
{
- ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42, Lists.newArrayList());
+ final ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42, Lists.newArrayList());
doTest(content,
null,
AmqpSequenceSection.class,
@@ -151,9 +150,9 @@
}
@Test
- public void testByteArrayMessageWithoutMimeType() throws Exception
+ void byteArrayMessageWithoutMimeType() throws Exception
{
- byte[] content = "testContent".getBytes(UTF_8);
+ final byte[] content = "testContent".getBytes(UTF_8);
doTest(content,
null,
DataSection.class,
@@ -163,9 +162,9 @@
}
@Test
- public void testByteArrayMessageWithMimeType() throws Exception
+ void byteArrayMessageWithMimeType() throws Exception
{
- byte[] content = "testContent".getBytes(UTF_8);
+ final byte[] content = "testContent".getBytes(UTF_8);
final String mimeType = "foo/bar";
doTest(content,
mimeType,
@@ -176,9 +175,9 @@
}
@Test
- public void testEmptyByteArrayMessageWithMimeType() throws Exception
+ void emptyByteArrayMessageWithMimeType() throws Exception
{
- byte[] content = new byte[0];
+ final byte[] content = new byte[0];
final String mimeType = "foo/bar";
doTest(content,
mimeType,
@@ -189,9 +188,9 @@
}
@Test
- public void testMapMessageWithMimeType() throws Exception
+ void mapMessageWithMimeType() throws Exception
{
- HashMap<Object, Object> content = new HashMap<>();
+ final HashMap<Object, Object> content = new HashMap<>();
content.put("key1", 37);
content.put("key2", "foo");
final String mimeType = "foo/bar";
@@ -204,9 +203,9 @@
}
@Test
- public void testMapMessageWithoutMimeType() throws Exception
+ void mapMessageWithoutMimeType() throws Exception
{
- HashMap<Object, Object> content = new HashMap<>();
+ final HashMap<Object, Object> content = new HashMap<>();
content.put("key1", 37);
content.put("key2", "foo");
doTest(content,
@@ -218,10 +217,10 @@
}
@Test
- public void testMapMessageWithMimeTypeWithNonJmsContent() throws Exception
+ void mapMessageWithMimeTypeWithNonJmsContent() throws Exception
{
- HashMap<Object, Object> content = new HashMap<>();
- content.put(37, Collections.singletonMap("foo", "bar"));
+ final HashMap<Object, Object> content = new HashMap<>();
+ content.put(37, Map.of("foo", "bar"));
final String mimeType = "foo/bar";
doTest(content,
mimeType,
@@ -232,9 +231,9 @@
}
@Test
- public void testSerializableMessageWithMimeType() throws Exception
+ void serializableMessageWithMimeType() throws Exception
{
- Serializable content = new MySerializable();
+ final Serializable content = new MySerializable();
final String mimeType = "foo/bar";
doTest(content,
mimeType,
@@ -245,9 +244,9 @@
}
@Test
- public void testSerializableMessageWithoutMimeType() throws Exception
+ void serializableMessageWithoutMimeType() throws Exception
{
- Serializable content = new MySerializable();
+ final Serializable content = new MySerializable();
doTest(content,
null,
DataSection.class,
@@ -257,7 +256,7 @@
}
@Test
- public void testNullMessageWithoutMimeType() throws Exception
+ void nullMessageWithoutMimeType() throws Exception
{
doTest(null,
null,
@@ -268,9 +267,9 @@
}
@Test
- public void testUuidMessageWithMimeType() throws Exception
+ void uuidMessageWithMimeType() throws Exception
{
- UUID content = UUID.randomUUID();
+ final UUID content = UUID.randomUUID();
final String mimeType = "foo/bar";
doTest(content,
mimeType,
@@ -280,12 +279,10 @@
null);
}
-
-
private byte[] getObjectStreamMessageBytes(final Serializable o) throws Exception
{
- try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos))
+ try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final ObjectOutputStream oos = new ObjectOutputStream(bos))
{
oos.writeObject(o);
return bos.toByteArray();
@@ -296,31 +293,30 @@
final int expectedNumberOfSections)
throws Exception
{
- SectionDecoder sectionDecoder = new SectionDecoderImpl(_typeRegistry.getSectionDecoderRegistry());
+ final SectionDecoder sectionDecoder = new SectionDecoderImpl(TYPE_REGISTRY.getSectionDecoderRegistry());
final List<EncodingRetainingSection<?>> sections = sectionDecoder.parseAll(content);
assertEquals(expectedNumberOfSections, (long) sections.size(), "Unexpected number of sections");
return sections;
}
-
protected InternalMessage getAmqMessage(final Serializable content, final String mimeType) throws Exception
{
final byte[] serializedContent = getObjectStreamMessageBytes(content);
configureMessageContent(serializedContent);
configureMessageHeader(mimeType);
- final InternalMessageHeader internalMessageHeader = new InternalMessageHeader(_amqpHeader);
+ final InternalMessageHeader internalMessageHeader = new InternalMessageHeader(AMQP_HEADER);
final int contentSize = serializedContent == null ? 0 : serializedContent.length;
final InternalMessageMetaData metaData =
new InternalMessageMetaData(false, internalMessageHeader, contentSize);
- when(_handle.getMetaData()).thenReturn(metaData);
+ when(HANDLE.getMetaData()).thenReturn(metaData);
- return ((InternalMessage) InternalMessageMetaDataType.INSTANCE.createMessage(_handle));
+ return ((InternalMessage) InternalMessageMetaDataType.INSTANCE.createMessage(HANDLE));
}
private void configureMessageHeader(final String mimeType)
{
- when(_amqpHeader.getMimeType()).thenReturn(mimeType);
+ when(AMQP_HEADER.getMimeType()).thenReturn(mimeType);
}
private void configureMessageContent(byte[] section)
@@ -330,24 +326,23 @@
section = new byte[0];
}
final QpidByteBuffer combined = QpidByteBuffer.wrap(section);
- when(_handle.getContentSize()).thenReturn(section.length);
+ when(HANDLE.getContentSize()).thenReturn(section.length);
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
- when(_handle.getContent(offsetCaptor.capture(),
- sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(),
- sizeCaptor.getValue()));
+ when(HANDLE.getContent(offsetCaptor.capture(), sizeCaptor.capture()))
+ .then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
}
private Byte getJmsMessageTypeAnnotation(final Message_1_0 convertedMessage)
{
- MessageAnnotationsSection messageAnnotationsSection = convertedMessage.getMessageAnnotationsSection();
+ final MessageAnnotationsSection messageAnnotationsSection = convertedMessage.getMessageAnnotationsSection();
if (messageAnnotationsSection != null)
{
- Map<Symbol, Object> messageAnnotations = messageAnnotationsSection.getValue();
+ final Map<Symbol, Object> messageAnnotations = messageAnnotationsSection.getValue();
if (messageAnnotations != null)
{
- Object annotation = messageAnnotations.get(Symbol.valueOf("x-opt-jms-msg-type"));
+ final Object annotation = messageAnnotations.get(Symbol.valueOf("x-opt-jms-msg-type"));
if (annotation instanceof Byte)
{
return ((Byte) annotation);
@@ -365,25 +360,24 @@
final Byte expectedJmsTypeAnnotation) throws Exception
{
final InternalMessage sourceMessage = getAmqMessage(messageBytes, mimeType);
- final Message_1_0 convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
+ final Message_1_0 convertedMessage = CONVERTER.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent();
- List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
- EncodingRetainingSection<?> encodingRetainingSection = sections.get(0);
+ final List<EncodingRetainingSection<?>> sections = getEncodingRetainingSections(content, 1);
+ final EncodingRetainingSection<?> encodingRetainingSection = sections.get(0);
assertEquals(expectedBodySection, encodingRetainingSection.getClass(), "Unexpected section type");
if (expectedContent instanceof byte[])
{
- assertArrayEquals(((byte[]) expectedContent),
- ((Binary) encodingRetainingSection.getValue()).getArray(),
- "Unexpected content");
+ assertArrayEquals(((byte[]) expectedContent), ((Binary) encodingRetainingSection.getValue()).getArray(),
+ "Unexpected content");
}
else
{
assertEquals(expectedContent, encodingRetainingSection.getValue(), "Unexpected content");
}
- Symbol contentType = getContentType(convertedMessage);
+ final Symbol contentType = getContentType(convertedMessage);
if (expectedContentType == null)
{
assertNull(contentType, "Content type should be null");
@@ -393,7 +387,7 @@
assertEquals(expectedContentType, contentType, "Unexpected content type");
}
- Byte jmsMessageTypeAnnotation = getJmsMessageTypeAnnotation(convertedMessage);
+ final Byte jmsMessageTypeAnnotation = getJmsMessageTypeAnnotation(convertedMessage);
if (expectedJmsTypeAnnotation == null)
{
assertNull(jmsMessageTypeAnnotation, "Unexpected annotation 'x-opt-jms-msg-type'");
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_v1_0_to_InternalTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_v1_0_to_InternalTest.java
index cc65542..27b6b12 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_v1_0_to_InternalTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/MessageConverter_v1_0_to_InternalTest.java
@@ -31,7 +31,6 @@
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -62,34 +61,34 @@
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class MessageConverter_v1_0_to_InternalTest extends UnitTestBase
+class MessageConverter_v1_0_to_InternalTest extends UnitTestBase
{
private static final MessageAnnotations MESSAGE_MESSAGE_ANNOTATION =
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 0));
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 0));
private static final MessageAnnotations OBJECT_MESSAGE_MESSAGE_ANNOTATION =
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 1));
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 1));
private static final MessageAnnotations MAP_MESSAGE_MESSAGE_ANNOTATION =
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 2));
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 2));
private static final MessageAnnotations BYTE_MESSAGE_MESSAGE_ANNOTATION =
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 3));
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 3));
private static final MessageAnnotations STREAM_MESSAGE_MESSAGE_ANNOTATION =
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 4));
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 4));
private static final MessageAnnotations TEXT_MESSAGE_MESSAGE_ANNOTATION =
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 5));
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 5));
private MessageConverter_v1_0_to_Internal _converter;
@BeforeAll
- public void setUp() throws Exception
+ void setUp()
{
_converter = new MessageConverter_v1_0_to_Internal();
}
@Test
- public void testAmqpValueWithNullWithTextMessageAnnotation()
+ void amqpValueWithNullWithTextMessageAnnotation()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage =
+ final Message_1_0 sourceMessage =
createTestMessage(TEXT_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -99,11 +98,11 @@
}
@Test
- public void testAmqpValueWithNullWithMessageAnnotation()
+ void amqpValueWithNullWithMessageAnnotation()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage =
+ final Message_1_0 sourceMessage =
createTestMessage(MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -113,11 +112,12 @@
}
@Test
- public void testAmqpValueWithNullWithObjectMessageAnnotation()
+ void amqpValueWithNullWithObjectMessageAnnotation()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage =
+ createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -127,11 +127,12 @@
}
@Test
- public void testAmqpValueWithNullWithMapMessageAnnotation()
+ void amqpValueWithNullWithMapMessageAnnotation()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(MAP_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage =
+ createTestMessage(MAP_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -140,11 +141,12 @@
}
@Test
- public void testAmqpValueWithNullWithBytesMessageAnnotation()
+ void amqpValueWithNullWithBytesMessageAnnotation()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(BYTE_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage =
+ createTestMessage(BYTE_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -154,11 +156,12 @@
}
@Test
- public void testAmqpValueWithNullWithStreamMessageAnnotation()
+ void amqpValueWithNullWithStreamMessageAnnotation()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(STREAM_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage =
+ createTestMessage(STREAM_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -167,14 +170,13 @@
}
@Test
- public void testAmqpValueWithNullWithUnknownMessageAnnotation()
+ void amqpValueWithNullWithUnknownMessageAnnotation()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage =
- createTestMessage(new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"),
- (byte) 11)),
- amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage =
+ createTestMessage(new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 11)),
+ amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -183,14 +185,14 @@
}
@Test
- public void testAmqpValueWithNullWithContentType()
+ void amqpValueWithNullWithContentType()
{
- Properties properties = new Properties();
+ final Properties properties = new Properties();
final String mimeType = "foo/bar";
properties.setContentType(Symbol.valueOf(mimeType));
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -199,11 +201,11 @@
}
@Test
- public void testAmqpValueWithNull()
+ void amqpValueWithNull()
{
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -212,11 +214,11 @@
}
@Test
- public void testAmqpValueWithString()
+ void amqpValueWithString()
{
final String expected = "testContent";
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -226,14 +228,14 @@
}
@Test
- public void testAmqpValueWithStringWithKnownTextualContentType()
+ void amqpValueWithStringWithKnownTextualContentType()
{
- Properties properties = new Properties();
+ final Properties properties = new Properties();
final String mimeType = "text/foo";
properties.setContentType(Symbol.valueOf(mimeType));
final Object expected = "content";
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -242,14 +244,14 @@
}
@Test
- public void testAmqpValueWithStringWithUnknownTextualContentType()
+ void amqpValueWithStringWithUnknownTextualContentType()
{
- Properties properties = new Properties();
+ final Properties properties = new Properties();
final String mimeType = "foo/bar";
properties.setContentType(Symbol.valueOf(mimeType));
final Object expected = "content";
final AmqpValue amqpValue = new AmqpValue(expected);
- Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -259,7 +261,7 @@
@Test
- public void testAmqpValueWithMap()
+ void amqpValueWithMap()
{
final Map<Object, Object> originalMap = new LinkedHashMap<>();
originalMap.put("binaryEntry", new Binary(new byte[]{0x00, (byte) 0xFF}));
@@ -267,15 +269,15 @@
originalMap.put("uuidEntry", UUID.randomUUID());
originalMap.put("nullEntry", null);
originalMap.put(43, "nonstringkey");
- originalMap.put("mapEntry", Collections.singletonMap("foo", "bar"));
+ originalMap.put("mapEntry", Map.of("foo", "bar"));
final AmqpValue amqpValue = new AmqpValue(originalMap);
- Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertNull(convertedMessage.getMessageHeader().getMimeType(), "Unexpected mime type");
- Map<Object, Object> convertedMap = (Map<Object, Object>) convertedMessage.getMessageBody();
+ final Map<Object, Object> convertedMap = (Map<Object, Object>) convertedMessage.getMessageBody();
assertEquals(originalMap.size(), (long) convertedMap.size(), "Unexpected size");
assertArrayEquals(((Binary) originalMap.get("binaryEntry")).getArray(), (byte[]) convertedMap.get("binaryEntry"),
@@ -289,21 +291,21 @@
}
@Test
- public void testAmqpValueWithList()
+ void amqpValueWithList()
{
final List<Object> originalList = new ArrayList<>();
originalList.add(new Binary(new byte[]{0x00, (byte) 0xFF}));
originalList.add(42);
originalList.add(null);
- originalList.add(Collections.singletonMap("foo", "bar"));
+ originalList.add(Map.of("foo", "bar"));
final AmqpValue amqpValue = new AmqpValue(originalList);
- Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertNull(convertedMessage.getMessageHeader().getMimeType(), "Unexpected mime type");
- List<Object> convertedList = ((List<Object>) convertedMessage.getMessageBody());
+ final List<Object> convertedList = ((List<Object>) convertedMessage.getMessageBody());
assertEquals(originalList.size(), (long) convertedList.size(), "Unexpected size");
assertArrayEquals(((Binary) originalList.get(0)).getArray(), (byte[]) convertedList.get(0),
"Unexpected binary item");
@@ -313,16 +315,15 @@
"Unexpected map item");
}
-
@Test
- public void testAmqpValueWithAmqpType()
+ void amqpValueWithAmqpType()
{
final Date originalValue = new Date();
final AmqpValue amqpValue = new AmqpValue(originalValue);
- Properties properties = new Properties();
+ final Properties properties = new Properties();
final String mimeType = "foo/bar";
properties.setContentType(Symbol.valueOf(mimeType));
- Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(properties, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -331,33 +332,32 @@
}
@Test
- public void testAmqpSequenceWithSimpleTypes()
+ void amqpSequenceWithSimpleTypes()
{
final List<Object> originalList = new ArrayList<>();
originalList.add(37);
originalList.add(42F);
final AmqpSequence amqpSequence = new AmqpSequence(originalList);
- Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
+ final Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertNull(convertedMessage.getMessageHeader().getMimeType(), "Unexpected mime type");
- List<Object> convertedList = ((List<Object>) convertedMessage.getMessageBody());
+ final List<Object> convertedList = ((List<Object>) convertedMessage.getMessageBody());
assertEquals(originalList.size(), (long) convertedList.size(), "Unexpected size");
assertEquals(originalList.get(0), convertedList.get(0), "Unexpected first item");
assertEquals(originalList.get(1), convertedList.get(1), "Unexpected second item");
}
@Test
- public void testDataWithMessageAnnotation()
+ void dataWithMessageAnnotation()
{
final byte[] data = "helloworld".getBytes(UTF_8);
doTestDataWithAnnotation(data, MESSAGE_MESSAGE_ANNOTATION, null, "application/octet-stream");
-
}
@Test
- public void testDataWithMessageAnnotationWithContentType()
+ void dataWithMessageAnnotationWithContentType()
{
final byte[] data = "helloworld".getBytes(UTF_8);
final String mimeType = "foo/bar";
@@ -365,106 +365,94 @@
}
@Test
- public void testDataWithObjectMessageAnnotation() throws Exception
+ void dataWithObjectMessageAnnotation() throws Exception
{
- byte[] bytes = "helloworld".getBytes(UTF_8);
+ final byte[] bytes = "helloworld".getBytes(UTF_8);
final byte[] expected = getObjectBytes(bytes);
- doTestDataWithAnnotation(expected, OBJECT_MESSAGE_MESSAGE_ANNOTATION,
- null,
- "application/x-java-serialized-object");
+ doTestDataWithAnnotation(expected, OBJECT_MESSAGE_MESSAGE_ANNOTATION, null, "application/x-java-serialized-object");
}
@Test
- public void testDataWithObjectMessageAnnotationWithContentType() throws Exception
+ void dataWithObjectMessageAnnotationWithContentType() throws Exception
{
- byte[] bytes = "helloworld".getBytes(UTF_8);
+ final byte[] bytes = "helloworld".getBytes(UTF_8);
final byte[] expected = getObjectBytes(bytes);
final String mimeType = "foo/bar";
doTestDataWithAnnotation(expected, OBJECT_MESSAGE_MESSAGE_ANNOTATION, mimeType, mimeType);
}
@Test
- public void testDataWithMapMessageAnnotation()
+ void dataWithMapMessageAnnotation()
{
- doTestDataWithAnnotation("helloworld".getBytes(UTF_8),
- MAP_MESSAGE_MESSAGE_ANNOTATION,
- null, "application/octet-stream");
+ doTestDataWithAnnotation("helloworld".getBytes(UTF_8), MAP_MESSAGE_MESSAGE_ANNOTATION, null,
+ "application/octet-stream");
}
@Test
- public void testDataWithMapMessageAnnotationWithContentType()
+ void dataWithMapMessageAnnotationWithContentType()
{
final String mimeType = "foor/bar";
- doTestDataWithAnnotation("helloworld".getBytes(UTF_8),
- MAP_MESSAGE_MESSAGE_ANNOTATION,
- mimeType, mimeType);
+ doTestDataWithAnnotation("helloworld".getBytes(UTF_8), MAP_MESSAGE_MESSAGE_ANNOTATION, mimeType, mimeType);
}
@Test
- public void testDataWithBytesMessageAnnotation()
+ void dataWithBytesMessageAnnotation()
{
- doTestDataWithAnnotation("helloworld".getBytes(UTF_8),
- BYTE_MESSAGE_MESSAGE_ANNOTATION,
- null, "application/octet-stream");
+ doTestDataWithAnnotation("helloworld".getBytes(UTF_8), BYTE_MESSAGE_MESSAGE_ANNOTATION, null,
+ "application/octet-stream");
}
@Test
- public void testDataWithBytesMessageAnnotationWithContentType()
+ void dataWithBytesMessageAnnotationWithContentType()
{
final String mimeType = "foo/bar";
- doTestDataWithAnnotation("helloworld".getBytes(UTF_8),
- BYTE_MESSAGE_MESSAGE_ANNOTATION,
- mimeType, mimeType);
+ doTestDataWithAnnotation("helloworld".getBytes(UTF_8), BYTE_MESSAGE_MESSAGE_ANNOTATION, mimeType, mimeType);
}
@Test
- public void testDataWithStreamMessageAnnotation()
+ void dataWithStreamMessageAnnotation()
{
- doTestDataWithAnnotation("helloworld".getBytes(UTF_8), STREAM_MESSAGE_MESSAGE_ANNOTATION,
- null, "application/octet-stream");
+ doTestDataWithAnnotation("helloworld".getBytes(UTF_8), STREAM_MESSAGE_MESSAGE_ANNOTATION, null,
+ "application/octet-stream");
}
@Test
- public void testDataWithStreamMessageAnnotationWithContentType()
+ void dataWithStreamMessageAnnotationWithContentType()
{
final String mimeType = "foo/bar";
- doTestDataWithAnnotation("helloworld".getBytes(UTF_8), STREAM_MESSAGE_MESSAGE_ANNOTATION,
- mimeType, mimeType);
+ doTestDataWithAnnotation("helloworld".getBytes(UTF_8), STREAM_MESSAGE_MESSAGE_ANNOTATION, mimeType, mimeType);
}
@Test
- public void testDataWithTextMessageAnnotation()
+ void dataWithTextMessageAnnotation()
{
- doTestDataWithAnnotation("helloworld".getBytes(UTF_8), TEXT_MESSAGE_MESSAGE_ANNOTATION, null, "application/octet-stream");
+ doTestDataWithAnnotation("helloworld".getBytes(UTF_8), TEXT_MESSAGE_MESSAGE_ANNOTATION, null,
+ "application/octet-stream");
}
@Test
- public void testDataWithTextMessageAnnotationWithContentType()
+ void dataWithTextMessageAnnotationWithContentType()
{
doTestDataWithAnnotation("helloworld".getBytes(UTF_8), TEXT_MESSAGE_MESSAGE_ANNOTATION, "foo/bar", "foo/bar");
}
@Test
- public void testDataWithUnsupportedMessageAnnotation()
+ void dataWithUnsupportedMessageAnnotation()
{
doTestDataWithAnnotation("helloworld".getBytes(UTF_8),
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"),
- (byte) 11)),
- null, "application/octet-stream");
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 11)), null, "application/octet-stream");
}
@Test
- public void testDataWithUnsupportedMessageAnnotationWithContentType()
+ void dataWithUnsupportedMessageAnnotationWithContentType()
{
final String mimeType = "foo/bar";
doTestDataWithAnnotation("helloworld".getBytes(UTF_8),
- new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"),
- (byte) 11)),
- mimeType, mimeType);
+ new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 11)), mimeType, mimeType);
}
@Test
- public void testData() throws Exception
+ void data() throws Exception
{
final byte[] expected = getObjectBytes("helloworld".getBytes(UTF_8));
final Data value = new Data(new Binary(expected));
@@ -478,10 +466,9 @@
}
@Test
- public void testNoBodyWithMessageAnnotation()
+ void noBodyWithMessageAnnotation()
{
- Message_1_0 sourceMessage = createTestMessage(MESSAGE_MESSAGE_ANNOTATION, null);
-
+ final Message_1_0 sourceMessage = createTestMessage(MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertNull(convertedMessage.getMessageHeader().getMimeType(), "Unexpected mime type");
@@ -489,10 +476,9 @@
}
@Test
- public void testNoBodyWithObjectMessageAnnotation()
+ void noBodyWithObjectMessageAnnotation()
{
- Message_1_0 sourceMessage = createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, null);
-
+ final Message_1_0 sourceMessage = createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("application/x-java-serialized-object", convertedMessage.getMessageHeader().getMimeType(),
@@ -502,10 +488,9 @@
}
@Test
- public void testNoBodyWithMapMessageAnnotation()
+ void noBodyWithMapMessageAnnotation()
{
- Message_1_0 sourceMessage = createTestMessage(MAP_MESSAGE_MESSAGE_ANNOTATION, null);
-
+ final Message_1_0 sourceMessage = createTestMessage(MAP_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertNull(convertedMessage.getMessageHeader().getMimeType(), "Unexpected mime type");
@@ -513,10 +498,9 @@
}
@Test
- public void testNoBodyWithBytesMessageAnnotation()
+ void noBodyWithBytesMessageAnnotation()
{
- Message_1_0 sourceMessage = createTestMessage(BYTE_MESSAGE_MESSAGE_ANNOTATION, null);
-
+ final Message_1_0 sourceMessage = createTestMessage(BYTE_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("application/octet-stream", convertedMessage.getMessageHeader().getMimeType(),
@@ -525,10 +509,9 @@
}
@Test
- public void testNoBodyWithStreamMessageAnnotation()
+ void noBodyWithStreamMessageAnnotation()
{
- Message_1_0 sourceMessage = createTestMessage(STREAM_MESSAGE_MESSAGE_ANNOTATION, null);
-
+ final Message_1_0 sourceMessage = createTestMessage(STREAM_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertNull(convertedMessage.getMessageHeader().getMimeType(), "Unexpected mime type");
@@ -536,10 +519,9 @@
}
@Test
- public void testNoBodyWithTextMessageAnnotation()
+ void noBodyWithTextMessageAnnotation()
{
- Message_1_0 sourceMessage = createTestMessage(TEXT_MESSAGE_MESSAGE_ANNOTATION, null);
-
+ final Message_1_0 sourceMessage = createTestMessage(TEXT_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("text/plain", convertedMessage.getMessageHeader().getMimeType(),
@@ -548,13 +530,13 @@
}
@Test
- public void testNoBodyWithTextMessageAnnotationWithKnownTextualContentType()
+ void noBodyWithTextMessageAnnotationWithKnownTextualContentType()
{
final String mimeType = "text/foo";
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(mimeType));
- Message_1_0 sourceMessage = createTestMessage(properties, TEXT_MESSAGE_MESSAGE_ANNOTATION, null);
+ final Message_1_0 sourceMessage = createTestMessage(properties, TEXT_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -563,12 +545,12 @@
}
@Test
- public void testNoBodyWithTextMessageAnnotationWithUnknownTextualContentType()
+ void noBodyWithTextMessageAnnotationWithUnknownTextualContentType()
{
final String mimeType = "foo/bar";
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(mimeType));
- Message_1_0 sourceMessage = createTestMessage(properties, TEXT_MESSAGE_MESSAGE_ANNOTATION, null);
+ final Message_1_0 sourceMessage = createTestMessage(properties, TEXT_MESSAGE_MESSAGE_ANNOTATION, null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -579,11 +561,10 @@
@Test
- public void testNoBodyWithUnknownMessageAnnotation()
+ void noBodyWithUnknownMessageAnnotation()
{
- Message_1_0 sourceMessage =
- createTestMessage(new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"),
- (byte) 11)), null);
+ final Message_1_0 sourceMessage =
+ createTestMessage(new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 11)), null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -592,14 +573,13 @@
}
@Test
- public void testNoBodyWithUnknownMessageAnnotationWithContentType()
+ void noBodyWithUnknownMessageAnnotationWithContentType()
{
-
final String mimeType = "foo/bar";
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(mimeType));
- Message_1_0 sourceMessage =
- createTestMessage(properties, new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"),
+ final Message_1_0 sourceMessage =
+ createTestMessage(properties, new MessageAnnotations(Map.of(Symbol.valueOf("x-opt-jms-msg-type"),
(byte) 11)), null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
@@ -609,7 +589,7 @@
}
@Test
- public void testNoBody()
+ void noBody()
{
final Message_1_0 sourceMessage = createTestMessage(null);
@@ -620,10 +600,10 @@
}
@Test
- public void testNoBodyWithContentTypeApplicationOctetStream()
+ void noBodyWithContentTypeApplicationOctetStream()
{
final String mimeType = "foo/bar";
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(mimeType));
final Message_1_0 sourceMessage = createTestMessage(properties, null);
@@ -634,7 +614,7 @@
}
@Test
- public void testMessageAnnotationTakesPrecedenceOverContentType()
+ void messageAnnotationTakesPrecedenceOverContentType()
{
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("application/octet-stream"));
@@ -647,43 +627,43 @@
assertNull(convertedMessage.getMessageBody(), "Unexpected content");
}
- private Message_1_0 createTestMessage(final EncodingRetainingSection encodingRetainingSection)
+ private Message_1_0 createTestMessage(final EncodingRetainingSection<?> encodingRetainingSection)
{
return createTestMessage(new Properties(), encodingRetainingSection);
}
- private Message_1_0 createTestMessage(final Properties properties, final EncodingRetainingSection section)
+ private Message_1_0 createTestMessage(final Properties properties, final EncodingRetainingSection<?> section)
{
return createTestMessage(new Header(),
- new DeliveryAnnotations(Collections.emptyMap()),
- new MessageAnnotations(Collections.emptyMap()),
+ new DeliveryAnnotations(Map.of()),
+ new MessageAnnotations(Map.of()),
properties,
- new ApplicationProperties(Collections.emptyMap()),
+ new ApplicationProperties(Map.of()),
0,
section);
}
private Message_1_0 createTestMessage(final Properties properties,
final MessageAnnotations messageAnnotations,
- final EncodingRetainingSection section)
+ final EncodingRetainingSection<?> section)
{
return createTestMessage(new Header(),
- new DeliveryAnnotations(Collections.emptyMap()),
+ new DeliveryAnnotations(Map.of()),
messageAnnotations,
properties,
- new ApplicationProperties(Collections.emptyMap()),
+ new ApplicationProperties(Map.of()),
0,
section);
}
private Message_1_0 createTestMessage(final MessageAnnotations messageAnnotations,
- final EncodingRetainingSection section)
+ final EncodingRetainingSection<?> section)
{
return createTestMessage(new Header(),
- new DeliveryAnnotations(Collections.emptyMap()),
+ new DeliveryAnnotations(Map.of()),
messageAnnotations,
new Properties(),
- new ApplicationProperties(Collections.emptyMap()),
+ new ApplicationProperties(Map.of()),
0,
section);
}
@@ -694,17 +674,17 @@
final Properties properties,
final ApplicationProperties applicationProperties,
final long arrivalTime,
- final EncodingRetainingSection section)
+ final EncodingRetainingSection<?> section)
{
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
- MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(),
- deliveryAnnotations.createEncodingRetainingSection(),
- messageAnnotations.createEncodingRetainingSection(),
- properties.createEncodingRetainingSection(),
- applicationProperties.createEncodingRetainingSection(),
- new Footer(Collections.emptyMap()).createEncodingRetainingSection(),
- arrivalTime,
- 0);
+ final MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(),
+ deliveryAnnotations.createEncodingRetainingSection(),
+ messageAnnotations.createEncodingRetainingSection(),
+ properties.createEncodingRetainingSection(),
+ applicationProperties.createEncodingRetainingSection(),
+ new Footer(Map.of()).createEncodingRetainingSection(),
+ arrivalTime,
+ 0);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (section != null)
@@ -715,9 +695,8 @@
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
- when(storedMessage.getContent(offsetCaptor.capture(),
- sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(),
- sizeCaptor.getValue()));
+ when(storedMessage.getContent(offsetCaptor.capture(), sizeCaptor.capture()))
+ .then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
}
else
{
@@ -729,8 +708,8 @@
private byte[] getObjectBytes(final Object object) throws IOException
{
final byte[] expected;
- try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos))
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final ObjectOutputStream oos = new ObjectOutputStream(baos))
{
oos.writeObject(object);
expected = baos.toByteArray();
@@ -745,10 +724,10 @@
final Data value = new Data(new Binary(data));
- Message_1_0 sourceMessage;
+ final Message_1_0 sourceMessage;
if (mimeType != null)
{
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(mimeType));
sourceMessage = createTestMessage(properties, messageAnnotations, value.createEncodingRetainingSection());
}
@@ -762,7 +741,5 @@
assertEquals(expectedMimeType, convertedMessage.getMessageHeader().getMimeType(),
"Unexpected mime type");
assertArrayEquals(data, ((byte[]) convertedMessage.getMessageBody()), "Unexpected content");
-
}
-
}
\ No newline at end of file
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Message_1_0_MutatorTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Message_1_0_MutatorTest.java
index 59f9a34..d8793f3 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Message_1_0_MutatorTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Message_1_0_MutatorTest.java
@@ -24,8 +24,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -49,50 +49,51 @@
import org.apache.qpid.server.store.TestMemoryMessageStore;
import org.apache.qpid.test.utils.UnitTestBase;
-public class Message_1_0_MutatorTest extends UnitTestBase
+class Message_1_0_MutatorTest extends UnitTestBase
{
private static final byte TEST_PRIORITY = (byte) 1;
private static final String TEST_HEADER_NAME = "foo";
private static final String TEST_HEADER_VALUE = "bar";
private static final String TEST_CONTENT_TYPE = "text/plain";
private static final String TEST_CONTENT = "testContent";
+
private MessageStore _messageStore;
private Message_1_0_Mutator _messageMutator;
@BeforeAll
- public void beforeAll()
+ void beforeAll()
{
_messageStore = new TestMemoryMessageStore();
}
@BeforeEach
- public void beforeEach()
+ void beforeEach()
{
final Message_1_0 message = createTestMessage();
_messageMutator = new Message_1_0_Mutator(message, _messageStore);
}
@AfterAll
- public void tearDown()
+ void tearDown()
{
_messageStore.closeMessageStore();
}
@Test
- public void setPriority()
+ void setPriority()
{
_messageMutator.setPriority((byte) (TEST_PRIORITY + 1));
assertThat(_messageMutator.getPriority(), is(equalTo((byte) (TEST_PRIORITY + 1))));
}
@Test
- public void getPriority()
+ void getPriority()
{
assertThat((int) _messageMutator.getPriority(), is(equalTo((int) TEST_PRIORITY)));
}
@Test
- public void create() throws Exception
+ void create() throws Exception
{
_messageMutator.setPriority((byte) (TEST_PRIORITY + 1));
@@ -127,17 +128,16 @@
final PropertiesSection propertiesSection = properties.createEncodingRetainingSection();
final ApplicationPropertiesSection applicationPropertiesSection =
- new ApplicationProperties(Collections.singletonMap(TEST_HEADER_NAME, TEST_HEADER_VALUE))
- .createEncodingRetainingSection();
+ new ApplicationProperties(Map.of(TEST_HEADER_NAME, TEST_HEADER_VALUE)).createEncodingRetainingSection();
final MessageMetaData_1_0 mmd = new MessageMetaData_1_0(headerSection,
- null,
- null,
- propertiesSection,
- applicationPropertiesSection,
- null,
- System.currentTimeMillis(),
- contentSize);
+ null,
+ null,
+ propertiesSection,
+ applicationPropertiesSection,
+ null,
+ System.currentTimeMillis(),
+ contentSize);
final MessageHandle<MessageMetaData_1_0> handle = _messageStore.addMessage(mmd);
handle.addContent(content);
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_Internal_to_v1_0Test.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_Internal_to_v1_0Test.java
index cc29928..01cd1e2 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_Internal_to_v1_0Test.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_Internal_to_v1_0Test.java
@@ -26,16 +26,16 @@
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -55,25 +55,25 @@
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class PropertyConverter_Internal_to_v1_0Test extends UnitTestBase
+class PropertyConverter_Internal_to_v1_0Test extends UnitTestBase
{
private MessageConverter_Internal_to_v1_0 _messageConverter;
private NamedAddressSpace _addressSpace;
@BeforeAll
- public void setUp() throws Exception
+ void setUp()
{
_messageConverter = new MessageConverter_Internal_to_v1_0();
_addressSpace = mock(NamedAddressSpace.class);
}
@Test
- public void testDurableTrueConversion()
+ void durableTrueConversion()
{
final AMQMessageHeader header = mock(AMQMessageHeader.class);
- InternalMessage originalMessage = createTestMessage(header, null, true);
+ final InternalMessage originalMessage = createTestMessage(header, null, true);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertTrue(convertedMessage.isPersistent(), "Unexpected persistence of message");
assertTrue(convertedMessage.getStoredMessage().getMetaData().isPersistent(),
@@ -81,12 +81,12 @@
}
@Test
- public void testDurableFalseConversion()
+ void durableFalseConversion()
{
final AMQMessageHeader header = mock(AMQMessageHeader.class);
- InternalMessage originalMessage = createTestMessage(header, null, false);
+ final InternalMessage originalMessage = createTestMessage(header, null, false);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertFalse(convertedMessage.isPersistent(), "Unexpected persistence of message");
assertFalse(convertedMessage.getStoredMessage().getMetaData().isPersistent(),
@@ -94,229 +94,222 @@
}
@Test
- public void testPriorityConversion()
+ void priorityConversion()
{
final AMQMessageHeader header = mock(AMQMessageHeader.class);
byte priority = (byte) 7;
when(header.getPriority()).thenReturn(priority);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(priority, (long) convertedMessage.getMessageHeader().getPriority(), "Unexpected priority");
}
@Test
- public void testExpirationConversion() throws InterruptedException
+ void expirationConversion() throws InterruptedException
{
- long ttl = 10000;
- long expiryTime = System.currentTimeMillis() + ttl;
+ final long ttl = 10000;
+ final long expiryTime = System.currentTimeMillis() + ttl;
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getExpiration()).thenReturn(expiryTime);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
Thread.sleep(1L);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Long convertedTtl = MessageConverter_from_1_0.getTtl(convertedMessage);
+ final Long convertedTtl = MessageConverter_from_1_0.getTtl(convertedMessage);
+ assertNotNull(convertedTtl);
assertEquals(expiryTime - originalMessage.getArrivalTime(), convertedTtl.longValue(), "Unexpected TTL");
}
@Test
- public void testContentEncodingConversion()
+ void contentEncodingConversion()
{
- String contentEncoding = "my-test-encoding";
+ final String contentEncoding = "my-test-encoding";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getEncoding()).thenReturn(contentEncoding);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Symbol convertedContentEncoding = MessageConverter_from_1_0.getContentEncoding(convertedMessage);
+ final Symbol convertedContentEncoding = MessageConverter_from_1_0.getContentEncoding(convertedMessage);
assertEquals(contentEncoding, convertedContentEncoding.toString(), "Unexpected content encoding");
}
@Test
- public void testMessageIdStringConversion()
+ void messageIdStringConversion()
{
final String messageId = "testMessageId";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getMessageId()).thenReturn(messageId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Object convertedMessageId = MessageConverter_from_1_0.getMessageId(convertedMessage);
+ final Object convertedMessageId = MessageConverter_from_1_0.getMessageId(convertedMessage);
assertEquals(messageId, convertedMessageId, "Unexpected messageId");
}
@Test
- public void testMessageIdUuidConversion()
+ void messageIdUuidConversion()
{
final UUID messageId = UUID.randomUUID();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getMessageId()).thenReturn(messageId.toString());
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Object convertedMessageId = MessageConverter_from_1_0.getMessageId(convertedMessage);
+ final Object convertedMessageId = MessageConverter_from_1_0.getMessageId(convertedMessage);
assertEquals(messageId, convertedMessageId, "Unexpected messageId");
}
@Test
- public void testMessageIdUnsignedLongConversion()
+ void messageIdUnsignedLongConversion()
{
final UnsignedLong messageId = UnsignedLong.valueOf(-1L);
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getMessageId()).thenReturn(messageId.toString());
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Object convertedMessageId = MessageConverter_from_1_0.getMessageId(convertedMessage);
+ final Object convertedMessageId = MessageConverter_from_1_0.getMessageId(convertedMessage);
assertEquals(messageId, convertedMessageId, "Unexpected messageId");
}
@Test
- public void testCorrelationIdStringConversion()
+ void correlationIdStringConversion()
{
final String correlationId = "testCorrelationId";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getCorrelationId()).thenReturn(correlationId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Object convertedCorrelationId = MessageConverter_from_1_0.getCorrelationId(convertedMessage);
+ final Object convertedCorrelationId = MessageConverter_from_1_0.getCorrelationId(convertedMessage);
assertEquals(correlationId, convertedCorrelationId, "Unexpected messageId");
}
@Test
- public void testCorrelationIdUuidConversion()
+ void correlationIdUuidConversion()
{
final UUID correlationId = UUID.randomUUID();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getCorrelationId()).thenReturn(correlationId.toString());
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Object convertedCorrelationId = MessageConverter_from_1_0.getCorrelationId(convertedMessage);
+ final Object convertedCorrelationId = MessageConverter_from_1_0.getCorrelationId(convertedMessage);
assertEquals(correlationId, convertedCorrelationId, "Unexpected correlationId");
}
@Test
- public void testCorrelationIdUnsignedLongConversion()
+ void correlationIdUnsignedLongConversion()
{
final UnsignedLong correlationId = UnsignedLong.valueOf(-1L);
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getCorrelationId()).thenReturn(correlationId.toString());
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Object convertedCorrelationId = MessageConverter_from_1_0.getCorrelationId(convertedMessage);
+ final Object convertedCorrelationId = MessageConverter_from_1_0.getCorrelationId(convertedMessage);
assertEquals(correlationId, convertedCorrelationId, "Unexpected correlationId");
}
@Test
- public void testUserIdConversion()
+ void userIdConversion()
{
final String userId = "testUserId";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getUserId()).thenReturn(userId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Binary convertedUserId = MessageConverter_from_1_0.getUserId(convertedMessage);
+ final Binary convertedUserId = MessageConverter_from_1_0.getUserId(convertedMessage);
assertArrayEquals(userId.getBytes(UTF_8), convertedUserId.getArray(), "Unexpected userId");
}
@Test
- public void testReplyToConversion()
+ void replyToConversion()
{
final String replyTo = "amq.direct/test";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getReplyTo()).thenReturn(replyTo);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- String convertedReplyTo = MessageConverter_from_1_0.getReplyTo(convertedMessage);
+ final String convertedReplyTo = MessageConverter_from_1_0.getReplyTo(convertedMessage);
assertEquals(replyTo, convertedReplyTo, "Unexpected replyTo");
}
@Test
- public void testToConversion()
+ void toConversion()
{
final String to = "amq.direct/test";
- InternalMessage originalMessage = createTestMessage(to);
-
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage originalMessage = createTestMessage(to);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(to, convertedMessage.getTo(), "Unexpected to");
}
@Test
- public void testTimestampConversion()
+ void timestampConversion()
{
final long timestamp = System.currentTimeMillis();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getTimestamp()).thenReturn(timestamp);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Date creationTime = MessageConverter_from_1_0.getCreationTime(convertedMessage);
+ final Date creationTime = MessageConverter_from_1_0.getCreationTime(convertedMessage);
assertNotNull(creationTime, "timestamp not converted");
assertEquals(timestamp, creationTime.getTime(), "Unexpected timestamp");
}
@Test
- public void testHeadersConversion()
+ void headersConversion()
{
- final Map<String, Object> properties = new HashMap<>();
- properties.put("testProperty1", "testProperty1Value");
- properties.put("intProperty", 1);
+ final Map<String, Object> properties = Map.of("testProperty1", "testProperty1Value",
+ "intProperty", 1);
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getHeaderNames()).thenReturn(properties.keySet());
doAnswer(invocation ->
- {
- final String originalArgument = (String) (invocation.getArguments())[0];
- return properties.get(originalArgument);
- }).when(header).getHeader(any(String.class));
- InternalMessage originalMessage = createTestMessage(header);
+ {
+ final String originalArgument = (String) (invocation.getArguments())[0];
+ return properties.get(originalArgument);
+ }).when(header).getHeader(any(String.class));
+ final InternalMessage originalMessage = createTestMessage(header);
final Message_1_0 convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Map<String, Object> convertedHeaders = convertedMessage.getApplicationPropertiesSection().getValue();
+ final Map<String, Object> convertedHeaders = convertedMessage.getApplicationPropertiesSection().getValue();
assertEquals(properties, new HashMap<>(convertedHeaders), "Unexpected application properties");
}
@Test
- public void testHeadersConversionWithNonSimpleTypes()
+ void headersConversionWithNonSimpleTypes()
{
- final Map<String, Object> properties = Collections.singletonMap("listProperty", Collections.emptyList());
+ final Map<String, Object> properties = Map.of("listProperty", List.of());
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getHeaderNames()).thenReturn(properties.keySet());
doAnswer(invocation ->
- {
- final String originalArgument = (String) (invocation.getArguments())[0];
- return properties.get(originalArgument);
- }).when(header).getHeader(any(String.class));
- InternalMessage originalMessage = createTestMessage(header);
+ {
+ final String originalArgument = (String) (invocation.getArguments())[0];
+ return properties.get(originalArgument);
+ }).when(header).getHeader(any(String.class));
+ final InternalMessage originalMessage = createTestMessage(header);
- try
- {
- _messageConverter.convert(originalMessage, _addressSpace);
- fail("Expected exception not thrown");
- }
- catch (MessageConversionException e)
- {
- // pass
- }
+ assertThrows(MessageConversionException.class,
+ () -> _messageConverter.convert(originalMessage, _addressSpace),
+ "Expected exception not thrown");
}
private InternalMessage createTestMessage(String to)
@@ -333,7 +326,7 @@
}
private InternalMessage createTestMessage(final AMQMessageHeader header,
- byte[] content,
+ final byte[] content,
final boolean persistent)
{
final InternalMessageHeader internalMessageHeader = new InternalMessageHeader(header);
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_v1_0_to_InternalTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_v1_0_to_InternalTest.java
index 4ea9735..e7ff1d6 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_v1_0_to_InternalTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/PropertyConverter_v1_0_to_InternalTest.java
@@ -28,7 +28,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -56,26 +55,26 @@
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class PropertyConverter_v1_0_to_InternalTest extends UnitTestBase
+class PropertyConverter_v1_0_to_InternalTest extends UnitTestBase
{
private MessageConverter_v1_0_to_Internal _messageConverter;
private NamedAddressSpace _addressSpace;
@BeforeAll
- public void setUp() throws Exception
+ void setUp()
{
_messageConverter = new MessageConverter_v1_0_to_Internal();
_addressSpace = mock(NamedAddressSpace.class);
}
@Test
- public void testDurableTrueConversion()
+ void durableTrueConversion()
{
final Header header = new Header();
header.setDurable(true);
final Message_1_0 originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertTrue(convertedMessage.isPersistent(), "Unexpected persistence of message");
assertTrue(convertedMessage.getStoredMessage().getMetaData().isPersistent(),
@@ -83,13 +82,13 @@
}
@Test
- public void testDurableFalseConversion()
+ void durableFalseConversion()
{
final Header header = new Header();
header.setDurable(false);
final Message_1_0 originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertFalse(convertedMessage.isPersistent(), "Unexpected persistence of message");
assertFalse(convertedMessage.getStoredMessage().getMetaData().isPersistent(),
@@ -97,70 +96,69 @@
}
@Test
- public void testPriorityConversion()
+ void priorityConversion()
{
final byte priority = 7;
final Header header = new Header();
header.setPriority(UnsignedByte.valueOf(priority));
final Message_1_0 originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(priority, (long) convertedMessage.getMessageHeader().getPriority(), "Unexpected priority");
}
@Test
- public void testAbsoluteExpiryTimeConversion()
+ void absoluteExpiryTimeConversion()
{
long ttl = 10000;
long arrivalTime = System.currentTimeMillis();
long expiryTime = arrivalTime + ttl;
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setAbsoluteExpiryTime(new Date(expiryTime));
- Message_1_0 originalMessage = createTestMessage(properties, arrivalTime);
+ final Message_1_0 originalMessage = createTestMessage(properties, arrivalTime);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(0, convertedMessage.getMessageHeader().getExpiration(), "Unexpected expiration");
}
@Test
- public void testTTLConversion()
+ void TTLConversion()
{
- long ttl = 10000;
- long arrivalTime = System.currentTimeMillis();
- long expiryTime = arrivalTime + ttl;
+ final long ttl = 10000;
+ final long arrivalTime = System.currentTimeMillis();
+ final long expiryTime = arrivalTime + ttl;
final Header header = new Header();
header.setTtl(UnsignedInteger.valueOf(ttl));
- Message_1_0 originalMessage = createTestMessage(header, arrivalTime);
+ final Message_1_0 originalMessage = createTestMessage(header, arrivalTime);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(expiryTime, convertedMessage.getMessageHeader().getExpiration(), "Unexpected expiration");
}
@Test
- public void testContentEncodingConversion()
+ void contentEncodingConversion()
{
- String contentEncoding = "my-test-encoding";
+ final String contentEncoding = "my-test-encoding";
final Properties properties = new Properties();
properties.setContentEncoding(Symbol.valueOf(contentEncoding));
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(contentEncoding, convertedMessage.getMessageHeader().getEncoding(), "Unexpected content encoding");
-
}
@Test
- public void testMessageIdStringConversion()
+ void messageIdStringConversion()
{
final String messageId = "testMessageId";
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setMessageId(messageId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
@@ -168,163 +166,163 @@
}
@Test
- public void testMessageIdUuidConversion()
+ void messageIdUuidConversion()
{
final UUID messageId = UUID.randomUUID();
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setMessageId(messageId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(messageId.toString(), convertedMessage.getMessageHeader().getMessageId(), "Unexpected messageId");
}
@Test
- public void testMessageIdUnsignedLongConversion()
+ void messageIdUnsignedLongConversion()
{
final UnsignedLong messageId = UnsignedLong.valueOf(-1L);
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setMessageId(messageId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(messageId.toString(), convertedMessage.getMessageHeader().getMessageId(), "Unexpected messageId");
}
@Test
- public void testMessageIdBinaryConversion()
+ void messageIdBinaryConversion()
{
final byte[] data = new byte[]{(byte) 0xc3, 0x28};
final Binary messageId = new Binary(data);
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setMessageId(messageId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(messageId.toString(), convertedMessage.getMessageHeader().getMessageId(), "Unexpected messageId");
}
@Test
- public void testCorrelationIdStringConversion()
+ void correlationIdStringConversion()
{
final String correlationId = "testMessageCorrelationId";
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setCorrelationId(correlationId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(correlationId, convertedMessage.getMessageHeader().getCorrelationId(), "Unexpected correlationId");
}
@Test
- public void testCorrelationIdUuidConversion()
+ void correlationIdUuidConversion()
{
final UUID correlationId = UUID.randomUUID();
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setCorrelationId(correlationId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(correlationId.toString(), convertedMessage.getMessageHeader().getCorrelationId(), "Unexpected correlationId");
}
@Test
- public void testCorrelationIdUnsignedLongConversion()
+ void correlationIdUnsignedLongConversion()
{
final UnsignedLong correlationId = UnsignedLong.valueOf(-1L);
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setCorrelationId(correlationId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(correlationId.toString(), convertedMessage.getMessageHeader().getCorrelationId(), "Unexpected correlationId");
}
@Test
- public void testCorrelationIdBinaryConversion()
+ void correlationIdBinaryConversion()
{
final byte[] data = new byte[]{(byte) 0xc3, 0x28};
final Binary correlationId = new Binary(data);
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setCorrelationId(correlationId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(correlationId.toString(), convertedMessage.getMessageHeader().getCorrelationId(), "Unexpected correlationId");
}
@Test
- public void testUserIdConversion()
+ void userIdConversion()
{
final byte[] data = new byte[]{(byte) 0xc3, 0x28};
final Binary userId = new Binary(data);
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setUserId(userId);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(new String(data, UTF_8), convertedMessage.getMessageHeader().getUserId(), "Unexpected userId");
}
@Test
- public void testReplyToConversion()
+ void replyToConversion()
{
final String replyTo = "amq.direct/test";
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setReplyTo(replyTo);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(replyTo, convertedMessage.getMessageHeader().getReplyTo(), "Unexpected replyTo");
}
@Test
- public void testCreationTimeConversion()
+ void creationTimeConversion()
{
final long creationTime = System.currentTimeMillis();
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setCreationTime(new Date(creationTime));
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(creationTime, convertedMessage.getMessageHeader().getTimestamp(), "Unexpected timestamp");
}
@Test
- public void testToConversionIntoToAndInitialRoutingAddressWhenToIncludesExchangeNameAndRoutingKey()
+ void toConversionIntoToAndInitialRoutingAddressWhenToIncludesExchangeNameAndRoutingKey()
{
final String exchangeName = "amq.direct";
final String routingKey = "test";
final String to = String.format("%s/%s", exchangeName, routingKey);
- Properties properties = new Properties();
+ final Properties properties = new Properties();
properties.setTo(to);
- Message_1_0 originalMessage = createTestMessage(properties);
+ final Message_1_0 originalMessage = createTestMessage(properties);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(to, convertedMessage.getTo(), "Unexpected to");
assertEquals("", convertedMessage.getInitialRoutingAddress(), "Unexpected initialRoutingAddress");
}
@Test
- public void testApplicationPropertiesConversion()
+ void applicationPropertiesConversion()
{
- Map<String, Object> properties = new HashMap<>();
+ final Map<String, Object> properties = new HashMap<>();
properties.put("testProperty1", "testProperty1Value");
properties.put("intProperty", 1);
properties.put("nullProperty", null);
- ApplicationProperties applicationProperties = new ApplicationProperties(properties);
- Message_1_0 originalMessage = createTestMessage(applicationProperties);
+ final ApplicationProperties applicationProperties = new ApplicationProperties(properties);
+ final Message_1_0 originalMessage = createTestMessage(applicationProperties);
final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
@@ -332,7 +330,6 @@
assertEquals(properties, new HashMap<>(headers), "Unexpected headers");
}
-
private Message_1_0 createTestMessage(final Header header)
{
return createTestMessage(header, 0);
@@ -340,13 +337,8 @@
private Message_1_0 createTestMessage(final Header header, long arrivalTime)
{
- return createTestMessage(header,
- new DeliveryAnnotations(Collections.emptyMap()),
- new MessageAnnotations(Collections.emptyMap()),
- new Properties(),
- new ApplicationProperties(Collections.emptyMap()),
- arrivalTime,
- null);
+ return createTestMessage(header, new DeliveryAnnotations(Map.of()), new MessageAnnotations(Map.of()),
+ new Properties(), new ApplicationProperties(Map.of()), arrivalTime, null);
}
private Message_1_0 createTestMessage(final Properties properties)
@@ -356,24 +348,14 @@
private Message_1_0 createTestMessage(final Properties properties, final long arrivalTime)
{
- return createTestMessage(new Header(),
- new DeliveryAnnotations(Collections.emptyMap()),
- new MessageAnnotations(Collections.emptyMap()),
- properties,
- new ApplicationProperties(Collections.emptyMap()),
- arrivalTime,
- null);
+ return createTestMessage(new Header(), new DeliveryAnnotations(Map.of()), new MessageAnnotations(Map.of()),
+ properties, new ApplicationProperties(Map.of()), arrivalTime, null);
}
private Message_1_0 createTestMessage(final ApplicationProperties applicationProperties)
{
- return createTestMessage(new Header(),
- new DeliveryAnnotations(Collections.emptyMap()),
- new MessageAnnotations(Collections.emptyMap()),
- new Properties(),
- applicationProperties,
- 0,
- null);
+ return createTestMessage(new Header(), new DeliveryAnnotations(Map.of()), new MessageAnnotations(Map.of()),
+ new Properties(), applicationProperties, 0, null);
}
private Message_1_0 createTestMessage(final Header header,
@@ -385,22 +367,22 @@
final byte[] content)
{
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
- MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(),
- deliveryAnnotations.createEncodingRetainingSection(),
- messageAnnotations.createEncodingRetainingSection(),
- properties.createEncodingRetainingSection(),
- applicationProperties.createEncodingRetainingSection(),
- new Footer(Collections.emptyMap()).createEncodingRetainingSection(),
- arrivalTime,
- content == null ? 0 : content.length);
+ final MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(),
+ deliveryAnnotations.createEncodingRetainingSection(),
+ messageAnnotations.createEncodingRetainingSection(),
+ properties.createEncodingRetainingSection(),
+ applicationProperties.createEncodingRetainingSection(),
+ new Footer(Map.of()).createEncodingRetainingSection(),
+ arrivalTime,
+ content == null ? 0 : content.length);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (content != null)
{
- Binary binary = new Binary(content);
- DataSection dataSection = new Data(binary).createEncodingRetainingSection();
- QpidByteBuffer qbb = dataSection.getEncodedForm();
- int length = qbb.remaining();
+ final Binary binary = new Binary(content);
+ final DataSection dataSection = new Data(binary).createEncodingRetainingSection();
+ final QpidByteBuffer qbb = dataSection.getEncodedForm();
+ final int length = qbb.remaining();
when(storedMessage.getContentSize()).thenReturn(length);
when(storedMessage.getContent(0, length)).thenReturn(qbb);
}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0Test.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0Test.java
index 0d0668b..f51f4b8 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0Test.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0Test.java
@@ -33,9 +33,9 @@
import java.net.InetSocketAddress;
import java.security.Principal;
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import javax.security.auth.Subject;
@@ -79,19 +79,20 @@
import org.apache.qpid.server.virtualhost.VirtualHostPrincipal;
import org.apache.qpid.test.utils.UnitTestBase;
-public class ProtocolEngine_1_0_0Test extends UnitTestBase
+@SuppressWarnings({"rawtypes"})
+class ProtocolEngine_1_0_0Test extends UnitTestBase
{
private AMQPConnection_1_0Impl _protocolEngine_1_0_0;
private ServerNetworkConnection _networkConnection;
private Broker<?> _broker;
private AmqpPort _port;
- private AuthenticationProvider _authenticationProvider;
+ private AuthenticationProvider<?> _authenticationProvider;
private FrameWriter _frameWriter;
- private AMQPConnection _connection;
+ private AMQPConnection<?> _connection;
private VirtualHost<?> _virtualHost;
@BeforeEach
- public void setUp() throws Exception
+ void setUp()
{
_networkConnection = mock(ServerNetworkConnection.class);
when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
@@ -124,7 +125,7 @@
doAnswer(invocation ->
{
_connection = connectionCaptor.getValue();
- throw new SoleConnectionEnforcementPolicyException(null, Collections.emptySet(), "abc1");
+ throw new SoleConnectionEnforcementPolicyException(null, Set.of(), "abc1");
}).when(_virtualHost).registerConnection(connectionCaptor.capture());
when(_virtualHost.getPrincipal()).thenReturn(mock(VirtualHostPrincipal.class));
when(_port.getAddressSpace(anyString())).thenReturn(_virtualHost);
@@ -133,7 +134,7 @@
final ArgumentCaptor<Principal> userCaptor = ArgumentCaptor.forClass(Principal.class);
when(subjectCreator.createSubjectWithGroups(userCaptor.capture())).then((Answer<Subject>) invocation ->
{
- Subject subject = new Subject();
+ final Subject subject = new Subject();
subject.getPrincipals().add(userCaptor.getValue());
return subject;
});
@@ -141,44 +142,43 @@
final ByteBufferSender sender = mock(ByteBufferSender.class);
when(_networkConnection.getSender()).thenReturn(sender);
- AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer()
+ final AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer()
.registerMessagingLayer()
.registerTransactionLayer()
.registerSecurityLayer();
_frameWriter = new FrameWriter(registry, new ByteBufferSender()
- {
+ {
+ @Override
+ public boolean isDirectBufferPreferred()
+ {
+ return false;
+ }
- @Override
- public boolean isDirectBufferPreferred()
- {
- return false;
- }
+ @Override
+ public void send(final QpidByteBuffer msg)
+ {
+ _protocolEngine_1_0_0.received(msg);
+ }
- @Override
- public void send(final QpidByteBuffer msg)
- {
- _protocolEngine_1_0_0.received(msg);
- }
+ @Override
+ public void flush()
+ {
- @Override
- public void flush()
- {
+ }
- }
+ @Override
+ public void close()
+ {
- @Override
- public void close()
- {
-
- }
- });
+ }
+ });
}
@Test
- public void testProtocolEngineWithNoSaslNonTLSandAnon()
+ void protocolEngineWithNoSaslNonTLSandAnon()
{
- final Map<String, Object> attrs = Collections.singletonMap(ConfiguredObject.NAME, getTestName());
+ final Map<String, Object> attrs = Map.of(ConfiguredObject.NAME, getTestName());
final AnonymousAuthenticationManager anonymousAuthenticationManager =
(new AnonymousAuthenticationManagerFactory()).create(null, attrs, _broker);
when(_port.getAuthenticationProvider()).thenReturn(anonymousAuthenticationManager);
@@ -187,21 +187,20 @@
createEngine(Transport.TCP);
_protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance()
- .getHeaderIdentifier()));
+ .getHeaderIdentifier()));
- Open open = new Open();
+ final Open open = new Open();
open.setContainerId("testContainerId");
- _frameWriter.send(new TransportFrame((int) (short) 0, open));
+ _frameWriter.send(new TransportFrame((short) 0, open));
verify(_virtualHost).registerConnection(any(AMQPConnection.class));
- AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
+ final AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
assertNotNull(principal);
assertEquals(principal, new AuthenticatedPrincipal(anonymousAuthenticationManager.getAnonymousPrincipal()));
-
}
@Test
- public void testProtocolEngineWithNoSaslNonTLSandNoAnon()
+ void protocolEngineWithNoSaslNonTLSandNoAnon()
{
allowMechanisms("foo");
@@ -209,16 +208,16 @@
_protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance().getHeaderIdentifier()));
- Open open = new Open();
+ final Open open = new Open();
open.setContainerId("testContainerId");
- _frameWriter.send(new TransportFrame((int) (short) 0, open));
+ _frameWriter.send(new TransportFrame((short) 0, open));
verify(_virtualHost, never()).registerConnection(any(AMQPConnection.class));
verify(_networkConnection).close();
}
@Test
- public void testProtocolEngineWithNoSaslTLSandExternal()
+ void protocolEngineWithNoSaslTLSandExternal()
{
final Principal principal = () -> "test";
when(_networkConnection.getPeerPrincipal()).thenReturn(principal);
@@ -228,58 +227,58 @@
createEngine(Transport.SSL);
_protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance().getHeaderIdentifier()));
- Open open = new Open();
+ final Open open = new Open();
open.setContainerId("testContainerId");
- _frameWriter.send(new TransportFrame((int) (short) 0, open));
+ _frameWriter.send(new TransportFrame((short) 0, open));
verify(_virtualHost).registerConnection(any(AMQPConnection.class));
- AuthenticatedPrincipal authPrincipal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
+ final AuthenticatedPrincipal authPrincipal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
assertNotNull(authPrincipal);
assertEquals(authPrincipal, new AuthenticatedPrincipal(principal));
}
@Test
- public void testProtocolEngineWithSaslNonTLSandAnon()
+ void protocolEngineWithSaslNonTLSandAnon()
{
- final Map<String, Object> attrs = Collections.singletonMap(ConfiguredObject.NAME, getTestName());
+ final Map<String, Object> attrs = Map.of(ConfiguredObject.NAME, getTestName());
final AnonymousAuthenticationManager anonymousAuthenticationManager =
(new AnonymousAuthenticationManagerFactory()).create(null, attrs, _broker);
when(_port.getAuthenticationProvider()).thenReturn(anonymousAuthenticationManager);
- when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(new SubjectCreator(anonymousAuthenticationManager, Collections.emptyList(), null));
+ when(_port.getSubjectCreator(anyBoolean(), anyString()))
+ .thenReturn(new SubjectCreator(anonymousAuthenticationManager, List.of(), null));
allowMechanisms(AnonymousAuthenticationManager.MECHANISM_NAME);
createEngine(Transport.TCP);
_protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0_SASL.getInstance()
- .getHeaderIdentifier()));
+ .getHeaderIdentifier()));
- SaslInit init = new SaslInit();
+ final SaslInit init = new SaslInit();
init.setMechanism(Symbol.valueOf("ANONYMOUS"));
_frameWriter.send(new SASLFrame(init));
_protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance()
- .getHeaderIdentifier()));
+ .getHeaderIdentifier()));
- Open open = new Open();
+ final Open open = new Open();
open.setContainerId("testContainerId");
- _frameWriter.send(new TransportFrame((int) (short) 0, open));
+ _frameWriter.send(new TransportFrame((short) 0, open));
verify(_virtualHost).registerConnection(any(AMQPConnection.class));
- AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
+ final AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
assertNotNull(principal);
assertEquals(principal, new AuthenticatedPrincipal(anonymousAuthenticationManager.getAnonymousPrincipal()));
}
-
- private void createEngine(Transport transport)
+ private void createEngine(final Transport transport)
{
_protocolEngine_1_0_0 =
new AMQPConnection_1_0Impl(_broker, _networkConnection, _port, transport, 1, new AggregateTicker());
}
- private void allowMechanisms(String... mechanisms)
+ private void allowMechanisms(final String... mechanisms)
{
- when(_authenticationProvider.getAvailableMechanisms(anyBoolean())).thenReturn(Arrays.asList(mechanisms));
+ when(_authenticationProvider.getAvailableMechanisms(anyBoolean())).thenReturn(List.of(mechanisms));
}
}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/SendingLinkEndpointTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/SendingLinkEndpointTest.java
index 269533d..811737f 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/SendingLinkEndpointTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/SendingLinkEndpointTest.java
@@ -45,20 +45,21 @@
import org.apache.qpid.server.protocol.v1_0.type.transport.Role;
import org.apache.qpid.test.utils.UnitTestBase;
-public class SendingLinkEndpointTest extends UnitTestBase
+@SuppressWarnings({"rawtypes", "unchecked"})
+class SendingLinkEndpointTest extends UnitTestBase
{
private static final String ADDRESS = "test";
private SendingLinkEndpoint _sendingLinkEndpoint;
@BeforeAll
- public void setUp() throws Exception
+ void setUp() throws Exception
{
- NamedAddressSpace addressSpace = mock(NamedAddressSpace.class);
+ final NamedAddressSpace addressSpace = mock(NamedAddressSpace.class);
final LinkImpl<Source, Target> link = mock(LinkImpl.class);
when(link.getSource()).thenReturn(new Source());
- Target target = new Target();
+ final Target target = new Target();
target.setAddress(ADDRESS);
when(link.getTarget()).thenReturn(target);
@@ -75,31 +76,31 @@
}
@Test
- public void receiveFlow() throws Exception
+ void receiveFlow() throws Exception
{
receiveAttach(_sendingLinkEndpoint);
_sendingLinkEndpoint.setDeliveryCount(new SequenceNumber(-1));
- Flow flow = new Flow();
+ final Flow flow = new Flow();
flow.setDeliveryCount(new SequenceNumber(-1).unsignedIntegerValue());
flow.setLinkCredit(UnsignedInteger.ONE);
_sendingLinkEndpoint.receiveFlow(flow);
- UnsignedInteger linkCredit = _sendingLinkEndpoint.getLinkCredit();
+ final UnsignedInteger linkCredit = _sendingLinkEndpoint.getLinkCredit();
assertThat(linkCredit, is(equalTo(UnsignedInteger.ONE)));
}
private void receiveAttach(final SendingLinkEndpoint sendingLinkEndpoint) throws Exception
{
- Attach attach = new Attach();
- Source source = new Source();
+ final Attach attach = new Attach();
+ final Source source = new Source();
source.setDurable(TerminusDurability.NONE);
source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
attach.setSource(source);
- Target target = new Target();
+ final Target target = new Target();
attach.setTarget(target);
attach.setHandle(new UnsignedInteger(0));
attach.setIncompleteUnsettled(false);
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java
index 11fe946..1bc14cd 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java
@@ -34,10 +34,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import javax.security.auth.Subject;
@@ -52,6 +51,7 @@
import org.mockito.stubbing.Answer;
import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.filter.AMQPFilterTypes;
import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.model.Binding;
@@ -88,51 +88,51 @@
import org.apache.qpid.server.virtualhost.TestMemoryVirtualHost;
import org.apache.qpid.test.utils.UnitTestBase;
-public class Session_1_0Test extends UnitTestBase
+@SuppressWarnings({"rawtypes", "unchecked"})
+class Session_1_0Test extends UnitTestBase
{
private static final AMQPDescribedTypeRegistry DESCRIBED_TYPE_REGISTRY = AMQPDescribedTypeRegistry.newInstance()
- .registerTransportLayer()
- .registerMessagingLayer()
- .registerTransactionLayer()
- .registerSecurityLayer()
- .registerExtensionSoleconnLayer();
+ .registerTransportLayer()
+ .registerMessagingLayer()
+ .registerTransactionLayer()
+ .registerSecurityLayer()
+ .registerExtensionSoleconnLayer();
private static final String TOPIC_NAME = "testTopic";
private static final String QUEUE_NAME = "testQueue";
private static final Symbol TOPIC_CAPABILITY = Symbol.getSymbol("topic");
private static final Symbol QUEUE_CAPABILITY = Symbol.getSymbol("queue");
private static final Symbol JMS_SELECTOR_FILTER = Symbol.getSymbol("jms-selector");
- private AMQPConnection_1_0 _connection;
+
+ private AMQPConnection_1_0<?> _connection;
private VirtualHost<?> _virtualHost;
private Session_1_0 _session;
private int _handle;
- private CurrentThreadTaskExecutor _taskExecutor;
+ private TaskExecutor _taskExecutor;
@BeforeEach
- public void setUp() throws Exception
+ void setUp()
{
- Map<String, Object> virtualHostAttributes = new HashMap<>();
- virtualHostAttributes.put(QueueManagingVirtualHost.NAME, "testVH");
- virtualHostAttributes.put(QueueManagingVirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
+ final Map<String, Object> virtualHostAttributes = Map.of(QueueManagingVirtualHost.NAME, "testVH",
+ QueueManagingVirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
_virtualHost = BrokerTestHelper.createVirtualHost(virtualHostAttributes, this);
- _taskExecutor = new CurrentThreadTaskExecutor();
- _taskExecutor.start();
+ _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
_connection = createAmqpConnection_1_0("testContainerId");
this._session = createSession_1_0(_connection, 0);
}
@AfterEach
- public void tearDown()
+ void tearDown()
{
_taskExecutor.stop();
}
@Test
- public void testReceiveAttachTopicNonDurableNoContainer()
+ void receiveAttachTopicNonDurableNoContainer()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createTopicAttach(false, linkName, address, true);
+ final Attach attach = createTopicAttach(false, linkName, address, true);
_session.receiveAttach(attach);
@@ -141,11 +141,11 @@
}
@Test
- public void testReceiveAttachTopicNonDurableWithContainer()
+ void receiveAttachTopicNonDurableWithContainer()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createTopicAttach(false, linkName, address, false);
+ final Attach attach = createTopicAttach(false, linkName, address, false);
_session.receiveAttach(attach);
@@ -154,11 +154,11 @@
}
@Test
- public void testReceiveAttachTopicDurableNoContainer()
+ void receiveAttachTopicDurableNoContainer()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createTopicAttach(true, linkName, address, true);
+ final Attach attach = createTopicAttach(true, linkName, address, true);
_session.receiveAttach(attach);
@@ -167,24 +167,24 @@
}
@Test
- public void testReceiveAttachTopicDurableWithContainer()
+ void receiveAttachTopicDurableWithContainer()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createTopicAttach(true, linkName+ "|1", address, false);
+ final Attach attach = createTopicAttach(true, linkName+ "|1", address, false);
_session.receiveAttach(attach);
assertAttachSent(_connection, _session, attach);
assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
- AMQPConnection_1_0 secondConnection = createAmqpConnection_1_0("testContainerId2");
- Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
- Attach attach2 = createTopicAttach(true, linkName + "|2", address, false);
+ final AMQPConnection_1_0<?> secondConnection = createAmqpConnection_1_0("testContainerId2");
+ final Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
+ final Attach attach2 = createTopicAttach(true, linkName + "|2", address, false);
secondSession.receiveAttach(attach2);
assertAttachSent(secondConnection, secondSession, attach2);
- Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
+ final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals(2, (long) queues.size(),
"Unexpected number of queues after second subscription with the same subscription name but different " +
"container id ");
@@ -192,20 +192,20 @@
}
@Test
- public void testReceiveAttachSharedTopicNonDurableNoContainer()
+ void receiveAttachSharedTopicNonDurableNoContainer()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createSharedTopicAttach(false, linkName, address, true);
- Attach attach2 = createSharedTopicAttach(false, linkName, address, true);
+ final Attach attach = createSharedTopicAttach(false, linkName, address, true);
+ final Attach attach2 = createSharedTopicAttach(false, linkName, address, true);
_session.receiveAttach(attach);
assertAttachSent(_connection, _session, attach);
assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
- AMQPConnection_1_0 secondConnection = createAmqpConnection_1_0();
- Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
+ final AMQPConnection_1_0<?> secondConnection = createAmqpConnection_1_0();
+ final Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
secondSession.receiveAttach(attach2);
@@ -214,27 +214,27 @@
final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals(1, (long) queues.size(), "Unexpected number of queues after attach");
- Queue<?> queue = queues.iterator().next();
+ final Queue<?> queue = queues.iterator().next();
- Collection<QueueConsumer<?,?>> consumers = queue.getConsumers();
+ final Collection<QueueConsumer<?,?>> consumers = queue.getConsumers();
assertEquals(2, (long) consumers.size(), "Unexpected number of consumers");
}
@Test
- public void testReceiveAttachSharedTopicNonDurableWithContainer()
+ void receiveAttachSharedTopicNonDurableWithContainer()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createSharedTopicAttach(false, linkName, address, false);
- Attach attach2 = createSharedTopicAttach(false, linkName, address, false);
+ final Attach attach = createSharedTopicAttach(false, linkName, address, false);
+ final Attach attach2 = createSharedTopicAttach(false, linkName, address, false);
_session.receiveAttach(attach);
assertAttachSent(_connection, _session, attach);
assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
- AMQPConnection_1_0 secondConnection = createAmqpConnection_1_0("testContainerId2");
- Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
+ final AMQPConnection_1_0<?> secondConnection = createAmqpConnection_1_0("testContainerId2");
+ final Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
secondSession.receiveAttach(attach2);
@@ -243,24 +243,24 @@
final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals(2, (long) queues.size(), "Unexpected number of queues after attach");
- for (Queue<?> queue : queues)
+ for (final Queue<?> queue : queues)
{
- Collection<QueueConsumer<?,?>> consumers = queue.getConsumers();
+ final Collection<QueueConsumer<?,?>> consumers = queue.getConsumers();
assertEquals(1, (long) consumers.size(),
"Unexpected number of consumers on queue " + queue.getName());
}
}
@Test
- public void testSeparateSubscriptionNameSpaces()
+ void separateSubscriptionNameSpaces()
{
- AMQPConnection_1_0 secondConnection = createAmqpConnection_1_0();
- Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
+ final AMQPConnection_1_0<?> secondConnection = createAmqpConnection_1_0();
+ final Session_1_0 secondSession = createSession_1_0(secondConnection, 0);
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach durableSharedWithContainerId = createSharedTopicAttach(true, linkName + "|1", address, false);
+ final Attach durableSharedWithContainerId = createSharedTopicAttach(true, linkName + "|1", address, false);
_session.receiveAttach(durableSharedWithContainerId);
assertAttachSent(_connection, _session, durableSharedWithContainerId, 0);
@@ -268,7 +268,7 @@
assertEquals(1, (long) queues.size(),
"Unexpected number of queues after durable non shared with containerId");
- Attach durableNonSharedWithContainerId = createTopicAttach(true, linkName, address, false);
+ final Attach durableNonSharedWithContainerId = createTopicAttach(true, linkName, address, false);
_session.receiveAttach(durableNonSharedWithContainerId);
assertAttachFailed(_connection, _session, durableNonSharedWithContainerId, 1);
@@ -276,7 +276,7 @@
assertEquals(1, (long) queues.size(),
"Unexpected number of queues after durable non shared with containerId");
- Attach nonDurableSharedWithContainerId = createSharedTopicAttach(false, linkName + "|3", address, false);
+ final Attach nonDurableSharedWithContainerId = createSharedTopicAttach(false, linkName + "|3", address, false);
_session.receiveAttach(nonDurableSharedWithContainerId);
assertAttachSent(_connection, _session, nonDurableSharedWithContainerId, 3);
@@ -284,7 +284,7 @@
assertEquals(2, (long) queues.size(),
"Unexpected number of queues after durable non shared with containerId");
- Attach durableSharedWithoutContainerId = createSharedTopicAttach(true, linkName + "|4", address, true);
+ final Attach durableSharedWithoutContainerId = createSharedTopicAttach(true, linkName + "|4", address, true);
secondSession.receiveAttach(durableSharedWithoutContainerId);
assertAttachSent(secondConnection, secondSession, durableSharedWithoutContainerId, 0);
@@ -292,7 +292,7 @@
assertEquals(3, (long) queues.size(),
"Unexpected number of queues after durable non shared with containerId");
- Attach nonDurableSharedWithoutContainerId = createSharedTopicAttach(false, linkName + "|5", address, true);
+ final Attach nonDurableSharedWithoutContainerId = createSharedTopicAttach(false, linkName + "|5", address, true);
secondSession.receiveAttach(nonDurableSharedWithoutContainerId);
assertAttachSent(secondConnection, secondSession, nonDurableSharedWithoutContainerId, 1);
@@ -300,7 +300,7 @@
assertEquals(4, (long) queues.size(),
"Unexpected number of queues after durable non shared with containerId");
- Attach nonDurableNonSharedWithoutContainerId = createTopicAttach(false, linkName + "|6", address, true);
+ final Attach nonDurableNonSharedWithoutContainerId = createTopicAttach(false, linkName + "|6", address, true);
secondSession.receiveAttach(nonDurableNonSharedWithoutContainerId);
assertAttachSent(secondConnection, secondSession, nonDurableNonSharedWithoutContainerId, 2);
@@ -308,7 +308,7 @@
assertEquals(5, (long) queues.size(),
"Unexpected number of queues after durable non shared with containerId");
- Attach nonDurableNonSharedWithContainerId = createTopicAttach(false, linkName + "|6", address, false);
+ final Attach nonDurableNonSharedWithContainerId = createTopicAttach(false, linkName + "|6", address, false);
_session.receiveAttach(nonDurableNonSharedWithContainerId);
assertAttachSent(_connection, _session, nonDurableNonSharedWithContainerId, 4);
@@ -318,27 +318,27 @@
}
@Test
- public void testReceiveAttachForInvalidUnsubscribe()
+ void receiveAttachForInvalidUnsubscribe()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach unsubscribeAttach = createTopicAttach(true, linkName, address, false);
+ final Attach unsubscribeAttach = createTopicAttach(true, linkName, address, false);
unsubscribeAttach.setSource(null);
_session.receiveAttach(unsubscribeAttach);
assertAttachFailed(_connection, _session, unsubscribeAttach);
- Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
+ final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals(0, (long) queues.size(), "Unexpected number of queues after unsubscribe");
}
@Test
- public void testNullSourceLookup()
+ void nullSourceLookup()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createTopicAttach(true, linkName, address, false);
+ final Attach attach = createTopicAttach(true, linkName, address, false);
_session.receiveAttach(attach);
@@ -347,33 +347,32 @@
sendDetach(_session, attach.getHandle(), false);
- Attach nullSourceAttach = createTopicAttach(true, linkName, address, false);
+ final Attach nullSourceAttach = createTopicAttach(true, linkName, address, false);
nullSourceAttach.setSource(null);
_session.receiveAttach(nullSourceAttach);
- ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
+ final ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(_connection, times(3)).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
- Attach sentAttach = (Attach) frameCapture.getAllValues().get(2);
+ final Attach sentAttach = (Attach) frameCapture.getAllValues().get(2);
assertEquals(nullSourceAttach.getName(), sentAttach.getName(), "Unexpected name");
assertEquals(Role.SENDER, sentAttach.getRole(), "Unexpected role");
assertNotNull(sentAttach.getSource(), "Unexpected source");
- Source source = (Source)sentAttach.getSource();
+ final Source source = (Source)sentAttach.getSource();
assertEquals(address, source.getAddress(), "Unexpected address");
assertTrue(Arrays.asList(source.getCapabilities()).contains(Symbol.valueOf("topic")),
"Unexpected source capabilities");
-
- Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
+ final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals(1, (long) queues.size(), "Unexpected number of queues after unsubscribe");
}
@Test
- public void testReceiveDetachClosed()
+ void receiveDetachClosed()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createTopicAttach(true, linkName, address, false);
+ final Attach attach = createTopicAttach(true, linkName, address, false);
_session.receiveAttach(attach);
@@ -382,19 +381,19 @@
sendDetach(_session, attach.getHandle(), true);
- Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
+ final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals(0, (long) queues.size(), "Unexpected number of queues after unsubscribe");
}
@Test
- public void testReceiveAttachToExistingQueue()
+ void receiveAttachToExistingQueue()
{
final String linkName = "testLink";
- Attach attach = createQueueAttach(false, linkName, QUEUE_NAME);
+ final Attach attach = createQueueAttach(false, linkName, QUEUE_NAME);
- Queue<?> queue = _virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, QUEUE_NAME));
- Exchange<?> exchange = _virtualHost.getChildByName(Exchange.class, "amq.direct");
- exchange.bind(QUEUE_NAME, QUEUE_NAME, Collections.emptyMap(), false);
+ final Queue<?> queue = _virtualHost.createChild(Queue.class, Map.of(Queue.NAME, QUEUE_NAME));
+ final Exchange<?> exchange = _virtualHost.getChildByName(Exchange.class, "amq.direct");
+ exchange.bind(QUEUE_NAME, QUEUE_NAME, Map.of(), false);
_session.receiveAttach(attach);
@@ -402,20 +401,20 @@
}
@Test
- public void testReceiveAttachToNonExistingQueue()
+ void receiveAttachToNonExistingQueue()
{
final String linkName = "testLink";
- Attach attach = createQueueAttach(false, linkName, QUEUE_NAME);
+ final Attach attach = createQueueAttach(false, linkName, QUEUE_NAME);
_session.receiveAttach(attach);
assertAttachFailed(_connection, _session, attach);
}
@Test
- public void testReceiveAttachRebindingQueueNoActiveLinks()
+ void receiveAttachRebindingQueueNoActiveLinks()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createSharedTopicAttach(true, linkName, address, true);
+ final Attach attach = createSharedTopicAttach(true, linkName, address, true);
_session.receiveAttach(attach);
assertAttachSent(_connection, _session, attach);
@@ -423,16 +422,16 @@
sendDetach(_session, attach.getHandle(), false);
- ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
+ final ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(_connection, times(2)).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
final boolean condition = frameCapture.getAllValues().get(1) instanceof Detach;
assertTrue(condition);
assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
- String topicName2 = TOPIC_NAME + "2";
+ final String topicName2 = TOPIC_NAME + "2";
final String address2 = "amq.direct/" + topicName2;
- Attach attach2 = createSharedTopicAttach(true, linkName + "|2", address2, true);
+ final Attach attach2 = createSharedTopicAttach(true, linkName + "|2", address2, true);
_session.receiveAttach(attach2);
assertAttachSent(_connection, _session, attach2, 2);
@@ -441,11 +440,11 @@
}
@Test
- public void testReceiveReattachRebindingQueueNoActiveLinks()
+ void receiveReattachRebindingQueueNoActiveLinks()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createSharedTopicAttach(true, linkName, address, true);
+ final Attach attach = createSharedTopicAttach(true, linkName, address, true);
_session.receiveAttach(attach);
assertAttachSent(_connection, _session, attach);
@@ -453,16 +452,16 @@
sendDetach(_session, attach.getHandle(), false);
- ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
+ final ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(_connection, times(2)).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
final boolean condition = frameCapture.getAllValues().get(1) instanceof Detach;
assertTrue(condition);
assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
- String topicName2 = TOPIC_NAME + "2";
+ final String topicName2 = TOPIC_NAME + "2";
final String address2 = "amq.direct/" + topicName2;
- Attach attach2 = createSharedTopicAttach(true, linkName, address2, true);
+ final Attach attach2 = createSharedTopicAttach(true, linkName, address2, true);
_session.receiveAttach(attach2);
assertAttachSent(_connection, _session, attach2, 2);
@@ -471,32 +470,32 @@
}
@Test
- public void testReceiveAttachTopicNonDurableNoContainerWithInvalidSelector()
+ void receiveAttachTopicNonDurableNoContainerWithInvalidSelector()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
- Attach attach = createTopicAttach(false, linkName, address, true);
+ final Attach attach = createTopicAttach(false, linkName, address, true);
setSelector(attach, "invalid selector");
_session.receiveAttach(attach);
assertAttachFailed(_connection, _session, attach);
final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
- assertEquals((long) 0, (long) queues.size(), "Unexpected number of queues after attach");
+ assertEquals(0, (long) queues.size(), "Unexpected number of queues after attach");
}
@Test
- public void testReceiveAttachTopicNonDurableNoContainerWithValidSelector()
+ void receiveAttachTopicNonDurableNoContainerWithValidSelector()
{
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
final String selectorExpression = "test='test'";
- Attach attach = createTopicAttach(false, linkName, address, true);
+ final Attach attach = createTopicAttach(false, linkName, address, true);
setSelector(attach, selectorExpression);
_session.receiveAttach(attach);
- Attach sentAttach = captureAttach(_connection, _session, 0);
+ final Attach sentAttach = captureAttach(_connection, _session, 0);
assertEquals(attach.getName(), sentAttach.getName(), "Unexpected name");
assertEquals(Role.SENDER, sentAttach.getRole(), "Unexpected role");
@@ -504,30 +503,30 @@
assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
- Binding binding = findBinding("amq.direct", TOPIC_NAME);
+ final Binding binding = findBinding("amq.direct", TOPIC_NAME);
assertNotNull(binding, "Binding is not found");
- Map<String,Object> arguments = binding.getArguments();
+ final Map<String,Object> arguments = binding.getArguments();
assertNotNull(arguments, "Unexpected arguments");
assertEquals(selectorExpression, arguments.get(AMQPFilterTypes.JMS_SELECTOR.toString()),
"Unexpected filter on binding");
}
@Test
- public void testLinkStealing()
+ void linkStealing()
{
- _virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, QUEUE_NAME));
- Attach attach = createQueueAttach(true, getTestName(), QUEUE_NAME);
+ _virtualHost.createChild(Queue.class, Map.of(Queue.NAME, QUEUE_NAME));
+ final Attach attach = createQueueAttach(true, getTestName(), QUEUE_NAME);
- AMQPConnection_1_0 connection1 = _connection;
- Session_1_0 session1 = _session;
+ final AMQPConnection_1_0<?> connection1 = _connection;
+ final Session_1_0 session1 = _session;
session1.receiveAttach(attach);
- Link_1_0<?,?> link = _virtualHost.getSendingLink(connection1.getRemoteContainerId(), attach.getName());
+ final Link_1_0<?,?> link = _virtualHost.getSendingLink(connection1.getRemoteContainerId(), attach.getName());
assertNotNull(link, "Link is not created");
assertAttachSent(connection1, session1, attach);
- AMQPConnection_1_0 connection2 = createAmqpConnection_1_0(connection1.getRemoteContainerId());
- Session_1_0 session2 = createSession_1_0(connection2, 0);
+ final AMQPConnection_1_0<?> connection2 = createAmqpConnection_1_0(connection1.getRemoteContainerId());
+ final Session_1_0 session2 = createSession_1_0(connection2, 0);
session2.receiveAttach(attach);
assertDetachSent(connection1, session1, LinkError.STOLEN, 1);
@@ -535,7 +534,7 @@
}
@Test
- public void testAttachSourceDynamicWithLifeTimePolicyDeleteOnClose()
+ void attachSourceDynamicWithLifeTimePolicyDeleteOnClose()
{
final Attach attach = createReceiverAttach(getTestName());
final Source source = createDynamicSource(new DeleteOnClose());
@@ -547,7 +546,7 @@
}
@Test
- public void testAttachSourceDynamicWithLifeTimePolicyDeleteOnCloseAndExpiryPolicyNever()
+ void attachSourceDynamicWithLifeTimePolicyDeleteOnCloseAndExpiryPolicyNever()
{
final Attach attach = createReceiverAttach(getTestName());
final Source source = createDynamicSource(new DeleteOnClose());
@@ -563,7 +562,7 @@
{
final Source source = new Source();
source.setDynamic(true);
- source.setDynamicNodeProperties(Collections.singletonMap(Session_1_0.LIFETIME_POLICY, lifetimePolicy));
+ source.setDynamicNodeProperties(Map.of(Session_1_0.LIFETIME_POLICY, lifetimePolicy));
return source;
}
@@ -574,21 +573,21 @@
return ((Source) (sentAttach.getSource())).getAddress();
}
- public void assertQueueDurability(final String queueName, final boolean expectedDurability)
+ void assertQueueDurability(final String queueName, final boolean expectedDurability)
{
- final Queue queue = _virtualHost.getChildByName(Queue.class, queueName);
+ final Queue<?> queue = _virtualHost.getChildByName(Queue.class, queueName);
assertNotNull(queue, "Queue not found");
assertEquals(queue.isDurable(), expectedDurability, "Unexpected durability");
}
private void assertFilter(final Attach sentAttach, final String selectorExpression)
{
- Source source = (Source)sentAttach.getSource();
- Map<Symbol, Filter> filter = source.getFilter();
+ final Source source = (Source)sentAttach.getSource();
+ final Map<Symbol, Filter> filter = source.getFilter();
assertNotNull(filter, "Filter is not set in response");
assertEquals(1, filter.size(), "Unexpected filter size");
assertTrue(filter.containsKey(JMS_SELECTOR_FILTER), "Selector is not found");
- Filter jmsSelectorFilter = filter.get(JMS_SELECTOR_FILTER);
+ final Filter jmsSelectorFilter = filter.get(JMS_SELECTOR_FILTER);
final boolean condition = jmsSelectorFilter instanceof JMSSelectorFilter;
assertTrue(condition, "Unexpected selector filter");
assertEquals(selectorExpression, ((JMSSelectorFilter) jmsSelectorFilter).getValue(), "Unexpected selector");
@@ -596,42 +595,33 @@
private Binding findBinding(final String exchangeName, final String bindingName)
{
- Exchange exchange = _virtualHost.findConfiguredObject(Exchange.class, exchangeName);
- Collection<Binding> bindings = exchange.getBindings();
- Binding binding = null;
- for (Binding b: bindings)
- {
- if (bindingName.equals(b.getName()))
- {
- binding = b;
- break;
- }
- }
- return binding;
+ final Exchange<?> exchange = _virtualHost.findConfiguredObject(Exchange.class, exchangeName);
+ return exchange.getBindings().stream()
+ .filter(binding -> bindingName.equals(binding.getName()))
+ .findFirst().orElse(null);
}
private void setSelector(final Attach attach, final String selectorExpression)
{
- JMSSelectorFilter selector = new JMSSelectorFilter(selectorExpression);
- final Map<Symbol, Filter>
- filter = Collections.singletonMap(Symbol.getSymbol("jms-selector"), selector);
+ final JMSSelectorFilter selector = new JMSSelectorFilter(selectorExpression);
+ final Map<Symbol, Filter> filter = Map.of(Symbol.getSymbol("jms-selector"), selector);
((Source)attach.getSource()).setFilter(filter);
}
private void assertAttachActions(final Queue<?> queue, final Attach receivedAttach)
{
- Collection<QueueConsumer<?,?>> consumers = queue.getConsumers();
+ final Collection<QueueConsumer<?,?>> consumers = queue.getConsumers();
assertEquals(1, (long) consumers.size(), "Unexpected consumers size");
- ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
+ final ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(_connection).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
- Attach sentAttach = (Attach) frameCapture.getValue();
+ final Attach sentAttach = (Attach) frameCapture.getValue();
assertEquals(receivedAttach.getName(), sentAttach.getName(), "Unexpected name");
assertEquals(Role.SENDER, sentAttach.getRole(), "Unexpected role");
- Source receivedSource = (Source) receivedAttach.getSource();
- Source sentSource = (Source) sentAttach.getSource();
+ final Source receivedSource = (Source) receivedAttach.getSource();
+ final Source sentSource = (Source) sentAttach.getSource();
assertEquals(receivedSource.getAddress(), sentSource.getAddress(), "Unexpected source address");
assertArrayEquals(receivedSource.getCapabilities(), sentSource.getCapabilities(),
"Unexpected source capabilities");
@@ -640,8 +630,8 @@
"Unexpected source expiry policy");
assertEquals(receivedSource.getDynamic(), sentSource.getDynamic(), "Unexpected source dynamic flag");
- Target receivedTarget = (Target) receivedAttach.getTarget();
- Target sentTarget = (Target) sentAttach.getTarget();
+ final Target receivedTarget = (Target) receivedAttach.getTarget();
+ final Target sentTarget = (Target) sentAttach.getTarget();
assertEquals(receivedTarget.getAddress(), sentTarget.getAddress(), "Unexpected target address");
assertArrayEquals(receivedTarget.getCapabilities(), sentTarget.getCapabilities(),
"Unexpected target capabilities");
@@ -659,42 +649,42 @@
final ErrorCondition expectedError,
final int invocationOffset)
{
- ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
+ final ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(connection, times(invocationOffset + 1)).sendFrame(eq(session.getChannelId()), frameCapture.capture());
- List<FrameBody> sentFrames = frameCapture.getAllValues();
+ final List<FrameBody> sentFrames = frameCapture.getAllValues();
final boolean condition = sentFrames.get(invocationOffset) instanceof Detach;
assertTrue(condition, "unexpected Frame sent");
- Detach sentDetach = (Detach) sentFrames.get(invocationOffset);
+ final Detach sentDetach = (Detach) sentFrames.get(invocationOffset);
assertTrue(sentDetach.getClosed(), "Unexpected closed state");
assertEquals(expectedError, sentDetach.getError().getCondition(), "Closed with unexpected error condition");
}
- private void assertAttachSent(final AMQPConnection_1_0 connection,
+ private void assertAttachSent(final AMQPConnection_1_0<?> connection,
final Session_1_0 session,
final Attach receivedAttach)
{
assertAttachSent(connection, session, receivedAttach, 0);
}
- private void assertAttachSent(final AMQPConnection_1_0 connection,
+ private void assertAttachSent(final AMQPConnection_1_0<?> connection,
final Session_1_0 session,
final Attach receivedAttach,
final int invocationOffset)
{
- Attach sentAttach = captureAttach(connection, session, invocationOffset);
+ final Attach sentAttach = captureAttach(connection, session, invocationOffset);
assertEquals(receivedAttach.getName(), sentAttach.getName(), "Unexpected name");
assertEquals(Role.SENDER, sentAttach.getRole(), "Unexpected role");
}
- private Attach captureAttach(final AMQPConnection_1_0 connection,
+ private Attach captureAttach(final AMQPConnection_1_0<?> connection,
final Session_1_0 session,
final int invocationOffset)
{
- ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
- verify(connection, times(invocationOffset + 1)).sendFrame(eq(session.getChannelId()),
- frameCapture.capture());
+ final ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
+ verify(connection, times(invocationOffset + 1))
+ .sendFrame(eq(session.getChannelId()), frameCapture.capture());
return (Attach) frameCapture.getAllValues().get(invocationOffset);
}
@@ -702,37 +692,40 @@
{
final Collection<Queue> queues = _virtualHost.getChildren(Queue.class);
assertEquals(1, (long) queues.size(), "Unexpected number of queues after attach");
- Queue<?> queue = queues.iterator().next();
+ final Queue<?> queue = queues.iterator().next();
assertEquals(expectedLifetimePolicy, queue.getLifetimePolicy(), "Unexpected queue durability");
- Collection<PublishingLink> queuePublishingLinks = queue.getPublishingLinks();
+ final Collection<PublishingLink> queuePublishingLinks = queue.getPublishingLinks();
assertEquals(1, (long) queuePublishingLinks.size(), "Unexpected number of publishing links");
assertEquals(publishingLinkName, queuePublishingLinks.iterator().next().getName(), "Unexpected link name");
- Exchange<?> exchange = _virtualHost.getChildByName(Exchange.class, "amq.direct");
+ final Exchange<?> exchange = _virtualHost.getChildByName(Exchange.class, "amq.direct");
assertTrue(exchange.hasBinding(publishingLinkName, queue), "Binding should exist");
}
- private void assertAttachFailed(final AMQPConnection_1_0 connection, final Session_1_0 session, final Attach attach, int invocationOffset)
+ private void assertAttachFailed(final AMQPConnection_1_0<?> connection,
+ final Session_1_0 session,
+ final Attach attach,
+ int invocationOffset)
{
- ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
+ final ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
verify(connection, times(invocationOffset + 2)).sendFrame(eq(session.getChannelId()), frameCapture.capture());
- List<FrameBody> sentFrames = frameCapture.getAllValues();
+ final List<FrameBody> sentFrames = frameCapture.getAllValues();
final boolean condition1 = sentFrames.get(invocationOffset) instanceof Attach;
assertTrue(condition1, "unexpected Frame sent");
- Attach sentAttach = (Attach) sentFrames.get(invocationOffset);
+ final Attach sentAttach = (Attach) sentFrames.get(invocationOffset);
assertEquals(attach.getName(), sentAttach.getName(), "Unexpected name");
assertEquals(Role.SENDER, sentAttach.getRole(), "Unexpected role");
assertNull(sentAttach.getSource(), "Unexpected source");
final boolean condition = sentFrames.get(invocationOffset + 1) instanceof Detach;
assertTrue(condition, "unexpected Frame sent");
- Detach sentDetach = (Detach) sentFrames.get(invocationOffset + 1);
+ final Detach sentDetach = (Detach) sentFrames.get(invocationOffset + 1);
assertTrue(sentDetach.getClosed(), "Unexpected closed state");
}
- private void assertAttachFailed(final AMQPConnection_1_0 connection, final Session_1_0 session, final Attach attach)
+ private void assertAttachFailed(final AMQPConnection_1_0<?> connection, final Session_1_0 session, final Attach attach)
{
assertAttachFailed(connection, session, attach, 0);
}
@@ -767,10 +760,10 @@
final boolean isGlobal,
final boolean isShared)
{
- Attach attach = createReceiverAttach(linkName);
- Source source = new Source();
+ final Attach attach = createReceiverAttach(linkName);
+ final Source source = new Source();
- List<Symbol> capabilities = new ArrayList<>();
+ final List<Symbol> capabilities = new ArrayList<>();
if (isGlobal)
{
capabilities.add(Symbol.getSymbol("global"));
@@ -781,8 +774,7 @@
}
capabilities.add(destinationTypeCapability);
-
- source.setCapabilities(capabilities.toArray(new Symbol[capabilities.size()]));
+ source.setCapabilities(capabilities.toArray(new Symbol[0]));
if (durable)
{
source.setDurable(TerminusDurability.CONFIGURATION);
@@ -798,10 +790,10 @@
return attach;
}
- private Attach createReceiverAttach(String linkName)
+ private Attach createReceiverAttach(final String linkName)
{
final Attach attach = new Attach();
- Target target = new Target();
+ final Target target = new Target();
attach.setTarget(target);
attach.setHandle(new UnsignedInteger(_handle++));
attach.setIncompleteUnsettled(false);
@@ -810,16 +802,15 @@
return attach;
}
- private AMQPConnection_1_0 createAmqpConnection_1_0()
+ private AMQPConnection_1_0<?> createAmqpConnection_1_0()
{
return createAmqpConnection_1_0(null);
}
- private AMQPConnection_1_0 createAmqpConnection_1_0(String containerId)
+ private AMQPConnection_1_0<?> createAmqpConnection_1_0(final String containerId)
{
- AMQPConnection_1_0 connection = BrokerTestHelper.mockAsSystemPrincipalSource(AMQPConnection_1_0.class);
- Subject subject =
- new Subject(true, Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
+ final AMQPConnection_1_0<?> connection = BrokerTestHelper.mockAsSystemPrincipalSource(AMQPConnection_1_0.class);
+ final Subject subject = new Subject(true, Set.of(), Set.of(), Set.of());
when(connection.getSubject()).thenReturn(subject);
when(connection.getAddressSpace()).thenReturn(_virtualHost);
when(connection.getEventLogger()).thenReturn(mock(EventLogger.class));
@@ -838,7 +829,7 @@
runnableCaptor.getValue().run();
return Futures.immediateFuture(null);
});
- AggregateTicker mockTicker = mock(AggregateTicker.class);
+ final AggregateTicker mockTicker = mock(AggregateTicker.class);
when(connection.getAggregateTicker()).thenReturn(mockTicker);
if (containerId != null)
{
@@ -852,9 +843,9 @@
return connection;
}
- private Session_1_0 createSession_1_0(final AMQPConnection_1_0 connection, int channelId)
+ private Session_1_0 createSession_1_0(final AMQPConnection_1_0<?> connection, int channelId)
{
- Begin begin = mock(Begin.class);
+ final Begin begin = mock(Begin.class);
when(begin.getNextOutgoingId()).thenReturn(new UnsignedInteger(channelId));
return new Session_1_0(connection, begin, channelId, channelId, 2048);
}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/TestLinkStoreFactory.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/TestLinkStoreFactory.java
index fa05331..849e115 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/TestLinkStoreFactory.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/TestLinkStoreFactory.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.protocol.v1_0;
import java.util.Collection;
-import java.util.Collections;
+import java.util.List;
import org.apache.qpid.server.model.NamedAddressSpace;
import org.apache.qpid.server.plugin.PluggableService;
@@ -52,7 +52,7 @@
@Override
public Collection<LinkDefinition<Source, Target>> openAndLoad(final LinkStoreUpdater updater) throws StoreException
{
- return Collections.emptyList();
+ return List.of();
}
@Override
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructorTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructorTest.java
index 7039889..e3982a6 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructorTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/StringTypeConstructorTest.java
@@ -32,19 +32,19 @@
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
-public class StringTypeConstructorTest
+class StringTypeConstructorTest
{
@Test
- public void construct() throws Exception
+ void construct() throws Exception
{
- StringTypeConstructor constructor = StringTypeConstructor.getInstance(1);
- Cache<ByteBuffer, String> original = StringTypeConstructor.getCache();
- Cache<ByteBuffer, String> cache = CacheBuilder.newBuilder().maximumSize(2).build();
+ final StringTypeConstructor constructor = StringTypeConstructor.getInstance(1);
+ final Cache<ByteBuffer, String> original = StringTypeConstructor.getCache();
+ final Cache<ByteBuffer, String> cache = CacheBuilder.newBuilder().maximumSize(2).build();
StringTypeConstructor.setCache(cache);
try
{
- String string1 = constructor.construct(QpidByteBuffer.wrap(new byte[]{4, 't', 'e', 's', 't'}), null);
- String string2 = constructor.construct(QpidByteBuffer.wrap(new byte[]{4, 't', 'e', 's', 't'}), null);
+ final String string1 = constructor.construct(QpidByteBuffer.wrap(new byte[]{4, 't', 'e', 's', 't'}), null);
+ final String string2 = constructor.construct(QpidByteBuffer.wrap(new byte[]{4, 't', 'e', 's', 't'}), null);
assertEquals(string1, string2);
assertSame(string1, string2);
}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java
index 1260a41..e0aa79e 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/ValueHandlerTest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.protocol.v1_0.codec;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -32,9 +32,9 @@
import org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError;
import org.apache.qpid.test.utils.UnitTestBase;
-public class ValueHandlerTest extends UnitTestBase
+class ValueHandlerTest extends UnitTestBase
{
- private final byte[] FORMAT_CODES = {
+ private static final byte[] FORMAT_CODES = {
0x00,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
0x60, 0x61,
@@ -50,25 +50,25 @@
};
private static final AMQPDescribedTypeRegistry TYPE_REGISTRY = AMQPDescribedTypeRegistry.newInstance()
- .registerTransportLayer()
- .registerMessagingLayer()
- .registerTransactionLayer()
- .registerSecurityLayer();
+ .registerTransportLayer()
+ .registerMessagingLayer()
+ .registerTransactionLayer()
+ .registerSecurityLayer();
private ValueHandler _valueHandle;
private ValueHandler _sectionValueHandler;
@BeforeAll
- public void setUp() throws Exception
+ void setUp()
{
_valueHandle = new ValueHandler(TYPE_REGISTRY);
_sectionValueHandler = new ValueHandler(TYPE_REGISTRY.getSectionDecoderRegistry());
}
@Test
- public void testIncompleteValueParsingFormatCodeOnly()
+ void incompleteValueParsingFormatCodeOnly()
{
- for (byte b : FORMAT_CODES)
+ for (final byte b : FORMAT_CODES)
{
byte[] in = {b};
performTest(b, in);
@@ -76,100 +76,99 @@
}
@Test
- public void testIncompleteValueParsingVariableOneFormatCodeOnlyAndSize()
+ void incompleteValueParsingVariableOneFormatCodeOnlyAndSize()
{
- byte[] variableOne = {(byte) 0xA0, (byte) 0xA1, (byte) 0xA3};
- for (byte b : variableOne)
+ final byte[] variableOne = {(byte) 0xA0, (byte) 0xA1, (byte) 0xA3};
+ for (final byte b : variableOne)
{
- byte[] in = {b, (byte) 1};
+ final byte[] in = {b, (byte) 1};
performTest(b, in);
}
}
@Test
- public void testIncompleteValueParsingVariableFour()
+ void incompleteValueParsingVariableFour()
{
- byte[] variableFour = {(byte) 0xB0, (byte) 0xB1, (byte) 0xB3};
- for (byte b : variableFour)
+ final byte[] variableFour = {(byte) 0xB0, (byte) 0xB1, (byte) 0xB3};
+ for (final byte b : variableFour)
{
- byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 2};
+ final byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 2};
performTest(b, in);
}
}
@Test
- public void testIncompleteValueParsingCompoundOneOrArrayOne()
+ void incompleteValueParsingCompoundOneOrArrayOne()
{
- byte[] compoundOne = {(byte) 0xC0, (byte) 0xC1, (byte) 0xE0};
- for (byte b : compoundOne)
+ final byte[] compoundOne = {(byte) 0xC0, (byte) 0xC1, (byte) 0xE0};
+ for (final byte b : compoundOne)
{
- byte[] in = {b, (byte) 1};
+ final byte[] in = {b, (byte) 1};
performTest(b, in);
}
}
@Test
- public void testIncompleteValueParsingCompoundFourOrArrayFour()
+ void incompleteValueParsingCompoundFourOrArrayFour()
{
- byte[] compoundFour = {(byte) 0xD0, (byte) 0xD1, (byte) 0xF0};
- for (byte b : compoundFour)
+ final byte[] compoundFour = {(byte) 0xD0, (byte) 0xD1, (byte) 0xF0};
+ for (final byte b : compoundFour)
{
- byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 1};
- performTest(b, in);
- }
- }
-
-
- @Test
- public void testIncompleteValueParsingCompoundOneWhenOnlySizeAndCountSpecified()
- {
- byte[] compoundOne = {(byte) 0xC0, (byte) 0xC1, (byte) 0xE0};
- for (byte b : compoundOne)
- {
- byte[] in = {b, (byte) 2, (byte) 1};
+ final byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 1};
performTest(b, in);
}
}
@Test
- public void testIncompleteValueParsingCompoundFourWhenOnlySizeAndCountSpecified()
+ void incompleteValueParsingCompoundOneWhenOnlySizeAndCountSpecified()
{
- byte[] compoundFour = {(byte) 0xD0, (byte) 0xD1, (byte) 0xF0};
- for (byte b : compoundFour)
+ final byte[] compoundOne = {(byte) 0xC0, (byte) 0xC1, (byte) 0xE0};
+ for (final byte b : compoundOne)
{
- byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 1};
+ final byte[] in = {b, (byte) 2, (byte) 1};
performTest(b, in);
}
}
@Test
- public void testIncompleteValueParsingArrayOneElementConstructor()
+ void incompleteValueParsingCompoundFourWhenOnlySizeAndCountSpecified()
{
- byte[] in = {(byte) 0xE0, (byte) 3, (byte) 1, 0x50};
+ final byte[] compoundFour = {(byte) 0xD0, (byte) 0xD1, (byte) 0xF0};
+ for (final byte b : compoundFour)
+ {
+ final byte[] in = {b, (byte) 0, (byte) 0, (byte) 0, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 1};
+ performTest(b, in);
+ }
+ }
+
+ @Test
+ void incompleteValueParsingArrayOneElementConstructor()
+ {
+ final byte[] in = {(byte) 0xE0, (byte) 3, (byte) 1, 0x50};
performTest((byte) 0xE0, in);
}
@Test
- public void testIncompleteValueParsingArrayOneElementConstructorWhenSizeIsWrong()
+ void incompleteValueParsingArrayOneElementConstructorWhenSizeIsWrong()
{
- byte[] in = {(byte) 0xE0, (byte) 2, (byte) 1, 0x50, (byte) 1};
+ final byte[] in = {(byte) 0xE0, (byte) 2, (byte) 1, 0x50, (byte) 1};
performTest((byte) 0xE0, in);
}
@Test
- public void testIncompleteValueParsingArrayFourElementConstructor()
+ void incompleteValueParsingArrayFourElementConstructor()
{
- byte[] in = {(byte) 0xF0, (byte) 0, (byte) 0, (byte) 0, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 1, 0x50};
+ final byte[] in = {(byte) 0xF0, (byte) 0, (byte) 0, (byte) 0, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 1, 0x50};
performTest((byte) 0xF0, in);
}
@Test
- public void testIncompleteSection()
+ void incompleteSection()
{
- byte[] in = { 0x00, 0x53, 0x75, (byte) 0xA0, 0x01, 0x00 };
+ final byte[] in = { 0x00, 0x53, 0x75, (byte) 0xA0, 0x01, 0x00 };
for (int i = in.length - 1; i > 1; --i)
{
- byte[] newArray = new byte[i];
+ final byte[] newArray = new byte[i];
System.arraycopy(in, 0, newArray, 0, i);
performSectionTest((byte) 0x00, newArray);
}
@@ -185,24 +184,14 @@
performTest(type, encodedBytes, _valueHandle);
}
- private void performTest(final byte type, final byte[] encodedBytes, ValueHandler valueHandler)
+ private void performTest(final byte type, final byte[] encodedBytes, final ValueHandler valueHandler)
{
- QpidByteBuffer qbb = QpidByteBuffer.wrap(encodedBytes);
+ final QpidByteBuffer qbb = QpidByteBuffer.wrap(encodedBytes);
- try
- {
- valueHandler.parse(qbb);
- fail(String.format("AmqpErrorException is expected for %#02x", type));
- }
- catch (AmqpErrorException e)
- {
- assertEquals(AmqpError.DECODE_ERROR, e.getError().getCondition(),
- String.format("Unexpected error code for %#02x", type));
-
- }
- catch (Exception e)
- {
- fail(String.format("Unexpected exception for %#02x: %s", type, e));
- }
+ final AmqpErrorException thrown = assertThrows(AmqpErrorException.class,
+ () -> valueHandler.parse(qbb),
+ String.format("AmqpErrorException is expected for %#02x", type));
+ assertEquals(AmqpError.DECODE_ERROR, thrown.getError().getCondition(),
+ String.format("Unexpected error code for %#02x", type));
}
}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/DeliveryRegistryImplTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/DeliveryRegistryImplTest.java
index 7c639e6..d88f59f 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/DeliveryRegistryImplTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/DeliveryRegistryImplTest.java
@@ -34,24 +34,25 @@
import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
import org.apache.qpid.test.utils.UnitTestBase;
-public class DeliveryRegistryImplTest extends UnitTestBase
+class DeliveryRegistryImplTest extends UnitTestBase
{
private static final UnsignedInteger DELIVERY_ID = UnsignedInteger.ZERO;
private static final UnsignedInteger DELIVERY_ID_2 = UnsignedInteger.ONE;
private static final Binary DELIVERY_TAG = new Binary(new byte[]{(byte) 32, (byte) 33});
private static final Binary DELIVERY_TAG_2 = new Binary(new byte[]{(byte) 32});
- private DeliveryRegistryImpl _registry;
private final UnsettledDelivery _unsettledDelivery = new UnsettledDelivery(DELIVERY_TAG, mock(LinkEndpoint.class));
+ private DeliveryRegistryImpl _registry;
+
@BeforeEach
- public void setUp()
+ void setUp()
{
_registry = new DeliveryRegistryImpl();
}
@Test
- public void addDelivery()
+ void addDelivery()
{
assertThat(_registry.size(), is(equalTo(0)));
@@ -61,7 +62,7 @@
}
@Test
- public void removeDelivery()
+ void removeDelivery()
{
_registry.addDelivery(DELIVERY_ID, _unsettledDelivery);
assertThat(_registry.size(), is(equalTo(1)));
@@ -71,7 +72,7 @@
}
@Test
- public void getDelivery()
+ void getDelivery()
{
_registry.addDelivery(DELIVERY_ID, _unsettledDelivery);
@@ -82,7 +83,7 @@
}
@Test
- public void removeDeliveriesForLinkEndpoint()
+ void removeDeliveriesForLinkEndpoint()
{
_registry.addDelivery(DELIVERY_ID, _unsettledDelivery);
_registry.addDelivery(DELIVERY_ID_2, new UnsettledDelivery(DELIVERY_TAG_2, _unsettledDelivery.getLinkEndpoint()));
@@ -96,7 +97,7 @@
}
@Test
- public void getDeliveryId()
+ void getDeliveryId()
{
_registry.addDelivery(DELIVERY_ID, _unsettledDelivery);
_registry.addDelivery(DELIVERY_ID_2, new UnsettledDelivery(DELIVERY_TAG, mock(LinkEndpoint.class)));
@@ -107,7 +108,7 @@
}
@Test
- public void size()
+ void size()
{
assertThat(_registry.size(), is(equalTo(0)));
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/UnsettledDeliveryTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/UnsettledDeliveryTest.java
index d604b5a..e914833 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/UnsettledDeliveryTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/delivery/UnsettledDeliveryTest.java
@@ -34,15 +34,16 @@
import org.apache.qpid.server.protocol.v1_0.type.Binary;
import org.apache.qpid.test.utils.UnitTestBase;
-public class UnsettledDeliveryTest extends UnitTestBase
+class UnsettledDeliveryTest extends UnitTestBase
{
private static final byte[] DATA = new byte[]{(byte) 32, (byte) 33, (byte) 34};
+
private Binary _deliveryTag;
private LinkEndpoint<?, ?> _linkEndpoint;
private UnsettledDelivery _unsettledDelivery;
@BeforeAll
- public void setUp()
+ void setUp()
{
_deliveryTag = new Binary(DATA);
_linkEndpoint = mock(LinkEndpoint.class);
@@ -50,47 +51,47 @@
}
@Test
- public void testGetDeliveryTag()
+ void getDeliveryTag()
{
assertThat(_unsettledDelivery.getDeliveryTag(), is(equalTo(_deliveryTag)));
}
@Test
- public void testGetLinkEndpoint()
+ void getLinkEndpoint()
{
assertThat(_unsettledDelivery.getLinkEndpoint(), is(equalTo(_linkEndpoint)));
}
@Test
- public void testEqualsToNewUnsettledDeliveryWithTheSameFields()
+ void equalsToNewUnsettledDeliveryWithTheSameFields()
{
assertThat(_unsettledDelivery.equals(new UnsettledDelivery(_deliveryTag, _linkEndpoint)), is(equalTo(true)));
}
@Test
- public void testEqualsToNewUnsettledDeliveryWithEqualsFields()
+ void equalsToNewUnsettledDeliveryWithEqualsFields()
{
assertThat(_unsettledDelivery.equals(new UnsettledDelivery(new Binary(DATA), _linkEndpoint)),
- is(equalTo(true)));
+ is(equalTo(true)));
}
@Test
- public void testNotEqualsWhenDeliveryTagIsDifferent()
+ void notEqualsWhenDeliveryTagIsDifferent()
{
assertThat(_unsettledDelivery.equals(new UnsettledDelivery(new Binary(new byte[]{(byte) 32, (byte) 33}),
- _linkEndpoint)), is(equalTo(false)));
+ _linkEndpoint)), is(equalTo(false)));
}
@Test
- public void testNotEqualsWhenLinkEndpointIsDifferent()
+ void notEqualsWhenLinkEndpointIsDifferent()
{
final LinkEndpoint<?, ?> linkEndpoint = mock(LinkEndpoint.class);
assertThat(_unsettledDelivery.equals(new UnsettledDelivery(new Binary(new byte[]{(byte) 32, (byte) 33}),
- linkEndpoint)), is(equalTo(false)));
+ linkEndpoint)), is(equalTo(false)));
}
@Test
- public void testHashCode()
+ void hashCodes()
{
int expected = Objects.hash(_deliveryTag, _linkEndpoint);
assertThat(_unsettledDelivery.hashCode(), is(equalTo(expected)));
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java
index 160e368..0f4aa8b 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java
@@ -40,25 +40,26 @@
import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
import org.apache.qpid.test.utils.UnitTestBase;
-public class FrameHandlerTest extends UnitTestBase
+class FrameHandlerTest extends UnitTestBase
{
private static final int MAX_FRAME_SIZE = 4096;
+
private ValueHandler _valueHandler;
@BeforeAll
- public void setUp() throws Exception
+ void setUp()
{
_valueHandler = new ValueHandler(AMQPDescribedTypeRegistry.newInstance());
}
@Test
- public void testSaslHeartbeat()
+ void saslHeartbeat()
{
- ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
+ final ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
when(connectionHandler.getMaxFrameSize()).thenReturn(MAX_FRAME_SIZE);
- FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
+ final FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
- QpidByteBuffer body = QpidByteBuffer.allocate(false, 8);
+ final QpidByteBuffer body = QpidByteBuffer.allocate(false, 8);
body.putInt(8); // size
body.put((byte)2); // DOFF
body.put((byte)1); // AMQP Frame Type
@@ -67,23 +68,23 @@
handler.parse(body);
- ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
+ final ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
verify(connectionHandler).handleError(errorCaptor.capture());
- Error error = errorCaptor.getValue();
+ final Error error = errorCaptor.getValue();
assertNotNull(error);
assertEquals(ConnectionError.FRAMING_ERROR, error.getCondition());
assertEquals("Empty (heartbeat) frames are not permitted during SASL negotiation", error.getDescription());
}
@Test
- public void testOversizedFrame()
+ void oversizedFrame()
{
- ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
+ final ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
when(connectionHandler.getMaxFrameSize()).thenReturn(MAX_FRAME_SIZE);
- FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
+ final FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
- QpidByteBuffer body = QpidByteBuffer.allocate(false, MAX_FRAME_SIZE + 8);
+ final QpidByteBuffer body = QpidByteBuffer.allocate(false, MAX_FRAME_SIZE + 8);
body.putInt(body.capacity()); // size
body.put((byte) 2); // DOFF
body.put((byte) 1); // AMQP Frame Type
@@ -93,10 +94,10 @@
handler.parse(body);
- ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
+ final ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
verify(connectionHandler).handleError(errorCaptor.capture());
- Error error = errorCaptor.getValue();
+ final Error error = errorCaptor.getValue();
assertNotNull(error);
assertEquals(ConnectionError.FRAMING_ERROR, error.getCondition());
assertEquals(String.format("specified frame size %s larger than maximum frame header size %s", body.capacity(),
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java
index 04e9a9f..ceb2212 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java
@@ -21,11 +21,11 @@
package org.apache.qpid.server.protocol.v1_0.store;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import java.util.Collection;
-import java.util.Collections;
+import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -71,15 +71,13 @@
_source.setDurable(TerminusDurability.UNSETTLED_STATE);
_source.setDynamic(Boolean.TRUE);
_source.setExpiryPolicy(TerminusExpiryPolicy.CONNECTION_CLOSE);
- _source.setFilter(Collections.singletonMap(Symbol.valueOf("foo"), NoLocalFilter.INSTANCE));
+ _source.setFilter(Map.of(Symbol.valueOf("foo"), NoLocalFilter.INSTANCE));
_source.setOutcomes(new Accepted().getSymbol());
- _source.setDynamicNodeProperties(Collections.singletonMap(Symbol.valueOf("dynamicProperty"),
- "dynamicPropertyValue"));
+ _source.setDynamicNodeProperties(Map.of(Symbol.valueOf("dynamicProperty"), "dynamicPropertyValue"));
_source.setTimeout(new UnsignedInteger(1));
_target.setTimeout(new UnsignedInteger(2));
- _target.setDynamicNodeProperties(Collections.singletonMap(Symbol.valueOf("targetDynamicProperty"),
- "targetDynamicPropertyValue"));
+ _target.setDynamicNodeProperties(Map.of(Symbol.valueOf("targetDynamicProperty"), "targetDynamicPropertyValue"));
_target.setDynamic(Boolean.TRUE);
_target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
_target.setAddress("bar");
@@ -94,22 +92,16 @@
}
@Test
- public void testOpenAndLoad()
+ public void openAndLoad()
{
Collection<LinkDefinition<Source, Target>> links = _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
assertTrue(links.isEmpty(), "Unexpected links");
- try
- {
- _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
- fail("Repeated open of already opened store should fail");
- }
- catch (StoreException e)
- {
- // pass
- }
+ assertThrows(StoreException.class,
+ () -> _linkStore.openAndLoad(new LinkStoreUpdaterImpl()),
+ "Repeated open of already opened store should fail");
- LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
+ final LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
_linkStore.saveLink(linkDefinition);
_linkStore.close();
@@ -117,48 +109,35 @@
assertEquals(1, links.size(), "Unexpected link number");
}
-
@Test
- public void testClose() throws Exception
+ public void close()
{
_linkStore.openAndLoad(new LinkStoreUpdaterImpl());
-
_linkStore.close();
- try
+
+ assertThrows(StoreException.class, () ->
{
LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
_linkStore.saveLink(linkDefinition);
- fail("Saving link with close store should fail");
- }
- catch (StoreException e)
- {
- // pass
- }
+ }, "Saving link with close store should fail");
}
@Test
- public void testSaveLink()
+ public void saveLink()
{
-
- LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
+ final LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
_linkStore.openAndLoad(new LinkStoreUpdaterImpl());
_linkStore.saveLink(linkDefinition);
_linkStore.close();
- try
- {
- _linkStore.saveLink(createLinkDefinition("2", "test2"));
- fail("Save on unopened database should fail");
- }
- catch (StoreException e)
- {
- // pass
- }
+ assertThrows(StoreException.class,
+ () -> _linkStore.saveLink(createLinkDefinition("2", "test2")),
+ "Save on unopened database should fail");
- Collection<LinkDefinition<Source, Target>> links = _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
+ final Collection<LinkDefinition<Source, Target>> links = _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
assertEquals(1, links.size(), "Unexpected link number");
- LinkDefinition<Source, Target> recoveredLink = links.iterator().next();
+ final LinkDefinition<Source, Target> recoveredLink = links.iterator().next();
assertEquals(linkDefinition.getName(), recoveredLink.getName(), "Unexpected link name");
assertEquals(linkDefinition.getRemoteContainerId(), recoveredLink.getRemoteContainerId(),
@@ -169,33 +148,27 @@
}
@Test
- public void testDeleteLink()
+ public void deleteLink()
{
_linkStore.openAndLoad(new LinkStoreUpdaterImpl());
- LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
+ final LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
_linkStore.saveLink(linkDefinition);
- LinkDefinition<Source, Target> linkDefinition2 = createLinkDefinition("2", "test2");
+ final LinkDefinition<Source, Target> linkDefinition2 = createLinkDefinition("2", "test2");
_linkStore.saveLink(linkDefinition2);
_linkStore.deleteLink(linkDefinition2);
_linkStore.close();
- try
- {
- _linkStore.deleteLink(linkDefinition);
- fail("Delete on unopened database should fail");
- }
- catch (StoreException e)
- {
- // pass
- }
+ assertThrows(StoreException.class,
+ () -> _linkStore.deleteLink(linkDefinition),
+ "Delete on unopened database should fail");
- Collection<LinkDefinition<Source, Target>> links = _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
+ final Collection<LinkDefinition<Source, Target>> links = _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
assertEquals(1, links.size(), "Unexpected link number");
- LinkDefinition<Source, Target> recoveredLink = links.iterator().next();
+ final LinkDefinition<Source, Target> recoveredLink = links.iterator().next();
assertEquals(linkDefinition.getName(), recoveredLink.getName(), "Unexpected link name");
assertEquals(linkDefinition.getRemoteContainerId(), recoveredLink.getRemoteContainerId(),
@@ -206,14 +179,14 @@
}
@Test
- public void testDelete()
+ public void delete()
{
_linkStore.openAndLoad(new LinkStoreUpdaterImpl());
- LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
+ final LinkDefinition<Source, Target> linkDefinition = createLinkDefinition("1", "test");
_linkStore.saveLink(linkDefinition);
- LinkDefinition<Source, Target> linkDefinition2 = createLinkDefinition("2", "test2");
+ final LinkDefinition<Source, Target> linkDefinition2 = createLinkDefinition("2", "test2");
_linkStore.saveLink(linkDefinition2);
_linkStore.close();
@@ -232,6 +205,6 @@
private LinkDefinitionImpl<Source, Target> createLinkDefinition(final String remoteContainerId, final String linkName)
{
- return new LinkDefinitionImpl(remoteContainerId, linkName, Role.RECEIVER, _source, _target);
+ return new LinkDefinitionImpl<>(remoteContainerId, linkName, Role.RECEIVER, _source, _target);
}
}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java
index f50903e..d54110b 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java
@@ -20,43 +20,38 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
import org.apache.qpid.test.utils.UnitTestBase;
import org.junit.jupiter.api.Test;
-public class SoleConnectionDetectionPolicyTest extends UnitTestBase
+class SoleConnectionDetectionPolicyTest extends UnitTestBase
{
@Test
- public void testValue()
+ void value()
{
assertEquals(new UnsignedInteger(0), SoleConnectionDetectionPolicy.STRONG.getValue());
assertEquals(new UnsignedInteger(1), SoleConnectionDetectionPolicy.WEAK.getValue());
}
@Test
- public void testValueOf()
+ void valueOf()
{
assertEquals(SoleConnectionDetectionPolicy.STRONG,
SoleConnectionDetectionPolicy.valueOf(new UnsignedInteger(0)));
assertEquals(SoleConnectionDetectionPolicy.WEAK,
SoleConnectionDetectionPolicy.valueOf(new UnsignedInteger(1)));
- try
- {
- SoleConnectionDetectionPolicy.valueOf(new UnsignedInteger(2));
- fail("An exception is expected");
- }
- catch (RuntimeException e)
- {
- assertNotNull(e.getMessage());
- }
+ final RuntimeException thrown = assertThrows(RuntimeException.class,
+ () -> SoleConnectionDetectionPolicy.valueOf(new UnsignedInteger(2)),
+ "An exception is expected");
+ assertNotNull(thrown.getMessage());
}
@Test
- public void testToString()
+ void toStrings()
{
assertEquals("strong", SoleConnectionDetectionPolicy.STRONG.toString());
assertEquals("weak", SoleConnectionDetectionPolicy.WEAK.toString());
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java
index d3a8357..61371cc 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java
@@ -20,44 +20,38 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
import org.apache.qpid.test.utils.UnitTestBase;
import org.junit.jupiter.api.Test;
-
-public class SoleConnectionEnforcementPolicyTest extends UnitTestBase
+class SoleConnectionEnforcementPolicyTest extends UnitTestBase
{
@Test
- public void testValue()
+ void value()
{
assertEquals(new UnsignedInteger(0), SoleConnectionEnforcementPolicy.REFUSE_CONNECTION.getValue());
assertEquals(new UnsignedInteger(1), SoleConnectionEnforcementPolicy.CLOSE_EXISTING.getValue());
}
@Test
- public void testValueOf()
+ void valueOf()
{
assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION,
SoleConnectionEnforcementPolicy.valueOf(new UnsignedInteger(0)));
assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING,
SoleConnectionEnforcementPolicy.valueOf(new UnsignedInteger(1)));
- try
- {
- SoleConnectionEnforcementPolicy.valueOf(new UnsignedInteger(2));
- fail("An exception is expected");
- }
- catch (RuntimeException e)
- {
- assertNotNull(e.getMessage());
- }
+ final RuntimeException thrown = assertThrows(RuntimeException.class,
+ () -> SoleConnectionEnforcementPolicy.valueOf(new UnsignedInteger(2)),
+ "An exception is expected");
+ assertNotNull(thrown.getMessage());
}
@Test
- public void testToString()
+ void toStrings()
{
assertEquals("refuse-connection", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION.toString());
assertEquals("close-existing", SoleConnectionEnforcementPolicy.CLOSE_EXISTING.toString());
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/StrongConnectionEstablishmentLimiterTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/StrongConnectionEstablishmentLimiterTest.java
index bcb3d13..396ebe0 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/StrongConnectionEstablishmentLimiterTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/StrongConnectionEstablishmentLimiterTest.java
@@ -20,8 +20,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verifyNoInteractions;
import java.util.HashSet;
import java.util.Objects;
@@ -38,27 +40,27 @@
import org.mockito.Mockito;
-public class StrongConnectionEstablishmentLimiterTest extends UnitTestBase
+class StrongConnectionEstablishmentLimiterTest extends UnitTestBase
{
private StrongConnectionEstablishmentLimiter _limiter;
private Registry _registry;
@BeforeAll
- public void setUp()
+ void setUp()
{
_registry = new Registry();
_limiter = (StrongConnectionEstablishmentLimiter) new StrongConnectionEstablishmentLimiter().append(_registry);
}
@Test
- public void testType()
+ void type()
{
assertEquals("EstablishmentPolicy.strong", _limiter.getType());
}
@Test
- public void testNoPolicy()
+ void noPolicy()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C", null);
final ConnectionSlot slot1 = _limiter.register(connection1);
@@ -86,7 +88,7 @@
}
@Test
- public void testNewConnectionWithPolicy()
+ void newConnectionWithPolicy()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C", null);
final ConnectionSlot slot1 = _limiter.register(connection1);
@@ -97,21 +99,18 @@
assertTrue(_registry.isRegistered(connection2));
final AMQPConnection_1_0<?> connection3 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
- try
- {
- _limiter.register(connection3);
- fail("A sole connection enforcement policy exception is expected");
- }
- catch (SoleConnectionEnforcementPolicyException e)
- {
- assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'refuse-connection'",
- e.getMessage());
- assertEquals(2, e.getExistingConnections().size());
- assertTrue(e.getExistingConnections().contains(connection1));
- assertTrue(e.getExistingConnections().contains(connection2));
- assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION, e.getPolicy());
- }
+ final SoleConnectionEnforcementPolicyException thrown = assertThrows(SoleConnectionEnforcementPolicyException.class,
+ () -> _limiter.register(connection3),
+ "A sole connection enforcement policy exception is expected");
+
+ assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'refuse-connection'",
+ thrown.getMessage());
+
+ assertEquals(2, thrown.getExistingConnections().size());
+ assertTrue(thrown.getExistingConnections().contains(connection1));
+ assertTrue(thrown.getExistingConnections().contains(connection2));
+ assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION, thrown.getPolicy());
slot2.free();
assertFalse(_registry.isRegistered(connection2));
@@ -123,27 +122,24 @@
}
@Test
- public void testExistingConnectionWithPolicy()
+ void existingConnectionWithPolicy()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
- try
- {
- _limiter.register(connection2);
- fail("A sole connection enforcement policy exception is expected");
- }
- catch (SoleConnectionEnforcementPolicyException e)
- {
- assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'close-existing'",
- e.getMessage());
- assertEquals(1, e.getExistingConnections().size());
- assertTrue(e.getExistingConnections().contains(connection1));
- assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING, e.getPolicy());
- }
+ final SoleConnectionEnforcementPolicyException thrown = assertThrows(SoleConnectionEnforcementPolicyException.class,
+ () -> _limiter.register(connection2),
+ "A sole connection enforcement policy exception is expected");
+
+ assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'close-existing'",
+ thrown.getMessage());
+
+ assertEquals(1, thrown.getExistingConnections().size());
+ assertTrue(thrown.getExistingConnections().contains(connection1));
+ assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING, thrown.getPolicy());
slot1.free();
assertFalse(_registry.isRegistered(connection1));
@@ -151,14 +147,14 @@
}
@Test
- public void testExistingClosedConnectionWithPolicy()
+ void existingClosedConnectionWithPolicy()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
- Mockito.doReturn(false).when(connection1).isClosing();
+ doReturn(false).when(connection1).isClosing();
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
- Mockito.doReturn(true).when(connection1).isClosing();
+ doReturn(true).when(connection1).isClosing();
final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
final ConnectionSlot slot2 = _limiter.register(connection2);
assertTrue(_registry.isRegistered(connection2));
@@ -173,14 +169,14 @@
}
@Test
- public void testClosedConnection()
+ void closedConnection()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
- Mockito.doReturn(true).when(connection1).isClosing();
+ doReturn(true).when(connection1).isClosing();
final ConnectionSlot slot2 = _limiter.register(connection2);
assertTrue(_registry.isRegistered(connection2));
@@ -194,33 +190,30 @@
}
@Test
- public void testNewConnectionWithPolicy_ClosedExisting()
+ void newConnectionWithPolicy_ClosedExisting()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
- Mockito.doReturn(false).when(connection1).isClosing();
+ doReturn(false).when(connection1).isClosing();
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
- Mockito.doReturn(true).when(connection1).isClosing();
+ doReturn(true).when(connection1).isClosing();
final AMQPConnection_1_0<?> connection2 = newConnection("C", null);
final ConnectionSlot slot2 = _limiter.register(connection2);
assertTrue(_registry.isRegistered(connection2));
final AMQPConnection_1_0<?> connection3 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
- try
- {
- _limiter.register(connection3);
- fail("A sole connection enforcement policy exception is expected");
- }
- catch (SoleConnectionEnforcementPolicyException e)
- {
- assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'close-existing'",
- e.getMessage());
- assertEquals(1, e.getExistingConnections().size());
- assertTrue(e.getExistingConnections().contains(connection2));
- assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING, e.getPolicy());
- }
+ final SoleConnectionEnforcementPolicyException thrown = assertThrows(SoleConnectionEnforcementPolicyException.class,
+ () -> _limiter.register(connection3),
+ "A sole connection enforcement policy exception is expected");
+
+ assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'close-existing'",
+ thrown.getMessage());
+
+ assertEquals(1, thrown.getExistingConnections().size());
+ assertTrue(thrown.getExistingConnections().contains(connection2));
+ assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING, thrown.getPolicy());
slot2.free();
assertFalse(_registry.isRegistered(connection2));
@@ -232,33 +225,30 @@
}
@Test
- public void testNewConnectionWithPolicy2_ClosedExisting()
+ void newConnectionWithPolicy2_ClosedExisting()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
- Mockito.doReturn(false).when(connection1).isClosing();
+ doReturn(false).when(connection1).isClosing();
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
- Mockito.doReturn(true).when(connection1).isClosing();
+ doReturn(true).when(connection1).isClosing();
final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
final ConnectionSlot slot2 = _limiter.register(connection2);
assertTrue(_registry.isRegistered(connection2));
final AMQPConnection_1_0<?> connection3 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
- try
- {
- _limiter.register(connection3);
- fail("A sole connection enforcement policy exception is expected");
- }
- catch (SoleConnectionEnforcementPolicyException e)
- {
- assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'refuse-connection'",
- e.getMessage());
- assertEquals(1, e.getExistingConnections().size());
- assertTrue(e.getExistingConnections().contains(connection2));
- assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION, e.getPolicy());
- }
+ final SoleConnectionEnforcementPolicyException thrown = assertThrows(SoleConnectionEnforcementPolicyException.class,
+ () -> _limiter.register(connection3),
+ "A sole connection enforcement policy exception is expected");
+
+ assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'refuse-connection'",
+ thrown.getMessage());
+
+ assertEquals(1, thrown.getExistingConnections().size());
+ assertTrue(thrown.getExistingConnections().contains(connection2));
+ assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION, thrown.getPolicy());
slot2.free();
assertFalse(_registry.isRegistered(connection2));
@@ -270,7 +260,7 @@
}
@Test
- public void testAnotherConnectionType()
+ void anotherConnectionType()
{
final AMQPConnection<?> connection = Mockito.mock(AMQPConnection.class);
final ConnectionSlot slot = _limiter.register(connection);
@@ -278,11 +268,11 @@
slot.free();
assertFalse(_registry.isRegistered(connection));
assertTrue(_registry.hasBeenRegistered(connection));
- Mockito.verifyNoInteractions(connection);
+ verifyNoInteractions(connection);
}
@Test
- public void testMultipleIndependentConnections()
+ void multipleIndependentConnections()
{
final AMQPConnection_1_0<?> connection1 = newConnection("C1", null);
final ConnectionSlot slot1 = _limiter.register(connection1);
@@ -310,7 +300,7 @@
}
@Test
- public void testMultipleIndependentConnections2()
+ void multipleIndependentConnections2()
{
final AMQPConnection_1_0<?> connection1 = newConnection(null, null);
final ConnectionSlot slot1 = _limiter.register(connection1);
@@ -340,17 +330,15 @@
private AMQPConnection_1_0<?> newConnection(String id, SoleConnectionEnforcementPolicy policy)
{
final AMQPConnection_1_0<?> connection = Mockito.mock(AMQPConnection_1_0.class);
- Mockito.doReturn(id).when(connection).getRemoteContainerId();
- Mockito.doReturn(policy).when(connection).getSoleConnectionEnforcementPolicy();
+ doReturn(id).when(connection).getRemoteContainerId();
+ doReturn(policy).when(connection).getSoleConnectionEnforcementPolicy();
return connection;
}
static final class Registry implements ConnectionLimiter
{
private final Set<AMQPConnection<?>> _registered;
-
private final Set<AMQPConnection<?>> _connections;
-
private final ConnectionLimiter _subLimiter;
public Registry()
@@ -360,7 +348,7 @@
_subLimiter = ConnectionLimiter.noLimits();
}
- private Registry(Registry limiter, ConnectionLimiter subLimiter)
+ private Registry(final Registry limiter, final ConnectionLimiter subLimiter)
{
_registered = limiter._registered;
_connections = limiter._connections;
@@ -377,17 +365,17 @@
}
@Override
- public ConnectionLimiter append(ConnectionLimiter limiter)
+ public ConnectionLimiter append(final ConnectionLimiter limiter)
{
return new Registry(this, _subLimiter.append(limiter));
}
- public boolean isRegistered(AMQPConnection<?> connection)
+ public boolean isRegistered(final AMQPConnection<?> connection)
{
return _connections.contains(connection);
}
- public boolean hasBeenRegistered(AMQPConnection<?> connection)
+ public boolean hasBeenRegistered(final AMQPConnection<?> connection)
{
return _registered.contains(connection);
}