Migrate tests to AssertJ

Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj
There is still a lot of work to do when complex and composite matchers are used.

* Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor
of `awaitility`
* Remove Hamcrest from dependencies and disable JUnit & Hamcrest
static imports to encourage to use only AssertJ
* Migrate JUnit assumptions in rules to AssertJ's assumptions
* Deprecate some custom matchers in favor of existing in Hamcrest
after upgrading the last to version `2.1`
* Replace `ExpectedException` rules with `assertThatThrownBy()`
* Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
Artem Bilan
2019-02-20 12:28:44 -05:00
parent b62c2a8fb3
commit 622d42c71a
916 changed files with 19714 additions and 21769 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,7 @@
package org.springframework.integration.ip.config;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Iterator;
import java.util.Set;
@@ -282,111 +274,111 @@ public class ParserUnitTests {
@Test
public void testInUdp() {
DirectFieldAccessor dfa = new DirectFieldAccessor(udpIn);
assertEquals(27, dfa.getPropertyValue("poolSize"));
assertEquals(29, dfa.getPropertyValue("receiveBufferSize"));
assertEquals(30, dfa.getPropertyValue("soReceiveBufferSize"));
assertEquals(31, dfa.getPropertyValue("soSendBufferSize"));
assertEquals(32, dfa.getPropertyValue("soTimeout"));
assertEquals("testInUdp", udpIn.getComponentName());
assertEquals("ip:udp-inbound-channel-adapter", udpIn.getComponentType());
assertEquals("127.0.0.1", dfa.getPropertyValue("localAddress"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertEquals(errorChannel, dfa.getPropertyValue("errorChannel"));
assertThat(dfa.getPropertyValue("poolSize")).isEqualTo(27);
assertThat(dfa.getPropertyValue("receiveBufferSize")).isEqualTo(29);
assertThat(dfa.getPropertyValue("soReceiveBufferSize")).isEqualTo(30);
assertThat(dfa.getPropertyValue("soSendBufferSize")).isEqualTo(31);
assertThat(dfa.getPropertyValue("soTimeout")).isEqualTo(32);
assertThat(udpIn.getComponentName()).isEqualTo("testInUdp");
assertThat(udpIn.getComponentType()).isEqualTo("ip:udp-inbound-channel-adapter");
assertThat(dfa.getPropertyValue("localAddress")).isEqualTo("127.0.0.1");
assertThat(dfa.getPropertyValue("taskExecutor")).isSameAs(taskExecutor);
assertThat(dfa.getPropertyValue("errorChannel")).isEqualTo(errorChannel);
DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa.getPropertyValue("mapper");
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);
assertFalse((Boolean) mapperAccessor.getPropertyValue("lookupHost"));
assertFalse(TestUtils.getPropertyValue(udpIn, "autoStartup", Boolean.class));
assertEquals(1234, dfa.getPropertyValue("phase"));
assertThat((Boolean) mapperAccessor.getPropertyValue("lookupHost")).isFalse();
assertThat(TestUtils.getPropertyValue(udpIn, "autoStartup", Boolean.class)).isFalse();
assertThat(dfa.getPropertyValue("phase")).isEqualTo(1234);
}
@Test
public void testInUdpMulticast() {
DirectFieldAccessor dfa = new DirectFieldAccessor(udpInMulticast);
assertEquals("225.6.7.8", dfa.getPropertyValue("group"));
assertEquals(27, dfa.getPropertyValue("poolSize"));
assertEquals(29, dfa.getPropertyValue("receiveBufferSize"));
assertEquals(30, dfa.getPropertyValue("soReceiveBufferSize"));
assertEquals(31, dfa.getPropertyValue("soSendBufferSize"));
assertEquals(32, dfa.getPropertyValue("soTimeout"));
assertEquals("127.0.0.1", dfa.getPropertyValue("localAddress"));
assertNotSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertNull(dfa.getPropertyValue("errorChannel"));
assertThat(dfa.getPropertyValue("group")).isEqualTo("225.6.7.8");
assertThat(dfa.getPropertyValue("poolSize")).isEqualTo(27);
assertThat(dfa.getPropertyValue("receiveBufferSize")).isEqualTo(29);
assertThat(dfa.getPropertyValue("soReceiveBufferSize")).isEqualTo(30);
assertThat(dfa.getPropertyValue("soSendBufferSize")).isEqualTo(31);
assertThat(dfa.getPropertyValue("soTimeout")).isEqualTo(32);
assertThat(dfa.getPropertyValue("localAddress")).isEqualTo("127.0.0.1");
assertThat(dfa.getPropertyValue("taskExecutor")).isNotSameAs(taskExecutor);
assertThat(dfa.getPropertyValue("errorChannel")).isNull();
DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa.getPropertyValue("mapper");
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);
assertTrue((Boolean) mapperAccessor.getPropertyValue("lookupHost"));
assertThat((Boolean) mapperAccessor.getPropertyValue("lookupHost")).isTrue();
}
@Test
public void testInTcp() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpIn);
assertSame(cfS1, dfa.getPropertyValue("serverConnectionFactory"));
assertEquals("testInTcp", tcpIn.getComponentName());
assertEquals("ip:tcp-inbound-channel-adapter", tcpIn.getComponentType());
assertEquals(errorChannel, dfa.getPropertyValue("errorChannel"));
assertFalse(cfS1.isLookupHost());
assertFalse(tcpIn.isAutoStartup());
assertEquals(124, tcpIn.getPhase());
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isSameAs(cfS1);
assertThat(tcpIn.getComponentName()).isEqualTo("testInTcp");
assertThat(tcpIn.getComponentType()).isEqualTo("ip:tcp-inbound-channel-adapter");
assertThat(dfa.getPropertyValue("errorChannel")).isEqualTo(errorChannel);
assertThat(cfS1.isLookupHost()).isFalse();
assertThat(tcpIn.isAutoStartup()).isFalse();
assertThat(tcpIn.getPhase()).isEqualTo(124);
TcpMessageMapper cfS1Mapper = TestUtils.getPropertyValue(cfS1, "mapper", TcpMessageMapper.class);
assertSame(mapper, cfS1Mapper);
assertTrue(TestUtils.getPropertyValue(cfS1Mapper, "applySequence", Boolean.class));
assertThat(cfS1Mapper).isSameAs(mapper);
assertThat(TestUtils.getPropertyValue(cfS1Mapper, "applySequence", Boolean.class)).isTrue();
Object socketSupport = TestUtils.getPropertyValue(cfS1, "tcpSocketFactorySupport");
assertTrue(socketSupport instanceof DefaultTcpNetSSLSocketFactorySupport);
assertNotNull(TestUtils.getPropertyValue(socketSupport, "sslContext"));
assertThat(socketSupport instanceof DefaultTcpNetSSLSocketFactorySupport).isTrue();
assertThat(TestUtils.getPropertyValue(socketSupport, "sslContext")).isNotNull();
TcpSSLContextSupport tcpSSLContextSupport = new DefaultTcpSSLContextSupport("http:foo", "file:bar", "", "");
assertTrue(TestUtils.getPropertyValue(tcpSSLContextSupport, "keyStore") instanceof UrlResource);
assertTrue(TestUtils.getPropertyValue(tcpSSLContextSupport, "trustStore") instanceof UrlResource);
assertThat(TestUtils.getPropertyValue(tcpSSLContextSupport, "keyStore") instanceof UrlResource).isTrue();
assertThat(TestUtils.getPropertyValue(tcpSSLContextSupport, "trustStore") instanceof UrlResource).isTrue();
}
@Test
public void testInTcpNioSSLDefaultConfig() {
assertFalse(cfS1Nio.isLookupHost());
assertTrue(TestUtils.getPropertyValue(cfS1Nio, "mapper.applySequence", Boolean.class));
assertThat(cfS1Nio.isLookupHost()).isFalse();
assertThat(TestUtils.getPropertyValue(cfS1Nio, "mapper.applySequence", Boolean.class)).isTrue();
Object connectionSupport = TestUtils.getPropertyValue(cfS1Nio, "tcpNioConnectionSupport");
assertTrue(connectionSupport instanceof DefaultTcpNioSSLConnectionSupport);
assertNotNull(TestUtils.getPropertyValue(connectionSupport, "sslContext"));
assertEquals(43, TestUtils.getPropertyValue(this.cfS1Nio, "sslHandshakeTimeout"));
assertSame(this.ctx.getBean(DefaultTcpNioSSLConnectionSupport.class),
TestUtils.getPropertyValue(this.cfS1Nio, "tcpNioConnectionSupport"));
assertThat(connectionSupport instanceof DefaultTcpNioSSLConnectionSupport).isTrue();
assertThat(TestUtils.getPropertyValue(connectionSupport, "sslContext")).isNotNull();
assertThat(TestUtils.getPropertyValue(this.cfS1Nio, "sslHandshakeTimeout")).isEqualTo(43);
assertThat(TestUtils.getPropertyValue(this.cfS1Nio, "tcpNioConnectionSupport"))
.isSameAs(this.ctx.getBean(DefaultTcpNioSSLConnectionSupport.class));
}
@Test
public void testOutUdp() {
DirectFieldAccessor dfa = new DirectFieldAccessor(udpOut);
assertEquals("localhost", dfa.getPropertyValue("host"));
assertThat(dfa.getPropertyValue("host")).isEqualTo("localhost");
DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa
.getPropertyValue("mapper");
String ackAddress = (String) new DirectFieldAccessor(mapper)
.getPropertyValue("ackAddress");
assertThat(ackAddress, startsWith("somehost:"));
assertEquals(51, dfa.getPropertyValue("ackTimeout"));
assertEquals(true, dfa.getPropertyValue("waitForAck"));
assertEquals(52, dfa.getPropertyValue("soReceiveBufferSize"));
assertEquals(53, dfa.getPropertyValue("soSendBufferSize"));
assertEquals(54, dfa.getPropertyValue("soTimeout"));
assertEquals("127.0.0.1", dfa.getPropertyValue("localAddress"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertEquals(23, dfa.getPropertyValue("order"));
assertEquals("testOutUdp", udpOut.getComponentName());
assertEquals("ip:udp-outbound-channel-adapter", udpOut.getComponentType());
assertThat(ackAddress).startsWith("somehost:");
assertThat(dfa.getPropertyValue("ackTimeout")).isEqualTo(51);
assertThat(dfa.getPropertyValue("waitForAck")).isEqualTo(true);
assertThat(dfa.getPropertyValue("soReceiveBufferSize")).isEqualTo(52);
assertThat(dfa.getPropertyValue("soSendBufferSize")).isEqualTo(53);
assertThat(dfa.getPropertyValue("soTimeout")).isEqualTo(54);
assertThat(dfa.getPropertyValue("localAddress")).isEqualTo("127.0.0.1");
assertThat(dfa.getPropertyValue("taskExecutor")).isSameAs(taskExecutor);
assertThat(dfa.getPropertyValue("order")).isEqualTo(23);
assertThat(udpOut.getComponentName()).isEqualTo("testOutUdp");
assertThat(udpOut.getComponentType()).isEqualTo("ip:udp-outbound-channel-adapter");
}
@Test
public void testOutUdpMulticast() {
DirectFieldAccessor dfa = new DirectFieldAccessor(udpOutMulticast);
assertEquals("225.6.7.8", dfa.getPropertyValue("host"));
assertThat(dfa.getPropertyValue("host")).isEqualTo("225.6.7.8");
DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa
.getPropertyValue("mapper");
String ackAddress = (String) new DirectFieldAccessor(mapper)
.getPropertyValue("ackAddress");
assertThat(ackAddress, startsWith("somehost:"));
assertEquals(51, dfa.getPropertyValue("ackTimeout"));
assertEquals(true, dfa.getPropertyValue("waitForAck"));
assertEquals(52, dfa.getPropertyValue("soReceiveBufferSize"));
assertEquals(53, dfa.getPropertyValue("soSendBufferSize"));
assertEquals(54, dfa.getPropertyValue("soTimeout"));
assertEquals(55, dfa.getPropertyValue("timeToLive"));
assertEquals(12, dfa.getPropertyValue("order"));
assertThat(ackAddress).startsWith("somehost:");
assertThat(dfa.getPropertyValue("ackTimeout")).isEqualTo(51);
assertThat(dfa.getPropertyValue("waitForAck")).isEqualTo(true);
assertThat(dfa.getPropertyValue("soReceiveBufferSize")).isEqualTo(52);
assertThat(dfa.getPropertyValue("soSendBufferSize")).isEqualTo(53);
assertThat(dfa.getPropertyValue("soTimeout")).isEqualTo(54);
assertThat(dfa.getPropertyValue("timeToLive")).isEqualTo(55);
assertThat(dfa.getPropertyValue("order")).isEqualTo(12);
}
@Test
@@ -397,197 +389,200 @@ public class ParserUnitTests {
TestUtils.getPropertyValue(this.udpChannel, "dispatcher"),
"handlers");
Iterator<MessageHandler> iterator = handlers.iterator();
assertSame(this.udpOutMulticast, iterator.next());
assertSame(this.udpOut, iterator.next());
assertThat(iterator.next()).isSameAs(this.udpOutMulticast);
assertThat(iterator.next()).isSameAs(this.udpOut);
}
@Test
public void udpAdvice() throws InterruptedException {
adviceCalled = new CountDownLatch(1);
this.udpAdviceChannel.send(new GenericMessage<String>("foo"));
assertTrue(adviceCalled.await(10, TimeUnit.SECONDS));
assertThat(adviceCalled.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
public void tcpAdvice() throws InterruptedException {
adviceCalled = new CountDownLatch(1);
this.tcpAdviceChannel.send(new GenericMessage<String>("foo"));
assertTrue(adviceCalled.await(10, TimeUnit.SECONDS));
assertThat(adviceCalled.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
public void tcpGatewayAdvice() throws InterruptedException {
adviceCalled = new CountDownLatch(1);
this.tcpAdviceGateChannel.send(new GenericMessage<String>("foo"));
assertTrue(adviceCalled.await(10, TimeUnit.SECONDS));
assertThat(adviceCalled.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
public void testOutTcp() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpOut);
assertSame(cfC1, dfa.getPropertyValue("clientConnectionFactory"));
assertEquals("testOutTcpNio", tcpOut.getComponentName());
assertEquals("ip:tcp-outbound-channel-adapter", tcpOut.getComponentType());
assertFalse(cfC1.isLookupHost());
assertEquals(35, dfa.getPropertyValue("order"));
assertFalse(tcpOutEndpoint.isAutoStartup());
assertEquals(125, tcpOutEndpoint.getPhase());
assertFalse((Boolean) TestUtils.getPropertyValue(
TestUtils.getPropertyValue(cfC1, "mapper"), "applySequence"));
assertEquals(10000L, TestUtils.getPropertyValue(cfC1, "readDelay"));
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(cfC1);
assertThat(tcpOut.getComponentName()).isEqualTo("testOutTcpNio");
assertThat(tcpOut.getComponentType()).isEqualTo("ip:tcp-outbound-channel-adapter");
assertThat(cfC1.isLookupHost()).isFalse();
assertThat(dfa.getPropertyValue("order")).isEqualTo(35);
assertThat(tcpOutEndpoint.isAutoStartup()).isFalse();
assertThat(tcpOutEndpoint.getPhase()).isEqualTo(125);
assertThat((Boolean) TestUtils.getPropertyValue(
TestUtils.getPropertyValue(cfC1, "mapper"), "applySequence")).isFalse();
assertThat(TestUtils.getPropertyValue(cfC1, "readDelay")).isEqualTo(10000L);
}
@Test
public void testInGateway1() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpInboundGateway1);
assertSame(cfS2, dfa.getPropertyValue("serverConnectionFactory"));
assertEquals(456L, dfa.getPropertyValue("replyTimeout"));
assertEquals("inGateway1", tcpInboundGateway1.getComponentName());
assertEquals("ip:tcp-inbound-gateway", tcpInboundGateway1.getComponentType());
assertEquals(errorChannel, tcpInboundGateway1.getErrorChannel());
assertTrue(cfS2.isLookupHost());
assertFalse(tcpInboundGateway1.isAutoStartup());
assertEquals(126, tcpInboundGateway1.getPhase());
assertFalse((Boolean) TestUtils.getPropertyValue(
TestUtils.getPropertyValue(cfS2, "mapper"), "applySequence"));
assertEquals(100L, TestUtils.getPropertyValue(cfS2, "readDelay"));
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isSameAs(cfS2);
assertThat(dfa.getPropertyValue("replyTimeout")).isEqualTo(456L);
assertThat(tcpInboundGateway1.getComponentName()).isEqualTo("inGateway1");
assertThat(tcpInboundGateway1.getComponentType()).isEqualTo("ip:tcp-inbound-gateway");
assertThat(tcpInboundGateway1.getErrorChannel()).isEqualTo(errorChannel);
assertThat(cfS2.isLookupHost()).isTrue();
assertThat(tcpInboundGateway1.isAutoStartup()).isFalse();
assertThat(tcpInboundGateway1.getPhase()).isEqualTo(126);
assertThat((Boolean) TestUtils.getPropertyValue(
TestUtils.getPropertyValue(cfS2, "mapper"), "applySequence")).isFalse();
assertThat(TestUtils.getPropertyValue(cfS2, "readDelay")).isEqualTo(100L);
}
@Test
public void testInGateway2() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpInboundGateway2);
assertSame(cfS3, dfa.getPropertyValue("serverConnectionFactory"));
assertEquals(456L, dfa.getPropertyValue("replyTimeout"));
assertEquals("inGateway2", tcpInboundGateway2.getComponentName());
assertEquals("ip:tcp-inbound-gateway", tcpInboundGateway2.getComponentType());
assertNull(dfa.getPropertyValue("errorChannel"));
assertEquals(Boolean.FALSE, dfa.getPropertyValue("isClientMode"));
assertNull(dfa.getPropertyValue("taskScheduler"));
assertEquals(60000L, dfa.getPropertyValue("retryInterval"));
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isSameAs(cfS3);
assertThat(dfa.getPropertyValue("replyTimeout")).isEqualTo(456L);
assertThat(tcpInboundGateway2.getComponentName()).isEqualTo("inGateway2");
assertThat(tcpInboundGateway2.getComponentType()).isEqualTo("ip:tcp-inbound-gateway");
assertThat(dfa.getPropertyValue("errorChannel")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("taskScheduler")).isNull();
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(60000L);
}
@Test
public void testOutGateway() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpOutboundGateway);
assertSame(cfC2, dfa.getPropertyValue("connectionFactory"));
assertEquals(234L, dfa.getPropertyValue("requestTimeout"));
assertThat(dfa.getPropertyValue("connectionFactory")).isSameAs(cfC2);
assertThat(dfa.getPropertyValue("requestTimeout")).isEqualTo(234L);
MessagingTemplate messagingTemplate = TestUtils.getPropertyValue(tcpOutboundGateway, "messagingTemplate",
MessagingTemplate.class);
assertEquals(Long.valueOf(567), TestUtils.getPropertyValue(messagingTemplate, "sendTimeout", Long.class));
assertEquals("789", TestUtils.getPropertyValue(tcpOutboundGateway, "remoteTimeoutExpression.literalValue"));
assertEquals("outGateway", tcpOutboundGateway.getComponentName());
assertEquals("ip:tcp-outbound-gateway", tcpOutboundGateway.getComponentType());
assertTrue(cfC2.isLookupHost());
assertEquals(24, dfa.getPropertyValue("order"));
assertThat(TestUtils.getPropertyValue(messagingTemplate, "sendTimeout", Long.class))
.isEqualTo(Long.valueOf(567));
assertThat(TestUtils.getPropertyValue(tcpOutboundGateway, "remoteTimeoutExpression.literalValue"))
.isEqualTo("789");
assertThat(tcpOutboundGateway.getComponentName()).isEqualTo("outGateway");
assertThat(tcpOutboundGateway.getComponentType()).isEqualTo("ip:tcp-outbound-gateway");
assertThat(cfC2.isLookupHost()).isTrue();
assertThat(dfa.getPropertyValue("order")).isEqualTo(24);
assertEquals("4000", TestUtils.getPropertyValue(outAdviceGateway, "remoteTimeoutExpression.expression"));
assertThat(TestUtils.getPropertyValue(outAdviceGateway, "remoteTimeoutExpression.expression"))
.isEqualTo("4000");
}
@Test
public void testConnClient1() {
assertTrue(client1 instanceof TcpNioClientConnectionFactory);
assertEquals("localhost", client1.getHost());
assertEquals(54, client1.getSoLinger());
assertEquals(1234, client1.getSoReceiveBufferSize());
assertEquals(1235, client1.getSoSendBufferSize());
assertEquals(1236, client1.getSoTimeout());
assertEquals(12, client1.getSoTrafficClass());
assertThat(client1 instanceof TcpNioClientConnectionFactory).isTrue();
assertThat(client1.getHost()).isEqualTo("localhost");
assertThat(client1.getSoLinger()).isEqualTo(54);
assertThat(client1.getSoReceiveBufferSize()).isEqualTo(1234);
assertThat(client1.getSoSendBufferSize()).isEqualTo(1235);
assertThat(client1.getSoTimeout()).isEqualTo(1236);
assertThat(client1.getSoTrafficClass()).isEqualTo(12);
DirectFieldAccessor dfa = new DirectFieldAccessor(client1);
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertEquals(true, dfa.getPropertyValue("usingDirectBuffers"));
assertNotNull(dfa.getPropertyValue("interceptorFactoryChain"));
assertThat(dfa.getPropertyValue("serializer")).isSameAs(serializer);
assertThat(dfa.getPropertyValue("deserializer")).isSameAs(deserializer);
assertThat(dfa.getPropertyValue("soTcpNoDelay")).isEqualTo(true);
assertThat(dfa.getPropertyValue("singleUse")).isEqualTo(true);
assertThat(dfa.getPropertyValue("taskExecutor")).isSameAs(taskExecutor);
assertThat(dfa.getPropertyValue("usingDirectBuffers")).isEqualTo(true);
assertThat(dfa.getPropertyValue("interceptorFactoryChain")).isNotNull();
}
@Test
public void testConnServer1() {
assertTrue(server1 instanceof TcpNioServerConnectionFactory);
assertEquals(55, server1.getSoLinger());
assertEquals(1234, server1.getSoReceiveBufferSize());
assertEquals(1235, server1.getSoSendBufferSize());
assertEquals(1236, server1.getSoTimeout());
assertEquals(12, server1.getSoTrafficClass());
assertThat(server1 instanceof TcpNioServerConnectionFactory).isTrue();
assertThat(server1.getSoLinger()).isEqualTo(55);
assertThat(server1.getSoReceiveBufferSize()).isEqualTo(1234);
assertThat(server1.getSoSendBufferSize()).isEqualTo(1235);
assertThat(server1.getSoTimeout()).isEqualTo(1236);
assertThat(server1.getSoTrafficClass()).isEqualTo(12);
DirectFieldAccessor dfa = new DirectFieldAccessor(server1);
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertEquals(123, dfa.getPropertyValue("backlog"));
assertEquals(true, dfa.getPropertyValue("usingDirectBuffers"));
assertNotNull(dfa.getPropertyValue("interceptorFactoryChain"));
assertThat(dfa.getPropertyValue("serializer")).isSameAs(serializer);
assertThat(dfa.getPropertyValue("deserializer")).isSameAs(deserializer);
assertThat(dfa.getPropertyValue("soTcpNoDelay")).isEqualTo(true);
assertThat(dfa.getPropertyValue("singleUse")).isEqualTo(true);
assertThat(dfa.getPropertyValue("taskExecutor")).isSameAs(taskExecutor);
assertThat(dfa.getPropertyValue("backlog")).isEqualTo(123);
assertThat(dfa.getPropertyValue("usingDirectBuffers")).isEqualTo(true);
assertThat(dfa.getPropertyValue("interceptorFactoryChain")).isNotNull();
}
@Test
public void testConnClient2() {
assertTrue(client2 instanceof TcpNetClientConnectionFactory);
assertEquals("localhost", client1.getHost());
assertEquals(54, client1.getSoLinger());
assertEquals(1234, client1.getSoReceiveBufferSize());
assertEquals(1235, client1.getSoSendBufferSize());
assertEquals(1236, client1.getSoTimeout());
assertEquals(12, client1.getSoTrafficClass());
assertThat(client2 instanceof TcpNetClientConnectionFactory).isTrue();
assertThat(client1.getHost()).isEqualTo("localhost");
assertThat(client1.getSoLinger()).isEqualTo(54);
assertThat(client1.getSoReceiveBufferSize()).isEqualTo(1234);
assertThat(client1.getSoSendBufferSize()).isEqualTo(1235);
assertThat(client1.getSoTimeout()).isEqualTo(1236);
assertThat(client1.getSoTrafficClass()).isEqualTo(12);
DirectFieldAccessor dfa = new DirectFieldAccessor(client1);
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertNotNull(dfa.getPropertyValue("interceptorFactoryChain"));
assertThat(dfa.getPropertyValue("serializer")).isSameAs(serializer);
assertThat(dfa.getPropertyValue("deserializer")).isSameAs(deserializer);
assertThat(dfa.getPropertyValue("soTcpNoDelay")).isEqualTo(true);
assertThat(dfa.getPropertyValue("singleUse")).isEqualTo(true);
assertThat(dfa.getPropertyValue("taskExecutor")).isSameAs(taskExecutor);
assertThat(dfa.getPropertyValue("interceptorFactoryChain")).isNotNull();
}
@Test
public void testConnServer2() {
assertTrue(server2 instanceof TcpNetServerConnectionFactory);
assertEquals(55, server1.getSoLinger());
assertEquals(1234, server1.getSoReceiveBufferSize());
assertEquals(1235, server1.getSoSendBufferSize());
assertEquals(1236, server1.getSoTimeout());
assertEquals(12, server1.getSoTrafficClass());
assertThat(server2 instanceof TcpNetServerConnectionFactory).isTrue();
assertThat(server1.getSoLinger()).isEqualTo(55);
assertThat(server1.getSoReceiveBufferSize()).isEqualTo(1234);
assertThat(server1.getSoSendBufferSize()).isEqualTo(1235);
assertThat(server1.getSoTimeout()).isEqualTo(1236);
assertThat(server1.getSoTrafficClass()).isEqualTo(12);
DirectFieldAccessor dfa = new DirectFieldAccessor(server1);
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
assertEquals(123, dfa.getPropertyValue("backlog"));
assertNotNull(dfa.getPropertyValue("interceptorFactoryChain"));
assertThat(dfa.getPropertyValue("serializer")).isSameAs(serializer);
assertThat(dfa.getPropertyValue("deserializer")).isSameAs(deserializer);
assertThat(dfa.getPropertyValue("soTcpNoDelay")).isEqualTo(true);
assertThat(dfa.getPropertyValue("singleUse")).isEqualTo(true);
assertThat(dfa.getPropertyValue("taskExecutor")).isSameAs(taskExecutor);
assertThat(dfa.getPropertyValue("backlog")).isEqualTo(123);
assertThat(dfa.getPropertyValue("interceptorFactoryChain")).isNotNull();
}
@Test
public void testNewOut1() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpNewOut1);
assertSame(client1, dfa.getPropertyValue("clientConnectionFactory"));
assertEquals(25, dfa.getPropertyValue("order"));
assertEquals(Boolean.FALSE, dfa.getPropertyValue("isClientMode"));
assertNull(dfa.getPropertyValue("taskScheduler"));
assertEquals(60000L, dfa.getPropertyValue("retryInterval"));
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(client1);
assertThat(dfa.getPropertyValue("order")).isEqualTo(25);
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("taskScheduler")).isNull();
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(60000L);
}
@Test
public void testNewOut2() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpNewOut2);
assertSame(server1, dfa.getPropertyValue("serverConnectionFactory"));
assertEquals(15, dfa.getPropertyValue("order"));
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isSameAs(server1);
assertThat(dfa.getPropertyValue("order")).isEqualTo(15);
}
@Test
public void testNewIn1() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpNewIn1);
assertSame(client1, dfa.getPropertyValue("clientConnectionFactory"));
assertNull(dfa.getPropertyValue("errorChannel"));
assertEquals(Boolean.FALSE, dfa.getPropertyValue("isClientMode"));
assertNull(dfa.getPropertyValue("taskScheduler"));
assertEquals(60000L, dfa.getPropertyValue("retryInterval"));
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(client1);
assertThat(dfa.getPropertyValue("errorChannel")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("taskScheduler")).isNull();
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(60000L);
}
@Test
public void testNewIn2() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpNewIn2);
assertSame(server1, dfa.getPropertyValue("serverConnectionFactory"));
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isSameAs(server1);
}
@Test
@@ -600,59 +595,59 @@ public class ParserUnitTests {
TestUtils.getPropertyValue(this.tcpChannel, "dispatcher"),
"handlers");
Iterator<MessageHandler> iterator = handlers.iterator();
assertSame(this.tcpNewOut2, iterator.next()); //15
assertSame(this.tcpOutboundGateway, iterator.next()); //24
assertSame(this.tcpNewOut1, iterator.next()); //25
assertSame(this.tcpOut, iterator.next()); //35
assertThat(iterator.next()).isSameAs(this.tcpNewOut2); //15
assertThat(iterator.next()).isSameAs(this.tcpOutboundGateway); //24
assertThat(iterator.next()).isSameAs(this.tcpNewOut1); //25
assertThat(iterator.next()).isSameAs(this.tcpOut); //35
}
@Test
public void testInClientMode() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpInClientMode);
assertSame(cfC3, dfa.getPropertyValue("clientConnectionFactory"));
assertNull(dfa.getPropertyValue("serverConnectionFactory"));
assertEquals(Boolean.TRUE, dfa.getPropertyValue("isClientMode"));
assertSame(sched, dfa.getPropertyValue("taskScheduler"));
assertEquals(123000L, dfa.getPropertyValue("retryInterval"));
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(cfC3);
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(sched);
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(123000L);
}
@Test
public void testOutClientMode() {
DirectFieldAccessor dfa = new DirectFieldAccessor(tcpOutClientMode);
assertSame(cfC4, dfa.getPropertyValue("clientConnectionFactory"));
assertNull(dfa.getPropertyValue("serverConnectionFactory"));
assertEquals(Boolean.TRUE, dfa.getPropertyValue("isClientMode"));
assertSame(sched, dfa.getPropertyValue("taskScheduler"));
assertEquals(124000L, dfa.getPropertyValue("retryInterval"));
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(cfC4);
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(sched);
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(124000L);
}
@Test
public void testInGatewayClientMode() {
DirectFieldAccessor dfa = new DirectFieldAccessor(inGatewayClientMode);
assertSame(cfC5, dfa.getPropertyValue("clientConnectionFactory"));
assertNull(dfa.getPropertyValue("serverConnectionFactory"));
assertEquals(Boolean.TRUE, dfa.getPropertyValue("isClientMode"));
assertSame(sched, dfa.getPropertyValue("taskScheduler"));
assertEquals(125000L, dfa.getPropertyValue("retryInterval"));
assertThat(dfa.getPropertyValue("clientConnectionFactory")).isSameAs(cfC5);
assertThat(dfa.getPropertyValue("serverConnectionFactory")).isNull();
assertThat(dfa.getPropertyValue("isClientMode")).isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("taskScheduler")).isSameAs(sched);
assertThat(dfa.getPropertyValue("retryInterval")).isEqualTo(125000L);
}
@Test
public void testAutoTcp() {
assertSame(tcpAutoChannel, TestUtils.getPropertyValue(tcpAutoAdapter, "outputChannel"));
assertThat(TestUtils.getPropertyValue(tcpAutoAdapter, "outputChannel")).isSameAs(tcpAutoChannel);
}
@Test
public void testAutoUdp() {
assertSame(udpAutoChannel, TestUtils.getPropertyValue(udpAutoAdapter, "outputChannel"));
assertThat(TestUtils.getPropertyValue(udpAutoAdapter, "outputChannel")).isSameAs(udpAutoChannel);
}
@Test
public void testSecureServer() {
DirectFieldAccessor dfa = new DirectFieldAccessor(secureServer);
assertSame(socketFactorySupport, dfa.getPropertyValue("tcpSocketFactorySupport"));
assertSame(socketSupport, dfa.getPropertyValue("tcpSocketSupport"));
assertEquals(34, TestUtils.getPropertyValue(this.secureServerNio, "sslHandshakeTimeout"));
assertSame(this.netConnectionSupport, dfa.getPropertyValue("tcpNetConnectionSupport"));
assertThat(dfa.getPropertyValue("tcpSocketFactorySupport")).isSameAs(socketFactorySupport);
assertThat(dfa.getPropertyValue("tcpSocketSupport")).isSameAs(socketSupport);
assertThat(TestUtils.getPropertyValue(this.secureServerNio, "sslHandshakeTimeout")).isEqualTo(34);
assertThat(dfa.getPropertyValue("tcpNetConnectionSupport")).isSameAs(this.netConnectionSupport);
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.config;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Test;
@@ -38,7 +38,7 @@ public class TcpConnectionFactoryFactoryBeanTest {
fb.setBeanFactory(mock(BeanFactory.class));
fb.afterPropertiesSet();
// INT-3578 IllegalArgumentException on 'readDelay'
assertEquals(100L, TestUtils.getPropertyValue(fb.getObject(), "readDelay"));
assertThat(TestUtils.getPropertyValue(fb.getObject(), "readDelay")).isEqualTo(100L);
}
@@ -50,7 +50,7 @@ public class TcpConnectionFactoryFactoryBeanTest {
fb.setReadDelay(1000);
fb.setBeanFactory(mock(BeanFactory.class));
fb.afterPropertiesSet();
assertEquals(1000L, TestUtils.getPropertyValue(fb.getObject(), "readDelay"));
assertThat(TestUtils.getPropertyValue(fb.getObject(), "readDelay")).isEqualTo(1000L);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.ip.dsl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -65,8 +64,8 @@ public class ConnectionFacforyTests {
client.afterPropertiesSet();
client.start();
client.getConnection().send(new GenericMessage<>("foo"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("foo", received.get().getPayload());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(received.get().getPayload()).isEqualTo("foo");
client.stop();
server.stop();
}
@@ -74,19 +73,19 @@ public class ConnectionFacforyTests {
@Test
public void shouldReturnNioFlavor() throws Exception {
AbstractServerConnectionFactory server = Tcp.nioServer(0).get();
assertTrue(server instanceof TcpNioServerConnectionFactory);
assertThat(server instanceof TcpNioServerConnectionFactory).isTrue();
AbstractClientConnectionFactory client = Tcp.nioClient("localhost", server.getPort()).get();
assertTrue(client instanceof TcpNioClientConnectionFactory);
assertThat(client instanceof TcpNioClientConnectionFactory).isTrue();
}
@Test
public void shouldReturnNetFlavor() throws Exception {
AbstractServerConnectionFactory server = Tcp.netServer(0).get();
assertTrue(server instanceof TcpNetServerConnectionFactory);
assertThat(server instanceof TcpNetServerConnectionFactory).isTrue();
AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
assertTrue(client instanceof TcpNetClientConnectionFactory);
assertThat(client instanceof TcpNetClientConnectionFactory).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,7 @@
package org.springframework.integration.ip.dsl;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -105,7 +100,7 @@ public class IpIntegrationTests {
public void testTcpAdapters() {
ApplicationEventPublisher publisher = e -> { };
AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).id("server").get();
assertEquals("server", server.getComponentName());
assertThat(server.getComponentName()).isEqualTo("server");
server.setApplicationEventPublisher(publisher);
server.afterPropertiesSet();
TcpReceivingChannelAdapter inbound = Tcp.inboundAdapter(server).get();
@@ -115,15 +110,15 @@ public class IpIntegrationTests {
inbound.start();
TestingUtilities.waitListening(server, null);
AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).id("client").get();
assertEquals("client", client.getComponentName());
assertThat(client.getComponentName()).isEqualTo("client");
client.setApplicationEventPublisher(publisher);
client.afterPropertiesSet();
TcpSendingMessageHandler handler = Tcp.outboundAdapter(client).get();
handler.start();
handler.handleMessage(new GenericMessage<>("foo"));
Message<?> receivedMessage = received.receive(10000);
assertNotNull(receivedMessage);
assertEquals("foo", Transformers.objectToString().transform(receivedMessage).getPayload());
assertThat(receivedMessage).isNotNull();
assertThat(Transformers.objectToString().transform(receivedMessage).getPayload()).isEqualTo("foo");
client.stop();
server.stop();
}
@@ -137,22 +132,22 @@ public class IpIntegrationTests {
MessagingTemplate messagingTemplate = new MessagingTemplate(this.clientTcpFlowInput);
assertThat(messagingTemplate.convertSendAndReceive("foo", String.class), equalTo("FOO"));
assertThat(messagingTemplate.convertSendAndReceive("foo", String.class)).isEqualTo("FOO");
assertTrue(this.adviceCalled.get());
assertThat(this.adviceCalled.get()).isTrue();
}
@Test
public void testUdp() throws Exception {
assertTrue(this.config.listeningLatch.await(10, TimeUnit.SECONDS));
assertEquals(this.udpInbound.getPort(), this.config.serverPort);
assertThat(this.config.listeningLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.serverPort).isEqualTo(this.udpInbound.getPort());
Message<String> outMessage = MessageBuilder.withPayload("foo")
.setHeader("udp_dest", "udp://localhost:" + this.udpInbound.getPort())
.build();
this.udpOut.send(outMessage);
Message<?> received = this.udpIn.receive(10000);
assertNotNull(received);
assertEquals("foo", Transformers.objectToString().transform(received).getPayload());
assertThat(received).isNotNull();
assertThat(Transformers.objectToString().transform(received).getPayload()).isEqualTo("foo");
}
@Test
@@ -166,7 +161,7 @@ public class IpIntegrationTests {
UdpMulticastOutboundChannelAdapterSpec udpMulticastOutboundChannelAdapterSpec2 =
udpMulticastOutboundChannelAdapterSpec1.timeToLive(10);
assertThat(udpMulticastOutboundChannelAdapterSpec2.get(), instanceOf(MulticastSendingMessageHandler.class));
assertThat(udpMulticastOutboundChannelAdapterSpec2.get()).isInstanceOf(MulticastSendingMessageHandler.class);
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,11 +46,11 @@ public class AutoStartTests {
@Test
public void testNetIn() throws Exception {
DirectFieldAccessor dfa = new DirectFieldAccessor(cfS1);
assertNull(dfa.getPropertyValue("serverSocket"));
assertThat(dfa.getPropertyValue("serverSocket")).isNull();
startAndStop();
assertNull(dfa.getPropertyValue("serverSocket"));
assertThat(dfa.getPropertyValue("serverSocket")).isNull();
startAndStop();
assertNull(dfa.getPropertyValue("serverSocket"));
assertThat(dfa.getPropertyValue("serverSocket")).isNull();
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,8 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.junit.Before;
import org.junit.Test;
@@ -66,7 +65,7 @@ public class ClientModeControlBusTests {
@Test
public void test() throws Exception {
assertTrue(controlBus.boolResult("@tcpIn.isClientMode()"));
assertThat(controlBus.boolResult("@tcpIn.isClientMode()")).isTrue();
int n = 0;
while (!controlBus.boolResult("@tcpIn.isClientModeConnected()")) {
Thread.sleep(100);
@@ -75,8 +74,8 @@ public class ClientModeControlBusTests {
fail("Connection never established");
}
}
assertTrue(controlBus.boolResult("@tcpIn.isRunning()"));
assertSame(taskScheduler, TestUtils.getPropertyValue(tcpIn, "taskScheduler"));
assertThat(controlBus.boolResult("@tcpIn.isRunning()")).isTrue();
assertThat(TestUtils.getPropertyValue(tcpIn, "taskScheduler")).isSameAs(taskScheduler);
controlBus.voidResult("@tcpIn.retryConnection()");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,7 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
@@ -118,14 +115,14 @@ public class ConnectionToConnectionTests {
TcpConnection connection = client.getConnection();
connection.send(MessageBuilder.withPayload("Test").build());
Message<?> message = serverSideChannel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
MessageHistory history = MessageHistory.read(message);
//org.springframework.integration.test.util.TestUtils
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, gatewayName, 0);
assertNotNull(componentHistoryRecord);
assertTrue(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway"));
assertNotNull(message);
assertEquals("Test", new String((byte[]) message.getPayload()));
assertThat(componentHistoryRecord).isNotNull();
assertThat(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway")).isTrue();
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test");
}
int clientOpens = 0;
int clientCloses = 0;
@@ -157,13 +154,13 @@ public class ConnectionToConnectionTests {
}
}
}
assertEquals(100, clientOpens);
assertEquals(100, clientCloses);
assertThat(clientOpens).isEqualTo(100);
assertThat(clientCloses).isEqualTo(100);
if (expectExceptionOnClose) {
assertEquals(100, clientExceptions);
assertThat(clientExceptions).isEqualTo(100);
}
assertEquals(100, serverOpens);
assertEquals(100, serverCloses);
assertThat(serverOpens).isEqualTo(100);
assertThat(serverCloses).isEqualTo(100);
}
@Test
@@ -176,29 +173,29 @@ public class ConnectionToConnectionTests {
connection.send(MessageBuilder.withPayload("Test").build());
connection.close();
Message<?> message = serverSideChannel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
MessageHistory history = MessageHistory.read(message);
//org.springframework.integration.test.util.TestUtils
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "gwNet", 0);
assertNotNull(componentHistoryRecord);
assertTrue(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway"));
assertNotNull(message);
assertEquals("Test", new String((byte[]) message.getPayload()));
assertThat(componentHistoryRecord).isNotNull();
assertThat(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway")).isTrue();
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test");
}
@Test
public void testLookup() throws Exception {
clientNet.start();
TcpConnection connection = clientNet.getConnection();
assertFalse(connection.getConnectionId().contains("localhost"));
assertThat(connection.getConnectionId().contains("localhost")).isFalse();
connection.close();
clientNet.setLookupHost(true);
connection = clientNet.getConnection();
assertTrue(connection.getConnectionId().contains("localhost"));
assertThat(connection.getConnectionId().contains("localhost")).isTrue();
connection.close();
clientNet.setLookupHost(false);
connection = clientNet.getConnection();
assertFalse(connection.getConnectionId().contains("localhost"));
assertThat(connection.getConnectionId().contains("localhost")).isFalse();
connection.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,7 @@
package org.springframework.integration.ip.tcp;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -83,11 +79,11 @@ public class InterceptedSharedConnectionTests {
input.send(MessageBuilder.withPayload("Test").build());
QueueChannel replies = ctx.getBean("replies", QueueChannel.class);
Message<?> message = replies.receive(10000);
assertNotNull(message);
assertEquals("Test", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("Test");
}
assertThat(this.listener.openEvent, notNullValue());
assertThat(this.listener.openEvent.getConnectionFactoryName(), equalTo("client"));
assertThat(this.listener.openEvent).isNotNull();
assertThat(this.listener.openEvent.getConnectionFactoryName()).isEqualTo("client");
}
public static class Listener implements ApplicationListener<TcpConnectionOpenEvent> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
@@ -78,12 +77,12 @@ public class SharedConnectionTests {
QueueChannel replies = ctx.getBean("replies", QueueChannel.class);
Message<?> message = replies.receive(10000);
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
assertThat(history).isNotNull();
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundClient", 0);
assertNotNull(componentHistoryRecord);
assertEquals("ip:tcp-inbound-channel-adapter", componentHistoryRecord.getProperty("type"));
assertNotNull(message);
assertEquals("Test", message.getPayload());
assertThat(componentHistoryRecord).isNotNull();
assertThat(componentHistoryRecord.getProperty("type")).isEqualTo("ip:tcp-inbound-channel-adapter");
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("Test");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -175,7 +175,7 @@ public class TcpConfigInboundGatewayTests {
break;
}
}
assertEquals("echo:" + greetings + "\r\n", sb.toString());
assertThat(sb.toString()).isEqualTo("echo:" + greetings + "\r\n");
}
@Test
@@ -210,7 +210,7 @@ public class TcpConfigInboundGatewayTests {
}
sb.append((char) c);
}
assertEquals("echo:" + greetings, sb.toString());
assertThat(sb.toString()).isEqualTo("echo:" + greetings);
}
@Test
@@ -232,7 +232,7 @@ public class TcpConfigInboundGatewayTests {
String greetings = "Hello World!";
new ObjectOutputStream(socket.getOutputStream()).writeObject(greetings);
String echo = (String) new ObjectInputStream(socket.getInputStream()).readObject();
assertEquals("echo:" + greetings, echo);
assertThat(echo).isEqualTo("echo:" + greetings);
}
@Test
@@ -274,7 +274,7 @@ public class TcpConfigInboundGatewayTests {
break;
}
}
assertEquals("echo:" + greetings, sb.toString());
assertThat(sb.toString()).isEqualTo("echo:" + greetings);
}
private void waitListening(TcpInboundGateway gateway) throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.Map;
@@ -190,7 +190,7 @@ public class TcpConfigOutboundGatewayTests {
Message<String> message = MessageBuilder.withPayload("test").build();
@SuppressWarnings("unchecked")
byte[] bytes = ((Message<byte[]>) gateway.handleRequestMessage(message)).getPayload();
assertEquals("echo:test", new String(bytes));
assertThat(new String(bytes)).isEqualTo("echo:test");
}
@Test
@@ -201,7 +201,7 @@ public class TcpConfigOutboundGatewayTests {
Message<String> message = MessageBuilder.withPayload("test").build();
@SuppressWarnings("unchecked")
Object response = ((Message<Object>) gateway.handleRequestMessage(message)).getPayload();
assertEquals("echo:test", response);
assertThat(response).isEqualTo("echo:test");
}
@Test
@@ -212,7 +212,7 @@ public class TcpConfigOutboundGatewayTests {
Message<String> message = MessageBuilder.withPayload("test").build();
@SuppressWarnings("unchecked")
byte[] bytes = ((Message<byte[]>) gateway.handleRequestMessage(message)).getPayload();
assertEquals("echo:test", new String(bytes));
assertThat(new String(bytes)).isEqualTo("echo:test");
}
@Test //INT-1029
@@ -220,7 +220,7 @@ public class TcpConfigOutboundGatewayTests {
// this.ctx.getBean("tcp-outbound-gateway-within-chain.handler", TcpOutboundGateway.class);
tcpOutboundGatewayInsideChain.send(MessageBuilder.withPayload("test").build());
byte[] bytes = (byte[]) replyChannel.receive().getPayload();
assertEquals("echo:test", new String(bytes).trim());
assertThat(new String(bytes).trim()).isEqualTo("echo:test");
}
@@ -228,14 +228,14 @@ public class TcpConfigOutboundGatewayTests {
Message<String> message = MessageBuilder.withPayload("test").build();
requestChannel.send(message);
byte[] bytes = (byte[]) replyChannel.receive().getPayload();
assertEquals("echo:test", new String(bytes).trim());
assertThat(new String(bytes).trim()).isEqualTo("echo:test");
}
private void testOutboundUsingConfigNio() {
Message<String> message = MessageBuilder.withPayload("test").build();
requestChannelNio.send(message);
byte[] bytes = (byte[]) replyChannel.receive().getPayload();
assertEquals("echo:test", new String(bytes).trim());
assertThat(new String(bytes).trim()).isEqualTo("echo:test");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.io.IOException;
@@ -87,9 +85,9 @@ public class TcpInboundGatewayTests {
handler.handleMessage(channel.receive(10000));
byte[] bytes = new byte[12];
readFully(socket1.getInputStream(), bytes);
assertEquals("Echo:Test1\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test1\r\n");
readFully(socket2.getInputStream(), bytes);
assertEquals("Echo:Test2\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test2\r\n");
gateway.stop();
scf.stop();
}
@@ -116,9 +114,9 @@ public class TcpInboundGatewayTests {
handler.handleMessage(channel.receive(10000));
byte[] bytes = new byte[12];
readFully(socket.getInputStream(), bytes);
assertEquals("Echo:Test1\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test1\r\n");
readFully(socket.getInputStream(), bytes);
assertEquals("Echo:Test2\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test2\r\n");
gateway.stop();
scf.stop();
}
@@ -142,9 +140,9 @@ public class TcpInboundGatewayTests {
socket.getOutputStream().write("Test1\r\nTest2\r\n".getBytes());
byte[] bytes = new byte[12];
readFully(socket.getInputStream(), bytes);
assertEquals("Echo:Test1\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test1\r\n");
readFully(socket.getInputStream(), bytes);
assertEquals("Echo:Test2\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test2\r\n");
latch2.await();
socket.close();
server.close();
@@ -157,7 +155,7 @@ public class TcpInboundGatewayTests {
}
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port.get());
ccf.setSingleUse(false);
TcpInboundGateway gateway = new TcpInboundGateway();
@@ -177,14 +175,14 @@ public class TcpInboundGatewayTests {
gateway.setTaskScheduler(taskScheduler);
gateway.start();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
latch2.countDown();
assertTrue(latch3.await(10, TimeUnit.SECONDS));
assertTrue(done.get());
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(done.get()).isTrue();
gateway.stop();
executorService.shutdown();
}
@@ -213,9 +211,9 @@ public class TcpInboundGatewayTests {
handler.handleMessage(channel.receive(10000));
byte[] bytes = new byte[12];
readFully(socket1.getInputStream(), bytes);
assertEquals("Echo:Test1\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test1\r\n");
readFully(socket2.getInputStream(), bytes);
assertEquals("Echo:Test2\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo("Echo:Test2\r\n");
gateway.stop();
scf.stop();
}
@@ -246,8 +244,8 @@ public class TcpInboundGatewayTests {
results.add(new String(bytes));
readFully(socket.getInputStream(), bytes);
results.add(new String(bytes));
assertTrue(results.remove("Echo:Test1\r\n"));
assertTrue(results.remove("Echo:Test2\r\n"));
assertThat(results.remove("Echo:Test1\r\n")).isTrue();
assertThat(results.remove("Echo:Test2\r\n")).isTrue();
gateway.stop();
scf.stop();
}
@@ -279,9 +277,9 @@ public class TcpInboundGatewayTests {
socket2.getOutputStream().write("Test2\r\n".getBytes());
byte[] bytes = new byte[errorMessage.length() + 2];
readFully(socket1.getInputStream(), bytes);
assertEquals(errorMessage + "\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo(errorMessage + "\r\n");
readFully(socket2.getInputStream(), bytes);
assertEquals(errorMessage + "\r\n", new String(bytes));
assertThat(new String(bytes)).isEqualTo(errorMessage + "\r\n");
gateway.stop();
scf.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,8 @@
package org.springframework.integration.ip.tcp;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -130,7 +124,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
ccf.setSerializer(new DefaultSerializer());
@@ -144,12 +138,12 @@ public class TcpOutboundGatewayTests {
gateway.setRequiresReply(true);
gateway.setOutputChannel(replyChannel);
// check the default remote timeout
assertEquals(10000L, TestUtils.getPropertyValue(gateway, "remoteTimeoutExpression.value"));
assertThat(TestUtils.getPropertyValue(gateway, "remoteTimeoutExpression.value")).isEqualTo(10000L);
gateway.setSendTimeout(123);
gateway.setRemoteTimeout(60000);
gateway.setSendTimeout(61000);
// ensure this did NOT change the remote timeout
assertEquals("60000", TestUtils.getPropertyValue(gateway, "remoteTimeoutExpression.literalValue"));
assertThat(TestUtils.getPropertyValue(gateway, "remoteTimeoutExpression.literalValue")).isEqualTo("60000");
gateway.setRequestTimeout(60000);
for (int i = 100; i < 200; i++) {
gateway.handleMessage(MessageBuilder.withPayload("Test" + i).build());
@@ -157,11 +151,11 @@ public class TcpOutboundGatewayTests {
Set<String> replies = new HashSet<String>();
for (int i = 100; i < 200; i++) {
Message<?> m = replyChannel.receive(10000);
assertNotNull(m);
assertThat(m).isNotNull();
replies.add((String) m.getPayload());
}
for (int i = 0; i < 100; i++) {
assertTrue(replies.remove("Reply" + i));
assertThat(replies.remove("Reply" + i)).isTrue();
}
done.set(true);
ccf.stop();
@@ -193,7 +187,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
ccf.setSerializer(new DefaultSerializer());
@@ -212,11 +206,11 @@ public class TcpOutboundGatewayTests {
Set<String> replies = new HashSet<String>();
for (int i = 100; i < 110; i++) {
Message<?> m = replyChannel.receive(10000);
assertNotNull(m);
assertThat(m).isNotNull();
replies.add((String) m.getPayload());
}
for (int i = 0; i < 10; i++) {
assertTrue(replies.remove("Reply" + i));
assertThat(replies.remove("Reply" + i)).isTrue();
}
done.set(true);
gateway.stop();
@@ -250,7 +244,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
ccf.setSerializer(new DefaultSerializer());
@@ -284,21 +278,21 @@ public class TcpOutboundGatewayTests {
fail("Unexpected " + e.getMessage());
}
else {
assertNotNull(e.getCause());
assertTrue(e.getCause() instanceof MessageTimeoutException);
assertThat(e.getCause()).isNotNull();
assertThat(e.getCause() instanceof MessageTimeoutException).isTrue();
}
timeouts++;
continue;
}
Message<?> m = replyChannel.receive(10000);
assertNotNull(m);
assertThat(m).isNotNull();
replies.add((String) m.getPayload());
}
if (timeouts < 1) {
fail("Expected ExecutionException");
}
for (int i = 0; i < 1; i++) {
assertTrue(replies.remove("Reply" + i));
assertThat(replies.remove("Reply" + i)).isTrue();
}
done.set(true);
gateway.stop();
@@ -387,7 +381,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
final TcpOutboundGateway gateway = new TcpOutboundGateway();
gateway.setConnectionFactory(ccf);
gateway.setRequestTimeout(Integer.MAX_VALUE);
@@ -414,7 +408,7 @@ public class TcpOutboundGatewayTests {
}
// wait until the server side has processed both requests
assertTrue(serverLatch.await(30, TimeUnit.SECONDS));
assertThat(serverLatch.await(30, TimeUnit.SECONDS)).isTrue();
List<String> replies = new ArrayList<String>();
int timeouts = 0;
for (int i = 0; i < 2; i++) {
@@ -429,18 +423,18 @@ public class TcpOutboundGatewayTests {
fail("Unexpected " + e.getMessage());
}
else {
assertNotNull(e.getCause());
assertThat(e.getCause(), instanceOf(MessageTimeoutException.class));
assertThat(e.getCause()).isNotNull();
assertThat(e.getCause()).isInstanceOf(MessageTimeoutException.class);
}
timeouts++;
continue;
}
}
assertEquals("Expected exactly one ExecutionException", 1, timeouts);
assertEquals(1, replies.size());
assertEquals(lastReceived.get().replace("Test", "Reply"), replies.get(0));
assertThat(timeouts).as("Expected exactly one ExecutionException").isEqualTo(1);
assertThat(replies.size()).isEqualTo(1);
assertThat(replies.get(0)).isEqualTo(lastReceived.get().replace("Test", "Reply"));
done.set(true);
assertEquals(0, TestUtils.getPropertyValue(gateway, "pendingReplies", Map.class).size());
assertThat(TestUtils.getPropertyValue(gateway, "pendingReplies", Map.class).size()).isEqualTo(0);
gateway.stop();
ccf.stop();
}
@@ -482,7 +476,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
// Failover
AbstractClientConnectionFactory factory1 = mock(AbstractClientConnectionFactory.class);
@@ -517,8 +511,8 @@ public class TcpOutboundGatewayTests {
GenericMessage<String> message = new GenericMessage<String>("foo");
gateway.handleMessage(message);
Message<?> reply = outputChannel.receive(0);
assertNotNull(reply);
assertEquals("bar", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("bar");
done.set(true);
gateway.stop();
verify(mockConn1).send(Mockito.any(Message.class));
@@ -563,7 +557,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
// Cache
AbstractClientConnectionFactory factory1 = mock(AbstractClientConnectionFactory.class);
@@ -601,8 +595,8 @@ public class TcpOutboundGatewayTests {
GenericMessage<String> message = new GenericMessage<String>("foo");
gateway.handleMessage(message);
Message<?> reply = outputChannel.receive(0);
assertNotNull(reply);
assertEquals("bar", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("bar");
done.set(true);
gateway.stop();
verify(mockConn1).send(Mockito.any(Message.class));
@@ -717,7 +711,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
final TcpOutboundGateway gateway = new TcpOutboundGateway();
gateway.setConnectionFactory(ccf);
gateway.setRequestTimeout(Integer.MAX_VALUE);
@@ -733,11 +727,11 @@ public class TcpOutboundGatewayTests {
fail("expected failure");
}
catch (Exception e) {
assertThat(e.getCause().getCause(), instanceOf(EOFException.class));
assertThat(e.getCause().getCause()).isInstanceOf(EOFException.class);
}
assertEquals(0, TestUtils.getPropertyValue(gateway, "pendingReplies", Map.class).size());
assertThat(TestUtils.getPropertyValue(gateway, "pendingReplies", Map.class).size()).isEqualTo(0);
Message<?> reply = replyChannel.receive(0);
assertNull(reply);
assertThat(reply).isNull();
done.set(true);
ccf.getConnection();
gateway.stop();
@@ -826,7 +820,7 @@ public class TcpOutboundGatewayTests {
}
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
final TcpOutboundGateway gateway = new TcpOutboundGateway();
gateway.setConnectionFactory(ccf);
gateway.setRequestTimeout(Integer.MAX_VALUE);
@@ -842,11 +836,11 @@ public class TcpOutboundGatewayTests {
fail("expected failure");
}
catch (Exception e) {
assertThat(e.getCause().getCause(), instanceOf(SocketTimeoutException.class));
assertThat(e.getCause().getCause()).isInstanceOf(SocketTimeoutException.class);
}
assertEquals(0, TestUtils.getPropertyValue(gateway, "pendingReplies", Map.class).size());
assertThat(TestUtils.getPropertyValue(gateway, "pendingReplies", Map.class).size()).isEqualTo(0);
Message<?> reply = replyChannel.receive(0);
assertNull(reply);
assertThat(reply).isNull();
done.set(true);
ccf.getConnection();
gateway.stop();
@@ -896,14 +890,14 @@ public class TcpOutboundGatewayTests {
while (n++ < 100 && pending.size() == 0) {
Thread.sleep(100);
}
assertTrue(pending.size() > 0);
assertThat(pending.size() > 0).isTrue();
String connectionId = pending.keySet().iterator().next();
this.executor.execute(() -> gateway.onMessage(new ErrorMessage(new RuntimeException(),
Collections.singletonMap(IpHeaders.CONNECTION_ID, connectionId))));
GenericMessage<String> message = new GenericMessage<>("FOO",
Collections.singletonMap(IpHeaders.CONNECTION_ID, connectionId));
gateway.onMessage(message);
assertThat(replies.receive(10000), equalTo(message));
assertThat(replies.receive(10000)).isEqualTo(message);
gateway.stop();
done.set(true);
server.close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.io.IOException;
@@ -88,11 +86,11 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket.getOutputStream().write("Test1\r\n".getBytes());
socket.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertEquals("Test1", new String((byte[]) message.getPayload()));
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test1");
message = channel.receive(10000);
assertNotNull(message);
assertEquals("Test2", new String((byte[]) message.getPayload()));
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test2");
scf.stop();
}
@@ -119,7 +117,7 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
}
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -141,11 +139,11 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
adapter.setTaskScheduler(taskScheduler);
adapter.start();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertEquals("Test1", new String((byte[]) message.getPayload()));
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test1");
message = channel.receive(10000);
assertNotNull(message);
assertEquals("Test2", new String((byte[]) message.getPayload()));
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test2");
adapter.stop();
adapter.start();
adapter.stop();
@@ -176,11 +174,11 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
Set<String> results = new HashSet<String>();
for (int i = 0; i < 1000; i++) {
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
results.add(new String((byte[]) message.getPayload()));
}
for (int i = 0; i < 1000; i++) {
assertTrue(results.remove("Test" + i));
assertThat(results.remove("Test" + i)).isTrue();
}
scf.stop();
}
@@ -206,16 +204,16 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket.getOutputStream().write("Test\r\n".getBytes());
socket.getOutputStream().write("Test\r\n".getBytes());
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
byte[] b = new byte[6];
readFully(socket.getInputStream(), b);
assertEquals("Test\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test\r\n");
readFully(socket.getInputStream(), b);
assertEquals("Test\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test\r\n");
scf.stop();
}
@@ -240,16 +238,16 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket.getOutputStream().write("Test\r\n".getBytes());
socket.getOutputStream().write("Test\r\n".getBytes());
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
byte[] b = new byte[6];
readFully(socket.getInputStream(), b);
assertEquals("Test\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test\r\n");
readFully(socket.getInputStream(), b);
assertEquals("Test\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test\r\n");
scf.stop();
}
@@ -273,15 +271,15 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
// with single use, results may come back in a different order
Set<String> results = new HashSet<String>();
results.add(new String((byte[]) message.getPayload()));
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
results.add(new String((byte[]) message.getPayload()));
assertTrue(results.contains("Test1"));
assertTrue(results.contains("Test2"));
assertThat(results.contains("Test1")).isTrue();
assertThat(results.contains("Test2")).isTrue();
scf.stop();
}
@@ -305,15 +303,15 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = channel.receive(60000);
assertNotNull(message);
assertThat(message).isNotNull();
// with single use, results may come back in a different order
Set<String> results = new HashSet<String>();
results.add(new String((byte[]) message.getPayload()));
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
results.add(new String((byte[]) message.getPayload()));
assertTrue(results.contains("Test1"));
assertTrue(results.contains("Test2"));
assertThat(results.contains("Test1")).isTrue();
assertThat(results.contains("Test2")).isTrue();
scf.stop();
}
@@ -351,16 +349,16 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket2.setSoTimeout(2000);
socket2.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
byte[] b = new byte[7];
readFully(socket1.getInputStream(), b);
assertEquals("Test1\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test1\r\n");
readFully(socket2.getInputStream(), b);
assertEquals("Test2\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test2\r\n");
scf.stop();
}
@@ -388,16 +386,16 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket2.setSoTimeout(2000);
socket2.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
byte[] b = new byte[7];
readFully(socket1.getInputStream(), b);
assertEquals("Test1\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test1\r\n");
readFully(socket2.getInputStream(), b);
assertEquals("Test2\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test2\r\n");
scf.stop();
}
@@ -430,13 +428,13 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
}
for (int i = 100; i < 200; i++) {
Message<?> message = channel.receive(60000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
}
byte[] b = new byte[9];
for (int i = 100; i < 200; i++) {
readFully(sockets.remove(0).getInputStream(), b);
assertEquals("Test" + i + "\r\n", new String(b));
assertThat(new String(b)).isEqualTo("Test" + i + "\r\n");
}
scf.stop();
}
@@ -510,20 +508,20 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.setSoTimeout(10000);
new ObjectOutputStream(socket.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket.getOutputStream()).writeObject("Test1");
new ObjectOutputStream(socket.getOutputStream()).writeObject("Test2");
Set<String> results = new HashSet<String>();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
results.add((String) message.getPayload());
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
results.add((String) message.getPayload());
assertTrue(results.contains("Test1"));
assertTrue(results.contains("Test2"));
assertThat(results.contains("Test1")).isTrue();
assertThat(results.contains("Test2")).isTrue();
}
private void singleNoOutboundInterceptorsGuts(AbstractServerConnectionFactory scf) throws Exception {
@@ -547,27 +545,27 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.setSoTimeout(10000);
new ObjectOutputStream(socket.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket.getOutputStream()).writeObject("Test1");
socket = SocketFactory.getDefault().createSocket("localhost", port);
new ObjectOutputStream(socket.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket.getOutputStream()).writeObject("Test2");
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
// with single use, results may come back in a different order
Set<Object> results = new HashSet<Object>();
results.add(message.getPayload());
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
results.add(message.getPayload());
assertTrue(results.contains("Test1"));
assertTrue(results.contains("Test2"));
assertThat(results.contains("Test1")).isTrue();
assertThat(results.contains("Test2")).isTrue();
}
private void singleSharedInterceptorsGuts(AbstractServerConnectionFactory scf) throws Exception {
@@ -593,28 +591,28 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
Socket socket1 = SocketFactory.getDefault().createSocket("localhost", port);
socket1.setSoTimeout(60000);
new ObjectOutputStream(socket1.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket1.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket1.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket1.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket1.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket1.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket1.getOutputStream()).writeObject("Test1");
Socket socket2 = SocketFactory.getDefault().createSocket("localhost", port);
socket2.setSoTimeout(60000);
new ObjectOutputStream(socket2.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket2.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket2.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket2.getOutputStream()).writeObject("Hello");
assertEquals("world!", new ObjectInputStream(socket2.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket2.getInputStream()).readObject()).isEqualTo("world!");
new ObjectOutputStream(socket2.getOutputStream()).writeObject("Test2");
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
handler.handleMessage(message);
assertEquals("Test1", new ObjectInputStream(socket1.getInputStream()).readObject());
assertEquals("Test2", new ObjectInputStream(socket2.getInputStream()).readObject());
assertThat(new ObjectInputStream(socket1.getInputStream()).readObject()).isEqualTo("Test1");
assertThat(new ObjectInputStream(socket2.getInputStream()).readObject()).isEqualTo("Test2");
}
@Test
@@ -641,11 +639,11 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
socket.getOutputStream().write("Test1\r\n".getBytes());
socket.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
assertThat(message).isNotNull();
assertThat(((Exception) message.getPayload()).getCause().getMessage()).isEqualTo("Failed");
message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
assertThat(message).isNotNull();
assertThat(((Exception) message.getPayload()).getCause().getMessage()).isEqualTo("Failed");
scf.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import java.io.IOException;
@@ -119,7 +117,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -137,11 +135,11 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply1", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply1");
mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply2", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply2");
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -172,7 +170,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -199,11 +197,11 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply1", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply1");
mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply2", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply2");
done.set(true);
handler.stop();
handler.start();
@@ -238,7 +236,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -257,13 +255,13 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Set<String> results = new HashSet<String>();
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add(new String((byte[]) mOut.getPayload()));
mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add(new String((byte[]) mOut.getPayload()));
assertTrue(results.remove("Reply1"));
assertTrue(results.remove("Reply2"));
assertThat(results.remove("Reply1")).isTrue();
assertThat(results.remove("Reply2")).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -294,7 +292,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -312,11 +310,11 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply1", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply1");
mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply2", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply2");
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -347,7 +345,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -366,13 +364,13 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Set<String> results = new HashSet<String>();
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add(new String((byte[]) mOut.getPayload()));
mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add(new String((byte[]) mOut.getPayload()));
assertTrue(results.remove("Reply1"));
assertTrue(results.remove("Reply2"));
assertThat(results.remove("Reply1")).isTrue();
assertThat(results.remove("Reply2")).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -406,7 +404,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -424,11 +422,11 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply1", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply1");
mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply2", new String((byte[]) mOut.getPayload()));
assertThat(mOut).isNotNull();
assertThat(new String((byte[]) mOut.getPayload())).isEqualTo("Reply2");
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -462,7 +460,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -481,13 +479,13 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Set<String> results = new HashSet<String>();
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add(new String((byte[]) mOut.getPayload()));
mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add(new String((byte[]) mOut.getPayload()));
assertTrue(results.remove("Reply1"));
assertTrue(results.remove("Reply2"));
assertThat(results.remove("Reply1")).isTrue();
assertThat(results.remove("Reply2")).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -518,7 +516,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -535,11 +533,11 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply1", mOut.getPayload());
assertThat(mOut).isNotNull();
assertThat(mOut.getPayload()).isEqualTo("Reply1");
mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply2", mOut.getPayload());
assertThat(mOut).isNotNull();
assertThat(mOut.getPayload()).isEqualTo("Reply2");
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -570,7 +568,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -588,13 +586,13 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Set<String> results = new HashSet<String>();
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add((String) mOut.getPayload());
mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add((String) mOut.getPayload());
assertTrue(results.remove("Reply1"));
assertTrue(results.remove("Reply2"));
assertThat(results.remove("Reply1")).isTrue();
assertThat(results.remove("Reply2")).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -627,7 +625,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -641,7 +639,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.setConnectionFactory(ccf);
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
assertTrue(semaphore.tryAcquire(4, 10000, TimeUnit.MILLISECONDS));
assertThat(semaphore.tryAcquire(4, 10000, TimeUnit.MILLISECONDS)).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -674,7 +672,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -688,7 +686,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.setConnectionFactory(ccf);
handler.handleMessage(MessageBuilder.withPayload("Test.1").build());
handler.handleMessage(MessageBuilder.withPayload("Test.2").build());
assertTrue(semaphore.tryAcquire(4, 10000, TimeUnit.MILLISECONDS));
assertThat(semaphore.tryAcquire(4, 10000, TimeUnit.MILLISECONDS)).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -722,7 +720,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -740,15 +738,15 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
adapter.setOutputChannel(channel);
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
assertTrue(semaphore.tryAcquire(2, 10000, TimeUnit.MILLISECONDS));
assertThat(semaphore.tryAcquire(2, 10000, TimeUnit.MILLISECONDS)).isTrue();
Set<String> replies = new HashSet<String>();
for (int i = 0; i < 2; i++) {
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
replies.add(new String((byte[]) mOut.getPayload()));
}
assertTrue(replies.remove("Reply1"));
assertTrue(replies.remove("Reply2"));
assertThat(replies.remove("Reply1")).isTrue();
assertThat(replies.remove("Reply2")).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -782,7 +780,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -800,15 +798,15 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
adapter.setOutputChannel(channel);
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
assertTrue(semaphore.tryAcquire(2, 10000, TimeUnit.MILLISECONDS));
assertThat(semaphore.tryAcquire(2, 10000, TimeUnit.MILLISECONDS)).isTrue();
Set<String> replies = new HashSet<String>();
for (int i = 0; i < 2; i++) {
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
replies.add(new String((byte[]) mOut.getPayload()));
}
assertTrue(replies.remove("Reply1"));
assertTrue(replies.remove("Reply2"));
assertThat(replies.remove("Reply1")).isTrue();
assertThat(replies.remove("Reply2")).isTrue();
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -858,7 +856,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -885,15 +883,15 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
e.printStackTrace();
fail("Exception at " + i);
}
assertTrue(semaphore.tryAcquire(100, 20000, TimeUnit.MILLISECONDS));
assertThat(semaphore.tryAcquire(100, 20000, TimeUnit.MILLISECONDS)).isTrue();
Set<String> replies = new HashSet<String>();
for (i = 100; i < 200; i++) {
Message<?> mOut = channel.receive(20000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
replies.add(new String((byte[]) mOut.getPayload()));
}
for (i = 0; i < 100; i++) {
assertTrue("Reply" + i + " missing", replies.remove("Reply" + i));
assertThat(replies.remove("Reply" + i)).as("Reply" + i + " missing").isTrue();
}
done.set(true);
ccf.stop();
@@ -938,7 +936,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -961,11 +959,11 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
handler.handleMessage(MessageBuilder.withPayload("Test").build());
handler.handleMessage(MessageBuilder.withPayload("Test").build());
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply1", mOut.getPayload());
assertThat(mOut).isNotNull();
assertThat(mOut.getPayload()).isEqualTo("Reply1");
mOut = channel.receive(10000);
assertNotNull(mOut);
assertEquals("Reply2", mOut.getPayload());
assertThat(mOut).isNotNull();
assertThat(mOut.getPayload()).isEqualTo("Reply2");
done.set(true);
ccf.stop();
serverSocket.get().close();
@@ -1005,7 +1003,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -1028,12 +1026,12 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
Set<String> results = new TreeSet<String>();
for (int i = 0; i < 1000; i++) {
Message<?> mOut = channel.receive(10000);
assertNotNull(mOut);
assertThat(mOut).isNotNull();
results.add((String) mOut.getPayload());
}
logger.debug("results: " + results);
for (int i = 100; i < 1100; i++) {
assertTrue("Missing Reply" + i, results.remove("Reply" + i));
assertThat(results.remove("Reply" + i)).as("Missing Reply" + i).isTrue();
}
done.set(true);
ccf.stop();
@@ -1074,7 +1072,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -1131,7 +1129,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
}
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
noopPublisher(ccf);
@@ -1168,8 +1166,8 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
String testPayload = "Hello, world!";
channelAdapterWithinChain.send(new GenericMessage<String>(testPayload));
Message<?> m = inbound.receive(1000);
assertNotNull(m);
assertEquals(testPayload, new String((byte[]) m.getPayload()));
assertThat(m).isNotNull();
assertThat(new String((byte[]) m.getPayload())).isEqualTo(testPayload);
ctx.close();
}
@@ -1186,10 +1184,10 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest
fail("Expected exception");
}
catch (Exception e) {
assertTrue(e instanceof MessagingException);
assertTrue(e.getCause() != null);
assertTrue(e.getCause() instanceof SocketException);
assertEquals("Failed to connect", e.getCause().getMessage());
assertThat(e instanceof MessagingException).isTrue();
assertThat(e.getCause() != null).isTrue();
assertThat(e.getCause() instanceof SocketException).isTrue();
assertThat(e.getCause().getMessage()).isEqualTo("Failed to connect");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,8 @@
package org.springframework.integration.ip.tcp;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,7 +51,7 @@ public class TcpSendingNoSocketTests {
fail("Exception expected");
}
catch (MessageHandlingException e) {
assertThat(e.getMessage(), startsWith("Unable to find outbound socket"));
assertThat(e.getMessage()).startsWith("Unable to find outbound socket");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
@@ -148,14 +141,14 @@ public class CachingClientConnectionFactoryTests {
cachedConn1.onMessage(new ErrorMessage(new RuntimeException()));
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger).debug(captor.capture());
assertThat(captor.getValue(), startsWith("Message discarded; no listener:"));
assertThat(captor.getValue()).startsWith("Message discarded; no listener:");
// end INT-3652
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
conn1.close();
conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
TcpConnection conn2 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn2.toString(), conn2.toString());
assertThat(conn2.toString()).isEqualTo("Cached:" + mockConn2.toString());
conn1.close();
conn2.close();
}
@@ -170,12 +163,12 @@ public class CachingClientConnectionFactoryTests {
CachingClientConnectionFactory cachingFactory = new CachingClientConnectionFactory(factory, 0);
cachingFactory.start();
TcpConnection conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
conn1.close();
conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
TcpConnection conn2 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn2.toString(), conn2.toString());
assertThat(conn2.toString()).isEqualTo("Cached:" + mockConn2.toString());
conn1.close();
conn2.close();
}
@@ -200,19 +193,19 @@ public class CachingClientConnectionFactoryTests {
CachingClientConnectionFactory cachingFactory = new CachingClientConnectionFactory(factory, 2);
cachingFactory.start();
TcpConnection conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
conn1.close();
conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
TcpConnection conn2 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn2.toString(), conn2.toString());
assertThat(conn2.toString()).isEqualTo("Cached:" + mockConn2.toString());
conn1.close();
conn2.close();
when(mockConn1.isOpen()).thenReturn(false);
TcpConnection conn2a = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn2.toString(), conn2a.toString());
assertSame(TestUtils.getPropertyValue(conn2, "theConnection"),
TestUtils.getPropertyValue(conn2a, "theConnection"));
assertThat(conn2a.toString()).isEqualTo("Cached:" + mockConn2.toString());
assertThat(TestUtils.getPropertyValue(conn2a, "theConnection"))
.isSameAs(TestUtils.getPropertyValue(conn2, "theConnection"));
conn2a.close();
}
@@ -227,12 +220,12 @@ public class CachingClientConnectionFactoryTests {
cachingFactory.setConnectionWaitTimeout(10);
cachingFactory.start();
TcpConnection conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
conn1.close();
conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
TcpConnection conn2 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn2.toString(), conn2.toString());
assertThat(conn2.toString()).isEqualTo("Cached:" + mockConn2.toString());
cachingFactory.getConnection();
}
@@ -249,12 +242,12 @@ public class CachingClientConnectionFactoryTests {
CachingClientConnectionFactory cachingFactory = new CachingClientConnectionFactory(factory, 2);
cachingFactory.start();
TcpConnection conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
conn1.close();
conn1 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn1.toString(), conn1.toString());
assertThat(conn1.toString()).isEqualTo("Cached:" + mockConn1.toString());
TcpConnection conn2 = cachingFactory.getConnection();
assertEquals("Cached:" + mockConn2.toString(), conn2.toString());
assertThat(conn2.toString()).isEqualTo("Cached:" + mockConn2.toString());
cachingFactory.stop();
Answer<Object> answer = new Answer<Object>() {
@@ -275,10 +268,10 @@ public class CachingClientConnectionFactoryTests {
when(mockConn2.isOpen()).thenReturn(false);
when(factory.isRunning()).thenReturn(true);
TcpConnection conn3 = cachingFactory.getConnection();
assertNotSame(TestUtils.getPropertyValue(conn1, "theConnection"),
TestUtils.getPropertyValue(conn3, "theConnection"));
assertNotSame(TestUtils.getPropertyValue(conn2, "theConnection"),
TestUtils.getPropertyValue(conn3, "theConnection"));
assertThat(TestUtils.getPropertyValue(conn3, "theConnection"))
.isNotSameAs(TestUtils.getPropertyValue(conn1, "theConnection"));
assertThat(TestUtils.getPropertyValue(conn3, "theConnection"))
.isNotSameAs(TestUtils.getPropertyValue(conn2, "theConnection"));
}
@Test
@@ -294,20 +287,20 @@ public class CachingClientConnectionFactoryTests {
cachingFactory.start();
TcpConnection conn1 = cachingFactory.getConnection();
TcpConnection conn2 = cachingFactory.getConnection();
assertNotSame(conn1, conn2);
assertThat(conn2).isNotSameAs(conn1);
Semaphore semaphore = TestUtils.getPropertyValue(
TestUtils.getPropertyValue(cachingFactory, "pool"), "permits", Semaphore.class);
assertEquals(0, semaphore.availablePermits());
assertThat(semaphore.availablePermits()).isEqualTo(0);
cachingFactory.setPoolSize(4);
TcpConnection conn3 = cachingFactory.getConnection();
TcpConnection conn4 = cachingFactory.getConnection();
assertEquals(0, semaphore.availablePermits());
assertThat(semaphore.availablePermits()).isEqualTo(0);
conn1.close();
conn1.close();
conn2.close();
conn3.close();
conn4.close();
assertEquals(4, semaphore.availablePermits());
assertThat(semaphore.availablePermits()).isEqualTo(4);
}
@Test
@@ -329,22 +322,22 @@ public class CachingClientConnectionFactoryTests {
TcpConnection conn4 = cachingFactory.getConnection();
Semaphore semaphore = TestUtils.getPropertyValue(
TestUtils.getPropertyValue(cachingFactory, "pool"), "permits", Semaphore.class);
assertEquals(0, semaphore.availablePermits());
assertThat(semaphore.availablePermits()).isEqualTo(0);
conn1.close();
assertEquals(1, semaphore.availablePermits());
assertThat(semaphore.availablePermits()).isEqualTo(1);
cachingFactory.setPoolSize(2);
assertEquals(0, semaphore.availablePermits());
assertEquals(3, cachingFactory.getActiveCount());
assertThat(semaphore.availablePermits()).isEqualTo(0);
assertThat(cachingFactory.getActiveCount()).isEqualTo(3);
conn2.close();
assertEquals(0, semaphore.availablePermits());
assertEquals(2, cachingFactory.getActiveCount());
assertThat(semaphore.availablePermits()).isEqualTo(0);
assertThat(cachingFactory.getActiveCount()).isEqualTo(2);
conn3.close();
assertEquals(1, cachingFactory.getActiveCount());
assertEquals(1, cachingFactory.getIdleCount());
assertThat(cachingFactory.getActiveCount()).isEqualTo(1);
assertThat(cachingFactory.getIdleCount()).isEqualTo(1);
conn4.close();
assertEquals(2, semaphore.availablePermits());
assertEquals(0, cachingFactory.getActiveCount());
assertEquals(2, cachingFactory.getIdleCount());
assertThat(semaphore.availablePermits()).isEqualTo(2);
assertThat(cachingFactory.getActiveCount()).isEqualTo(0);
assertThat(cachingFactory.getIdleCount()).isEqualTo(2);
verify(mockConn1).close();
verify(mockConn2).close();
}
@@ -375,12 +368,12 @@ public class CachingClientConnectionFactoryTests {
fail("Expected IOException");
}
catch (IOException e) {
assertEquals("Foo", e.getMessage());
assertThat(e.getMessage()).isEqualTo("Foo");
}
// Before INT-3163 this failed with a timeout - connection not returned to pool after failure on send()
TcpConnection cached2 = cccf.getConnection();
assertTrue(cached1.getConnectionId().contains(conn1.getConnectionId()));
assertTrue(cached2.getConnectionId().contains(conn2.getConnectionId()));
assertThat(cached1.getConnectionId().contains(conn1.getConnectionId())).isTrue();
assertThat(cached2.getConnectionId().contains(conn2.getConnectionId())).isTrue();
}
private CachingClientConnectionFactory createCCCFWith2Connections(TcpConnectionSupport conn1, TcpConnectionSupport conn2)
@@ -461,14 +454,14 @@ public class CachingClientConnectionFactoryTests {
this.outbound.send(new GenericMessage<>("Hello, world!"));
Message<?> m = inbound.receive(20_000);
assertNotNull(m);
assertThat(m).isNotNull();
String connectionId = m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class);
// assert we use the same connection from the pool
outbound.send(new GenericMessage<String>("Hello, world!"));
m = inbound.receive(20_000);
assertNotNull(m);
assertEquals(connectionId, m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class));
assertThat(m).isNotNull();
assertThat(m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class)).isEqualTo(connectionId);
}
@Test
@@ -493,8 +486,8 @@ public class CachingClientConnectionFactoryTests {
this.toGateway.send(new GenericMessage<>("Hello, world!"));
Message<?> m = fromGateway.receive(1000);
assertNotNull(m);
assertEquals("foo:" + "Hello, world!", new String((byte[]) m.getPayload()));
assertThat(m).isNotNull();
assertThat(new String((byte[]) m.getPayload())).isEqualTo("foo:" + "Hello, world!");
BlockingQueue<?> connections = TestUtils
.getPropertyValue(this.gatewayCF, "pool.available", BlockingQueue.class);
@@ -507,15 +500,15 @@ public class CachingClientConnectionFactoryTests {
// assert we use the same connection from the pool
toGateway.send(new GenericMessage<String>("Hello, world2!"));
m = fromGateway.receive(1000);
assertNotNull(m);
assertEquals("foo:" + "Hello, world2!", new String((byte[]) m.getPayload()));
assertThat(m).isNotNull();
assertThat(new String((byte[]) m.getPayload())).isEqualTo("foo:" + "Hello, world2!");
assertEquals(2, connectionIds.size());
assertEquals(connectionIds.get(0), connectionIds.get(1));
assertThat(connectionIds.size()).isEqualTo(2);
assertThat(connectionIds.get(1)).isEqualTo(connectionIds.get(0));
okToRun.set(false);
exec.shutdownNow();
assertTrue(exec.awaitTermination(20, TimeUnit.SECONDS));
assertThat(exec.awaitTermination(20, TimeUnit.SECONDS)).isTrue();
}
@Test
@@ -539,7 +532,7 @@ public class CachingClientConnectionFactoryTests {
while (n++ < 100 && connection.isOpen()) {
Thread.sleep(100);
}
assertFalse(connection.isOpen());
assertThat(connection.isOpen()).isFalse();
cccf.stop();
}
@@ -614,16 +607,16 @@ public class CachingClientConnectionFactoryTests {
conn1.send(message);
conn1.close();
TcpConnection conn2 = cachingFactory.getConnection();
assertSame(((TcpConnectionInterceptorSupport) conn1).getTheConnection(),
((TcpConnectionInterceptorSupport) conn2).getTheConnection());
assertThat(((TcpConnectionInterceptorSupport) conn2).getTheConnection())
.isSameAs(((TcpConnectionInterceptorSupport) conn1).getTheConnection());
conn2.send(message);
conn1 = cachingFactory.getConnection();
assertNotSame(((TcpConnectionInterceptorSupport) conn1).getTheConnection(),
((TcpConnectionInterceptorSupport) conn2).getTheConnection());
assertThat(((TcpConnectionInterceptorSupport) conn2).getTheConnection())
.isNotSameAs(((TcpConnectionInterceptorSupport) conn1).getTheConnection());
conn1.send(message);
conn1.close();
conn2.close();
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
server1.stop();
TestingUtilities.waitStopListening(server1, 10000L);
TestingUtilities.waitUntilFactoryHasThisNumberOfConnections(factory1, 0);
@@ -633,9 +626,9 @@ public class CachingClientConnectionFactoryTests {
conn2.send(message);
conn1.close();
conn2.close();
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
SimplePool<?> pool = TestUtils.getPropertyValue(cachingFactory, "pool", SimplePool.class);
assertEquals(2, pool.getIdleCount());
assertThat(pool.getIdleCount()).isEqualTo(2);
server2.stop();
}
@@ -681,17 +674,17 @@ public class CachingClientConnectionFactoryTests {
conn1.send(message);
conn1.close();
TcpConnection conn2 = cachingFactory.getConnection();
assertSame(((TcpConnectionInterceptorSupport) conn1).getTheConnection(),
((TcpConnectionInterceptorSupport) conn2).getTheConnection());
assertThat(((TcpConnectionInterceptorSupport) conn2).getTheConnection())
.isSameAs(((TcpConnectionInterceptorSupport) conn1).getTheConnection());
conn2.send(message);
conn1 = cachingFactory.getConnection();
assertNotSame(((TcpConnectionInterceptorSupport) conn1).getTheConnection(),
((TcpConnectionInterceptorSupport) conn2).getTheConnection());
assertThat(((TcpConnectionInterceptorSupport) conn2).getTheConnection())
.isNotSameAs(((TcpConnectionInterceptorSupport) conn1).getTheConnection());
conn1.send(message);
conn1.close();
conn2.close();
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertEquals(3, latch1.getCount());
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(latch1.getCount()).isEqualTo(3);
server1.stop();
server2.stop();
}
@@ -722,15 +715,15 @@ public class CachingClientConnectionFactoryTests {
TcpConnectionSupport connection2 = cache.getConnection();
connection2.send(new GenericMessage<String>("foo"));
connection2.close();
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertSame(connectionIds.get(0), connectionIds.get(1));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(connectionIds.get(1)).isSameAs(connectionIds.get(0));
for (int i = 0; i < 100; i++) {
TcpConnectionSupport connection = cache.getConnection();
connection.send(new GenericMessage<String>("foo"));
connection.close();
}
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertSame(connectionIds.get(0), connectionIds.get(101));
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(connectionIds.get(101)).isSameAs(connectionIds.get(0));
in.stop();
cache.stop();
}
@@ -797,11 +790,11 @@ public class CachingClientConnectionFactoryTests {
gate.start();
gate.handleMessage(new GenericMessage<String>("foo"));
Message<byte[]> result = (Message<byte[]>) outputChannel.receive(10000);
assertNotNull(result);
assertEquals("foo", new String(result.getPayload()));
assertThat(result).isNotNull();
assertThat(new String(result.getPayload())).isEqualTo("foo");
result = (Message<byte[]>) outputChannel.receive(10000);
assertNotNull(result);
assertEquals("bar", new String(result.getPayload()));
assertThat(result).isNotNull();
assertThat(new String(result.getPayload())).isEqualTo("bar");
handler.stop();
gate.stop();
verify(logger, never()).error(anyString());
@@ -838,9 +831,9 @@ public class CachingClientConnectionFactoryTests {
cachingFactory.start();
cachingFactory.getConnection();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNotNull(received.get());
assertNotNull(received.get().getHeaders().get(IpHeaders.ACTUAL_CONNECTION_ID));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(received.get()).isNotNull();
assertThat(received.get().getHeaders().get(IpHeaders.ACTUAL_CONNECTION_ID)).isNotNull();
cachingFactory.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,17 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
@@ -49,7 +40,6 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.net.ServerSocketFactory;
import org.apache.commons.logging.Log;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -113,19 +103,20 @@ public class ConnectionEventTests {
}
catch (Exception e) {
}
assertTrue(theEvent.size() > 0);
assertNotNull(theEvent.get(0));
assertTrue(theEvent.get(0) instanceof TcpConnectionExceptionEvent);
assertTrue(theEvent.get(0).toString().endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "]"));
assertThat(theEvent.get(0).toString(),
containsString("RuntimeException: foo, failedMessage=GenericMessage [payload=bar"));
assertThat(theEvent.size() > 0).isTrue();
assertThat(theEvent.get(0)).isNotNull();
assertThat(theEvent.get(0) instanceof TcpConnectionExceptionEvent).isTrue();
assertThat(theEvent.get(0).toString().endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "]"))
.isTrue();
assertThat(theEvent.get(0).toString())
.contains("RuntimeException: foo, failedMessage=GenericMessage [payload=bar");
TcpConnectionExceptionEvent event = (TcpConnectionExceptionEvent) theEvent.get(0);
assertNotNull(event.getCause());
assertSame(toBeThrown, event.getCause().getCause());
assertTrue(theEvent.size() > 1);
assertNotNull(theEvent.get(1));
assertTrue(theEvent.get(1).toString()
.endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "] **CLOSED**"));
assertThat(event.getCause()).isNotNull();
assertThat(event.getCause().getCause()).isSameAs(toBeThrown);
assertThat(theEvent.size() > 1).isTrue();
assertThat(theEvent.get(1)).isNotNull();
assertThat(theEvent.get(1).toString()
.endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "] **CLOSED**")).isTrue();
}
@Test
@@ -173,12 +164,12 @@ public class ConnectionEventTests {
fail("expected exception");
}
catch (MessageHandlingException e) {
assertThat(e.getMessage(), Matchers.containsString("Unable to find outbound socket"));
assertThat(e.getMessage()).contains("Unable to find outbound socket");
}
assertNotNull(theEvent.get());
assertThat(theEvent.get()).isNotNull();
TcpConnectionFailedCorrelationEvent event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
assertEquals("bar", event.getConnectionId());
assertSame(message, ((MessagingException) event.getCause()).getFailedMessage());
assertThat(event.getConnectionId()).isEqualTo("bar");
assertThat(((MessagingException) event.getCause()).getFailedMessage()).isSameAs(message);
}
@Test
@@ -212,10 +203,10 @@ public class ConnectionEventTests {
.setHeader(IpHeaders.CONNECTION_ID, "bar")
.build();
gw.onMessage(message);
assertNotNull(theEvent.get());
assertThat(theEvent.get()).isNotNull();
TcpConnectionFailedCorrelationEvent event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
assertEquals("bar", event.getConnectionId());
assertSame(message, ((MessagingException) event.getCause()).getFailedMessage());
assertThat(event.getConnectionId()).isEqualTo("bar");
assertThat(((MessagingException) event.getCause()).getFailedMessage()).isSameAs(message);
gw.stop();
scf.stop();
}
@@ -247,21 +238,21 @@ public class ConnectionEventTests {
.setHeader(IpHeaders.CONNECTION_ID, "bar")
.build();
gw.onMessage(message);
assertNotNull(theEvent.get());
assertThat(theEvent.get()).isNotNull();
TcpConnectionFailedCorrelationEvent event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
assertEquals("bar", event.getConnectionId());
assertThat(event.getConnectionId()).isEqualTo("bar");
MessagingException messagingException = (MessagingException) event.getCause();
assertSame(message, messagingException.getFailedMessage());
assertEquals("Cannot correlate response - no pending reply for bar", messagingException.getMessage());
assertThat(messagingException.getFailedMessage()).isSameAs(message);
assertThat(messagingException.getMessage()).isEqualTo("Cannot correlate response - no pending reply for bar");
message = new GenericMessage<String>("foo");
gw.onMessage(message);
assertNotNull(theEvent.get());
assertThat(theEvent.get()).isNotNull();
event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
assertNull(event.getConnectionId());
assertThat(event.getConnectionId()).isNull();
messagingException = (MessagingException) event.getCause();
assertSame(message, messagingException.getFailedMessage());
assertEquals("Cannot correlate response - no connection id", messagingException.getMessage());
assertThat(messagingException.getFailedMessage()).isSameAs(message);
assertThat(messagingException.getMessage()).isEqualTo("Cannot correlate response - no connection id");
gw.stop();
ccf.stop();
}
@@ -299,18 +290,18 @@ public class ConnectionEventTests {
new DirectFieldAccessor(factory).setPropertyValue("logger", logger);
factory.start();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
String actual = theEvent.toString();
assertThat(actual, containsString("cause=java.net.BindException"));
assertThat(actual, containsString("source="
+ "sf, port=" + factory.getPort()));
assertThat(actual).contains("cause=java.net.BindException");
assertThat(actual).contains("source="
+ "sf, port=" + factory.getPort());
ArgumentCaptor<String> reasonCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Throwable> throwableCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(logger).error(reasonCaptor.capture(), throwableCaptor.capture());
assertThat(reasonCaptor.getValue(), startsWith("Error on Server"));
assertThat(reasonCaptor.getValue(), endsWith("; port = " + factory.getPort()));
assertThat(throwableCaptor.getValue(), instanceOf(BindException.class));
assertThat(reasonCaptor.getValue()).startsWith("Error on Server");
assertThat(reasonCaptor.getValue()).endsWith("; port = " + factory.getPort());
assertThat(throwableCaptor.getValue()).isInstanceOf(BindException.class);
ss.close();
}
@@ -349,9 +340,9 @@ public class ConnectionEventTests {
fail("expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(UnknownHostException.class));
assertThat(e).isInstanceOf(UnknownHostException.class);
TcpConnectionFailedEvent event = (TcpConnectionFailedEvent) failEvent.get();
assertSame(e, event.getCause());
assertThat(event.getCause()).isSameAs(e);
}
ccf.stop();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@@ -65,13 +65,14 @@ public class ConnectionFactoryShutDownTests {
}
latch2.countDown();
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
StopWatch watch = new StopWatch();
watch.start();
factory.stop();
watch.stop();
assertTrue("Expected < 10000, was: " + watch.getLastTaskTimeMillis(), watch.getLastTaskTimeMillis() < 10000);
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(watch.getLastTaskTimeMillis() < 10000).as("Expected < 10000, was: " + watch.getLastTaskTimeMillis())
.isTrue();
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.Mockito.atLeast;
@@ -77,11 +71,11 @@ public class ConnectionFactoryTests {
@Test
public void factoryBeanTests() {
TcpConnectionFactoryFactoryBean fb = new TcpConnectionFactoryFactoryBean("client");
assertEquals(AbstractClientConnectionFactory.class, fb.getObjectType());
assertThat(fb.getObjectType()).isEqualTo(AbstractClientConnectionFactory.class);
fb = new TcpConnectionFactoryFactoryBean("server");
assertEquals(AbstractServerConnectionFactory.class, fb.getObjectType());
assertThat(fb.getObjectType()).isEqualTo(AbstractServerConnectionFactory.class);
fb = new TcpConnectionFactoryFactoryBean();
assertEquals(AbstractConnectionFactory.class, fb.getObjectType());
assertThat(fb.getObjectType()).isEqualTo(AbstractConnectionFactory.class);
}
@Test
@@ -142,9 +136,9 @@ public class ConnectionFactoryTests {
adapter.setOutputChannel(new NullChannel());
adapter.setConnectionFactory(serverFactory);
adapter.start();
assertTrue("Listening event not received", serverListeningLatch.await(10, TimeUnit.SECONDS));
assertThat(events.get(0), instanceOf(TcpConnectionServerListeningEvent.class));
assertThat(((TcpConnectionServerListeningEvent) events.get(0)).getPort(), equalTo(serverFactory.getPort()));
assertThat(serverListeningLatch.await(10, TimeUnit.SECONDS)).as("Listening event not received").isTrue();
assertThat(events.get(0)).isInstanceOf(TcpConnectionServerListeningEvent.class);
assertThat(((TcpConnectionServerListeningEvent) events.get(0)).getPort()).isEqualTo(serverFactory.getPort());
int port = serverFactory.getPort();
TcpNetClientConnectionFactory clientFactory = new TcpNetClientConnectionFactory("localhost", port);
clientFactory.registerListener(message -> false);
@@ -153,29 +147,32 @@ public class ConnectionFactoryTests {
clientFactory.start();
TcpConnectionSupport client = clientFactory.getConnection();
List<String> clients = clientFactory.getOpenConnectionIds();
assertEquals(1, clients.size());
assertTrue(clients.contains(client.getConnectionId()));
assertTrue("Server connection failed to register", serverConnectionInitLatch.await(10, TimeUnit.SECONDS));
assertThat(clients.size()).isEqualTo(1);
assertThat(clients.contains(client.getConnectionId())).isTrue();
assertThat(serverConnectionInitLatch.await(10, TimeUnit.SECONDS)).as("Server connection failed to register")
.isTrue();
List<String> servers = serverFactory.getOpenConnectionIds();
assertEquals(1, servers.size());
assertTrue(serverFactory.closeConnection(servers.get(0)));
assertThat(servers.size()).isEqualTo(1);
assertThat(serverFactory.closeConnection(servers.get(0))).isTrue();
servers = serverFactory.getOpenConnectionIds();
assertEquals(0, servers.size());
assertThat(servers.size()).isEqualTo(0);
int n = 0;
clients = clientFactory.getOpenConnectionIds();
while (n++ < 100 && clients.size() > 0) {
Thread.sleep(100);
clients = clientFactory.getOpenConnectionIds();
}
assertEquals(0, clients.size());
assertTrue(eventLatch.await(10, TimeUnit.SECONDS));
assertThat("Expected at least " + expectedEvents + " events; got: " + events.size() + " : " + events,
events.size(), greaterThanOrEqualTo(expectedEvents));
assertThat(clients.size()).isEqualTo(0);
assertThat(eventLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(events.size())
.as("Expected at least " + expectedEvents + " events; got: " + events.size() + " : " + events)
.isGreaterThanOrEqualTo(expectedEvents);
FooEvent event = new FooEvent(client, "foo");
client.publishEvent(event);
assertThat("Expected at least " + expectedEvents + " events; got: " + events.size() + " : " + events,
events.size(), greaterThanOrEqualTo(expectedEvents + 1));
assertThat(events.size())
.as("Expected at least " + expectedEvents + " events; got: " + events.size() + " : " + events)
.isGreaterThanOrEqualTo(expectedEvents + 1);
try {
event = new FooEvent(mock(TcpConnectionSupport.class), "foo");
@@ -183,13 +180,13 @@ public class ConnectionFactoryTests {
fail("Expected exception");
}
catch (IllegalArgumentException e) {
assertTrue("Can only publish events with this as the source".equals(e.getMessage()));
assertThat("Can only publish events with this as the source".equals(e.getMessage())).isTrue();
}
SocketAddress address = serverFactory.getServerSocketAddress();
if (address instanceof InetSocketAddress) {
InetSocketAddress inetAddress = (InetSocketAddress) address;
assertEquals(port, inetAddress.getPort());
assertThat(inetAddress.getPort()).isEqualTo(port);
}
serverFactory.stop();
scheduler.shutdown();
@@ -231,7 +228,7 @@ public class ConnectionFactoryTests {
return null;
}).when(logger).debug(contains(message));
factory.start();
assertTrue("missing info log", latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).as("missing info log").isTrue();
// stop on a different thread because it waits for the executor
new SimpleAsyncTaskExecutor()
.execute(factory::stop);
@@ -240,13 +237,13 @@ public class ConnectionFactoryTests {
while (n++ < 200 && accessor.getPropertyValue(property) != null) {
Thread.sleep(100);
}
assertTrue("Stop was not invoked in time", n < 200);
assertThat(n < 200).as("Stop was not invoked in time").isTrue();
latch2.countDown();
assertTrue("missing debug log", latch3.await(10, TimeUnit.SECONDS));
assertThat(latch3.await(10, TimeUnit.SECONDS)).as("missing debug log").isTrue();
String expected = "foo, port=" + factory.getPort() + message;
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, atLeast(1)).debug(captor.capture());
assertThat(captor.getAllValues(), hasItem(expected));
assertThat(captor.getAllValues()).contains(expected);
factory.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.Socket;
import java.util.concurrent.CountDownLatch;
@@ -60,7 +56,7 @@ public class ConnectionTimeoutTests {
TcpConnection connection = client.getConnection();
Socket socket = TestUtils.getPropertyValue(connection, "socket", Socket.class);
// should default to 0 (infinite) timeout
assertEquals(0, socket.getSoTimeout());
assertThat(socket.getSoTimeout()).isEqualTo(0);
connection.close();
server.stop();
client.stop();
@@ -80,9 +76,9 @@ public class ConnectionTimeoutTests {
client.start();
TcpConnection connection = client.getConnection();
Socket socket = TestUtils.getPropertyValue(connection, "socket", Socket.class);
assertEquals(1000, socket.getSoTimeout());
assertTrue(clientCloseLatch.await(3, TimeUnit.SECONDS));
assertFalse(connection.isOpen());
assertThat(socket.getSoTimeout()).isEqualTo(1000);
assertThat(clientCloseLatch.await(3, TimeUnit.SECONDS)).isTrue();
assertThat(connection.isOpen()).isFalse();
server.stop();
client.stop();
}
@@ -131,10 +127,10 @@ public class ConnectionTimeoutTests {
TcpConnection connection = client.getConnection();
Thread.sleep(1000);
connection.send(MessageBuilder.withPayload("foo").build());
assertTrue(replyLatch.await(5, TimeUnit.SECONDS));
assertNotNull(reply.get());
assertTrue(clientClosedLatch.await(10, TimeUnit.SECONDS));
assertFalse(connection.isOpen());
assertThat(replyLatch.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(reply.get()).isNotNull();
assertThat(clientClosedLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(connection.isOpen()).isFalse();
server.stop();
client.stop();
}
@@ -170,14 +166,14 @@ public class ConnectionTimeoutTests {
client.start();
TcpConnection connection = client.getConnection();
Socket socket = TestUtils.getPropertyValue(connection, "socket", Socket.class);
assertEquals(2000, socket.getSoTimeout());
assertThat(socket.getSoTimeout()).isEqualTo(2000);
Thread.sleep(1000);
connection.send(MessageBuilder.withPayload("foo").build());
Thread.sleep(1400);
assertTrue(connection.isOpen());
assertTrue(clientCloseLatch.await(2000, TimeUnit.SECONDS));
assertNull(reply.get());
assertFalse(connection.isOpen());
assertThat(connection.isOpen()).isTrue();
assertThat(clientCloseLatch.await(2000, TimeUnit.SECONDS)).isTrue();
assertThat(reply.get()).isNull();
assertThat(connection.isOpen()).isFalse();
server.stop();
client.stop();
}
@@ -209,10 +205,10 @@ public class ConnectionTimeoutTests {
Thread.sleep(500);
connection.send(MessageBuilder.withPayload("foo").build());
Thread.sleep(700);
assertTrue(connection.isOpen());
assertTrue(clientCloseLatch.await(2, TimeUnit.SECONDS));
assertNull(reply.get());
assertFalse(connection.isOpen());
assertThat(connection.isOpen()).isTrue();
assertThat(clientCloseLatch.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(reply.get()).isNull();
assertThat(connection.isOpen()).isFalse();
server.stop();
client.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -343,22 +339,20 @@ public class FailoverClientConnectionFactoryTests {
conn1.send(new GenericMessage<String>("foo1"));
conn1.close();
TcpConnection conn2 = failoverFactory.getConnection();
assertSame(
(TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection(),
(TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
assertThat((TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection())
.isSameAs((TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection());
conn2.send(new GenericMessage<String>("foo2"));
conn1 = failoverFactory.getConnection();
assertNotSame(
(TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection(),
(TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
assertThat((TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection())
.isNotSameAs((TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection());
conn1.send(new GenericMessage<String>("foo3"));
conn1.close();
conn2.close();
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
server1.stop();
TestingUtilities.waitStopListening(server1, 10000L);
TestingUtilities.waitUntilFactoryHasThisNumberOfConnections(factory1, 0);
@@ -368,9 +362,9 @@ public class FailoverClientConnectionFactoryTests {
conn2.send(new GenericMessage<String>("foo5"));
conn1.close();
conn2.close();
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
SimplePool<?> pool = TestUtils.getPropertyValue(cachingFactory2, "pool", SimplePool.class);
assertEquals(2, pool.getIdleCount());
assertThat(pool.getIdleCount()).isEqualTo(2);
server2.stop();
}
@@ -416,14 +410,14 @@ public class FailoverClientConnectionFactoryTests {
outbound.handleMessage(new GenericMessage<String>("foo"));
Message<byte[]> result = (Message<byte[]>) replyChannel.receive(10000);
assertNotNull(result);
assertEquals("foo", new String(result.getPayload()));
assertThat(result).isNotNull();
assertThat(new String(result.getPayload())).isEqualTo("foo");
// INT-4024 - second reply had bad connection id
outbound.handleMessage(new GenericMessage<String>("foo"));
result = (Message<byte[]>) replyChannel.receive(10000);
assertNotNull(result);
assertEquals("foo", new String(result.getPayload()));
assertThat(result).isNotNull();
assertThat(new String(result.getPayload())).isEqualTo("foo");
inbound.stop();
outbound.stop();
@@ -476,23 +470,21 @@ public class FailoverClientConnectionFactoryTests {
conn1.send(message);
conn1.close();
TcpConnection conn2 = failoverFactory.getConnection();
assertSame(
(TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection(),
(TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
assertThat((TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection())
.isSameAs((TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection());
conn2.send(message);
conn1 = failoverFactory.getConnection();
assertNotSame(
(TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection(),
(TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
assertThat((TestUtils.getPropertyValue(conn2, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection())
.isNotSameAs((TestUtils.getPropertyValue(conn1, "delegate", TcpConnectionInterceptorSupport.class))
.getTheConnection());
conn1.send(message);
conn1.close();
conn2.close();
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertEquals(3, latch1.getCount());
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(latch1.getCount()).isEqualTo(3);
server1.stop();
server2.stop();
}
@@ -529,9 +521,9 @@ public class FailoverClientConnectionFactoryTests {
socket = getSocket(client1);
port1 = socket.getLocalPort();
}
assertTrue(singleUse | holder.connectionId.get().contains(Integer.toString(port1)));
assertThat(singleUse | holder.connectionId.get().contains(Integer.toString(port1))).isTrue();
Message<?> replyMessage = replyChannel.receive(10000);
assertNotNull(replyMessage);
assertThat(replyMessage).isNotNull();
holder.server1.stop();
TestingUtilities.waitStopListening(holder.server1, 10000L);
TestingUtilities.waitUntilFactoryHasThisNumberOfConnections(client1, 0);
@@ -540,9 +532,9 @@ public class FailoverClientConnectionFactoryTests {
socket = getSocket(client2);
port2 = socket.getLocalPort();
}
assertTrue(singleUse | holder.connectionId.get().contains(Integer.toString(port2)));
assertThat(singleUse | holder.connectionId.get().contains(Integer.toString(port2))).isTrue();
replyMessage = replyChannel.receive(10000);
assertNotNull(replyMessage);
assertThat(replyMessage).isNotNull();
holder.gateway2.stop();
outGateway.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.InputStream;
@@ -72,14 +68,14 @@ public class PushbackTcpTests {
Collections.singletonMap(MessageHeaders.REPLY_CHANNEL, replies));
channel1.send(message);
channel2.send(message);
assertThat(replies.getQueueSize(), equalTo(2));
assertThat(replies.getQueueSize()).isEqualTo(2);
Message<?> replyA = replies.receive(0);
Message<?> replyB = replies.receive(0);
assertThat((String) replyA.getPayload(), containsString("ip_connectionId:pushback:"));
assertThat(replyB.getPayload(), not(equalTo(replyA.getPayload())));
assertThat((String) replyA.getPayload()).contains("ip_connectionId:pushback:");
assertThat(replyB.getPayload()).isNotEqualTo(replyA.getPayload());
CompositeDeserializer deserializer = server.getBean(CompositeDeserializer.class);
assertTrue(deserializer.receivedCrLf);
assertTrue(deserializer.receivedStxEtx);
assertThat(deserializer.receivedCrLf).isTrue();
assertThat(deserializer.receivedStxEtx).isTrue();
System.getProperties().remove(PORT);
client.close();
server.close();
@@ -99,14 +95,14 @@ public class PushbackTcpTests {
Collections.singletonMap(MessageHeaders.REPLY_CHANNEL, replies));
channel1.send(message);
channel2.send(message);
assertThat(replies.getQueueSize(), equalTo(2));
assertThat(replies.getQueueSize()).isEqualTo(2);
Message<?> replyA = replies.receive(0);
Message<?> replyB = replies.receive(0);
assertThat((String) replyA.getPayload(), containsString("ip_connectionId:pushback:"));
assertThat(replyB.getPayload(), not(equalTo(replyA.getPayload())));
assertThat((String) replyA.getPayload()).contains("ip_connectionId:pushback:");
assertThat(replyB.getPayload()).isNotEqualTo(replyA.getPayload());
CompositeDeserializer deserializer = server.getBean(CompositeDeserializer.class);
assertTrue(deserializer.receivedCrLf);
assertTrue(deserializer.receivedStxEtx);
assertThat(deserializer.receivedCrLf).isTrue();
assertThat(deserializer.receivedStxEtx).isTrue();
System.getProperties().remove(PORT);
client.close();
server.close();
@@ -128,14 +124,14 @@ public class PushbackTcpTests {
Collections.singletonMap(MessageHeaders.REPLY_CHANNEL, replies));
channel1.send(message);
channel2.send(message);
assertThat(replies.getQueueSize(), equalTo(2));
assertThat(replies.getQueueSize()).isEqualTo(2);
Message<?> replyA = replies.receive(0);
Message<?> replyB = replies.receive(0);
assertThat((String) replyA.getPayload(), containsString("ip_connectionId:pushback:"));
assertThat(replyB.getPayload(), not(equalTo(replyA.getPayload())));
assertThat((String) replyA.getPayload()).contains("ip_connectionId:pushback:");
assertThat(replyB.getPayload()).isNotEqualTo(replyA.getPayload());
CompositeDeserializer deserializer = server.getBean(CompositeDeserializer.class);
assertTrue(deserializer.receivedCrLf);
assertTrue(deserializer.receivedStxEtx);
assertThat(deserializer.receivedCrLf).isTrue();
assertThat(deserializer.receivedStxEtx).isTrue();
System.getProperties().remove(PORT);
client.close();
server.close();
@@ -148,7 +144,7 @@ public class PushbackTcpTests {
Thread.sleep(100);
port = serverCF.getPort();
}
assertTrue(n < 200);
assertThat(n < 200).isTrue();
return port;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.IOException;
import java.io.InputStream;
@@ -111,7 +111,7 @@ public class SOLingerTests {
byte[] buff = new byte[test.length() + 5];
try {
readFully(socket.getInputStream(), buff);
assertEquals("echo:" + test, new String(buff));
assertThat(new String(buff)).isEqualTo("echo:" + test);
}
catch (SocketException se) {
if (hasLinger) {
@@ -123,7 +123,7 @@ public class SOLingerTests {
}
int n = socket.getInputStream().read();
// we expect an orderly close
assertEquals(-1, n);
assertThat(n).isEqualTo(-1);
}
catch (Exception e) {
e.printStackTrace();
@@ -146,7 +146,7 @@ public class SOLingerTests {
// if we do, verify it is as expected, if not, the RST
// arrived before the final data.
readFully(socket.getInputStream(), buff);
assertEquals("echo:" + test, new String(buff));
assertThat(new String(buff)).isEqualTo("echo:" + test);
socket.getInputStream().read();
fail("Expected SocketException");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.anyOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -119,7 +114,7 @@ public class SocketSupportTests {
connectionFactory.registerListener(mock(TcpListener.class));
connectionFactory.start();
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
verify(socketSupport).postProcessServerSocket(serverSocket);
verify(socketSupport).postProcessSocket(socket);
latch2.countDown();
@@ -171,19 +166,20 @@ public class SocketSupportTests {
clientConnectionFactory.setTcpSocketSupport(clientSocketSupport);
clientConnectionFactory.start();
clientConnectionFactory.getConnection().send(new GenericMessage<String>("Hello, world!"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(0, ppServerSocketCountClient.get());
assertEquals(1, ppSocketCountClient.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(ppServerSocketCountClient.get()).isEqualTo(0);
assertThat(ppSocketCountClient.get()).isEqualTo(1);
assertEquals(1, ppServerSocketCountServer.get());
assertEquals(1, ppSocketCountServer.get());
assertThat(ppServerSocketCountServer.get()).isEqualTo(1);
assertThat(ppSocketCountServer.get()).isEqualTo(1);
clientConnectionFactory.stop();
serverConnectionFactory.stop();
}
/*
$ keytool -genkeypair -alias sitestcertkey -keyalg RSA -validity 36500 -keystore src/test/resources/test.ks -ext san=dns:localhost
$ keytool -genkeypair -alias sitestcertkey -keyalg RSA -validity 36500 -keystore src/test/resources/test.ks -ext
san=dns:localhost
Enter keystore password: secret
Re-enter new password: secret
What is your first and last name?
@@ -254,7 +250,8 @@ public class SocketSupportTests {
Enter keystore password:
Certificate stored in file <src/test/resources/test.cer>
$ keytool -import -alias sitestcertkey -file src/test/resources/test.cer -keystore src/test/resources/test.truststore.ks
$ keytool -import -alias sitestcertkey -file src/test/resources/test.cer -keystore src/test/resources/test
.truststore.ks
Enter keystore password: secret
Re-enter new password: secret
Owner: CN=Spring Integration, OU=Spring, O=Pivotal Software Inc., L=San Francisco, ST=CA, C=US
@@ -358,9 +355,9 @@ public class SocketSupportTests {
TcpConnection connection = client.getConnection();
connection.send(new GenericMessage<String>("Hello, world!"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
assertNotNull(messages.get(0).getHeaders().get("cipher"));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
assertThat(messages.get(0).getHeaders().get("cipher")).isNotNull();
client.stop();
server.stop();
@@ -417,8 +414,8 @@ public class SocketSupportTests {
client.start();
TcpConnection connection = client.getConnection();
connection.send(new GenericMessage<String>("Hello, world!"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
}
finally {
client.stop();
@@ -463,16 +460,16 @@ public class SocketSupportTests {
client.start();
TcpConnection connection = client.getConnection();
assertEquals(34, TestUtils.getPropertyValue(connection, "handshakeTimeout"));
assertThat(TestUtils.getPropertyValue(connection, "handshakeTimeout")).isEqualTo(34);
connection.send(new GenericMessage<String>("Hello, world!"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
assertNotNull(messages.get(0).getHeaders().get("cipher"));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
assertThat(messages.get(0).getHeaders().get("cipher")).isNotNull();
Map<?, ?> connections = TestUtils.getPropertyValue(server, "connections", Map.class);
Object serverConnection = connections.get(serverConnectionId.get());
assertNotNull(serverConnection);
assertEquals(43, TestUtils.getPropertyValue(serverConnection, "handshakeTimeout"));
assertThat(serverConnection).isNotNull();
assertThat(TestUtils.getPropertyValue(serverConnection, "handshakeTimeout")).isEqualTo(43);
client.stop();
server.stop();
@@ -487,11 +484,11 @@ public class SocketSupportTests {
}
catch (IOException e) {
if (!(e instanceof ClosedChannelException)) {
assertThat(e.getMessage(),
anyOf(
containsString("Socket closed during SSL Handshake"),
containsString("Broken pipe"),
containsString("Connection reset by peer")));
assertThat(e.getMessage())
.satisfiesAnyOf(
s -> assertThat(s).contains("Socket closed during SSL Handshake"),
s -> assertThat(s).contains("Broken pipe"),
s -> assertThat(s).contains("Connection reset by peer"));
}
}
}
@@ -533,8 +530,8 @@ public class SocketSupportTests {
client.start();
TcpConnection connection = client.getConnection();
connection.send(new GenericMessage<String>("Hello, world!"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
}
finally {
client.stop();
@@ -595,21 +592,21 @@ public class SocketSupportTests {
client.start();
TcpConnection connection = client.getConnection();
assertEquals(30, TestUtils.getPropertyValue(connection, "handshakeTimeout"));
assertThat(TestUtils.getPropertyValue(connection, "handshakeTimeout")).isEqualTo(30);
byte[] bytes = new byte[100000];
connection.send(new GenericMessage<String>("Hello, world!" + new String(bytes)));
assertTrue(latch.await(60, TimeUnit.SECONDS));
assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
byte[] payload = (byte[]) messages.get(0).getPayload();
assertEquals(13 + bytes.length, payload.length);
assertEquals("Hello, world!", new String(payload).substring(0, 13));
assertThat(payload.length).isEqualTo(13 + bytes.length);
assertThat(new String(payload).substring(0, 13)).isEqualTo("Hello, world!");
payload = (byte[]) messages.get(1).getPayload();
assertEquals(13 + bytes.length, payload.length);
assertEquals("Hello, world!", new String(payload).substring(0, 13));
assertThat(payload.length).isEqualTo(13 + bytes.length);
assertThat(new String(payload).substring(0, 13)).isEqualTo("Hello, world!");
Map<?, ?> connections = TestUtils.getPropertyValue(server, "connections", Map.class);
Object serverConnection = connections.get(serverConnectionId.get());
assertNotNull(serverConnection);
assertEquals(30, TestUtils.getPropertyValue(serverConnection, "handshakeTimeout"));
assertThat(serverConnection).isNotNull();
assertThat(TestUtils.getPropertyValue(serverConnection, "handshakeTimeout")).isEqualTo(30);
client.stop();
server.stop();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -58,29 +54,29 @@ public class TcpConnectionEventListenerTests {
eventProducer.start();
TcpConnectionSupport connection = Mockito.mock(TcpConnectionSupport.class);
assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(TcpConnectionOpenEvent.class)));
assertThat(eventProducer.supportsEventType(ResolvableType.forClass(TcpConnectionOpenEvent.class))).isTrue();
TcpConnectionEvent event1 = new TcpConnectionOpenEvent(connection, "foo");
eventProducer.onApplicationEvent(event1);
assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(FooEvent.class)));
assertThat(eventProducer.supportsEventType(ResolvableType.forClass(FooEvent.class))).isTrue();
FooEvent event2 = new FooEvent(connection, "foo");
eventProducer.onApplicationEvent(event2);
assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(BarEvent.class)));
assertThat(eventProducer.supportsEventType(ResolvableType.forClass(BarEvent.class))).isTrue();
BarEvent event3 = new BarEvent(connection, "foo");
eventProducer.onApplicationEvent(event3);
Message<?> message = outputChannel.receive(0);
assertNotNull(message);
assertSame(event1, message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isSameAs(event1);
message = outputChannel.receive(0);
assertNotNull(message);
assertSame(event2, message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isSameAs(event2);
message = outputChannel.receive(0);
assertNotNull(message);
assertSame(event3, message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isSameAs(event3);
message = outputChannel.receive(0);
assertNull(message);
assertThat(message).isNull();
}
@Test
@@ -98,24 +94,24 @@ public class TcpConnectionEventListenerTests {
eventProducer.start();
TcpConnectionSupport connection = Mockito.mock(TcpConnectionSupport.class);
assertFalse(eventProducer.supportsEventType(ResolvableType.forClass(TcpConnectionOpenEvent.class)));
assertThat(eventProducer.supportsEventType(ResolvableType.forClass(TcpConnectionOpenEvent.class))).isFalse();
assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(FooEvent.class)));
assertThat(eventProducer.supportsEventType(ResolvableType.forClass(FooEvent.class))).isTrue();
FooEvent event2 = new FooEvent(connection, "foo");
eventProducer.onApplicationEvent(event2);
assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(BarEvent.class)));
assertThat(eventProducer.supportsEventType(ResolvableType.forClass(BarEvent.class))).isTrue();
BarEvent event3 = new BarEvent(connection, "foo");
eventProducer.onApplicationEvent(event3);
Message<?> message = outputChannel.receive(0);
assertNotNull(message);
assertSame(event2, message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isSameAs(event2);
message = outputChannel.receive(0);
assertNotNull(message);
assertSame(event3, message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isSameAs(event3);
message = outputChannel.receive(0);
assertNull(message);
assertThat(message).isNull();
}
@SuppressWarnings("serial")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -89,12 +84,12 @@ public class TcpMessageMapperTests {
when(connection.getPort()).thenReturn(1234);
when(connection.getSocketInfo()).thenReturn(info);
Message<?> message = mapper.toMessage(connection);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertSame(local, message.getHeaders().get(IpHeaders.LOCAL_ADDRESS));
assertNull(message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertThat(new String((byte[]) message.getPayload())).isEqualTo(TEST_PAYLOAD);
assertThat(message.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("MyHost");
assertThat(message.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(message.getHeaders().get(IpHeaders.LOCAL_ADDRESS)).isSameAs(local);
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isNull();
}
@Test
@@ -112,14 +107,15 @@ public class TcpMessageMapperTests {
when(connection.getPort()).thenReturn(1234);
when(connection.getSocketInfo()).thenReturn(info);
Message<?> message = mapper.toMessage(connection);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertSame(local, message.getHeaders().get(IpHeaders.LOCAL_ADDRESS));
assertEquals("application/octet-stream;charset=UTF-8", message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertThat(new String((byte[]) message.getPayload())).isEqualTo(TEST_PAYLOAD);
assertThat(message.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("MyHost");
assertThat(message.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(message.getHeaders().get(IpHeaders.LOCAL_ADDRESS)).isSameAs(local);
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE))
.isEqualTo("application/octet-stream;charset=UTF-8");
MimeType parseOk = MimeType.valueOf((String) message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertEquals(message.getHeaders().get(MessageHeaders.CONTENT_TYPE), parseOk.toString());
assertThat(parseOk.toString()).isEqualTo(message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
@Test
@@ -138,14 +134,15 @@ public class TcpMessageMapperTests {
when(connection.getPort()).thenReturn(1234);
when(connection.getSocketInfo()).thenReturn(info);
Message<?> message = mapper.toMessage(connection);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertSame(local, message.getHeaders().get(IpHeaders.LOCAL_ADDRESS));
assertEquals("application/octet-stream;charset=ISO-8859-1", message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertThat(new String((byte[]) message.getPayload())).isEqualTo(TEST_PAYLOAD);
assertThat(message.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("MyHost");
assertThat(message.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(message.getHeaders().get(IpHeaders.LOCAL_ADDRESS)).isSameAs(local);
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE))
.isEqualTo("application/octet-stream;charset=ISO-8859-1");
MimeType parseOk = MimeType.valueOf((String) message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertEquals(message.getHeaders().get(MessageHeaders.CONTENT_TYPE), parseOk.toString());
assertThat(parseOk.toString()).isEqualTo(message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
@Test(expected = IllegalArgumentException.class)
@@ -156,7 +153,7 @@ public class TcpMessageMapperTests {
mapper.setContentType("");
}
catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("'contentType' could not be parsed"));
assertThat(e.getMessage()).contains("'contentType' could not be parsed");
throw e;
}
}
@@ -217,23 +214,23 @@ public class TcpMessageMapperTests {
};
Message<?> message = mapper.toMessage(connection);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message
.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message
.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message
.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals(0, new IntegrationMessageHeaderAccessor(message).getSequenceNumber());
assertThat(new String((byte[]) message.getPayload())).isEqualTo(TEST_PAYLOAD);
assertThat(message
.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("MyHost");
assertThat(message
.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message
.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(new IntegrationMessageHeaderAccessor(message).getSequenceNumber()).isEqualTo(0);
message = mapper.toMessage(connection);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message
.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message
.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message
.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals(0, new IntegrationMessageHeaderAccessor(message).getSequenceNumber());
assertThat(new String((byte[]) message.getPayload())).isEqualTo(TEST_PAYLOAD);
assertThat(message
.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("MyHost");
assertThat(message
.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message
.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(new IntegrationMessageHeaderAccessor(message).getSequenceNumber()).isEqualTo(0);
}
@Test
@@ -300,29 +297,29 @@ public class TcpMessageMapperTests {
};
Message<?> message = mapper.toMessage(connection);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message
.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message
.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message
.getHeaders().get(IpHeaders.REMOTE_PORT));
assertThat(new String((byte[]) message.getPayload())).isEqualTo(TEST_PAYLOAD);
assertThat(message
.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("MyHost");
assertThat(message
.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message
.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
IntegrationMessageHeaderAccessor headerAccessor = new IntegrationMessageHeaderAccessor(message);
assertEquals(1, headerAccessor.getSequenceNumber());
assertEquals(message.getHeaders().get(IpHeaders.CONNECTION_ID), headerAccessor.getCorrelationId());
assertThat(headerAccessor.getSequenceNumber()).isEqualTo(1);
assertThat(headerAccessor.getCorrelationId()).isEqualTo(message.getHeaders().get(IpHeaders.CONNECTION_ID));
message = mapper.toMessage(connection);
headerAccessor = new IntegrationMessageHeaderAccessor(message);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message
.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message
.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message
.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals(2, headerAccessor.getSequenceNumber());
assertEquals(message.getHeaders().get(IpHeaders.CONNECTION_ID), headerAccessor.getCorrelationId());
assertNotNull(message.getHeaders().get("foo"));
assertEquals("bar", message.getHeaders().get("foo"));
assertThat(new String((byte[]) message.getPayload())).isEqualTo(TEST_PAYLOAD);
assertThat(message
.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("MyHost");
assertThat(message
.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message
.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(headerAccessor.getSequenceNumber()).isEqualTo(2);
assertThat(headerAccessor.getCorrelationId()).isEqualTo(message.getHeaders().get(IpHeaders.CONNECTION_ID));
assertThat(message.getHeaders().get("foo")).isNotNull();
assertThat(message.getHeaders().get("foo")).isEqualTo("bar");
}
@@ -333,7 +330,7 @@ public class TcpMessageMapperTests {
TcpMessageMapper mapper = new TcpMessageMapper();
mapper.setStringToBytes(true);
byte[] bArray = (byte[]) mapper.fromMessage(message);
assertEquals(s, new String(bArray));
assertThat(new String(bArray)).isEqualTo(s);
}
@@ -344,7 +341,7 @@ public class TcpMessageMapperTests {
TcpMessageMapper mapper = new TcpMessageMapper();
mapper.setStringToBytes(false);
String out = (String) mapper.fromMessage(message);
assertEquals(s, out);
assertThat(out).isEqualTo(s);
}
@@ -360,7 +357,8 @@ public class TcpMessageMapperTests {
MapJsonSerializer serializer = new MapJsonSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(map, baos);
assertEquals("{\"headers\":{\"bar\":\"baz\"},\"payload\":\"foo\"}\n", new String(baos.toByteArray(), "UTF-8"));
assertThat(new String(baos.toByteArray(), "UTF-8"))
.isEqualTo("{\"headers\":{\"bar\":\"baz\"},\"payload\":\"foo\"}\n");
}
@Test
@@ -378,12 +376,12 @@ public class TcpMessageMapperTests {
when(connection.getPort()).thenReturn(1234);
when(connection.getConnectionId()).thenReturn("someId");
Message<?> message = mapper.toMessage(connection);
assertEquals("foo", message.getPayload());
assertEquals("baz", message.getHeaders().get("bar"));
assertEquals("someHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals("someId", message.getHeaders().get(IpHeaders.CONNECTION_ID));
assertThat(message.getPayload()).isEqualTo("foo");
assertThat(message.getHeaders().get("bar")).isEqualTo("baz");
assertThat(message.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("someHost");
assertThat(message.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(message.getHeaders().get(IpHeaders.CONNECTION_ID)).isEqualTo("someId");
}
@Test
@@ -408,12 +406,12 @@ public class TcpMessageMapperTests {
when(connection.getPort()).thenReturn(1234);
when(connection.getConnectionId()).thenReturn("someId");
Message<?> message = mapper.toMessage(connection);
assertEquals("foo", message.getPayload());
assertEquals("baz", message.getHeaders().get("bar"));
assertEquals("someHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals("someId", message.getHeaders().get(IpHeaders.CONNECTION_ID));
assertThat(message.getPayload()).isEqualTo("foo");
assertThat(message.getHeaders().get("bar")).isEqualTo("baz");
assertThat(message.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("someHost");
assertThat(message.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(message.getHeaders().get(IpHeaders.CONNECTION_ID)).isEqualTo("someId");
}
@Test
@@ -432,12 +430,12 @@ public class TcpMessageMapperTests {
when(connection.getPort()).thenReturn(1234);
when(connection.getConnectionId()).thenReturn("someId");
Message<?> message = mapper.toMessage(connection);
assertEquals("foo", message.getPayload());
assertEquals("baz", message.getHeaders().get("bar"));
assertEquals("someHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals("someId", message.getHeaders().get(IpHeaders.CONNECTION_ID));
assertThat(message.getPayload()).isEqualTo("foo");
assertThat(message.getHeaders().get("bar")).isEqualTo("baz");
assertThat(message.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("someHost");
assertThat(message.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(message.getHeaders().get(IpHeaders.CONNECTION_ID)).isEqualTo("someId");
}
@Test
@@ -456,12 +454,12 @@ public class TcpMessageMapperTests {
when(connection.getPort()).thenReturn(1234);
when(connection.getConnectionId()).thenReturn("someId");
Message<?> message = mapper.toMessage(connection);
assertEquals("foo", message.getPayload());
assertEquals("baz", message.getHeaders().get("bar"));
assertEquals("someHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals("someId", message.getHeaders().get(IpHeaders.CONNECTION_ID));
assertThat(message.getPayload()).isEqualTo("foo");
assertThat(message.getHeaders().get("bar")).isEqualTo("baz");
assertThat(message.getHeaders().get(IpHeaders.HOSTNAME)).isEqualTo("someHost");
assertThat(message.getHeaders().get(IpHeaders.IP_ADDRESS)).isEqualTo("1.1.1.1");
assertThat(message.getHeaders().get(IpHeaders.REMOTE_PORT)).isEqualTo(1234);
assertThat(message.getHeaders().get(IpHeaders.CONNECTION_ID)).isEqualTo("someId");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -73,11 +72,10 @@ public class TcpNetConnectionTests {
connection.registerListener(mock(TcpListener.class));
connection.setMapper(new TcpMessageMapper());
connection.run();
assertNotNull(log.get());
assertEquals("Read exception " +
connection.getConnectionId() +
" MessageMappingException:Expected STX to begin message",
log.get());
assertThat(log.get()).isNotNull();
assertThat(log.get()).isEqualTo("Read exception " +
connection.getConnectionId() +
" MessageMappingException:Expected STX to begin message");
}
@Test
@@ -89,7 +87,7 @@ public class TcpNetConnectionTests {
ChannelInputStream inputStream =
TestUtils.getPropertyValue(connection, "channelInputStream", ChannelInputStream.class);
inputStream.write(ByteBuffer.wrap(new byte[] { (byte) 0x80 }));
assertEquals(0x80, inputStream.read());
assertThat(inputStream.read()).isEqualTo(0x80);
}
@Test
@@ -132,9 +130,9 @@ public class TcpNetConnectionTests {
};
inboundConnection.registerListener(listener);
inboundConnection.run();
assertNotNull(inboundMessage.get());
assertEquals("foo", inboundMessage.get().getPayload());
assertEquals("baz", inboundMessage.get().getHeaders().get("bar"));
assertThat(inboundMessage.get()).isNotNull();
assertThat(inboundMessage.get().getPayload()).isEqualTo("foo");
assertThat(inboundMessage.get().getHeaders().get("bar")).isEqualTo("baz");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.net.Socket;
import java.util.ArrayList;
@@ -68,7 +64,8 @@ public class TcpNioConnectionReadTests {
AbstractByteArraySerializer serializer, TcpListener listener, TcpSender sender) throws Exception {
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
scf.setUsingDirectBuffers(true);
scf.setApplicationEventPublisher(e -> { });
scf.setApplicationEventPublisher(e -> {
});
scf.setSerializer(serializer);
scf.setDeserializer(serializer);
scf.registerListener(listener);
@@ -95,13 +92,13 @@ public class TcpNioConnectionReadTests {
CountDownLatch done = SocketTestUtils.testSendLength(scf.getPort(), latch);
latch.countDown();
assertTrue(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS));
assertEquals("Did not receive data", 2, responses.size());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String((byte[]) responses.get(0).getPayload()));
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String((byte[]) responses.get(1).getPayload()));
assertThat(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(responses.size()).as("Did not receive data").isEqualTo(2);
assertThat(new String((byte[]) responses.get(0).getPayload())).as("Data")
.isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
assertThat(new String((byte[]) responses.get(1).getPayload())).as("Data")
.isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
scf.stop();
done.countDown();
}
@@ -129,11 +126,10 @@ public class TcpNioConnectionReadTests {
scf.setBacklog(howMany + 5);
// Fire up the sender.
CountDownLatch done = SocketTestUtils.testSendFragmented(scf.getPort(), howMany, false);
assertTrue(semaphore.tryAcquire(howMany, 20000, TimeUnit.MILLISECONDS));
assertEquals("Expected", howMany, responses.size());
assertThat(semaphore.tryAcquire(howMany, 20000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(responses.size()).as("Expected").isEqualTo(howMany);
for (int i = 0; i < howMany; i++) {
assertEquals("Data", "xx",
new String(((Message<byte[]>) responses.get(0)).getPayload()));
assertThat(new String(((Message<byte[]>) responses.get(0)).getPayload())).as("Data").isEqualTo("xx");
}
scf.stop();
done.countDown();
@@ -155,13 +151,13 @@ public class TcpNioConnectionReadTests {
CountDownLatch done = SocketTestUtils.testSendStxEtx(scf.getPort(), latch);
latch.countDown();
assertTrue(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS));
assertEquals("Did not receive data", 2, responses.size());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(((Message<byte[]>) responses.get(0)).getPayload()));
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(((Message<byte[]>) responses.get(1)).getPayload()));
assertThat(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(responses.size()).as("Did not receive data").isEqualTo(2);
assertThat(new String(((Message<byte[]>) responses.get(0)).getPayload())).as("Data")
.isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
assertThat(new String(((Message<byte[]>) responses.get(1)).getPayload())).as("Data")
.isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
scf.stop();
done.countDown();
}
@@ -182,13 +178,13 @@ public class TcpNioConnectionReadTests {
CountDownLatch done = SocketTestUtils.testSendCrLf(scf.getPort(), latch);
latch.countDown();
assertTrue(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS));
assertTrue(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS));
assertEquals("Did not receive data", 2, responses.size());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(((Message<byte[]>) responses.get(0)).getPayload()));
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(((Message<byte[]>) responses.get(1)).getPayload()));
assertThat(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(semaphore.tryAcquire(1, 10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(responses.size()).as("Did not receive data").isEqualTo(2);
assertThat(new String(((Message<byte[]>) responses.get(0)).getPayload())).as("Data")
.isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
assertThat(new String(((Message<byte[]>) responses.get(1)).getPayload())).as("Data")
.isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
scf.stop();
done.countDown();
}
@@ -229,16 +225,17 @@ public class TcpNioConnectionReadTests {
CountDownLatch done = SocketTestUtils.testSendLengthOverflow(scf.getPort());
whileOpen(semaphore, added);
assertEquals(1, added.size());
assertThat(added.size()).isEqualTo(1);
assertTrue(errorMessageLetch.await(10, TimeUnit.SECONDS));
assertThat(errorMessageLetch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(errorMessageRef.get().getMessage(),
anyOf(containsString("Message length 2147483647 exceeds max message length: 2048"),
containsString("Connection is closed")));
assertThat(errorMessageRef.get().getMessage())
.satisfiesAnyOf(
s -> assertThat(s).contains("Message length 2147483647 exceeds max message length: 2048"),
s -> assertThat(s).contains("Connection is closed"));
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertTrue(removed.size() > 0);
assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(removed.size() > 0).isTrue();
scf.stop();
done.countDown();
}
@@ -248,11 +245,11 @@ public class TcpNioConnectionReadTests {
ByteArrayStxEtxSerializer serializer = new ByteArrayStxEtxSerializer();
serializer.setMaxMessageSize(1024);
final Semaphore semaphore = new Semaphore(0);
final List<TcpConnection> added = new ArrayList<TcpConnection>();
final List<TcpConnection> removed = new ArrayList<TcpConnection>();
final List<TcpConnection> added = new ArrayList<>();
final List<TcpConnection> removed = new ArrayList<>();
final CountDownLatch errorMessageLetch = new CountDownLatch(1);
final AtomicReference<Throwable> errorMessageRef = new AtomicReference<Throwable>();
final AtomicReference<Throwable> errorMessageRef = new AtomicReference<>();
AbstractServerConnectionFactory scf = getConnectionFactory(serializer, message -> {
if (message instanceof ErrorMessage) {
@@ -280,16 +277,17 @@ public class TcpNioConnectionReadTests {
CountDownLatch done = SocketTestUtils.testSendStxEtxOverflow(scf.getPort());
whileOpen(semaphore, added);
assertEquals(1, added.size());
assertThat(added.size()).isEqualTo(1);
assertTrue(errorMessageLetch.await(10, TimeUnit.SECONDS));
assertThat(errorMessageLetch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(errorMessageRef.get().getMessage(),
anyOf(containsString("Connection is closed"),
containsString("ETX not found before max message length: 1024")));
assertThat(errorMessageRef.get().getMessage())
.satisfiesAnyOf(
s -> assertThat(s).contains("ETX not found before max message length: 1024"),
s -> assertThat(s).contains("Connection is closed"));
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertTrue(removed.size() > 0);
assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(removed.size() > 0).isTrue();
scf.stop();
done.countDown();
}
@@ -331,16 +329,17 @@ public class TcpNioConnectionReadTests {
CountDownLatch done = SocketTestUtils.testSendCrLfOverflow(scf.getPort());
whileOpen(semaphore, added);
assertEquals(1, added.size());
assertThat(added.size()).isEqualTo(1);
assertTrue(errorMessageLetch.await(10, TimeUnit.SECONDS));
assertThat(errorMessageLetch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(errorMessageRef.get().getMessage(),
anyOf(containsString("Connection is closed"),
containsString("CRLF not found before max message length: 1024")));
assertThat(errorMessageRef.get().getMessage())
.satisfiesAnyOf(
s -> assertThat(s).contains("CRLF not found before max message length: 1024"),
s -> assertThat(s).contains("Connection is closed"));
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertTrue(removed.size() > 0);
assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(removed.size() > 0).isTrue();
scf.stop();
done.countDown();
}
@@ -384,15 +383,17 @@ public class TcpNioConnectionReadTests {
Socket socket = SocketFactory.getDefault().createSocket("localhost", scf.getPort());
socket.close();
whileOpen(semaphore, added);
assertEquals(1, added.size());
assertThat(added.size()).isEqualTo(1);
assertTrue(errorMessageLetch.await(10, TimeUnit.SECONDS));
assertThat(errorMessageLetch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(errorMessageRef.get().getMessage(),
anyOf(containsString("Connection is closed"), containsString("Stream closed after 2 of 3")));
assertThat(errorMessageRef.get().getMessage())
.satisfiesAnyOf(
s -> assertThat(s).contains("Stream closed after 2 of 3"),
s -> assertThat(s).contains("Connection is closed"));
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertTrue(removed.size() > 0);
assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(removed).hasSizeGreaterThan(0);
scf.stop();
}
@@ -436,15 +437,17 @@ public class TcpNioConnectionReadTests {
socket.getOutputStream().write("partial".getBytes());
socket.close();
whileOpen(semaphore, added);
assertEquals(1, added.size());
assertThat(added).hasSize(1);
assertTrue(errorMessageLetch.await(10, TimeUnit.SECONDS));
assertThat(errorMessageLetch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(errorMessageRef.get().getMessage(),
anyOf(containsString("Connection is closed"), containsString("Socket closed during message assembly")));
assertThat(errorMessageRef.get().getMessage())
.satisfiesAnyOf(
s -> assertThat(s).contains("Socket closed during message assembly"),
s -> assertThat(s).contains("Connection is closed"));
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertTrue(removed.size() > 0);
assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(removed.size() > 0).isTrue();
scf.stop();
}
@@ -512,24 +515,25 @@ public class TcpNioConnectionReadTests {
socket.getOutputStream().write(shortMessage.getBytes());
socket.close();
whileOpen(semaphore, added);
assertEquals(1, added.size());
assertThat(added).hasSize(1);
assertTrue(errorMessageLetch.await(10, TimeUnit.SECONDS));
assertThat(errorMessageLetch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(errorMessageRef.get().getMessage(),
anyOf(containsString("Connection is closed"),
containsString("Socket closed during message assembly"),
containsString("Stream closed after 2 of 3")));
assertThat(errorMessageRef.get().getMessage())
.satisfiesAnyOf(
s -> assertThat(s).contains("Socket closed during message assembly"),
s -> assertThat(s).contains("Stream closed after 2 of 3"),
s -> assertThat(s).contains("Connection is closed"));
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertTrue(removed.size() > 0);
assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(removed).hasSizeGreaterThan(0);
scf.stop();
}
private void whileOpen(Semaphore semaphore, final List<TcpConnection> added)
throws InterruptedException {
int n = 0;
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
while (added.get(0).isOpen()) {
Thread.sleep(50);
if (n++ > 200) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,8 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.Mockito.doAnswer;
@@ -139,7 +133,7 @@ public class TcpNioConnectionTests {
e.printStackTrace();
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
factory.setApplicationEventPublisher(nullPublisher);
@@ -150,8 +144,9 @@ public class TcpNioConnectionTests {
connection.send(MessageBuilder.withPayload(new byte[1000000]).build());
}
catch (Exception e) {
assertTrue("Expected SocketTimeoutException, got " + e.getClass().getSimpleName() +
":" + e.getMessage(), e instanceof SocketTimeoutException);
assertThat(e instanceof SocketTimeoutException)
.as("Expected SocketTimeoutException, got " + e.getClass().getSimpleName() +
":" + e.getMessage()).isTrue();
}
done.countDown();
factory.stop();
@@ -179,7 +174,7 @@ public class TcpNioConnectionTests {
e.printStackTrace();
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
factory.setApplicationEventPublisher(nullPublisher);
@@ -195,7 +190,7 @@ public class TcpNioConnectionTests {
break;
}
}
assertTrue(!connection.isOpen());
assertThat(!connection.isOpen()).isTrue();
}
catch (Exception e) {
fail("Unexpected exception " + e);
@@ -223,7 +218,7 @@ public class TcpNioConnectionTests {
e.printStackTrace();
}
});
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost",
serverSocket.get().getLocalPort());
factory.setApplicationEventPublisher(nullPublisher);
@@ -232,9 +227,9 @@ public class TcpNioConnectionTests {
try {
TcpConnection connection = factory.getConnection();
Map<SocketChannel, TcpNioConnection> connections = factory.getConnections();
assertEquals(1, connections.size());
assertThat(connections.size()).isEqualTo(1);
connection.close();
assertTrue(!connection.isOpen());
assertThat(!connection.isOpen()).isTrue();
TestUtils.getPropertyValue(factory, "selector", Selector.class).wakeup();
int n = 0;
while (connections.size() > 0) {
@@ -243,7 +238,7 @@ public class TcpNioConnectionTests {
break;
}
}
assertEquals(0, connections.size());
assertThat(connections.size()).isEqualTo(0);
}
catch (Exception e) {
e.printStackTrace();
@@ -282,30 +277,30 @@ public class TcpNioConnectionTests {
HashSet<SelectionKey> keys = new HashSet<>();
when(selector.selectedKeys()).thenReturn(keys);
factory.processNioSelections(1, selector, null, connections);
assertEquals(3, connections.size()); // all open
assertThat(connections.size()).isEqualTo(3); // all open
ReflectionUtils.setField(field, chan1, false);
factory.processNioSelections(1, selector, null, connections);
assertEquals(3, connections.size()); // interval didn't pass
assertThat(connections.size()).isEqualTo(3); // interval didn't pass
Thread.sleep(110);
factory.processNioSelections(1, selector, null, connections);
assertEquals(2, connections.size()); // first is closed
assertThat(connections.size()).isEqualTo(2); // first is closed
ReflectionUtils.setField(field, chan2, false);
factory.processNioSelections(1, selector, null, connections);
assertEquals(2, connections.size()); // interval didn't pass
assertThat(connections.size()).isEqualTo(2); // interval didn't pass
Thread.sleep(110);
factory.processNioSelections(1, selector, null, connections);
assertEquals(1, connections.size()); // second is closed
assertThat(connections.size()).isEqualTo(1); // second is closed
ReflectionUtils.setField(field, chan3, false);
factory.processNioSelections(1, selector, null, connections);
assertEquals(1, connections.size()); // interval didn't pass
assertThat(connections.size()).isEqualTo(1); // interval didn't pass
Thread.sleep(110);
factory.processNioSelections(1, selector, null, connections);
assertEquals(0, connections.size()); // third is closed
assertThat(connections.size()).isEqualTo(0); // third is closed
assertEquals(0, TestUtils.getPropertyValue(factory, "connections", Map.class).size());
assertThat(TestUtils.getPropertyValue(factory, "connections", Map.class).size()).isEqualTo(0);
}
@Test
@@ -343,7 +338,7 @@ public class TcpNioConnectionTests {
fail("Expected exception, got " + o);
}
catch (ExecutionException e) {
assertEquals("Timed out waiting for buffer space", e.getCause().getMessage());
assertThat(e.getCause().getMessage()).isEqualTo("Timed out waiting for buffer space");
}
finally {
exec.shutdownNow();
@@ -388,7 +383,7 @@ public class TcpNioConnectionTests {
return null;
});
future.get(60, TimeUnit.SECONDS);
assertTrue(messageLatch.await(10, TimeUnit.SECONDS));
assertThat(messageLatch.await(10, TimeUnit.SECONDS)).isTrue();
exec.shutdownNow();
}
@@ -404,12 +399,12 @@ public class TcpNioConnectionTests {
stream.write(ByteBuffer.wrap("foo".getBytes()));
byte[] out = new byte[2];
int n = stream.read(out);
assertEquals(2, n);
assertEquals("fo", new String(out));
assertThat(n).isEqualTo(2);
assertThat(new String(out)).isEqualTo("fo");
out = new byte[2];
n = stream.read(out);
assertEquals(1, n);
assertEquals("o\u0000", new String(out));
assertThat(n).isEqualTo(1);
assertThat(new String(out)).isEqualTo("o\u0000");
}
@Test
@@ -424,8 +419,8 @@ public class TcpNioConnectionTests {
stream.write(ByteBuffer.wrap("bar".getBytes()));
byte[] out = new byte[6];
int n = stream.read(out);
assertEquals(6, n);
assertEquals("foobar", new String(out));
assertThat(n).isEqualTo(6);
assertThat(new String(out)).isEqualTo("foobar");
}
@Test
@@ -439,8 +434,8 @@ public class TcpNioConnectionTests {
stream.write(ByteBuffer.wrap("foo".getBytes()));
byte[] out = new byte[5];
int n = stream.read(out, 1, 4);
assertEquals(3, n);
assertEquals("\u0000foo\u0000", new String(out));
assertThat(n).isEqualTo(3);
assertThat(new String(out)).isEqualTo("\u0000foo\u0000");
}
@Test
@@ -465,8 +460,8 @@ public class TcpNioConnectionTests {
}
catch (IllegalArgumentException e) {
}
assertEquals(0, stream.read(out, 0, 0));
assertEquals(3, stream.read(out));
assertThat(stream.read(out, 0, 0)).isEqualTo(0);
assertThat(stream.read(out)).isEqualTo(3);
}
@Test
@@ -489,10 +484,10 @@ public class TcpNioConnectionTests {
latch.countDown();
});
Thread.sleep(1000);
assertEquals(0x00, out[0]);
assertThat(out[0]).isEqualTo((byte) 0x00);
stream.write(ByteBuffer.wrap("foo".getBytes()));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("foo\u0000", new String(out));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(new String(out)).isEqualTo("foo\u0000");
}
@Test
@@ -558,10 +553,10 @@ public class TcpNioConnectionTests {
};
inboundConnection.registerListener(listener);
inboundConnection.readPacket();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNotNull(inboundMessage.get());
assertEquals("foo", inboundMessage.get().getPayload());
assertEquals("baz", inboundMessage.get().getHeaders().get("bar"));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(inboundMessage.get()).isNotNull();
assertThat(inboundMessage.get().getPayload()).isEqualTo("foo");
assertThat(inboundMessage.get().getHeaders().get("bar")).isEqualTo("baz");
}
@Test
@@ -602,12 +597,12 @@ public class TcpNioConnectionTests {
}
Thread.sleep(100);
}
assertTrue("Could not open socket to localhost:" + port, n < 100);
assertThat(n < 100).as("Could not open socket to localhost:" + port).isTrue();
socket.getOutputStream().write("foo\r\n".getBytes());
socket.close();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(threadName.get(), containsString("assembler"));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(threadName.get()).contains("assembler");
factory.stop();
@@ -652,7 +647,7 @@ public class TcpNioConnectionTests {
}
Thread.sleep(1);
}
assertTrue("Could not open socket to localhost:" + port, n < 100);
assertThat(n < 100).as("Could not open socket to localhost:" + port).isTrue();
sockets[i] = socket;
}
for (int i = 0; i < numberOfSockets; i++) {
@@ -682,7 +677,7 @@ public class TcpNioConnectionTests {
sockets[i].close();
}
assertTrue("latch is still " + latch.getCount(), latch.await(60, TimeUnit.SECONDS));
assertThat(latch.await(60, TimeUnit.SECONDS)).as("latch is still " + latch.getCount()).isTrue();
factory.stop();
@@ -750,7 +745,7 @@ public class TcpNioConnectionTests {
TestingUtilities.waitListening(factory, 10000L);
int port = factory.getPort();
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
assertTrue(connectionLatch.await(10, TimeUnit.SECONDS));
assertThat(connectionLatch.await(10, TimeUnit.SECONDS)).isTrue();
TcpNioConnection connection = (TcpNioConnection) TestUtils.getPropertyValue(factory, "connections", Map.class)
.values().iterator().next();
@@ -758,7 +753,8 @@ public class TcpNioConnectionTests {
DirectFieldAccessor dfa = new DirectFieldAccessor(connection);
dfa.setPropertyValue("logger", logger);
ChannelInputStream cis = spy(TestUtils.getPropertyValue(connection, "channelInputStream", ChannelInputStream.class));
ChannelInputStream cis = spy(TestUtils
.getPropertyValue(connection, "channelInputStream", ChannelInputStream.class));
dfa.setPropertyValue("channelInputStream", cis);
final CountDownLatch readerLatch = new CountDownLatch(4); // 3 dataAvailable, 1 continuing
@@ -799,11 +795,11 @@ public class TcpNioConnectionTests {
socket.getOutputStream().write("foo\r\n".getBytes());
assertTrue(assemblerLatch.await(10, TimeUnit.SECONDS));
assertTrue(readerFinishedLatch.await(10, TimeUnit.SECONDS));
assertThat(assemblerLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(readerFinishedLatch.await(10, TimeUnit.SECONDS)).isTrue();
StackTraceElement[] stackTrace = assembler.get().getStackTrace();
assertThat(Arrays.asList(stackTrace).toString(), not(containsString("ChannelInputStream.getNextBuffer")));
assertThat(Arrays.asList(stackTrace).toString()).doesNotContain("ChannelInputStream.getNextBuffer");
socket.close();
factory.stop();
@@ -831,13 +827,13 @@ public class TcpNioConnectionTests {
});
cf.afterPropertiesSet();
cf.start();
assertTrue(listening.await(10, TimeUnit.SECONDS));
assertThat(listening.await(10, TimeUnit.SECONDS)).isTrue();
Socket socket = SocketFactory.getDefault().createSocket("localhost", cf.getPort());
socket.getOutputStream().write("x".getBytes());
assertTrue(reading.await(10, TimeUnit.SECONDS));
assertThat(reading.await(10, TimeUnit.SECONDS)).isTrue();
socket.close();
cf.stop();
assertThat(watch.getLastTaskTimeMillis(), lessThan(950L));
assertThat(watch.getLastTaskTimeMillis()).isLessThan(950L);
}
private void readFully(InputStream is, byte[] buff) throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.InputStream;
@@ -46,6 +46,7 @@ public class TcpNioConnectionWriteTests {
private AbstractConnectionFactory getClientConnectionFactory(boolean direct,
final int port, AbstractByteArraySerializer serializer) {
TcpNioClientConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ccf.setSerializer(serializer);
ccf.setDeserializer(serializer);
@@ -88,8 +89,8 @@ public class TcpNioConnectionWriteTests {
byte[] buff = new byte[testString.length() + 4];
readFully(is, buff);
ByteBuffer buffer = ByteBuffer.wrap(buff);
assertEquals(testString.length(), buffer.getInt());
assertEquals(testString, new String(buff, 4, testString.length()));
assertThat(buffer.getInt()).isEqualTo(testString.length());
assertThat(new String(buff, 4, testString.length())).isEqualTo(testString);
server.close();
latch.countDown();
}
@@ -126,9 +127,9 @@ public class TcpNioConnectionWriteTests {
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 2];
readFully(is, buff);
assertEquals(ByteArrayStxEtxSerializer.STX, buff[0]);
assertEquals(testString, new String(buff, 1, testString.length()));
assertEquals(ByteArrayStxEtxSerializer.ETX, buff[testString.length() + 1]);
assertThat(buff[0]).isEqualTo((byte) ByteArrayStxEtxSerializer.STX);
assertThat(new String(buff, 1, testString.length())).isEqualTo(testString);
assertThat(buff[testString.length() + 1]).isEqualTo((byte) ByteArrayStxEtxSerializer.ETX);
server.close();
latch.countDown();
}
@@ -165,9 +166,9 @@ public class TcpNioConnectionWriteTests {
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 2];
readFully(is, buff);
assertEquals(testString, new String(buff, 0, testString.length()));
assertEquals('\r', buff[testString.length()]);
assertEquals('\n', buff[testString.length() + 1]);
assertThat(new String(buff, 0, testString.length())).isEqualTo(testString);
assertThat(buff[testString.length()]).isEqualTo((byte) '\r');
assertThat(buff[testString.length() + 1]).isEqualTo((byte) '\n');
server.close();
latch.countDown();
}
@@ -205,8 +206,8 @@ public class TcpNioConnectionWriteTests {
byte[] buff = new byte[testString.length() + 4];
readFully(is, buff);
ByteBuffer buffer = ByteBuffer.wrap(buff);
assertEquals(testString.length(), buffer.getInt());
assertEquals(testString, new String(buff, 4, testString.length()));
assertThat(buffer.getInt()).isEqualTo(testString.length());
assertThat(new String(buff, 4, testString.length())).isEqualTo(testString);
server.close();
latch.countDown();
}
@@ -243,9 +244,9 @@ public class TcpNioConnectionWriteTests {
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 2];
readFully(is, buff);
assertEquals(ByteArrayStxEtxSerializer.STX, buff[0]);
assertEquals(testString, new String(buff, 1, testString.length()));
assertEquals(ByteArrayStxEtxSerializer.ETX, buff[testString.length() + 1]);
assertThat(buff[0]).isEqualTo((byte) ByteArrayStxEtxSerializer.STX);
assertThat(new String(buff, 1, testString.length())).isEqualTo(testString);
assertThat(buff[testString.length() + 1]).isEqualTo((byte) ByteArrayStxEtxSerializer.ETX);
server.close();
latch.countDown();
}
@@ -282,9 +283,9 @@ public class TcpNioConnectionWriteTests {
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 2];
readFully(is, buff);
assertEquals(testString, new String(buff, 0, testString.length()));
assertEquals('\r', buff[testString.length()]);
assertEquals('\n', buff[testString.length() + 1]);
assertThat(new String(buff, 0, testString.length())).isEqualTo(testString);
assertThat(buff[testString.length()]).isEqualTo((byte) '\r');
assertThat(buff[testString.length() + 1]).isEqualTo((byte) '\n');
server.close();
latch.countDown();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,7 @@
package org.springframework.integration.ip.tcp.connection;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
@@ -79,7 +74,7 @@ public class ThreadAffinityClientConnectionFactoryTests {
Thread.sleep(100);
port = serverCF.getPort();
}
assertTrue(n < 200);
assertThat(n < 200).isTrue();
return port;
}
@@ -97,21 +92,21 @@ public class ThreadAffinityClientConnectionFactoryTests {
channel.send(message);
channel.send(message);
clientFactory.releaseConnection();
assertThat(replies.getQueueSize(), equalTo(4));
assertThat(replies.getQueueSize()).isEqualTo(4);
Message<?> replyA = replies.receive(0);
Message<?> replyB = replies.receive(0);
Message<?> replyC = replies.receive(0);
Message<?> replyD = replies.receive(0);
assertThat((String) replyA.getPayload(), containsString("ip_connectionId"));
assertThat(replyA.getPayload(), equalTo(replyB.getPayload()));
assertThat(replyC.getPayload(), equalTo(replyD.getPayload()));
assertThat(replyC.getPayload(), not(equalTo(replyA.getPayload())));
assertThat((String) replyA.getPayload()).contains("ip_connectionId");
assertThat(replyA.getPayload()).isEqualTo(replyB.getPayload());
assertThat(replyC.getPayload()).isEqualTo(replyD.getPayload());
assertThat(replyC.getPayload()).isNotEqualTo(replyA.getPayload());
System.getProperties().remove(PORT);
int n = 0;
while (n++ < 200 && serverCF.getOpenConnectionIds().size() > 0) {
Thread.sleep(100);
}
assertThat(n, lessThan(200));
assertThat(n).isLessThan(200);
client.close();
server.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,8 @@
package org.springframework.integration.ip.tcp.serializer;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import java.io.ByteArrayInputStream;
@@ -80,11 +75,9 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayLengthHeaderSerializer serializer = new ByteArrayLengthHeaderSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
server.close();
done.countDown();
}
@@ -99,11 +92,9 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayStxEtxSerializer serializer = new ByteArrayStxEtxSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
server.close();
done.countDown();
}
@@ -118,11 +109,9 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
server.close();
done.countDown();
}
@@ -137,8 +126,7 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayRawSerializer serializer = new ByteArrayRawSerializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
server.close();
}
@@ -152,8 +140,7 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
ByteArrayElasticRawDeserializer serializer = new ByteArrayElasticRawDeserializer();
byte[] out = serializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING,
new String(out));
assertThat(new String(out)).as("Data").isEqualTo(SocketTestUtils.TEST_STRING + SocketTestUtils.TEST_STRING);
try {
serializer.deserialize(socket.getInputStream());
fail("Expected end of Stream");
@@ -174,9 +161,9 @@ public class DeserializationTests {
socket.setSoTimeout(5000);
DefaultDeserializer deserializer = new DefaultDeserializer();
Object out = deserializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING, out);
assertThat(out).as("Data").isEqualTo(SocketTestUtils.TEST_STRING);
out = deserializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketTestUtils.TEST_STRING, out);
assertThat(out).as("Data").isEqualTo(SocketTestUtils.TEST_STRING);
server.close();
done.countDown();
}
@@ -306,10 +293,10 @@ public class DeserializationTests {
try {
byte[] bytes = serializer.deserialize(inputStream);
assertEquals(1, bytes.length);
assertEquals("s".getBytes()[0], bytes[0]);
assertThat(bytes.length).isEqualTo(1);
assertThat(bytes[0]).isEqualTo("s".getBytes()[0]);
bytes = serializer.deserialize(inputStream);
assertEquals(0, bytes.length);
assertThat(bytes.length).isEqualTo(0);
}
finally {
inputStream.close();
@@ -322,19 +309,19 @@ public class DeserializationTests {
doDeserialize(new ByteArrayLengthHeaderSerializer(), "Message length 1718579042 exceeds max message length: 5");
TcpDeserializationExceptionEvent event = doDeserialize(new ByteArrayLengthHeaderSerializer(),
"Stream closed after 3 of 4", new byte[] { 0, 0, 0 }, 5); // closed during header read
assertEquals(-1, event.getOffset());
assertEquals(new String(new byte[] { 0, 0, 0 }), new String(event.getBuffer()).substring(0, 3));
assertThat(event.getOffset()).isEqualTo(-1);
assertThat(new String(event.getBuffer()).substring(0, 3)).isEqualTo(new String(new byte[] { 0, 0, 0 }));
event = doDeserialize(new ByteArrayLengthHeaderSerializer(),
"Stream closed after 1 of 2", new byte[] { 0, 0, 0, 2, 7 }, 5); // closed during data read
assertEquals(-1, event.getOffset());
assertEquals(new String(new byte[] { 7 }), new String(event.getBuffer()).substring(0, 1));
assertThat(event.getOffset()).isEqualTo(-1);
assertThat(new String(event.getBuffer()).substring(0, 1)).isEqualTo(new String(new byte[] { 7 }));
doDeserialize(new ByteArrayLfSerializer(), "Terminator '0xa' not found before max message length: 5");
doDeserialize(new ByteArrayRawSerializer(), "Socket was not closed before max message length: 5");
doDeserialize(new ByteArraySingleTerminatorSerializer((byte) 0xfe), "Terminator '0xfe' not found before max message length: 5");
doDeserialize(new ByteArrayStxEtxSerializer(), "Expected STX to begin message");
event = doDeserialize(new ByteArrayStxEtxSerializer(),
"Socket closed during message assembly", new byte[] { 0x02, 0, 0 }, 5);
assertEquals(2, event.getOffset());
assertThat(event.getOffset()).isEqualTo(2);
}
private TcpDeserializationExceptionEvent doDeserialize(AbstractByteArraySerializer deser, String expectedMessage) {
@@ -367,9 +354,9 @@ public class DeserializationTests {
fail("expected exception");
}
catch (Exception e) {
assertNotNull(event.get());
assertSame(e, event.get().getCause());
assertThat(e.getMessage(), containsString(expectedMessage));
assertThat(event.get()).isNotNull();
assertThat(event.get().getCause()).isSameAs(e);
assertThat(e.getMessage()).contains(expectedMessage);
}
return event.get();
}
@@ -427,12 +414,12 @@ public class DeserializationTests {
// short reply should not be received.
exec.execute(command);
message = serverSideChannel.receive(10000);
assertNotNull(message);
assertEquals("Test", new String((byte[]) message.getPayload()));
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test");
String shortReply = reply.substring(0, reply.length() - 1);
((MessageChannel) message.getHeaders().getReplyChannel()).send(new GenericMessage<String>(shortReply));
message = outputChannel.receive(6000);
assertNull(message);
assertThat(message).isNull();
// good message should be received
if ((deserializer instanceof ByteArrayRawSerializer)) { // restore old behavior
@@ -440,12 +427,12 @@ public class DeserializationTests {
}
exec.execute(command);
message = serverSideChannel.receive(10000);
assertNotNull(message);
assertEquals("Test", new String((byte[]) message.getPayload()));
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test");
((MessageChannel) message.getHeaders().getReplyChannel()).send(new GenericMessage<String>(reply));
message = outputChannel.receive(10000);
assertNotNull(message);
assertEquals(reply, new String(((byte[]) message.getPayload())));
assertThat(message).isNotNull();
assertThat(new String(((byte[]) message.getPayload()))).isEqualTo(reply);
}
private static class CustomDeserializer extends AbstractByteArraySerializer {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
package org.springframework.integration.ip.tcp.serializer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,6 +30,8 @@ import org.junit.Test;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.0.4
*
*/
@@ -55,13 +57,13 @@ public class LengthHeaderSerializationTests {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
serializer.serialize(TEST.getBytes(), bos);
byte[] bytes = bos.toByteArray();
assertEquals(0, bytes[0]);
assertEquals(0, bytes[1]);
assertEquals(0, bytes[2]);
assertEquals(TEST.length(), bytes[3]);
assertThat(bytes[0]).isEqualTo((byte) 0);
assertThat(bytes[1]).isEqualTo((byte) 0);
assertThat(bytes[2]).isEqualTo((byte) 0);
assertThat(bytes[3]).isEqualTo((byte) TEST.length());
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
bytes = serializer.deserialize(bis);
assertEquals(TEST, new String(bytes));
assertThat(new String(bytes)).isEqualTo(TEST);
bytes[0] = -1;
bis = new ByteArrayInputStream(bytes);
try {
@@ -78,10 +80,10 @@ public class LengthHeaderSerializationTests {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
serializer.serialize(test255.getBytes(), bos);
byte[] bytes = bos.toByteArray();
assertEquals(test255.length(), bytes[0] & 0xff);
assertThat(bytes[0] & 0xff).isEqualTo(test255.length());
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
bytes = serializer.deserialize(bis);
assertEquals(test255, new String(bytes));
assertThat(new String(bytes)).isEqualTo(test255);
test255 += "x";
try {
serializer.serialize(test255.getBytes(), bos);
@@ -97,11 +99,11 @@ public class LengthHeaderSerializationTests {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
serializer.serialize(test255.getBytes(), bos);
byte[] bytes = bos.toByteArray();
assertEquals(0, bytes[0]);
assertEquals(test255.length(), bytes[1] & 0xff);
assertThat(bytes[0]).isEqualTo((byte) 0);
assertThat(bytes[1] & 0xff).isEqualTo(test255.length());
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
bytes = serializer.deserialize(bis);
assertEquals(test255, new String(bytes));
assertThat(new String(bytes)).isEqualTo(test255);
}
@Test
@@ -112,11 +114,11 @@ public class LengthHeaderSerializationTests {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
serializer.serialize(testFFFF.getBytes(), bos);
byte[] bytes = bos.toByteArray();
assertEquals(0xff, bytes[0] & 0xff);
assertEquals(0xff, bytes[1] & 0xff);
assertThat(bytes[0] & 0xff).isEqualTo(0xff);
assertThat(bytes[1] & 0xff).isEqualTo(0xff);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
bytes = serializer.deserialize(bis);
assertEquals(testFFFF, new String(bytes));
assertThat(new String(bytes)).isEqualTo(testFFFF);
testFFFF += "x";
try {
serializer.serialize(testFFFF.getBytes(), bos);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.tcp.serializer;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
import java.util.Map;
@@ -37,8 +37,8 @@ public class MapJsonSerializerTests {
MapJsonSerializer deserializer = new MapJsonSerializer();
ByteArrayInputStream bais = new ByteArrayInputStream(twoJson.getBytes("UTF-8"));
Map<?, ?> map = deserializer.deserialize(bais);
assertNotNull(map);
assertThat(map).isNotNull();
map = deserializer.deserialize(bais);
assertNotNull(map);
assertThat(map).isNotNull();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,8 @@
package org.springframework.integration.ip.tcp.serializer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -43,7 +42,7 @@ public class PooledDeserializationTests {
for (int i = 0; i < 5; i++) {
bais.reset();
byte[] bytes = deser.deserialize(bais);
assertEquals("foo", new String(bytes));
assertThat(new String(bytes)).isEqualTo("foo");
}
try {
deser.deserialize(bais);
@@ -52,8 +51,8 @@ public class PooledDeserializationTests {
catch (SoftEndOfStreamException e) {
// expected
}
assertEquals(1, TestUtils.getPropertyValue(deser, "pool.allocated", Set.class).size());
assertEquals(0, TestUtils.getPropertyValue(deser, "pool.inUse", Set.class).size());
assertThat(TestUtils.getPropertyValue(deser, "pool.allocated", Set.class).size()).isEqualTo(1);
assertThat(TestUtils.getPropertyValue(deser, "pool.inUse", Set.class).size()).isEqualTo(0);
}
@Test
@@ -63,10 +62,10 @@ public class PooledDeserializationTests {
deser.setMaxMessageSize(3);
ByteArrayInputStream bais = new ByteArrayInputStream("foo".getBytes());
byte[] bytes = deser.deserialize(bais);
assertEquals("foo", new String(bytes));
assertEquals(1, TestUtils.getPropertyValue(deser, "pool.allocated", Set.class).size());
assertEquals(0, TestUtils.getPropertyValue(deser, "pool.inUse", Set.class).size());
assertNotSame(bytes, TestUtils.getPropertyValue(deser, "pool.allocated", Set.class).iterator().next());
assertThat(new String(bytes)).isEqualTo("foo");
assertThat(TestUtils.getPropertyValue(deser, "pool.allocated", Set.class).size()).isEqualTo(1);
assertThat(TestUtils.getPropertyValue(deser, "pool.inUse", Set.class).size()).isEqualTo(0);
assertThat(TestUtils.getPropertyValue(deser, "pool.allocated", Set.class).iterator().next()).isNotSameAs(bytes);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.tcp.serializer;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.InputStream;
@@ -68,8 +68,8 @@ public class SerializationTests {
byte[] buff = new byte[testString.length() + 4];
readFully(is, buff);
ByteBuffer buffer = ByteBuffer.wrap(buff);
assertEquals(testString.length(), buffer.getInt());
assertEquals(testString, new String(buff, 4, testString.length()));
assertThat(buffer.getInt()).isEqualTo(testString.length());
assertThat(new String(buff, 4, testString.length())).isEqualTo(testString);
server.close();
latch.countDown();
}
@@ -101,9 +101,9 @@ public class SerializationTests {
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 2];
readFully(is, buff);
assertEquals(ByteArrayStxEtxSerializer.STX, buff[0]);
assertEquals(testString, new String(buff, 1, testString.length()));
assertEquals(ByteArrayStxEtxSerializer.ETX, buff[testString.length() + 1]);
assertThat(buff[0]).isEqualTo((byte) ByteArrayStxEtxSerializer.STX);
assertThat(new String(buff, 1, testString.length())).isEqualTo(testString);
assertThat(buff[testString.length() + 1]).isEqualTo((byte) ByteArrayStxEtxSerializer.ETX);
server.close();
latch.countDown();
}
@@ -135,9 +135,9 @@ public class SerializationTests {
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 2];
readFully(is, buff);
assertEquals(testString, new String(buff, 0, testString.length()));
assertEquals('\r', buff[testString.length()]);
assertEquals('\n', buff[testString.length() + 1]);
assertThat(new String(buff, 0, testString.length())).isEqualTo(testString);
assertThat(buff[testString.length()]).isEqualTo((byte) '\r');
assertThat(buff[testString.length() + 1]).isEqualTo((byte) '\n');
server.close();
latch.countDown();
}
@@ -170,8 +170,8 @@ public class SerializationTests {
InputStream is = socket.getInputStream();
byte[] buff = new byte[testString.length() + 1];
readFully(is, buff);
assertEquals(testString, new String(buff, 0, testString.length()));
assertEquals(-1, buff[testString.length()]);
assertThat(new String(buff, 0, testString.length())).isEqualTo(testString);
assertThat(buff[testString.length()]).isEqualTo((byte) -1);
latch.countDown();
server.close();
}
@@ -201,9 +201,9 @@ public class SerializationTests {
socket.setSoTimeout(5000);
InputStream is = socket.getInputStream();
ObjectInputStream ois = new ObjectInputStream(is);
assertEquals(testString, ois.readObject());
assertThat(ois.readObject()).isEqualTo(testString);
ois = new ObjectInputStream(is);
assertEquals(testString, ois.readObject());
assertThat(ois.readObject()).isEqualTo(testString);
latch.countDown();
server.close();
}

View File

@@ -16,10 +16,7 @@
package org.springframework.integration.ip.tcp.serializer;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -35,66 +32,66 @@ public class TcpCodecsTests {
@Test
public void testAll() {
AbstractByteArraySerializer codec = TcpCodecs.crlf();
assertThat(codec, instanceOf(ByteArrayCrLfSerializer.class));
assertThat(codec).isInstanceOf(ByteArrayCrLfSerializer.class);
codec = TcpCodecs.lf();
assertThat(codec, instanceOf(ByteArrayLfSerializer.class));
assertThat(codec).isInstanceOf(ByteArrayLfSerializer.class);
codec = TcpCodecs.raw();
assertThat(codec, instanceOf(ByteArrayRawSerializer.class));
assertThat(codec).isInstanceOf(ByteArrayRawSerializer.class);
codec = TcpCodecs.stxetx();
assertThat(codec, instanceOf(ByteArrayStxEtxSerializer.class));
assertThat(codec).isInstanceOf(ByteArrayStxEtxSerializer.class);
codec = TcpCodecs.singleTerminator((byte) 23);
assertThat(codec, instanceOf(ByteArraySingleTerminatorSerializer.class));
assertEquals((byte) 23, TestUtils.getPropertyValue(codec, "terminator"));
assertThat(codec).isInstanceOf(ByteArraySingleTerminatorSerializer.class);
assertThat(TestUtils.getPropertyValue(codec, "terminator")).isEqualTo((byte) 23);
codec = TcpCodecs.lengthHeader1();
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertEquals(1, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(1);
codec = TcpCodecs.lengthHeader2();
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertEquals(2, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(2);
codec = TcpCodecs.lengthHeader4();
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertEquals(4, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(4);
codec = TcpCodecs.lengthHeader(1);
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertEquals(1, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(1);
codec = TcpCodecs.lengthHeader(2);
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertEquals(2, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(2);
codec = TcpCodecs.lengthHeader(4);
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertEquals(4, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(4);
}
@Test
public void testMaxLengths() {
AbstractByteArraySerializer codec = TcpCodecs.crlf(123);
assertThat(codec, instanceOf(ByteArrayCrLfSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertThat(codec).isInstanceOf(ByteArrayCrLfSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
codec = TcpCodecs.lf(123);
assertThat(codec, instanceOf(ByteArrayLfSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertThat(codec).isInstanceOf(ByteArrayLfSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
codec = TcpCodecs.raw(123);
assertThat(codec, instanceOf(ByteArrayRawSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertThat(codec).isInstanceOf(ByteArrayRawSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
codec = TcpCodecs.stxetx(123);
assertThat(codec, instanceOf(ByteArrayStxEtxSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertThat(codec).isInstanceOf(ByteArrayStxEtxSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
codec = TcpCodecs.singleTerminator((byte) 23, 123);
assertThat(codec, instanceOf(ByteArraySingleTerminatorSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertEquals((byte) 23, TestUtils.getPropertyValue(codec, "terminator"));
assertThat(codec).isInstanceOf(ByteArraySingleTerminatorSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
assertThat(TestUtils.getPropertyValue(codec, "terminator")).isEqualTo((byte) 23);
codec = TcpCodecs.lengthHeader1(123);
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertEquals(1, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(1);
codec = TcpCodecs.lengthHeader2(123);
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertEquals(2, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(2);
codec = TcpCodecs.lengthHeader4(123);
assertThat(codec, instanceOf(ByteArrayLengthHeaderSerializer.class));
assertThat(codec.getMaxMessageSize(), equalTo(123));
assertEquals(4, TestUtils.getPropertyValue(codec, "headerSize"));
assertThat(codec).isInstanceOf(ByteArrayLengthHeaderSerializer.class);
assertThat(codec.getMaxMessageSize()).isEqualTo(123);
assertThat(TestUtils.getPropertyValue(codec, "headerSize")).isEqualTo(4);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
package org.springframework.integration.ip.udp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.net.DatagramPacket;
import java.net.InetSocketAddress;
@@ -68,20 +66,20 @@ public class DatagramPacketMessageMapperTests {
DatagramPacket packet = mapper.fromMessage(message);
packet.setSocketAddress(new InetSocketAddress("localhost", 22222));
Message<byte[]> messageOut = mapper.toMessage(packet);
assertEquals(new String(message.getPayload()), new String(messageOut.getPayload()));
assertThat(new String(messageOut.getPayload())).isEqualTo(new String(message.getPayload()));
if (ack) {
assertEquals(messageOut.getHeaders().get(IpHeaders.ACK_ID).toString(),
message.getHeaders().getId().toString());
assertThat(message.getHeaders().getId().toString())
.isEqualTo(messageOut.getHeaders().get(IpHeaders.ACK_ID).toString());
}
assertTrue(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME)).contains("localhost"));
assertThat(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME)).contains("localhost")).isTrue();
mapper.setLookupHost(false);
messageOut = mapper.toMessage(packet);
assertEquals(new String(message.getPayload()), new String(messageOut.getPayload()));
assertThat(new String(messageOut.getPayload())).isEqualTo(new String(message.getPayload()));
if (ack) {
assertEquals(messageOut.getHeaders().get(IpHeaders.ACK_ID).toString(),
message.getHeaders().getId().toString());
assertThat(message.getHeaders().getId().toString())
.isEqualTo(messageOut.getHeaders().get(IpHeaders.ACK_ID).toString());
}
assertFalse(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME)).contains("localhost"));
assertThat(((String) messageOut.getHeaders().get(IpHeaders.HOSTNAME)).contains("localhost")).isFalse();
}
@Test
@@ -103,7 +101,8 @@ public class DatagramPacketMessageMapperTests {
fail("Truncated message exception expected");
}
catch (MessageMappingException e) {
assertTrue(e.getMessage().contains("expected " + (bigLen + 4) + ", received " + (test.length() + 4)));
assertThat(e.getMessage().contains("expected " + (bigLen + 4) + ", received " + (test.length() + 4)))
.isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.ip.udp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.net.DatagramPacket;
@@ -81,7 +80,7 @@ public class DatagramPacketMulticastSendingHandlerTests {
int offset = receivedPacket.getOffset();
byte[] dest = new byte[length];
System.arraycopy(src, offset, dest, 0, length);
assertEquals(payload, new String(dest));
assertThat(new String(dest)).isEqualTo(payload);
received.countDown();
}
catch (Exception e) {
@@ -92,13 +91,13 @@ public class DatagramPacketMulticastSendingHandlerTests {
Executor executor = new SimpleAsyncTaskExecutor();
executor.execute(catcher);
executor.execute(catcher);
assertTrue(listening.await(10000, TimeUnit.MILLISECONDS));
assertThat(listening.await(10000, TimeUnit.MILLISECONDS)).isTrue();
MulticastSendingMessageHandler handler = new MulticastSendingMessageHandler(multicastAddress, testPort);
handler.setBeanFactory(mock(BeanFactory.class));
handler.setLocalAddress(this.multicastRule.getNic());
handler.afterPropertiesSet();
handler.handleMessage(MessageBuilder.withPayload(payload).build());
assertTrue(received.await(10000, TimeUnit.MILLISECONDS));
assertThat(received.await(10000, TimeUnit.MILLISECONDS)).isTrue();
handler.stop();
socket.close();
}
@@ -131,7 +130,7 @@ public class DatagramPacketMulticastSendingHandlerTests {
InetAddress group = InetAddress.getByName(multicastAddress);
socket1.joinGroup(group);
listening.countDown();
assertTrue(ackListening.await(10, TimeUnit.SECONDS));
assertThat(ackListening.await(10, TimeUnit.SECONDS)).isTrue();
socket1.receive(receivedPacket);
socket1.close();
byte[] src = receivedPacket.getData();
@@ -139,7 +138,7 @@ public class DatagramPacketMulticastSendingHandlerTests {
int offset = receivedPacket.getOffset();
byte[] dest = new byte[6];
System.arraycopy(src, offset + length - 6, dest, 0, 6);
assertEquals(payload, new String(dest));
assertThat(new String(dest)).isEqualTo(payload);
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
mapper.setAcknowledge(true);
mapper.setLengthCheck(true);
@@ -162,7 +161,7 @@ public class DatagramPacketMulticastSendingHandlerTests {
Executor executor = new SimpleAsyncTaskExecutor();
executor.execute(catcher);
executor.execute(catcher);
assertTrue(listening.await(10000, TimeUnit.MILLISECONDS));
assertThat(listening.await(10000, TimeUnit.MILLISECONDS)).isTrue();
MulticastSendingMessageHandler handler =
new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 10000);
handler.setLocalAddress(this.multicastRule.getNic());
@@ -174,7 +173,7 @@ public class DatagramPacketMulticastSendingHandlerTests {
ackPort.set(handler.getAckPort());
ackListening.countDown();
handler.handleMessage(MessageBuilder.withPayload(payload).build());
assertTrue(ackSent.await(10000, TimeUnit.MILLISECONDS));
assertThat(ackSent.await(10000, TimeUnit.MILLISECONDS)).isTrue();
handler.stop();
socket.close();
}
@@ -184,7 +183,7 @@ public class DatagramPacketMulticastSendingHandlerTests {
while (n++ < 100 && handler.getAckPort() == 0) {
Thread.sleep(100);
}
assertTrue(n < 100);
assertThat(n < 100).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
package org.springframework.integration.ip.udp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.net.DatagramPacket;
@@ -66,18 +65,18 @@ public class DatagramPacketSendingHandlerTests {
e.printStackTrace();
}
});
assertTrue(listening.await(10, TimeUnit.SECONDS));
assertThat(listening.await(10, TimeUnit.SECONDS)).isTrue();
UnicastSendingMessageHandler handler =
new UnicastSendingMessageHandler("localhost", testPort.get());
String payload = "foo";
handler.handleMessage(MessageBuilder.withPayload(payload).build());
assertTrue(received.await(3000, TimeUnit.MILLISECONDS));
assertThat(received.await(3000, TimeUnit.MILLISECONDS)).isTrue();
byte[] src = receivedPacket.getData();
int length = receivedPacket.getLength();
int offset = receivedPacket.getOffset();
byte[] dest = new byte[length];
System.arraycopy(src, offset, dest, 0, length);
assertEquals(payload, new String(dest));
assertThat(new String(dest)).isEqualTo(payload);
handler.stop();
}
@@ -98,7 +97,7 @@ public class DatagramPacketSendingHandlerTests {
DatagramSocket socket = new DatagramSocket();
testPort.set(socket.getLocalPort());
listening.countDown();
assertTrue(ackListening.await(10, TimeUnit.SECONDS));
assertThat(ackListening.await(10, TimeUnit.SECONDS)).isTrue();
socket.receive(receivedPacket);
socket.close();
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
@@ -129,13 +128,13 @@ public class DatagramPacketSendingHandlerTests {
ackListening.countDown();
String payload = "foobar";
handler.handleMessage(MessageBuilder.withPayload(payload).build());
assertTrue(ackSent.await(10000, TimeUnit.MILLISECONDS));
assertThat(ackSent.await(10000, TimeUnit.MILLISECONDS)).isTrue();
byte[] src = receivedPacket.getData();
int length = receivedPacket.getLength();
int offset = receivedPacket.getOffset();
byte[] dest = new byte[6];
System.arraycopy(src, offset + length - 6, dest, 0, 6);
assertEquals(payload, new String(dest));
assertThat(new String(dest)).isEqualTo(payload);
handler.stop();
}
@@ -144,7 +143,7 @@ public class DatagramPacketSendingHandlerTests {
while (n++ < 100 && handler.getAckPort() == 0) {
Thread.sleep(100);
}
assertTrue(n < 100);
assertThat(n < 100).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,10 @@
package org.springframework.integration.ip.udp;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -86,8 +85,8 @@ public class MultiClientTests {
}
for (int i = 0; i < drivers * 3; i++) {
Message<byte[]> messageOut = (Message<byte[]>) queue.receive(10000);
assertNotNull(messageOut);
Assert.assertEquals(payload, new String(messageOut.getPayload()));
assertThat(messageOut).isNotNull();
assertThat(new String(messageOut.getPayload())).isEqualTo(payload);
}
adapter.stop();
done.set(true);
@@ -134,8 +133,8 @@ public class MultiClientTests {
}
for (int i = 0; i < drivers * 3; i++) {
Message<byte[]> messageOut = (Message<byte[]>) queue.receive(20000);
assertNotNull(messageOut);
Assert.assertEquals(payload, new String(messageOut.getPayload()));
assertThat(messageOut).isNotNull();
assertThat(new String(messageOut.getPayload())).isEqualTo(payload);
}
adapter.stop();
done.set(true);
@@ -182,8 +181,8 @@ public class MultiClientTests {
}
for (int i = 0; i < drivers * 3; i++) {
Message<byte[]> messageOut = (Message<byte[]>) queue.receive(10000);
assertNotNull(messageOut);
Assert.assertEquals(payload, new String(messageOut.getPayload()));
assertThat(messageOut).isNotNull();
assertThat(new String(messageOut.getPayload())).isEqualTo(payload);
}
adapter.stop();
done.set(true);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,8 @@
package org.springframework.integration.ip.udp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import java.io.IOException;
@@ -85,7 +82,7 @@ public class UdpChannelAdapterTests {
final CountDownLatch stopLatch = new CountDownLatch(1);
final CountDownLatch exitLatch = new CountDownLatch(1);
final AtomicBoolean stopping = new AtomicBoolean();
final AtomicReference<Exception> exceptionHolder = new AtomicReference<Exception>();
final AtomicReference<Exception> exceptionHolder = new AtomicReference<>();
UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(0) {
@Override
@@ -95,7 +92,7 @@ public class UdpChannelAdapterTests {
stopLatch.await(10, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
fail();
fail("Test is interrupted");
}
return true;
}
@@ -156,14 +153,14 @@ public class UdpChannelAdapterTests {
datagramSocket.close();
@SuppressWarnings("unchecked")
Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(10000);
assertNotNull(receivedMessage);
assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
assertThat(receivedMessage).isNotNull();
assertThat(new String(receivedMessage.getPayload())).isEqualTo(new String(message.getPayload()));
stopping.set(true);
adapter.stop();
stopLatch.countDown();
exitLatch.await(10, TimeUnit.SECONDS);
// Previously it failed with NPE
assertNull(exceptionHolder.get());
assertThat(exceptionHolder.get()).isNull();
}
@SuppressWarnings("unchecked")
@@ -200,20 +197,20 @@ public class UdpChannelAdapterTests {
}
});
Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(10000);
assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
assertThat(new String(receivedMessage.getPayload())).isEqualTo(new String(message.getPayload()));
String replyString = "reply:" + System.currentTimeMillis();
byte[] replyBytes = replyString.getBytes();
DatagramPacket reply = new DatagramPacket(replyBytes, replyBytes.length);
reply.setSocketAddress(new InetSocketAddress(
(String) receivedMessage.getHeaders().get(IpHeaders.IP_ADDRESS),
(Integer) receivedMessage.getHeaders().get(IpHeaders.PORT)));
assertTrue(receiverReadyLatch.await(10, TimeUnit.SECONDS));
assertThat(receiverReadyLatch.await(10, TimeUnit.SECONDS)).isTrue();
DatagramSocket datagramSocket = new DatagramSocket();
datagramSocket.send(reply);
assertTrue(replyReceivedLatch.await(10, TimeUnit.SECONDS));
assertThat(replyReceivedLatch.await(10, TimeUnit.SECONDS)).isTrue();
DatagramPacket answerPacket = theAnswer.get();
assertNotNull(answerPacket);
assertEquals(replyString, new String(answerPacket.getData(), 0, answerPacket.getLength()));
assertThat(answerPacket).isNotNull();
assertThat(new String(answerPacket.getData(), 0, answerPacket.getLength())).isEqualTo(replyString);
datagramSocket.close();
socket.close();
adapter.stop();
@@ -240,7 +237,7 @@ public class UdpChannelAdapterTests {
Message<byte[]> message = MessageBuilder.withPayload("ABCD".getBytes()).build();
handler.handleMessage(message);
Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(10000);
assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
assertThat(new String(receivedMessage.getPayload())).isEqualTo(new String(message.getPayload()));
adapter.stop();
handler.stop();
}
@@ -267,8 +264,8 @@ public class UdpChannelAdapterTests {
datagramSocket.close();
Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(10000);
assertNotNull(receivedMessage);
assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
assertThat(receivedMessage).isNotNull();
assertThat(new String(receivedMessage.getPayload())).isEqualTo(new String(message.getPayload()));
adapter.stop();
}
@@ -291,8 +288,8 @@ public class UdpChannelAdapterTests {
handler.handleMessage(message);
Message<byte[]> receivedMessage = (Message<byte[]>) channel.receive(10000);
assertNotNull(receivedMessage);
assertEquals(new String(message.getPayload()), new String(receivedMessage.getPayload()));
assertThat(receivedMessage).isNotNull();
assertThat(new String(receivedMessage.getPayload())).isEqualTo(new String(message.getPayload()));
adapter.stop();
handler.stop();
}
@@ -320,8 +317,8 @@ public class UdpChannelAdapterTests {
datagramSocket.send(packet);
datagramSocket.close();
Message<?> receivedMessage = errorChannel.receive(10000);
assertNotNull(receivedMessage);
assertEquals("Failed", ((Exception) receivedMessage.getPayload()).getCause().getMessage());
assertThat(receivedMessage).isNotNull();
assertThat(((Exception) receivedMessage.getPayload()).getCause().getMessage()).isEqualTo("Failed");
adapter.stop();
}
@@ -337,8 +334,8 @@ public class UdpChannelAdapterTests {
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.receive(packet);
assertEquals("FOO", new String(packet.getData()));
assertEquals(receiverServerPort, packet.getPort());
assertThat(new String(packet.getData())).isEqualTo("FOO");
assertThat(packet.getPort()).isEqualTo(receiverServerPort);
socket.close();
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,8 @@
package org.springframework.integration.ip.udp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.Date;
import java.util.Properties;
@@ -90,7 +89,7 @@ public class UdpMulticastEndToEndTests implements Runnable {
while (n++ < 100 && launcher.getReceiverPort() == 0) {
Thread.sleep(100);
}
assertTrue("Receiver failed to listen", n < 100);
assertThat(n < 100).as("Receiver failed to listen").isTrue();
ClassPathXmlApplicationContext applicationContext = createContext(launcher, location);
launcher.launchSender(applicationContext);
@@ -143,8 +142,8 @@ public class UdpMulticastEndToEndTests implements Runnable {
// tell the receiver to we're done
doneProcessing.countDown();
}
assertTrue(firstReceived.await(2, TimeUnit.SECONDS));
assertEquals(testingIpText, new String(finalMessage.getPayload()));
assertThat(firstReceived.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(new String(finalMessage.getPayload())).isEqualTo(testingIpText);
}
public int getReceiverPort() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
package org.springframework.integration.ip.udp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.Date;
import java.util.Properties;
@@ -108,7 +106,7 @@ public class UdpUnicastEndToEndTests implements Runnable {
while (n++ < 100 && launcher.getReceiverPort() == 0) {
Thread.sleep(100);
}
assertTrue("Receiver failed to listen", n < 100);
assertThat(n < 100).as("Receiver failed to listen").isTrue();
ClassPathXmlApplicationContext applicationContext = createContext(launcher, location);
launcher.launchSender(applicationContext);
@@ -156,8 +154,8 @@ public class UdpUnicastEndToEndTests implements Runnable {
// tell the receiver to we're done
doneProcessing.countDown();
}
assertTrue(firstReceived.await(5, TimeUnit.SECONDS));
assertEquals(testingIpText, new String(finalMessage.getPayload()));
assertThat(firstReceived.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(new String(finalMessage.getPayload())).isEqualTo(testingIpText);
}
public int getReceiverPort() {
@@ -203,8 +201,8 @@ public class UdpUnicastEndToEndTests implements Runnable {
finalMessage = (Message<byte[]>) channel.receive();
MessageHistory history = MessageHistory.read(finalMessage);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "udpReceiver", 0);
assertNotNull(componentHistoryRecord);
assertEquals("ip:udp-inbound-channel-adapter", componentHistoryRecord.get("type"));
assertThat(componentHistoryRecord).isNotNull();
assertThat(componentHistoryRecord.get("type")).isEqualTo("ip:udp-inbound-channel-adapter");
firstReceived.countDown();
try {
doneProcessing.await();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.springframework.integration.ip.util;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -31,7 +31,7 @@ public class RegexUtilsTests {
@Test
public void testRegex() {
String s = "xxx$^[]{()}+*\\?|.xxx";
assertEquals("xxx\\$\\^\\[\\]\\{\\(\\)\\}\\+\\*\\\\\\?\\|\\.xxx", RegexUtils.escapeRegexSpecials(s));
assertThat(RegexUtils.escapeRegexSpecials(s)).isEqualTo("xxx\\$\\^\\[\\]\\{\\(\\)\\}\\+\\*\\\\\\?\\|\\.xxx");
}
}