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

@@ -92,6 +92,7 @@ subprojects { subproject ->
aspectjVersion = '1.9.2'
assertjVersion = '3.12.0'
assertkVersion = '0.13'
awaitilityVersion = '3.1.6'
boonVersion = '0.34'
commonsDbcp2Version = '2.5.0'
commonsIoVersion = '2.6'
@@ -102,7 +103,7 @@ subprojects { subproject ->
googleJsr305Version = '3.0.2'
groovyVersion = '2.5.6'
guavaVersion = '26.0-jre'
hamcrestVersion = '1.3'
hamcrestVersion = '2.1'
hazelcastVersion = '3.11.1'
hibernateVersion = '5.4.1.Final'
hsqldbVersion = '2.4.1'
@@ -159,12 +160,18 @@ subprojects { subproject ->
// dependencies that are common across all java projects
dependencies {
if (!(subproject.name ==~ /.*-test.*/)) {
testCompile project(":spring-integration-test-support")
testCompile (project(":spring-integration-test-support")) {
exclude group: 'org.hamcrest'
}
}
// JSR-305 only used for non-required meta-annotations
compileOnly("com.google.code.findbugs:jsr305:$googleJsr305Version")
testCompile("com.google.code.findbugs:jsr305:$googleJsr305Version")
compileOnly "com.google.code.findbugs:jsr305:$googleJsr305Version"
testCompile "com.google.code.findbugs:jsr305:$googleJsr305Version"
testCompile ("org.awaitility:awaitility:$awaitilityVersion") {
exclude group: 'org.hamcrest'
}
testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion"
@@ -179,7 +186,7 @@ subprojects { subproject ->
testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
testRuntime "org.apache.logging.log4j:log4j-jcl:$log4jVersion"
testCompile("com.willowtreeapps.assertk:assertk-jvm:$assertkVersion")
testCompile "com.willowtreeapps.assertk:assertk-jvm:$assertkVersion"
testCompile "org.jetbrains.kotlin:kotlin-reflect"
testCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
@@ -330,9 +337,10 @@ subprojects { subproject ->
project('spring-integration-test-support') {
description = 'Spring Integration Test Support - **No SI Dependencies Allowed**'
dependencies {
compile "org.hamcrest:hamcrest-core:$hamcrestVersion"
compile "org.hamcrest:hamcrest-library:$hamcrestVersion"
compile "junit:junit:$junit4Version"
compile ("junit:junit:$junit4Version") {
exclude group: 'org.hamcrest'
}
compile ("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion", optional)
compileOnly 'org.apiguardian:apiguardian-api:1.0.0'
compile "org.mockito:mockito-core:$mockitoVersion"
@@ -459,6 +467,7 @@ project('spring-integration-http') {
compile ("com.rometools:rome:$romeToolsVersion", optional)
testCompile project(":spring-integration-security")
testCompile "org.hamcrest:hamcrest-core:$hamcrestVersion"
testCompile ("org.springframework.security:spring-security-config:$springSecurityVersion") {
exclude group: 'org.springframework'
}
@@ -674,7 +683,8 @@ project('spring-integration-webflux') {
}
compile "org.springframework:spring-webflux:$springVersion"
compile ("io.projectreactor.netty:reactor-netty:$reactorNettyVersion" , optional)
testCompile "org.hamcrest:hamcrest-core:$hamcrestVersion"
testCompile "org.springframework:spring-webmvc:$springVersion"
testCompile ("org.springframework.security:spring-security-config:$springSecurityVersion") {
exclude group: 'org.springframework'

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 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,13 +16,8 @@
package org.springframework.integration.amqp.channel;
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.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;
@@ -34,9 +29,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.amqp.core.AmqpTemplate;
@@ -80,9 +73,6 @@ public class ChannelTests {
public static final BrokerRunning brokerIsRunning =
BrokerRunning.isRunningWithEmptyQueues("pollableWithEP", "withEP", "testConvertFail");
@Rule
public ExpectedException exception = ExpectedException.none();
@Autowired
private PublishSubscribeAmqpChannel channel;
@@ -136,8 +126,8 @@ public class ChannelTests {
this.pubSubWithEP.destroy();
this.withEP.destroy();
this.pollableWithEP.destroy();
assertEquals(0,
TestUtils.getPropertyValue(connectionFactory, "connectionListener.delegates", Collection.class).size());
assertThat(TestUtils.getPropertyValue(connectionFactory, "connectionListener.delegates", Collection.class)
.size()).isEqualTo(0);
}
@SuppressWarnings("unchecked")
@@ -147,7 +137,8 @@ public class ChannelTests {
final Object consumersMonitor = TestUtils.getPropertyValue(channel, "container.consumersMonitor");
int n = 0;
while (n++ < 100) {
Set<BlockingQueueConsumer> consumers = TestUtils.getPropertyValue(channel, "container.consumers", Set.class);
Set<BlockingQueueConsumer> consumers = TestUtils
.getPropertyValue(channel, "container.consumers", Set.class);
synchronized (consumersMonitor) {
if (!consumers.isEmpty()) {
BlockingQueueConsumer newConsumer = consumers.iterator().next();
@@ -158,7 +149,7 @@ public class ChannelTests {
}
Thread.sleep(100);
}
assertTrue("Failed to restart consumer", n < 100);
assertThat(n < 100).as("Failed to restart consumer").isTrue();
}
/*
@@ -177,21 +168,21 @@ public class ChannelTests {
channel.afterPropertiesSet();
channel.onCreate(null);
assertNotNull(admin.getQueueProperties("implicit"));
assertThat(admin.getQueueProperties("implicit")).isNotNull();
admin.deleteQueue("explicit");
channel.setQueueName("explicit");
channel.afterPropertiesSet();
channel.onCreate(null);
assertNotNull(admin.getQueueProperties("explicit"));
assertThat(admin.getQueueProperties("explicit")).isNotNull();
admin.deleteQueue("explicit");
admin.declareQueue(new Queue("explicit", false)); // verify no declaration if exists with non-standard props
channel.afterPropertiesSet();
channel.onCreate(null);
assertNotNull(admin.getQueueProperties("explicit"));
assertThat(admin.getQueueProperties("explicit")).isNotNull();
admin.deleteQueue("explicit");
}
@@ -203,7 +194,7 @@ public class ChannelTests {
channelFactoryBean.setBeanName("testChannel");
channelFactoryBean.afterPropertiesSet();
AbstractAmqpChannel channel = channelFactoryBean.getObject();
assertThat(channel, instanceOf(PointToPointSubscribableAmqpChannel.class));
assertThat(channel).isInstanceOf(PointToPointSubscribableAmqpChannel.class);
channelFactoryBean = new AmqpChannelFactoryBean();
channelFactoryBean.setBeanFactory(mock(BeanFactory.class));
@@ -212,7 +203,7 @@ public class ChannelTests {
channelFactoryBean.setPubSub(true);
channelFactoryBean.afterPropertiesSet();
channel = channelFactoryBean.getObject();
assertThat(channel, instanceOf(PublishSubscribeAmqpChannel.class));
assertThat(channel).isInstanceOf(PublishSubscribeAmqpChannel.class);
RabbitAdmin rabbitAdmin = new RabbitAdmin(this.connectionFactory);
rabbitAdmin.deleteQueue("testChannel");
@@ -225,24 +216,24 @@ public class ChannelTests {
Message<?> message = MessageBuilder.withPayload(foo).setHeader("baz", "qux").build();
this.pollableWithEP.send(message);
Message<?> received = this.pollableWithEP.receive(10000);
assertNotNull(received);
assertThat(received.getPayload(), equalTo(foo));
assertThat(received.getHeaders().get("baz"), equalTo("qux"));
assertThat(received).isNotNull();
assertThat(received.getPayload()).isEqualTo(foo);
assertThat(received.getHeaders().get("baz")).isEqualTo("qux");
this.withEP.send(message);
received = this.out.receive(10000);
assertNotNull(received);
assertThat(received.getPayload(), equalTo(foo));
assertThat(received.getHeaders().get("baz"), equalTo("qux"));
assertThat(received).isNotNull();
assertThat(received.getPayload()).isEqualTo(foo);
assertThat(received.getHeaders().get("baz")).isEqualTo("qux");
this.pubSubWithEP.send(message);
received = this.out.receive(10000);
assertNotNull(received);
assertThat(received.getPayload(), equalTo(foo));
assertThat(received.getHeaders().get("baz"), equalTo("qux"));
assertThat(received).isNotNull();
assertThat(received.getPayload()).isEqualTo(foo);
assertThat(received.getHeaders().get("baz")).isEqualTo("qux");
assertSame(this.mapperIn, TestUtils.getPropertyValue(this.pollableWithEP, "inboundHeaderMapper"));
assertSame(this.mapperOut, TestUtils.getPropertyValue(this.pollableWithEP, "outboundHeaderMapper"));
assertThat(TestUtils.getPropertyValue(this.pollableWithEP, "inboundHeaderMapper")).isSameAs(this.mapperIn);
assertThat(TestUtils.getPropertyValue(this.pollableWithEP, "outboundHeaderMapper")).isSameAs(this.mapperOut);
}
@Test
@@ -257,9 +248,9 @@ public class ChannelTests {
MessageListener.class);
willThrow(new MessageConversionException("foo", new IllegalStateException("bar")))
.given(messageConverter).fromMessage(any(org.springframework.amqp.core.Message.class));
this.exception.expect(MessageConversionException.class);
this.exception.expectCause(instanceOf(IllegalStateException.class));
listener.onMessage(mock(org.springframework.amqp.core.Message.class));
assertThatThrownBy(() -> listener.onMessage(mock(org.springframework.amqp.core.Message.class)))
.isInstanceOf(MessageConversionException.class)
.hasCauseInstanceOf(IllegalStateException.class);
}
public static class Foo {

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,11 +16,8 @@
package org.springframework.integration.amqp.channel;
import static org.hamcrest.Matchers.containsString;
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.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
@@ -87,8 +84,8 @@ public class DispatcherHasNoSubscribersTests {
fail("Exception expected");
}
catch (MessageDeliveryException e) {
assertThat(e.getMessage(),
containsString("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'."));
assertThat(e.getMessage())
.contains("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.");
}
}
@@ -135,19 +132,18 @@ public class DispatcherHasNoSubscribersTests {
}
private void verifyLogReceived(final List<String> logList) {
assertTrue("Failed to get expected exception", logList.size() > 0);
assertThat(logList.size() > 0).as("Failed to get expected exception").isTrue();
boolean expectedExceptionFound = false;
while (logList.size() > 0) {
String message = logList.remove(0);
assertNotNull("Failed to get expected exception", message);
assertThat(message).as("Failed to get expected exception").isNotNull();
if (message.startsWith("Dispatcher has no subscribers")) {
expectedExceptionFound = true;
assertThat(message,
containsString("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'."));
assertThat(message).contains("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.");
break;
}
}
assertTrue("Failed to get expected exception", expectedExceptionFound);
assertThat(expectedExceptionFound).as("Failed to get expected exception").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,7 @@
package org.springframework.integration.amqp.config;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.List;
@@ -73,30 +66,33 @@ public class AmqpChannelParserTests {
public void interceptor() {
MessageChannel channel = context.getBean("channelWithInterceptor", MessageChannel.class);
List<?> interceptorList = TestUtils.getPropertyValue(channel, "interceptors.interceptors", List.class);
assertEquals(1, interceptorList.size());
assertEquals(TestInterceptor.class, interceptorList.get(0).getClass());
assertEquals(Integer.MAX_VALUE, TestUtils.getPropertyValue(
TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue());
assertThat(interceptorList.size()).isEqualTo(1);
assertThat(interceptorList.get(0).getClass()).isEqualTo(TestInterceptor.class);
assertThat(TestUtils.getPropertyValue(
TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue())
.isEqualTo(Integer.MAX_VALUE);
channel = context.getBean("pubSub", MessageChannel.class);
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
assertSame(mbf, TestUtils.getPropertyValue(channel, "container.messageListener.messageBuilderFactory"));
assertTrue(TestUtils.getPropertyValue(channel, "container.missingQueuesFatal", Boolean.class));
assertFalse(TestUtils.getPropertyValue(channel, "container.transactional", Boolean.class));
assertFalse(TestUtils.getPropertyValue(channel, "amqpTemplate.transactional", Boolean.class));
assertThat(TestUtils.getPropertyValue(channel, "container"), instanceOf(SimpleMessageListenerContainer.class));
assertThat(TestUtils.getPropertyValue(channel, "container.messageListener.messageBuilderFactory"))
.isSameAs(mbf);
assertThat(TestUtils.getPropertyValue(channel, "container.missingQueuesFatal", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(channel, "container.transactional", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(channel, "amqpTemplate.transactional", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(channel, "container")).isInstanceOf(SimpleMessageListenerContainer.class);
}
@Test
public void subscriberLimit() {
MessageChannel channel = context.getBean("channelWithSubscriberLimit", MessageChannel.class);
assertEquals(1, TestUtils.getPropertyValue(
TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue());
assertFalse(TestUtils.getPropertyValue(channel, "container.missingQueuesFatal", Boolean.class));
assertFalse(TestUtils.getPropertyValue(channel, "container.transactional", Boolean.class));
assertTrue(TestUtils.getPropertyValue(channel, "amqpTemplate.transactional", Boolean.class));
assertFalse(TestUtils.getPropertyValue(channel, "extractPayload", Boolean.class));
assertThat(TestUtils.getPropertyValue(channel, "container"), instanceOf(DirectMessageListenerContainer.class));
assertEquals(2, TestUtils.getPropertyValue(channel, "container.consumersPerQueue"));
assertThat(TestUtils.getPropertyValue(
TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue())
.isEqualTo(1);
assertThat(TestUtils.getPropertyValue(channel, "container.missingQueuesFatal", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(channel, "container.transactional", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(channel, "amqpTemplate.transactional", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(channel, "extractPayload", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(channel, "container")).isInstanceOf(DirectMessageListenerContainer.class);
assertThat(TestUtils.getPropertyValue(channel, "container.consumersPerQueue")).isEqualTo(2);
}
@Test
@@ -104,19 +100,19 @@ public class AmqpChannelParserTests {
checkExtract(this.pollableWithEP);
checkExtract(this.withEP);
checkExtract(this.pubSubWithEP);
assertEquals(MessageDeliveryMode.NON_PERSISTENT,
TestUtils.getPropertyValue(this.withEP, "defaultDeliveryMode"));
assertFalse(TestUtils.getPropertyValue(this.withEP, "headersMappedLast", Boolean.class));
assertNull(TestUtils.getPropertyValue(this.pollableWithEP, "defaultDeliveryMode"));
assertTrue(TestUtils.getPropertyValue(this.pollableWithEP, "headersMappedLast", Boolean.class));
assertThat(TestUtils.getPropertyValue(this.withEP, "defaultDeliveryMode"))
.isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(TestUtils.getPropertyValue(this.withEP, "headersMappedLast", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(this.pollableWithEP, "defaultDeliveryMode")).isNull();
assertThat(TestUtils.getPropertyValue(this.pollableWithEP, "headersMappedLast", Boolean.class)).isTrue();
}
private void checkExtract(AbstractAmqpChannel channel) {
assertThat(TestUtils.getPropertyValue(channel, "outboundHeaderMapper").toString(),
containsString("Mock for AmqpHeaderMapper"));
assertThat(TestUtils.getPropertyValue(channel, "inboundHeaderMapper").toString(),
containsString("Mock for AmqpHeaderMapper"));
assertTrue(TestUtils.getPropertyValue(channel, "extractPayload", Boolean.class));
assertThat(TestUtils.getPropertyValue(channel, "outboundHeaderMapper").toString())
.contains("Mock for AmqpHeaderMapper");
assertThat(TestUtils.getPropertyValue(channel, "inboundHeaderMapper").toString())
.contains("Mock for AmqpHeaderMapper");
assertThat(TestUtils.getPropertyValue(channel, "extractPayload", Boolean.class)).isTrue();
}
private static class TestInterceptor implements ChannelInterceptor {

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,7 @@
package org.springframework.integration.amqp.config;
import static org.hamcrest.Matchers.instanceOf;
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.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -66,33 +60,36 @@ public class AmqpInboundChannelAdapterParserTests {
public void verifyIdAsChannel() {
Object channel = context.getBean("rabbitInbound");
Object adapter = context.getBean("rabbitInbound.adapter");
assertEquals(DirectChannel.class, channel.getClass());
assertEquals(AmqpInboundChannelAdapter.class, adapter.getClass());
assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(adapter, "autoStartup"));
assertEquals(Integer.MAX_VALUE / 2, TestUtils.getPropertyValue(adapter, "phase"));
assertTrue(TestUtils.getPropertyValue(adapter, "messageListenerContainer.missingQueuesFatal", Boolean.class));
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer"),
instanceOf(SimpleMessageListenerContainer.class));
assertThat(channel.getClass()).isEqualTo(DirectChannel.class);
assertThat(adapter.getClass()).isEqualTo(AmqpInboundChannelAdapter.class);
assertThat(TestUtils.getPropertyValue(adapter, "autoStartup")).isEqualTo(Boolean.TRUE);
assertThat(TestUtils.getPropertyValue(adapter, "phase")).isEqualTo(Integer.MAX_VALUE / 2);
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer.missingQueuesFatal", Boolean.class))
.isTrue();
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer"))
.isInstanceOf(SimpleMessageListenerContainer.class);
}
@Test
public void verifyDMCC() {
Object adapter = context.getBean("dmlc.adapter");
assertEquals(AmqpInboundChannelAdapter.class, adapter.getClass());
assertFalse(TestUtils.getPropertyValue(adapter, "messageListenerContainer.missingQueuesFatal", Boolean.class));
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer"),
instanceOf(DirectMessageListenerContainer.class));
assertEquals(2, TestUtils.getPropertyValue(adapter, "messageListenerContainer.consumersPerQueue"));
assertThat(adapter.getClass()).isEqualTo(AmqpInboundChannelAdapter.class);
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer.missingQueuesFatal", Boolean.class))
.isFalse();
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer"))
.isInstanceOf(DirectMessageListenerContainer.class);
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer.consumersPerQueue")).isEqualTo(2);
}
@Test
public void verifyLifeCycle() {
Object adapter = context.getBean("autoStartFalse.adapter");
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
assertEquals(123, TestUtils.getPropertyValue(adapter, "phase"));
assertEquals(AcknowledgeMode.NONE,
TestUtils.getPropertyValue(adapter, "messageListenerContainer.acknowledgeMode"));
assertFalse(TestUtils.getPropertyValue(adapter, "messageListenerContainer.missingQueuesFatal", Boolean.class));
assertThat(TestUtils.getPropertyValue(adapter, "autoStartup")).isEqualTo(Boolean.FALSE);
assertThat(TestUtils.getPropertyValue(adapter, "phase")).isEqualTo(123);
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer.acknowledgeMode"))
.isEqualTo(AcknowledgeMode.NONE);
assertThat(TestUtils.getPropertyValue(adapter, "messageListenerContainer.missingQueuesFatal", Boolean.class))
.isFalse();
}
@Test
@@ -116,12 +113,12 @@ public class AmqpInboundChannelAdapterParserTests {
listener.onMessage(amqpMessage, null);
QueueChannel requestChannel = context.getBean("requestChannel", QueueChannel.class);
org.springframework.messaging.Message<?> siMessage = requestChannel.receive(0);
assertEquals("foo", siMessage.getHeaders().get("foo"));
assertNull(siMessage.getHeaders().get("bar"));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertThat(siMessage.getHeaders().get("foo")).isEqualTo("foo");
assertThat(siMessage.getHeaders().get("bar")).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING)).isNotNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID)).isNotNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNotNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNotNull();
}
@Test
@@ -145,12 +142,12 @@ public class AmqpInboundChannelAdapterParserTests {
listener.onMessage(amqpMessage, null);
QueueChannel requestChannel = context.getBean("requestChannel", QueueChannel.class);
org.springframework.messaging.Message<?> siMessage = requestChannel.receive(0);
assertEquals("foo", siMessage.getHeaders().get("foo"));
assertNull(siMessage.getHeaders().get("bar"));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID));
assertNull(siMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertThat(siMessage.getHeaders().get("foo")).isEqualTo("foo");
assertThat(siMessage.getHeaders().get("bar")).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING)).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID)).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNull();
}
@Test
@@ -175,12 +172,12 @@ public class AmqpInboundChannelAdapterParserTests {
QueueChannel requestChannel = context.getBean("requestChannel", QueueChannel.class);
org.springframework.messaging.Message<?> siMessage = requestChannel.receive(0);
assertNull(siMessage.getHeaders().get("foo"));
assertNull(siMessage.getHeaders().get("bar"));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID));
assertNull(siMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertThat(siMessage.getHeaders().get("foo")).isNull();
assertThat(siMessage.getHeaders().get("bar")).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING)).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID)).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNull();
}
@Test
@@ -204,12 +201,12 @@ public class AmqpInboundChannelAdapterParserTests {
listener.onMessage(amqpMessage, null);
QueueChannel requestChannel = context.getBean("requestChannel", QueueChannel.class);
org.springframework.messaging.Message<?> siMessage = requestChannel.receive(0);
assertNotNull(siMessage.getHeaders().get("bar"));
assertNotNull(siMessage.getHeaders().get("foo"));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertNotNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertThat(siMessage.getHeaders().get("bar")).isNotNull();
assertThat(siMessage.getHeaders().get("foo")).isNotNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING)).isNotNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID)).isNotNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNotNull();
assertThat(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNotNull();
}
@Test
@@ -219,8 +216,8 @@ public class AmqpInboundChannelAdapterParserTests {
this.getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'"));
assertThat(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'")).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,10 +16,7 @@
package org.springframework.integration.amqp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.isNull;
import java.lang.reflect.Field;
@@ -72,28 +69,31 @@ public class AmqpInboundGatewayParserTests {
MessageConverter gatewayConverter = TestUtils.getPropertyValue(gateway, "amqpMessageConverter", MessageConverter.class);
MessageConverter templateConverter = TestUtils.getPropertyValue(gateway, "amqpTemplate.messageConverter", MessageConverter.class);
TestConverter testConverter = context.getBean("testConverter", TestConverter.class);
assertSame(testConverter, gatewayConverter);
assertSame(testConverter, templateConverter);
assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(gateway, "autoStartup"));
assertEquals(0, TestUtils.getPropertyValue(gateway, "phase"));
assertEquals(Long.valueOf(1234L), TestUtils.getPropertyValue(gateway, "replyTimeout", Long.class));
assertEquals(Long.valueOf(1234L), TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout", Long.class));
assertTrue(TestUtils.getPropertyValue(gateway, "messageListenerContainer.missingQueuesFatal", Boolean.class));
assertThat(gatewayConverter).isSameAs(testConverter);
assertThat(templateConverter).isSameAs(testConverter);
assertThat(TestUtils.getPropertyValue(gateway, "autoStartup")).isEqualTo(Boolean.TRUE);
assertThat(TestUtils.getPropertyValue(gateway, "phase")).isEqualTo(0);
assertThat(TestUtils.getPropertyValue(gateway, "replyTimeout", Long.class)).isEqualTo(Long.valueOf(1234L));
assertThat(TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout", Long.class))
.isEqualTo(Long.valueOf(1234L));
assertThat(TestUtils.getPropertyValue(gateway, "messageListenerContainer.missingQueuesFatal", Boolean.class))
.isTrue();
}
@Test
public void verifyLifeCycle() {
Object gateway = context.getBean("autoStartFalseGateway");
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(gateway, "autoStartup"));
assertEquals(123, TestUtils.getPropertyValue(gateway, "phase"));
assertFalse(TestUtils.getPropertyValue(gateway, "messageListenerContainer.missingQueuesFatal", Boolean.class));
assertThat(TestUtils.getPropertyValue(gateway, "autoStartup")).isEqualTo(Boolean.FALSE);
assertThat(TestUtils.getPropertyValue(gateway, "phase")).isEqualTo(123);
assertThat(TestUtils.getPropertyValue(gateway, "messageListenerContainer.missingQueuesFatal", Boolean.class))
.isFalse();
Object amqpTemplate = context.getBean("amqpTemplate");
assertSame(amqpTemplate, TestUtils.getPropertyValue(gateway, "amqpTemplate"));
assertThat(TestUtils.getPropertyValue(gateway, "amqpTemplate")).isSameAs(amqpTemplate);
Address defaultReplyTo = TestUtils.getPropertyValue(gateway, "defaultReplyTo", Address.class);
Address expected = new Address("fooExchange/barRoutingKey");
assertEquals(expected.getExchangeName(), defaultReplyTo.getExchangeName());
assertEquals(expected.getRoutingKey(), defaultReplyTo.getRoutingKey());
assertEquals(expected, defaultReplyTo);
assertThat(defaultReplyTo.getExchangeName()).isEqualTo(expected.getExchangeName());
assertThat(defaultReplyTo.getRoutingKey()).isEqualTo(expected.getRoutingKey());
assertThat(defaultReplyTo).isEqualTo(expected);
}
@Test
@@ -117,7 +117,7 @@ public class AmqpInboundGatewayParserTests {
Object[] args = invocation.getArguments();
Message amqpReplyMessage = (Message) args[2];
MessageProperties properties = amqpReplyMessage.getMessageProperties();
assertEquals("bar", properties.getHeaders().get("bar"));
assertThat(properties.getHeaders().get("bar")).isEqualTo("bar");
return null;
}).when(amqpTemplate).send(Mockito.any(String.class), Mockito.any(String.class),
Mockito.any(Message.class), isNull());
@@ -150,8 +150,8 @@ public class AmqpInboundGatewayParserTests {
this.getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'"));
assertThat(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'")).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,13 +16,8 @@
package org.springframework.integration.amqp.config;
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.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.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
@@ -107,14 +102,14 @@ public class AmqpOutboundChannelAdapterParserTests {
public void verifyIdAsChannel() {
Object channel = context.getBean("rabbitOutbound");
Object adapter = context.getBean("rabbitOutbound.adapter");
assertEquals(DirectChannel.class, channel.getClass());
assertEquals(EventDrivenConsumer.class, adapter.getClass());
assertThat(channel.getClass()).isEqualTo(DirectChannel.class);
assertThat(adapter.getClass()).isEqualTo(EventDrivenConsumer.class);
MessageHandler handler = TestUtils.getPropertyValue(adapter, "handler", MessageHandler.class);
assertTrue(handler instanceof NamedComponent);
assertEquals("amqp:outbound-channel-adapter", ((NamedComponent) handler).getComponentType());
assertThat(handler instanceof NamedComponent).isTrue();
assertThat(((NamedComponent) handler).getComponentType()).isEqualTo("amqp:outbound-channel-adapter");
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
assertTrue(TestUtils.getPropertyValue(handler, "lazyConnect", Boolean.class));
assertThat(adviceCalled).isEqualTo(1);
assertThat(TestUtils.getPropertyValue(handler, "lazyConnect", Boolean.class)).isTrue();
}
@Test
@@ -123,12 +118,12 @@ public class AmqpOutboundChannelAdapterParserTests {
AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivenConsumer, "handler",
AmqpOutboundEndpoint.class);
assertNotNull(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode"));
assertFalse(TestUtils.getPropertyValue(endpoint, "lazyConnect", Boolean.class));
assertEquals("42",
TestUtils.getPropertyValue(endpoint, "delayExpression", org.springframework.expression.Expression.class)
.getExpressionString());
assertFalse(TestUtils.getPropertyValue(endpoint, "headersMappedLast", Boolean.class));
assertThat(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode")).isNotNull();
assertThat(TestUtils.getPropertyValue(endpoint, "lazyConnect", Boolean.class)).isFalse();
assertThat(TestUtils
.getPropertyValue(endpoint, "delayExpression", org.springframework.expression.Expression.class)
.getExpressionString()).isEqualTo("42");
assertThat(TestUtils.getPropertyValue(endpoint, "headersMappedLast", Boolean.class)).isFalse();
Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate");
amqpTemplateField.setAccessible(true);
@@ -140,11 +135,12 @@ public class AmqpOutboundChannelAdapterParserTests {
Object[] args = invocation.getArguments();
org.springframework.amqp.core.Message amqpMessage = (org.springframework.amqp.core.Message) args[2];
MessageProperties properties = amqpMessage.getMessageProperties();
assertEquals("foo", properties.getHeaders().get("foo"));
assertEquals("foobar", properties.getHeaders().get("foobar"));
assertNull(properties.getHeaders().get("bar"));
assertEquals(shouldBePersistent.get() ? MessageDeliveryMode.PERSISTENT
: MessageDeliveryMode.NON_PERSISTENT, properties.getDeliveryMode());
assertThat(properties.getHeaders().get("foo")).isEqualTo("foo");
assertThat(properties.getHeaders().get("foobar")).isEqualTo("foobar");
assertThat(properties.getHeaders().get("bar")).isNull();
assertThat(properties.getDeliveryMode()).isEqualTo(shouldBePersistent.get() ?
MessageDeliveryMode.PERSISTENT
: MessageDeliveryMode.NON_PERSISTENT);
return null;
})
.when(amqpTemplate).send(Mockito.any(String.class), Mockito.any(String.class),
@@ -178,9 +174,9 @@ public class AmqpOutboundChannelAdapterParserTests {
AmqpOutboundEndpoint.class);
NullChannel nullChannel = context.getBean(NullChannel.class);
MessageChannel ackChannel = context.getBean("ackChannel", MessageChannel.class);
assertSame(ackChannel, TestUtils.getPropertyValue(endpoint, "confirmAckChannel"));
assertSame(nullChannel, TestUtils.getPropertyValue(endpoint, "confirmNackChannel"));
assertSame(context.getBean("ems"), TestUtils.getPropertyValue(endpoint, "errorMessageStrategy"));
assertThat(TestUtils.getPropertyValue(endpoint, "confirmAckChannel")).isSameAs(ackChannel);
assertThat(TestUtils.getPropertyValue(endpoint, "confirmNackChannel")).isSameAs(nullChannel);
assertThat(TestUtils.getPropertyValue(endpoint, "errorMessageStrategy")).isSameAs(context.getBean("ems"));
}
@SuppressWarnings("rawtypes")
@@ -191,7 +187,7 @@ public class AmqpOutboundChannelAdapterParserTests {
List chainHandlers = TestUtils.getPropertyValue(eventDrivenConsumer, "handler.handlers", List.class);
AmqpOutboundEndpoint endpoint = (AmqpOutboundEndpoint) chainHandlers.get(0);
assertNull(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode"));
assertThat(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode")).isNull();
Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate");
amqpTemplateField.setAccessible(true);
@@ -202,8 +198,8 @@ public class AmqpOutboundChannelAdapterParserTests {
Object[] args = invocation.getArguments();
org.springframework.amqp.core.Message amqpMessage = (org.springframework.amqp.core.Message) args[2];
MessageProperties properties = amqpMessage.getMessageProperties();
assertEquals("hello", new String(amqpMessage.getBody()));
assertEquals(MessageDeliveryMode.PERSISTENT, properties.getDeliveryMode());
assertThat(new String(amqpMessage.getBody())).isEqualTo("hello");
assertThat(properties.getDeliveryMode()).isEqualTo(MessageDeliveryMode.PERSISTENT);
return null;
})
.when(amqpTemplate).send(Mockito.any(String.class), Mockito.any(String.class),
@@ -226,9 +222,9 @@ public class AmqpOutboundChannelAdapterParserTests {
fail("Expected BeanDefinitionParsingException");
}
catch (BeansException e) {
assertTrue(e instanceof BeanDefinitionParsingException);
assertTrue(e.getMessage().contains("The 'channel' attribute isn't allowed for " +
"'amqp:outbound-channel-adapter' when it is used as a nested element"));
assertThat(e instanceof BeanDefinitionParsingException).isTrue();
assertThat(e.getMessage().contains("The 'channel' attribute isn't allowed for " +
"'amqp:outbound-channel-adapter' when it is used as a nested element")).isTrue();
}
}
@@ -292,8 +288,8 @@ public class AmqpOutboundChannelAdapterParserTests {
this.getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'"));
assertThat(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'")).isTrue();
}
}
@@ -301,9 +297,9 @@ public class AmqpOutboundChannelAdapterParserTests {
public void testInt2971AmqpOutboundChannelAdapterWithCustomHeaderMapper() {
AmqpHeaderMapper headerMapper = TestUtils.getPropertyValue(this.amqpMessageHandlerWithCustomHeaderMapper,
"headerMapper", AmqpHeaderMapper.class);
assertSame(this.context.getBean("customHeaderMapper"), headerMapper);
assertTrue(TestUtils.getPropertyValue(this.amqpMessageHandlerWithCustomHeaderMapper,
"headersMappedLast", Boolean.class));
assertThat(headerMapper).isSameAs(this.context.getBean("customHeaderMapper"));
assertThat(TestUtils.getPropertyValue(this.amqpMessageHandlerWithCustomHeaderMapper,
"headersMappedLast", Boolean.class)).isTrue();
}
@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,12 +16,7 @@
package org.springframework.integration.amqp.config;
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.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.isNull;
import java.lang.reflect.Field;
@@ -74,32 +69,32 @@ public class AmqpOutboundGatewayParserTests {
@Test
public void testGatewayConfig() {
Object edc = this.context.getBean("rabbitGateway");
assertFalse(TestUtils.getPropertyValue(edc, "autoStartup", Boolean.class));
assertThat(TestUtils.getPropertyValue(edc, "autoStartup", Boolean.class)).isFalse();
AmqpOutboundEndpoint gateway = TestUtils.getPropertyValue(edc, "handler", AmqpOutboundEndpoint.class);
assertEquals("amqp:outbound-gateway", gateway.getComponentType());
assertTrue(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
assertThat(gateway.getComponentType()).isEqualTo("amqp:outbound-gateway");
assertThat(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class)).isTrue();
checkGWProps(this.context, gateway);
AsyncAmqpOutboundGateway async = this.context.getBean("asyncGateway.handler", AsyncAmqpOutboundGateway.class);
assertEquals("amqp:outbound-async-gateway", async.getComponentType());
assertThat(async.getComponentType()).isEqualTo("amqp:outbound-async-gateway");
checkGWProps(this.context, async);
assertSame(this.context.getBean("asyncTemplate"), TestUtils.getPropertyValue(async, "template"));
assertSame(this.context.getBean("ems"), TestUtils.getPropertyValue(gateway, "errorMessageStrategy"));
assertThat(TestUtils.getPropertyValue(async, "template")).isSameAs(this.context.getBean("asyncTemplate"));
assertThat(TestUtils.getPropertyValue(gateway, "errorMessageStrategy")).isSameAs(this.context.getBean("ems"));
}
protected void checkGWProps(ApplicationContext context, Orderable gateway) {
assertEquals(5, gateway.getOrder());
assertEquals(context.getBean("fromRabbit"), TestUtils.getPropertyValue(gateway, "outputChannel"));
assertThat(gateway.getOrder()).isEqualTo(5);
assertThat(TestUtils.getPropertyValue(gateway, "outputChannel")).isEqualTo(context.getBean("fromRabbit"));
MessageChannel returnChannel = context.getBean("returnChannel", MessageChannel.class);
assertSame(returnChannel, TestUtils.getPropertyValue(gateway, "returnChannel"));
assertThat(TestUtils.getPropertyValue(gateway, "returnChannel")).isSameAs(returnChannel);
Long sendTimeout = TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout", Long.class);
assertEquals(Long.valueOf(777), sendTimeout);
assertTrue(TestUtils.getPropertyValue(gateway, "lazyConnect", Boolean.class));
assertEquals("42",
TestUtils.getPropertyValue(gateway, "delayExpression", org.springframework.expression.Expression.class)
.getExpressionString());
assertThat(sendTimeout).isEqualTo(Long.valueOf(777));
assertThat(TestUtils.getPropertyValue(gateway, "lazyConnect", Boolean.class)).isTrue();
assertThat(TestUtils
.getPropertyValue(gateway, "delayExpression", org.springframework.expression.Expression.class)
.getExpressionString()).isEqualTo("42");
}
@Test
@@ -108,11 +103,11 @@ public class AmqpOutboundGatewayParserTests {
AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivenConsumer, "handler",
AmqpOutboundEndpoint.class);
assertNotNull(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode"));
assertFalse(TestUtils.getPropertyValue(endpoint, "lazyConnect", Boolean.class));
assertThat(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode")).isNotNull();
assertThat(TestUtils.getPropertyValue(endpoint, "lazyConnect", Boolean.class)).isFalse();
assertFalse(TestUtils.getPropertyValue(endpoint, "requiresReply", Boolean.class));
assertTrue(TestUtils.getPropertyValue(endpoint, "headersMappedLast", Boolean.class));
assertThat(TestUtils.getPropertyValue(endpoint, "requiresReply", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(endpoint, "headersMappedLast", Boolean.class)).isTrue();
Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate");
amqpTemplateField.setAccessible(true);
@@ -124,9 +119,10 @@ public class AmqpOutboundGatewayParserTests {
Object[] args = invocation.getArguments();
org.springframework.amqp.core.Message amqpRequestMessage = (org.springframework.amqp.core.Message) args[2];
MessageProperties properties = amqpRequestMessage.getMessageProperties();
assertEquals("foo", properties.getHeaders().get("foo"));
assertEquals(shouldBePersistent.get() ? MessageDeliveryMode.PERSISTENT
: MessageDeliveryMode.NON_PERSISTENT, properties.getDeliveryMode());
assertThat(properties.getHeaders().get("foo")).isEqualTo("foo");
assertThat(properties.getDeliveryMode()).isEqualTo(shouldBePersistent.get() ?
MessageDeliveryMode.PERSISTENT
: MessageDeliveryMode.NON_PERSISTENT);
// mock reply AMQP message
MessageProperties amqpProperties = new MessageProperties();
amqpProperties.setAppId("test.appId");
@@ -149,13 +145,13 @@ public class AmqpOutboundGatewayParserTests {
// verify reply
QueueChannel queueChannel = this.context.getBean("fromRabbit", QueueChannel.class);
Message<?> replyMessage = queueChannel.receive(0);
assertNotNull(replyMessage);
assertEquals("bar", replyMessage.getHeaders().get("bar"));
assertEquals("foo", replyMessage.getHeaders().get("foo")); // copied from request Message
assertNull(replyMessage.getHeaders().get("foobar"));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertThat(replyMessage).isNotNull();
assertThat(replyMessage.getHeaders().get("bar")).isEqualTo("bar");
assertThat(replyMessage.getHeaders().get("foo")).isEqualTo("foo"); // copied from request Message
assertThat(replyMessage.getHeaders().get("foobar")).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.DELIVERY_MODE)).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNull();
shouldBePersistent.set(true);
message = MessageBuilder.withPayload("hello")
@@ -164,7 +160,7 @@ public class AmqpOutboundGatewayParserTests {
.build();
requestChannel.send(message);
replyMessage = queueChannel.receive(0);
assertNotNull(replyMessage);
assertThat(replyMessage).isNotNull();
}
@Test
@@ -173,8 +169,8 @@ public class AmqpOutboundGatewayParserTests {
AmqpOutboundEndpoint endpoint = TestUtils.getPropertyValue(eventDrivenConsumer, "handler",
AmqpOutboundEndpoint.class);
assertNull(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode"));
assertFalse(TestUtils.getPropertyValue(endpoint, "headersMappedLast", Boolean.class));
assertThat(TestUtils.getPropertyValue(endpoint, "defaultDeliveryMode")).isNull();
assertThat(TestUtils.getPropertyValue(endpoint, "headersMappedLast", Boolean.class)).isFalse();
Field amqpTemplateField = ReflectionUtils.findField(AmqpOutboundEndpoint.class, "amqpTemplate");
amqpTemplateField.setAccessible(true);
@@ -185,13 +181,13 @@ public class AmqpOutboundGatewayParserTests {
Object[] args = invocation.getArguments();
org.springframework.amqp.core.Message amqpRequestMessage = (org.springframework.amqp.core.Message) args[2];
MessageProperties properties = amqpRequestMessage.getMessageProperties();
assertEquals("foo", properties.getHeaders().get("foo"));
assertThat(properties.getHeaders().get("foo")).isEqualTo("foo");
// mock reply AMQP message
MessageProperties amqpProperties = new MessageProperties();
amqpProperties.setAppId("test.appId");
amqpProperties.setHeader("foobar", "foobar");
amqpProperties.setHeader("bar", "bar");
assertEquals(MessageDeliveryMode.PERSISTENT, properties.getDeliveryMode());
assertThat(properties.getDeliveryMode()).isEqualTo(MessageDeliveryMode.PERSISTENT);
amqpProperties.setReceivedDeliveryMode(properties.getDeliveryMode());
return new org.springframework.amqp.core.Message("hello".getBytes(), amqpProperties);
})
@@ -210,12 +206,12 @@ public class AmqpOutboundGatewayParserTests {
// verify reply
QueueChannel queueChannel = this.context.getBean("fromRabbit", QueueChannel.class);
Message<?> replyMessage = queueChannel.receive(0);
assertEquals("bar", replyMessage.getHeaders().get("bar"));
assertEquals("foo", replyMessage.getHeaders().get("foo")); // copied from request Message
assertNull(replyMessage.getHeaders().get("foobar"));
assertNotNull(replyMessage.getHeaders().get(AmqpHeaders.RECEIVED_DELIVERY_MODE));
assertNotNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertNotNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertThat(replyMessage.getHeaders().get("bar")).isEqualTo("bar");
assertThat(replyMessage.getHeaders().get("foo")).isEqualTo("foo"); // copied from request Message
assertThat(replyMessage.getHeaders().get("foobar")).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.RECEIVED_DELIVERY_MODE)).isNotNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNotNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNotNull();
}
@Test
@@ -234,7 +230,7 @@ public class AmqpOutboundGatewayParserTests {
Object[] args = invocation.getArguments();
org.springframework.amqp.core.Message amqpRequestMessage = (org.springframework.amqp.core.Message) args[2];
MessageProperties properties = amqpRequestMessage.getMessageProperties();
assertNull(properties.getHeaders().get("foo"));
assertThat(properties.getHeaders().get("foo")).isNull();
// mock reply AMQP message
MessageProperties amqpProperties = new MessageProperties();
amqpProperties.setAppId("test.appId");
@@ -257,13 +253,13 @@ public class AmqpOutboundGatewayParserTests {
// verify reply
QueueChannel queueChannel = context.getBean("fromRabbit", QueueChannel.class);
Message<?> replyMessage = queueChannel.receive(0);
assertNull(replyMessage.getHeaders().get("bar"));
assertEquals("foo", replyMessage.getHeaders().get("foo")); // copied from request Message
assertNull(replyMessage.getHeaders().get("foobar"));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertEquals(1, adviceCalled);
assertThat(replyMessage.getHeaders().get("bar")).isNull();
assertThat(replyMessage.getHeaders().get("foo")).isEqualTo("foo"); // copied from request Message
assertThat(replyMessage.getHeaders().get("foobar")).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.DELIVERY_MODE)).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNull();
assertThat(adviceCalled).isEqualTo(1);
}
@Test //INT-1029
@@ -283,7 +279,7 @@ public class AmqpOutboundGatewayParserTests {
Object[] args = invocation.getArguments();
org.springframework.amqp.core.Message amqpRequestMessage = (org.springframework.amqp.core.Message) args[2];
MessageProperties properties = amqpRequestMessage.getMessageProperties();
assertNull(properties.getHeaders().get("foo"));
assertThat(properties.getHeaders().get("foo")).isNull();
// mock reply AMQP message
MessageProperties amqpProperties = new MessageProperties();
amqpProperties.setAppId("test.appId");
@@ -307,13 +303,13 @@ public class AmqpOutboundGatewayParserTests {
// verify reply
QueueChannel queueChannel = this.context.getBean("fromRabbit", QueueChannel.class);
Message<?> replyMessage = queueChannel.receive(0);
assertEquals("hello", new String((byte[]) replyMessage.getPayload()));
assertNull(replyMessage.getHeaders().get("bar"));
assertEquals("foo", replyMessage.getHeaders().get("foo")); // copied from request Message
assertNull(replyMessage.getHeaders().get("foobar"));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
assertNull(replyMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertThat(new String((byte[]) replyMessage.getPayload())).isEqualTo("hello");
assertThat(replyMessage.getHeaders().get("bar")).isNull();
assertThat(replyMessage.getHeaders().get("foo")).isEqualTo("foo"); // copied from request Message
assertThat(replyMessage.getHeaders().get("foobar")).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.DELIVERY_MODE)).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE)).isNull();
assertThat(replyMessage.getHeaders().get(AmqpHeaders.APP_ID)).isNull();
}
@@ -324,8 +320,8 @@ public class AmqpOutboundGatewayParserTests {
this.getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'"));
assertThat(e.getMessage().startsWith("Configuration problem: The 'header-mapper' attribute " +
"is mutually exclusive with 'mapped-request-headers' or 'mapped-reply-headers'")).isTrue();
}
}

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.amqp.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.ClassRule;
import org.junit.Test;
@@ -58,8 +57,8 @@ public class OutboundGatewayIntegrationTests {
String payload = "foo";
this.toRabbit.send(new GenericMessage<String>(payload));
Message<?> receive = this.fromRabbit.receive(10000);
assertNotNull(receive);
assertEquals(payload.toUpperCase(), receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo(payload.toUpperCase());
}

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,7 @@
package org.springframework.integration.amqp.config;
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.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -67,16 +65,16 @@ public class OutboundGatewayTests {
@Test
public void testVanillaConfiguration() throws Exception {
assertTrue(context.getBeanFactory().containsBeanDefinition("vanilla"));
assertThat(context.getBeanFactory().containsBeanDefinition("vanilla")).isTrue();
context.getBean("vanilla");
}
@Test
public void testExpressionBasedConfiguration() throws Exception {
assertTrue(context.getBeanFactory().containsBeanDefinition("expression"));
assertThat(context.getBeanFactory().containsBeanDefinition("expression")).isTrue();
Object target = context.getBean("expression");
assertNotNull(ReflectionTestUtils.getField(ReflectionTestUtils.getField(target, "handler"),
"routingKeyGenerator"));
assertThat(ReflectionTestUtils.getField(ReflectionTestUtils.getField(target, "handler"),
"routingKeyGenerator")).isNotNull();
}
@Test
@@ -103,12 +101,12 @@ public class OutboundGatewayTests {
endpoint.setBeanFactory(context);
endpoint.afterPropertiesSet();
Message<?> message = new GenericMessage<String>("Hello, world!");
assertEquals("foobar", TestUtils.getPropertyValue(endpoint, "routingKeyGenerator", MessageProcessor.class)
.processMessage(message));
assertEquals("barbar", TestUtils.getPropertyValue(endpoint, "exchangeNameGenerator", MessageProcessor.class)
.processMessage(message));
assertEquals("bazbar", TestUtils.getPropertyValue(endpoint, "correlationDataGenerator", MessageProcessor.class)
.processMessage(message));
assertThat(TestUtils.getPropertyValue(endpoint, "routingKeyGenerator", MessageProcessor.class)
.processMessage(message)).isEqualTo("foobar");
assertThat(TestUtils.getPropertyValue(endpoint, "exchangeNameGenerator", MessageProcessor.class)
.processMessage(message)).isEqualTo("barbar");
assertThat(TestUtils.getPropertyValue(endpoint, "correlationDataGenerator", MessageProcessor.class)
.processMessage(message)).isEqualTo("bazbar");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 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,13 +16,7 @@
package org.springframework.integration.amqp.dsl;
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.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.atomic.AtomicReference;
@@ -112,11 +106,11 @@ public class AmqpTests {
@Test
public void testAmqpInboundGatewayFlow() {
assertNotNull(this.amqpInboundGatewayContainer);
assertSame(this.amqpTemplate, TestUtils.getPropertyValue(this.amqpInboundGateway, "amqpTemplate"));
assertThat(this.amqpInboundGatewayContainer).isNotNull();
assertThat(TestUtils.getPropertyValue(this.amqpInboundGateway, "amqpTemplate")).isSameAs(this.amqpTemplate);
Object result = this.amqpTemplate.convertSendAndReceive(this.amqpQueue.getName(), "world");
assertEquals("HELLO WORLD", result);
assertThat(result).isEqualTo("HELLO WORLD");
this.amqpInboundGateway.stop();
//INTEXT-209
@@ -125,7 +119,7 @@ public class AmqpTests {
this.amqpTemplate.convertAndSend(this.amqpQueue.getName(), "world");
((RabbitTemplate) this.amqpTemplate).setReceiveTimeout(10000);
result = this.amqpTemplate.receiveAndConvert("defaultReplyTo");
assertEquals("HELLO WORLD", result);
assertThat(result).isEqualTo("HELLO WORLD");
}
@Autowired
@@ -153,8 +147,8 @@ public class AmqpTests {
}
while (i < 10);
assertNotNull(receive);
assertEquals("HELLO THROUGH THE AMQP", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("HELLO THROUGH THE AMQP");
((Lifecycle) this.amqpOutboundInput).stop();
}
@@ -165,8 +159,8 @@ public class AmqpTests {
this.rabbitConnectionFactory)
.autoStartup(false)
.templateChannelTransacted(true));
assertTrue(TestUtils.getPropertyValue(flow, "currentMessageChannel.amqpTemplate.transactional",
Boolean.class));
assertThat(TestUtils.getPropertyValue(flow, "currentMessageChannel.amqpTemplate.transactional",
Boolean.class)).isTrue();
}
@Autowired
@@ -181,8 +175,8 @@ public class AmqpTests {
.build());
Message<?> receive = replyChannel.receive(10000);
assertNotNull(receive);
assertEquals("HELLO ASYNC GATEWAY", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("HELLO ASYNC GATEWAY");
this.asyncOutboundGateway.stop();
}
@@ -197,19 +191,19 @@ public class AmqpTests {
@Test
public void testInboundMessagingExceptionFlow() {
this.amqpTemplate.convertAndSend("si.dsl.exception.test", "foo");
assertNotNull(this.amqpTemplate.receive("si.dsl.exception.test.dlq", 30_000));
assertNull(this.lefe.get());
assertNotNull(this.raw.get());
assertThat(this.amqpTemplate.receive("si.dsl.exception.test.dlq", 30_000)).isNotNull();
assertThat(this.lefe.get()).isNull();
assertThat(this.raw.get()).isNotNull();
this.raw.set(null);
}
@Test
public void testInboundConversionExceptionFlow() {
this.amqpTemplate.convertAndSend("si.dsl.conv.exception.test", "foo");
assertNotNull(this.amqpTemplate.receive("si.dsl.conv.exception.test.dlq", 30_000));
assertNotNull(this.lefe.get());
assertThat(this.lefe.get().getCause(), instanceOf(MessageConversionException.class));
assertNotNull(this.raw.get());
assertThat(this.amqpTemplate.receive("si.dsl.conv.exception.test.dlq", 30_000)).isNotNull();
assertThat(this.lefe.get()).isNotNull();
assertThat(this.lefe.get().getCause()).isInstanceOf(MessageConversionException.class);
assertThat(this.raw.get()).isNotNull();
this.raw.set(null);
this.lefe.set(null);
}
@@ -225,11 +219,11 @@ public class AmqpTests {
@Test
public void unitTestChannel() {
assertEquals(MessageDeliveryMode.NON_PERSISTENT,
TestUtils.getPropertyValue(this.unitChannel, "defaultDeliveryMode"));
assertSame(this.mapperIn, TestUtils.getPropertyValue(this.unitChannel, "inboundHeaderMapper"));
assertSame(this.mapperOut, TestUtils.getPropertyValue(this.unitChannel, "outboundHeaderMapper"));
assertTrue(TestUtils.getPropertyValue(this.unitChannel, "extractPayload", Boolean.class));
assertThat(TestUtils.getPropertyValue(this.unitChannel, "defaultDeliveryMode"))
.isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(TestUtils.getPropertyValue(this.unitChannel, "inboundHeaderMapper")).isSameAs(this.mapperIn);
assertThat(TestUtils.getPropertyValue(this.unitChannel, "outboundHeaderMapper")).isSameAs(this.mapperOut);
assertThat(TestUtils.getPropertyValue(this.unitChannel, "extractPayload", Boolean.class)).isTrue();
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-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.amqp.inbound;
import static org.hamcrest.Matchers.equalTo;
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.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -126,16 +122,16 @@ public class AmqpMessageSourceIntegrationTests {
template.convertAndSend(DSL_QUEUE, "bar");
template.convertAndSend(INTERCEPT_QUEUE, "baz");
template.convertAndSend(NOAUTOACK_QUEUE, "qux");
assertTrue(this.config.latch.await(10, TimeUnit.SECONDS));
assertThat(this.config.received, equalTo("foo"));
assertThat(this.config.latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.received).isEqualTo("foo");
Message dead = template.receive(DLQ, 10_000);
assertNotNull(dead);
assertThat(this.config.fromDsl, equalTo("bar"));
assertThat(this.config.fromInterceptedSource, equalTo("BAZ"));
assertNull(template.receive(NOAUTOACK_QUEUE));
assertThat(this.config.requeueLatch.getCount(), equalTo(1L));
assertThat(dead).isNotNull();
assertThat(this.config.fromDsl).isEqualTo("bar");
assertThat(this.config.fromInterceptedSource).isEqualTo("BAZ");
assertThat(template.receive(NOAUTOACK_QUEUE)).isNull();
assertThat(this.config.requeueLatch.getCount()).isEqualTo(1L);
this.config.callback.acknowledge(Status.REQUEUE);
assertTrue(this.config.requeueLatch.await(10, TimeUnit.SECONDS));
assertThat(this.config.requeueLatch.await(10, TimeUnit.SECONDS)).isTrue();
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-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.amqp.inbound;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.willReturn;
@@ -70,9 +68,9 @@ public class AmqpMessageSourceTests {
AmqpMessageSource source = new AmqpMessageSource(ccf, "foo");
source.setRawMessageHeader(true);
Message<?> received = source.receive();
assertThat(received.getHeaders().get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE),
instanceOf(org.springframework.amqp.core.Message.class));
assertThat(received.getHeaders().get(AmqpHeaders.CONSUMER_QUEUE), equalTo("foo"));
assertThat(received.getHeaders().get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE))
.isInstanceOf(org.springframework.amqp.core.Message.class);
assertThat(received.getHeaders().get(AmqpHeaders.CONSUMER_QUEUE)).isEqualTo("foo");
// make sure channel is not cached
org.springframework.amqp.rabbit.connection.Connection conn = ccf.createConnection();
Channel notCached = conn.createChannel(false); // should not have been "closed"

View File

@@ -17,18 +17,6 @@
package org.springframework.integration.amqp.inbound;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
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.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
@@ -125,10 +113,10 @@ public class InboundEndpointTests {
listener.onMessage(amqpMessage, rabbitChannel);
Message<?> result = channel.receive(1000);
assertEquals(payload, result.getPayload());
assertThat(result.getPayload()).isEqualTo(payload);
assertSame(rabbitChannel, result.getHeaders().get(AmqpHeaders.CHANNEL));
assertEquals(123L, result.getHeaders().get(AmqpHeaders.DELIVERY_TAG));
assertThat(result.getHeaders().get(AmqpHeaders.CHANNEL)).isSameAs(rabbitChannel);
assertThat(result.getHeaders().get(AmqpHeaders.DELIVERY_TAG)).isEqualTo(123L);
}
@Test
@@ -161,7 +149,7 @@ public class InboundEndpointTests {
Message<?> result = new JsonToObjectTransformer().transform(receive);
assertEquals(payload, result.getPayload());
assertThat(result.getPayload()).isEqualTo(payload);
}
@Test
@@ -179,8 +167,8 @@ public class InboundEndpointTests {
final Channel rabbitChannel = mock(Channel.class);
channel.subscribe(new MessageTransformingHandler(message -> {
assertSame(rabbitChannel, message.getHeaders().get(AmqpHeaders.CHANNEL));
assertEquals(123L, message.getHeaders().get(AmqpHeaders.DELIVERY_TAG));
assertThat(message.getHeaders().get(AmqpHeaders.CHANNEL)).isSameAs(rabbitChannel);
assertThat(message.getHeaders().get(AmqpHeaders.DELIVERY_TAG)).isEqualTo(123L);
return MessageBuilder.fromMessage(message)
.setHeader(JsonHeaders.TYPE_ID, "foo")
.setHeader(JsonHeaders.CONTENT_TYPE_ID, "bar")
@@ -197,13 +185,13 @@ public class InboundEndpointTests {
org.springframework.amqp.core.Message message =
invocation.getArgument(2);
Map<String, Object> headers = message.getMessageProperties().getHeaders();
assertTrue(headers.containsKey(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertNotEquals("foo", headers.get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertFalse(headers.containsKey(JsonHeaders.CONTENT_TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertFalse(headers.containsKey(JsonHeaders.KEY_TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertFalse(headers.containsKey(JsonHeaders.TYPE_ID));
assertFalse(headers.containsKey(JsonHeaders.KEY_TYPE_ID));
assertFalse(headers.containsKey(JsonHeaders.CONTENT_TYPE_ID));
assertThat(headers.containsKey(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, ""))).isTrue();
assertThat(headers.get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, ""))).isNotEqualTo("foo");
assertThat(headers.containsKey(JsonHeaders.CONTENT_TYPE_ID.replaceFirst(JsonHeaders.PREFIX, ""))).isFalse();
assertThat(headers.containsKey(JsonHeaders.KEY_TYPE_ID.replaceFirst(JsonHeaders.PREFIX, ""))).isFalse();
assertThat(headers.containsKey(JsonHeaders.TYPE_ID)).isFalse();
assertThat(headers.containsKey(JsonHeaders.KEY_TYPE_ID)).isFalse();
assertThat(headers.containsKey(JsonHeaders.CONTENT_TYPE_ID)).isFalse();
sendLatch.countDown();
return null;
}).when(rabbitTemplate)
@@ -227,7 +215,7 @@ public class InboundEndpointTests {
ChannelAwareMessageListener listener = (ChannelAwareMessageListener) container.getMessageListener();
listener.onMessage(amqpMessage, rabbitChannel);
assertTrue(sendLatch.await(10, TimeUnit.SECONDS));
assertThat(sendLatch.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
@@ -349,15 +337,15 @@ public class InboundEndpointTests {
listener.onMessage(org.springframework.amqp.core.MessageBuilder.withBody("foo".getBytes())
.andProperties(new MessageProperties()).build(), null);
Message<?> errorMessage = errors.receive(0);
assertNotNull(errorMessage);
assertThat(errorMessage.getPayload(), instanceOf(MessagingException.class));
assertThat(errorMessage).isNotNull();
assertThat(errorMessage.getPayload()).isInstanceOf(MessagingException.class);
MessagingException payload = (MessagingException) errorMessage.getPayload();
assertThat(payload.getMessage(), containsString("Dispatcher has no"));
assertThat(StaticMessageHeaderAccessor.getDeliveryAttempt(payload.getFailedMessage()).get(), equalTo(3));
assertThat(payload.getMessage()).contains("Dispatcher has no");
assertThat(StaticMessageHeaderAccessor.getDeliveryAttempt(payload.getFailedMessage()).get()).isEqualTo(3);
org.springframework.amqp.core.Message amqpMessage = errorMessage.getHeaders()
.get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, org.springframework.amqp.core.Message.class);
assertThat(amqpMessage, notNullValue());
assertNull(errors.receive(0));
assertThat(amqpMessage).isNotNull();
assertThat(errors.receive(0)).isNull();
}
@Test
@@ -376,15 +364,15 @@ public class InboundEndpointTests {
listener.onMessage(org.springframework.amqp.core.MessageBuilder.withBody("foo".getBytes())
.andProperties(new MessageProperties()).build(), null);
Message<?> errorMessage = errors.receive(0);
assertNotNull(errorMessage);
assertThat(errorMessage.getPayload(), instanceOf(MessagingException.class));
assertThat(errorMessage).isNotNull();
assertThat(errorMessage.getPayload()).isInstanceOf(MessagingException.class);
MessagingException payload = (MessagingException) errorMessage.getPayload();
assertThat(payload.getMessage(), containsString("Dispatcher has no"));
assertThat(StaticMessageHeaderAccessor.getDeliveryAttempt(payload.getFailedMessage()).get(), equalTo(3));
assertThat(payload.getMessage()).contains("Dispatcher has no");
assertThat(StaticMessageHeaderAccessor.getDeliveryAttempt(payload.getFailedMessage()).get()).isEqualTo(3);
org.springframework.amqp.core.Message amqpMessage = errorMessage.getHeaders()
.get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, org.springframework.amqp.core.Message.class);
assertThat(amqpMessage, notNullValue());
assertNull(errors.receive(0));
assertThat(amqpMessage).isNotNull();
assertThat(errors.receive(0)).isNull();
}
public static class Foo {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 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,9 +16,7 @@
package org.springframework.integration.amqp.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Rule;
@@ -89,16 +87,16 @@ public class ManualAckTests {
adapter.start();
this.template.convertAndSend("Hello, world");
Message<?> out = bar.receive(5000);
assertNotNull(out);
assertEquals(1, out.getPayload());
assertThat(out).isNotNull();
assertThat(out.getPayload()).isEqualTo(1);
out = bar.receive(5000);
assertNotNull(out);
assertEquals(2, out.getPayload());
assertThat(out).isNotNull();
assertThat(out.getPayload()).isEqualTo(2);
out = bar.receive(5000);
assertNotNull(out);
assertEquals(3, out.getPayload());
assertThat(out).isNotNull();
assertThat(out.getPayload()).isEqualTo(3);
out = bar.receive(1000);
assertNull(out);
assertThat(out).isNull();
adapter.stop();
}

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,11 +16,7 @@
package org.springframework.integration.amqp.outbound;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Rule;
import org.junit.Test;
@@ -108,24 +104,24 @@ public class AmqpOutboundEndpointTests {
.build();
this.pcRequestChannel.send(message);
Message<?> ack = this.ackChannel.receive(10000);
assertNotNull(ack);
assertEquals("foo", ack.getPayload());
assertEquals(Boolean.TRUE, ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM));
assertThat(ack).isNotNull();
assertThat(ack.getPayload()).isEqualTo("foo");
assertThat(ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM)).isEqualTo(Boolean.TRUE);
org.springframework.amqp.core.Message received = this.amqpTemplateConfirms.receive(this.queue.getName());
assertEquals("\"hello\"", new String(received.getBody(), "UTF-8"));
assertEquals("application/json", received.getMessageProperties().getContentType());
assertEquals("java.lang.String", received.getMessageProperties().getHeaders()
.get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertThat(new String(received.getBody(), "UTF-8")).isEqualTo("\"hello\"");
assertThat(received.getMessageProperties().getContentType()).isEqualTo("application/json");
assertThat(received.getMessageProperties().getHeaders()
.get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, ""))).isEqualTo("java.lang.String");
// test whole message is correlation
message = MessageBuilder.withPayload("hello")
.build();
this.pcMessageCorrelationRequestChannel.send(message);
ack = ackChannel.receive(10000);
assertNotNull(ack);
assertSame(message.getPayload(), ack.getPayload());
assertEquals(Boolean.TRUE, ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM));
assertThat(ack).isNotNull();
assertThat(ack.getPayload()).isSameAs(message.getPayload());
assertThat(ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM)).isEqualTo(Boolean.TRUE);
while (this.amqpTemplateConfirms.receive(this.queue.getName()) != null) {
// drain
@@ -139,9 +135,9 @@ public class AmqpOutboundEndpointTests {
.build();
this.pcRequestChannelForAdapter.send(message);
Message<?> ack = this.ackChannel.receive(10000);
assertNotNull(ack);
assertEquals("foo", ack.getPayload());
assertEquals(Boolean.TRUE, ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM));
assertThat(ack).isNotNull();
assertThat(ack.getPayload()).isEqualTo("foo");
assertThat(ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM)).isEqualTo(Boolean.TRUE);
}
@Test
@@ -150,8 +146,8 @@ public class AmqpOutboundEndpointTests {
Message<?> message = MessageBuilder.withPayload("hello").build();
this.returnRequestChannel.send(message);
Message<?> returned = returnChannel.receive(10000);
assertNotNull(returned);
assertEquals(message.getPayload(), returned.getPayload());
assertThat(returned).isNotNull();
assertThat(returned.getPayload()).isEqualTo(message.getPayload());
}
@Test
@@ -159,11 +155,11 @@ public class AmqpOutboundEndpointTests {
Message<?> message = MessageBuilder.withPayload("hello").build();
this.returnRequestChannel.send(message);
Message<?> returned = returnChannel.receive(10000);
assertNotNull(returned);
assertThat(returned, instanceOf(ErrorMessage.class));
assertThat(returned.getPayload(), instanceOf(ReturnedAmqpMessageException.class));
assertThat(returned).isNotNull();
assertThat(returned).isInstanceOf(ErrorMessage.class);
assertThat(returned.getPayload()).isInstanceOf(ReturnedAmqpMessageException.class);
ReturnedAmqpMessageException payload = (ReturnedAmqpMessageException) returned.getPayload();
assertEquals(message.getPayload(), payload.getFailedMessage().getPayload());
assertThat(payload.getFailedMessage().getPayload()).isEqualTo(message.getPayload());
}
@Test
@@ -178,18 +174,18 @@ public class AmqpOutboundEndpointTests {
.build();
this.ctRequestChannel.send(message);
org.springframework.amqp.core.Message m = receive(template);
assertNotNull(m);
assertEquals("\"hello\"", new String(m.getBody(), "UTF-8"));
assertEquals("application/json", m.getMessageProperties().getContentType());
assertEquals("java.lang.String",
m.getMessageProperties().getHeaders().get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertThat(m).isNotNull();
assertThat(new String(m.getBody(), "UTF-8")).isEqualTo("\"hello\"");
assertThat(m.getMessageProperties().getContentType()).isEqualTo("application/json");
assertThat(m.getMessageProperties().getHeaders().get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")))
.isEqualTo("java.lang.String");
message = MessageBuilder.withPayload("hello")
.build();
this.ctRequestChannel.send(message);
m = receive(template);
assertNotNull(m);
assertEquals("hello", new String(m.getBody(), "UTF-8"));
assertEquals("text/plain", m.getMessageProperties().getContentType());
assertThat(m).isNotNull();
assertThat(new String(m.getBody(), "UTF-8")).isEqualTo("hello");
assertThat(m.getMessageProperties().getContentType()).isEqualTo("text/plain");
while (template.receive() != null) {
// drain
}
@@ -202,7 +198,7 @@ public class AmqpOutboundEndpointTests {
Thread.sleep(100);
message = template.receive();
}
assertNotNull(message);
assertThat(message).isNotNull();
return message;
}

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,11 +16,7 @@
package org.springframework.integration.amqp.outbound;
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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.startsWith;
@@ -153,14 +149,14 @@ public class AsyncAmqpGatewayTests {
gateway.handleMessage(message);
Message<?> ack = ackChannel.receive(10000);
assertNotNull(ack);
assertEquals("foo", ack.getPayload());
assertEquals(true, ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM));
assertThat(ack).isNotNull();
assertThat(ack.getPayload()).isEqualTo("foo");
assertThat(ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM)).isEqualTo(true);
waitForAckBeforeReplying.countDown();
Message<?> received = outputChannel.receive(10000);
assertNotNull(received);
assertEquals("FOO", received.getPayload());
assertThat(received).isNotNull();
assertThat(received.getPayload()).isEqualTo("FOO");
// timeout tests
asyncTemplate.setReceiveTimeout(10);
@@ -169,7 +165,7 @@ public class AsyncAmqpGatewayTests {
// reply timeout with no requiresReply
message = MessageBuilder.withPayload("bar").setErrorChannel(errorChannel).build();
gateway.handleMessage(message);
assertTrue(replyTimeoutLatch.await(10, TimeUnit.SECONDS));
assertThat(replyTimeoutLatch.await(10, TimeUnit.SECONDS)).isTrue();
// reply timeout with requiresReply
gateway.setRequiresReply(true);
@@ -177,10 +173,10 @@ public class AsyncAmqpGatewayTests {
gateway.handleMessage(message);
received = errorChannel.receive(10000);
assertThat(received, instanceOf(ErrorMessage.class));
assertThat(received).isInstanceOf(ErrorMessage.class);
ErrorMessage error = (ErrorMessage) received;
assertThat(error.getPayload(), instanceOf(MessagingException.class));
assertThat(error.getPayload().getCause(), instanceOf(AmqpReplyTimeoutException.class));
assertThat(error.getPayload()).isInstanceOf(MessagingException.class);
assertThat(error.getPayload().getCause()).isInstanceOf(AmqpReplyTimeoutException.class);
asyncTemplate.setReceiveTimeout(30000);
receiver.setMessageListener(messageListener);
@@ -194,20 +190,20 @@ public class AsyncAmqpGatewayTests {
message = MessageBuilder.withPayload("qux").setErrorChannel(errorChannel).build();
gateway.handleMessage(message);
received = errorChannel.receive(10000);
assertThat(received, instanceOf(ErrorMessage.class));
assertThat(received).isInstanceOf(ErrorMessage.class);
error = (ErrorMessage) received;
assertThat(error.getPayload(), instanceOf(MessagingException.class));
assertEquals("QUX", ((MessagingException) error.getPayload()).getFailedMessage().getPayload());
assertThat(error.getPayload()).isInstanceOf(MessagingException.class);
assertThat(((MessagingException) error.getPayload()).getFailedMessage().getPayload()).isEqualTo("QUX");
gateway.setRoutingKey(UUID.randomUUID().toString());
message = MessageBuilder.withPayload("fiz").setErrorChannel(errorChannel).build();
gateway.handleMessage(message);
Message<?> returned = returnChannel.receive(10000);
assertNotNull(returned);
assertThat(returned, instanceOf(ErrorMessage.class));
assertThat(returned.getPayload(), instanceOf(ReturnedAmqpMessageException.class));
assertThat(returned).isNotNull();
assertThat(returned).isInstanceOf(ErrorMessage.class);
assertThat(returned.getPayload()).isInstanceOf(ReturnedAmqpMessageException.class);
ReturnedAmqpMessageException payload = (ReturnedAmqpMessageException) returned.getPayload();
assertEquals("fiz", payload.getFailedMessage().getPayload());
assertThat(payload.getFailedMessage().getPayload()).isEqualTo("fiz");
ackChannel.receive(10000);
ackChannel.purge(null);
@@ -226,12 +222,12 @@ public class AsyncAmqpGatewayTests {
gateway.handleMessage(message);
ack = ackChannel.receive(10000);
assertNotNull(ack);
assertThat(returned, instanceOf(ErrorMessage.class));
assertThat(returned.getPayload(), instanceOf(ReturnedAmqpMessageException.class));
assertThat(ack).isNotNull();
assertThat(returned).isInstanceOf(ErrorMessage.class);
assertThat(returned.getPayload()).isInstanceOf(ReturnedAmqpMessageException.class);
NackedAmqpMessageException nack = (NackedAmqpMessageException) ack.getPayload();
assertEquals("buz", nack.getFailedMessage().getPayload());
assertEquals("nacknack", nack.getNackReason());
assertThat(nack.getFailedMessage().getPayload()).isEqualTo("buz");
assertThat(nack.getNackReason()).isEqualTo("nacknack");
asyncTemplate.stop();
receiver.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,11 +16,7 @@
package org.springframework.integration.amqp.outbound;
import static org.hamcrest.Matchers.equalTo;
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.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -76,19 +72,19 @@ public class OutboundEndpointTests {
endpoint.handleMessage(new GenericMessage<>("foo"));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(amqpTemplate).send(eq("foo"), eq("bar"), captor.capture(), isNull());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42));
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(42);
endpoint.setExpectReply(true);
endpoint.setOutputChannel(new NullChannel());
endpoint.handleMessage(new GenericMessage<>("foo"));
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture(), isNull());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42));
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(42);
endpoint.setDelay(23);
endpoint.setRoutingKey("baz");
endpoint.afterPropertiesSet();
endpoint.handleMessage(new GenericMessage<>("foo"));
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("baz"), captor.capture(), isNull());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(23));
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(23);
}
@Test
@@ -111,7 +107,7 @@ public class OutboundEndpointTests {
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
gateway.handleMessage(new GenericMessage<>("foo"));
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42));
assertThat(captor.getValue().getMessageProperties().getDelay()).isEqualTo(42);
}
@Test
@@ -130,8 +126,8 @@ public class OutboundEndpointTests {
.setHeader(MessageHeaders.CONTENT_TYPE, "bar")
.build();
endpoint.handleMessage(message);
assertNotNull(amqpMessage.get());
assertEquals("bar", amqpMessage.get().getMessageProperties().getContentType());
assertThat(amqpMessage.get()).isNotNull();
assertThat(amqpMessage.get().getMessageProperties().getContentType()).isEqualTo("bar");
}
@Test
@@ -156,9 +152,9 @@ public class OutboundEndpointTests {
.setReplyChannel(new QueueChannel())
.build();
endpoint.handleMessage(message);
assertNotNull(amqpMessage.get());
assertEquals("bar", amqpMessage.get().getMessageProperties().getContentType());
assertNull(amqpMessage.get().getMessageProperties().getHeaders().get(MessageHeaders.REPLY_CHANNEL));
assertThat(amqpMessage.get()).isNotNull();
assertThat(amqpMessage.get().getMessageProperties().getContentType()).isEqualTo("bar");
assertThat(amqpMessage.get().getMessageProperties().getHeaders().get(MessageHeaders.REPLY_CHANNEL)).isNull();
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-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.
@@ -17,7 +17,6 @@
package org.springframework.integration.amqp.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.BDDMockito.willReturn;
@@ -75,8 +74,8 @@ public class BoundRabbitChannelAdviceIntegrationTests {
return i.callRealMethod();
}).given(logger).debug(anyString());
this.gate.send("a,b,c");
assertTrue(this.config.latch.await(10, TimeUnit.SECONDS));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(this.config.latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.received).containsExactly("A", "B", "C");
}

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.
@@ -17,9 +17,7 @@
package org.springframework.integration.amqp.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import java.util.Date;
@@ -103,27 +101,27 @@ public class DefaultAmqpHeaderMapperTests {
fail("Unexpected header in properties.headers: " + headerKey);
}
}
assertEquals("test.appId", amqpProperties.getAppId());
assertEquals("test.clusterId", amqpProperties.getClusterId());
assertEquals("test.contentEncoding", amqpProperties.getContentEncoding());
assertEquals(99L, amqpProperties.getContentLength());
assertEquals("test.contentType", amqpProperties.getContentType());
assertEquals(testCorrelationId, amqpProperties.getCorrelationId());
assertEquals(Integer.valueOf(1234), amqpProperties.getDelay());
assertEquals(MessageDeliveryMode.NON_PERSISTENT, amqpProperties.getDeliveryMode());
assertEquals(1234L, amqpProperties.getDeliveryTag());
assertEquals("test.expiration", amqpProperties.getExpiration());
assertEquals(new Integer(42), amqpProperties.getMessageCount());
assertEquals("test.messageId", amqpProperties.getMessageId());
assertEquals("test.receivedExchange", amqpProperties.getReceivedExchange());
assertEquals("test.receivedRoutingKey", amqpProperties.getReceivedRoutingKey());
assertEquals("test.replyTo", amqpProperties.getReplyTo());
assertEquals(testTimestamp, amqpProperties.getTimestamp());
assertEquals("test.type", amqpProperties.getType());
assertEquals("test.userId", amqpProperties.getUserId());
assertThat(amqpProperties.getAppId()).isEqualTo("test.appId");
assertThat(amqpProperties.getClusterId()).isEqualTo("test.clusterId");
assertThat(amqpProperties.getContentEncoding()).isEqualTo("test.contentEncoding");
assertThat(amqpProperties.getContentLength()).isEqualTo(99L);
assertThat(amqpProperties.getContentType()).isEqualTo("test.contentType");
assertThat(amqpProperties.getCorrelationId()).isEqualTo(testCorrelationId);
assertThat(amqpProperties.getDelay()).isEqualTo(Integer.valueOf(1234));
assertThat(amqpProperties.getDeliveryMode()).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(amqpProperties.getDeliveryTag()).isEqualTo(1234L);
assertThat(amqpProperties.getExpiration()).isEqualTo("test.expiration");
assertThat(amqpProperties.getMessageCount()).isEqualTo(new Integer(42));
assertThat(amqpProperties.getMessageId()).isEqualTo("test.messageId");
assertThat(amqpProperties.getReceivedExchange()).isEqualTo("test.receivedExchange");
assertThat(amqpProperties.getReceivedRoutingKey()).isEqualTo("test.receivedRoutingKey");
assertThat(amqpProperties.getReplyTo()).isEqualTo("test.replyTo");
assertThat(amqpProperties.getTimestamp()).isEqualTo(testTimestamp);
assertThat(amqpProperties.getType()).isEqualTo("test.type");
assertThat(amqpProperties.getUserId()).isEqualTo("test.userId");
assertNull(amqpProperties.getHeaders().get(MessageHeaders.ERROR_CHANNEL));
assertNull(amqpProperties.getHeaders().get(MessageHeaders.REPLY_CHANNEL));
assertThat(amqpProperties.getHeaders().get(MessageHeaders.ERROR_CHANNEL)).isNull();
assertThat(amqpProperties.getHeaders().get(MessageHeaders.REPLY_CHANNEL)).isNull();
}
@Test
@@ -138,14 +136,14 @@ public class DefaultAmqpHeaderMapperTests {
MessageProperties amqpProperties = new MessageProperties();
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertEquals("text/html", amqpProperties.getContentType());
assertThat(amqpProperties.getContentType()).isEqualTo("text/html");
headerMap.put(AmqpHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
integrationHeaders = new MessageHeaders(headerMap);
amqpProperties = new MessageProperties();
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertEquals(MimeTypeUtils.APPLICATION_JSON_VALUE, amqpProperties.getContentType());
assertThat(amqpProperties.getContentType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON_VALUE);
}
@Test
@@ -160,7 +158,7 @@ public class DefaultAmqpHeaderMapperTests {
MessageProperties amqpProperties = new MessageProperties();
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertEquals("text/html", amqpProperties.getContentType());
assertThat(amqpProperties.getContentType()).isEqualTo("text/html");
}
@@ -193,26 +191,26 @@ public class DefaultAmqpHeaderMapperTests {
amqpProperties.setHeader(AmqpHeaders.SPRING_REPLY_CORRELATION, "test.correlation");
amqpProperties.setHeader(AmqpHeaders.SPRING_REPLY_TO_STACK, "test.replyTo2");
Map<String, Object> headerMap = headerMapper.toHeadersFromReply(amqpProperties);
assertEquals("test.appId", headerMap.get(AmqpHeaders.APP_ID));
assertEquals("test.clusterId", headerMap.get(AmqpHeaders.CLUSTER_ID));
assertEquals("test.contentEncoding", headerMap.get(AmqpHeaders.CONTENT_ENCODING));
assertEquals(99L, headerMap.get(AmqpHeaders.CONTENT_LENGTH));
assertEquals("test.contentType", headerMap.get(AmqpHeaders.CONTENT_TYPE));
assertEquals(testCorrelationId, headerMap.get(AmqpHeaders.CORRELATION_ID));
assertEquals(MessageDeliveryMode.NON_PERSISTENT, headerMap.get(AmqpHeaders.RECEIVED_DELIVERY_MODE));
assertEquals(1234L, headerMap.get(AmqpHeaders.DELIVERY_TAG));
assertEquals("test.expiration", headerMap.get(AmqpHeaders.EXPIRATION));
assertEquals(42, headerMap.get(AmqpHeaders.MESSAGE_COUNT));
assertEquals("test.messageId", headerMap.get(AmqpHeaders.MESSAGE_ID));
assertEquals(4567, headerMap.get(AmqpHeaders.RECEIVED_DELAY));
assertEquals("test.receivedExchange", headerMap.get(AmqpHeaders.RECEIVED_EXCHANGE));
assertEquals("test.receivedRoutingKey", headerMap.get(AmqpHeaders.RECEIVED_ROUTING_KEY));
assertEquals("test.replyTo", headerMap.get(AmqpHeaders.REPLY_TO));
assertEquals(testTimestamp, headerMap.get(AmqpHeaders.TIMESTAMP));
assertEquals("test.type", headerMap.get(AmqpHeaders.TYPE));
assertEquals("test.userId", headerMap.get(AmqpHeaders.RECEIVED_USER_ID));
assertEquals("test.correlation", headerMap.get(AmqpHeaders.SPRING_REPLY_CORRELATION));
assertEquals("test.replyTo2", headerMap.get(AmqpHeaders.SPRING_REPLY_TO_STACK));
assertThat(headerMap.get(AmqpHeaders.APP_ID)).isEqualTo("test.appId");
assertThat(headerMap.get(AmqpHeaders.CLUSTER_ID)).isEqualTo("test.clusterId");
assertThat(headerMap.get(AmqpHeaders.CONTENT_ENCODING)).isEqualTo("test.contentEncoding");
assertThat(headerMap.get(AmqpHeaders.CONTENT_LENGTH)).isEqualTo(99L);
assertThat(headerMap.get(AmqpHeaders.CONTENT_TYPE)).isEqualTo("test.contentType");
assertThat(headerMap.get(AmqpHeaders.CORRELATION_ID)).isEqualTo(testCorrelationId);
assertThat(headerMap.get(AmqpHeaders.RECEIVED_DELIVERY_MODE)).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(headerMap.get(AmqpHeaders.DELIVERY_TAG)).isEqualTo(1234L);
assertThat(headerMap.get(AmqpHeaders.EXPIRATION)).isEqualTo("test.expiration");
assertThat(headerMap.get(AmqpHeaders.MESSAGE_COUNT)).isEqualTo(42);
assertThat(headerMap.get(AmqpHeaders.MESSAGE_ID)).isEqualTo("test.messageId");
assertThat(headerMap.get(AmqpHeaders.RECEIVED_DELAY)).isEqualTo(4567);
assertThat(headerMap.get(AmqpHeaders.RECEIVED_EXCHANGE)).isEqualTo("test.receivedExchange");
assertThat(headerMap.get(AmqpHeaders.RECEIVED_ROUTING_KEY)).isEqualTo("test.receivedRoutingKey");
assertThat(headerMap.get(AmqpHeaders.REPLY_TO)).isEqualTo("test.replyTo");
assertThat(headerMap.get(AmqpHeaders.TIMESTAMP)).isEqualTo(testTimestamp);
assertThat(headerMap.get(AmqpHeaders.TYPE)).isEqualTo("test.type");
assertThat(headerMap.get(AmqpHeaders.RECEIVED_USER_ID)).isEqualTo("test.userId");
assertThat(headerMap.get(AmqpHeaders.SPRING_REPLY_CORRELATION)).isEqualTo("test.correlation");
assertThat(headerMap.get(AmqpHeaders.SPRING_REPLY_TO_STACK)).isEqualTo("test.replyTo2");
}
@Test
@@ -225,7 +223,7 @@ public class DefaultAmqpHeaderMapperTests {
String testCorrelationId = "foo";
amqpProperties.setCorrelationId(testCorrelationId);
Map<String, Object> headerMap = headerMapper.toHeadersFromReply(amqpProperties);
assertEquals(testCorrelationId, headerMap.get(AmqpHeaders.CORRELATION_ID));
assertThat(headerMap.get(AmqpHeaders.CORRELATION_ID)).isEqualTo(testCorrelationId);
}
@@ -236,8 +234,8 @@ public class DefaultAmqpHeaderMapperTests {
amqpProperties.setConsumerTag("consumerTag");
amqpProperties.setConsumerQueue("consumerQueue");
Map<String, Object> headerMap = headerMapper.toHeadersFromRequest(amqpProperties);
assertEquals("consumerTag", headerMap.get(AmqpHeaders.CONSUMER_TAG));
assertEquals("consumerQueue", headerMap.get(AmqpHeaders.CONSUMER_QUEUE));
assertThat(headerMap.get(AmqpHeaders.CONSUMER_TAG)).isEqualTo("consumerTag");
assertThat(headerMap.get(AmqpHeaders.CONSUMER_QUEUE)).isEqualTo("consumerQueue");
}
@Test
@@ -248,7 +246,7 @@ public class DefaultAmqpHeaderMapperTests {
MessageHeaders integrationHeaders = new MessageHeaders(headerMap);
MessageProperties amqpProperties = new MessageProperties();
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertNull(amqpProperties.getHeaders().get(MessageHeaders.ID));
assertThat(amqpProperties.getHeaders().get(MessageHeaders.ID)).isNull();
}
@Test
@@ -259,7 +257,7 @@ public class DefaultAmqpHeaderMapperTests {
MessageHeaders integrationHeaders = new MessageHeaders(headerMap);
MessageProperties amqpProperties = new MessageProperties();
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertNull(amqpProperties.getHeaders().get(MessageHeaders.TIMESTAMP));
assertThat(amqpProperties.getHeaders().get(MessageHeaders.TIMESTAMP)).isNull();
}
@Test // INT-2090
@@ -272,9 +270,9 @@ public class DefaultAmqpHeaderMapperTests {
headerMap.put("__TypeId__", "java.lang.Integer");
MessageHeaders integrationHeaders = new MessageHeaders(headerMap);
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertEquals("java.lang.String", amqpProperties.getHeaders().get("__TypeId__"));
assertThat(amqpProperties.getHeaders().get("__TypeId__")).isEqualTo("java.lang.String");
Object result = converter.fromMessage(new Message("123".getBytes(), amqpProperties));
assertEquals(String.class, result.getClass());
assertThat(result.getClass()).isEqualTo(String.class);
}
@Test
@@ -285,31 +283,31 @@ public class DefaultAmqpHeaderMapperTests {
amqpProperties.getHeaders().put("foo", "bar");
amqpProperties.getHeaders().put("x-foo", "bar");
Map<String, Object> headers = mapper.toHeadersFromRequest(amqpProperties);
assertNull(headers.get(AmqpHeaders.DELIVERY_MODE));
assertEquals(MessageDeliveryMode.NON_PERSISTENT, headers.get(AmqpHeaders.RECEIVED_DELIVERY_MODE));
assertEquals("bar", headers.get("foo"));
assertEquals("bar", headers.get("x-foo"));
assertThat(headers.get(AmqpHeaders.DELIVERY_MODE)).isNull();
assertThat(headers.get(AmqpHeaders.RECEIVED_DELIVERY_MODE)).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(headers.get("foo")).isEqualTo("bar");
assertThat(headers.get("x-foo")).isEqualTo("bar");
amqpProperties = new MessageProperties();
headers.put(AmqpHeaders.DELIVERY_MODE, MessageDeliveryMode.NON_PERSISTENT);
mapper.fromHeadersToReply(new MessageHeaders(headers), amqpProperties);
assertEquals(MessageDeliveryMode.NON_PERSISTENT, amqpProperties.getDeliveryMode());
assertEquals("bar", amqpProperties.getHeaders().get("foo"));
assertNull(amqpProperties.getHeaders().get("x-foo"));
assertThat(amqpProperties.getDeliveryMode()).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(amqpProperties.getHeaders().get("foo")).isEqualTo("bar");
assertThat(amqpProperties.getHeaders().get("x-foo")).isNull();
mapper = DefaultAmqpHeaderMapper.outboundMapper();
mapper.fromHeadersToRequest(new MessageHeaders(headers), amqpProperties);
assertEquals(MessageDeliveryMode.NON_PERSISTENT, amqpProperties.getDeliveryMode());
assertEquals("bar", amqpProperties.getHeaders().get("foo"));
assertNull(amqpProperties.getHeaders().get("x-foo"));
assertThat(amqpProperties.getDeliveryMode()).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(amqpProperties.getHeaders().get("foo")).isEqualTo("bar");
assertThat(amqpProperties.getHeaders().get("x-foo")).isNull();
amqpProperties.setReceivedDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
amqpProperties.setHeader("x-death", "foo");
headers = mapper.toHeadersFromReply(amqpProperties);
assertEquals(MessageDeliveryMode.NON_PERSISTENT, headers.get(AmqpHeaders.RECEIVED_DELIVERY_MODE));
assertNull(headers.get(AmqpHeaders.DELIVERY_MODE));
assertEquals("bar", headers.get("foo"));
assertEquals("foo", headers.get("x-death"));
assertThat(headers.get(AmqpHeaders.RECEIVED_DELIVERY_MODE)).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
assertThat(headers.get(AmqpHeaders.DELIVERY_MODE)).isNull();
assertThat(headers.get("foo")).isEqualTo("bar");
assertThat(headers.get("x-death")).isEqualTo("foo");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 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.amqp.support;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.After;
import org.junit.Before;
@@ -77,7 +76,7 @@ public class JsonConverterCompatibilityTests {
});
Object received = this.rabbitTemplate.receiveAndConvert(JSON_TESTQ);
assertThat(received, instanceOf(Foo.class));
assertThat(received).isInstanceOf(Foo.class);
}
public static class Foo {

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,9 +16,8 @@
package org.springframework.integration.amqp.support;
import static org.hamcrest.CoreMatchers.equalTo;
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;
@@ -48,23 +47,23 @@ public class MappingUtilsTests {
boolean headersMappedLast = false;
org.springframework.amqp.core.Message mapped = MappingUtils.mapMessage(requestMessage, converter, headerMapper,
defaultDeliveryMode, headersMappedLast);
assertThat(mapped.getMessageProperties().getContentType(), equalTo("text/plain"));
assertThat(mapped.getMessageProperties().getContentType()).isEqualTo("text/plain");
headersMappedLast = true;
mapped = MappingUtils.mapMessage(requestMessage, converter, headerMapper,
defaultDeliveryMode, headersMappedLast);
assertThat(mapped.getMessageProperties().getContentType(), equalTo("my/ct"));
assertThat(mapped.getMessageProperties().getContentType()).isEqualTo("my/ct");
ContentTypeDelegatingMessageConverter ctdConverter = new ContentTypeDelegatingMessageConverter();
ctdConverter.addDelegate("my/ct", converter);
mapped = MappingUtils.mapMessage(requestMessage, ctdConverter, headerMapper,
defaultDeliveryMode, headersMappedLast);
assertThat(mapped.getMessageProperties().getContentType(), equalTo("my/ct"));
assertThat(mapped.getMessageProperties().getContentType()).isEqualTo("my/ct");
headersMappedLast = false;
mapped = MappingUtils.mapMessage(requestMessage, ctdConverter, headerMapper,
defaultDeliveryMode, headersMappedLast);
assertThat(mapped.getMessageProperties().getContentType(), equalTo("text/plain"));
assertThat(mapped.getMessageProperties().getContentType()).isEqualTo("text/plain");
headersMappedLast = true;
requestMessage = MessageBuilder.withPayload("foo")
@@ -76,8 +75,8 @@ public class MappingUtilsTests {
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException e) {
assertThat(e.getMessage(),
equalTo("contentType header must be a MimeType or String, found: java.lang.Integer"));
assertThat(e.getMessage())
.isEqualTo("contentType header must be a MimeType or String, found: java.lang.Integer");
}
}

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.aggregator;
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 static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -139,15 +135,15 @@ public class AbstractCorrelatingMessageHandlerTests {
.build();
handler.handleMessage(message);
assertTrue(waitReapCompleteLatch.await(20, TimeUnit.SECONDS));
assertThat(waitReapCompleteLatch.await(20, TimeUnit.SECONDS)).isTrue();
// Before INT-2751 we got bar + bar + qux
assertEquals(2, outputMessages.size()); // bar + qux
assertThat(outputMessages.size()).isEqualTo(2); // bar + qux
// normal release
assertEquals(2, ((MessageGroup) outputMessages.get(0).getPayload()).size()); // 'bar'
assertThat(((MessageGroup) outputMessages.get(0).getPayload()).size()).isEqualTo(2); // 'bar'
// reaper release
assertEquals(1, ((MessageGroup) outputMessages.get(1).getPayload()).size()); // 'qux'
assertThat(((MessageGroup) outputMessages.get(1).getPayload()).size()).isEqualTo(1); // 'qux'
assertNull(discards.receive(0));
assertThat(discards.receive(0)).isNull();
exec.shutdownNow();
}
@@ -171,11 +167,13 @@ public class AbstractCorrelatingMessageHandlerTests {
.build();
handler.handleMessage(message);
assertEquals(1, outputMessages.size());
assertThat(outputMessages.size()).isEqualTo(1);
assertEquals(1, TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size());
assertThat(TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size())
.isEqualTo(1);
groupStore.expireMessageGroups(0);
assertEquals(0, TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size());
assertThat(TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size())
.isEqualTo(0);
}
@Test // INT-2833
@@ -200,11 +198,13 @@ public class AbstractCorrelatingMessageHandlerTests {
handler.setMinimumTimeoutForEmptyGroups(10_000);
assertEquals(1, outputMessages.size());
assertThat(outputMessages.size()).isEqualTo(1);
assertEquals(1, TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size());
assertThat(TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size())
.isEqualTo(1);
groupStore.expireMessageGroups(0);
assertEquals(1, TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size());
assertThat(TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size())
.isEqualTo(1);
handler.setMinimumTimeoutForEmptyGroups(10);
@@ -220,8 +220,9 @@ public class AbstractCorrelatingMessageHandlerTests {
}
}
assertTrue(n < 200);
assertEquals(0, TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size());
assertThat(n < 200).isTrue();
assertThat(TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size())
.isEqualTo(0);
}
@Test
@@ -245,9 +246,9 @@ public class AbstractCorrelatingMessageHandlerTests {
new DirectFieldAccessor(group).setPropertyValue("lastModified", groupNow.getLastModified());
forceComplete.invoke(handler, group);
Message<?> message = outputChannel.receive(0);
assertNotNull(message);
assertThat(message).isNotNull();
Collection<?> payload = (Collection<?>) message.getPayload();
assertEquals(1, payload.size());
assertThat(payload.size()).isEqualTo(1);
}
@Test /* INT-3216 */
@@ -267,10 +268,10 @@ public class AbstractCorrelatingMessageHandlerTests {
forceComplete.setAccessible(true);
MessageGroup group = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class)
.get("foo");
assertTrue(group.isComplete());
assertThat(group.isComplete()).isTrue();
forceComplete.invoke(handler, group);
verify(mgs, never()).getMessageGroup("foo");
assertNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNull();
}
/*
@@ -294,12 +295,12 @@ public class AbstractCorrelatingMessageHandlerTests {
forceComplete.setAccessible(true);
MessageGroup groupInStore = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class)
.get("foo");
assertTrue(groupInStore.isComplete());
assertFalse(group.isComplete());
assertThat(groupInStore.isComplete()).isTrue();
assertThat(group.isComplete()).isFalse();
new DirectFieldAccessor(group).setPropertyValue("lastModified", groupInStore.getLastModified());
forceComplete.invoke(handler, group);
verify(mgs).getMessageGroup("foo");
assertNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNull();
}
/*
@@ -322,14 +323,14 @@ public class AbstractCorrelatingMessageHandlerTests {
forceComplete.setAccessible(true);
MessageGroup groupInStore = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class)
.get("foo");
assertFalse(groupInStore.isComplete());
assertFalse(group.isComplete());
assertThat(groupInStore.isComplete()).isFalse();
assertThat(group.isComplete()).isFalse();
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(group);
directFieldAccessor.setPropertyValue("lastModified", groupInStore.getLastModified());
directFieldAccessor.setPropertyValue("timestamp", groupInStore.getTimestamp() - 1);
forceComplete.invoke(handler, group);
verify(mgs).getMessageGroup("foo");
assertNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNull();
}
@Test
@@ -373,13 +374,13 @@ public class AbstractCorrelatingMessageHandlerTests {
/* Previously lock for the groupId hasn't been unlocked from the 'forceComplete', because it wasn't
reachable in case of exception from the BasicMessageGroupStore.removeMessageGroup
*/
assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
assertThat(executorService.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
/* Since MessageGroup had been marked as 'complete', but hasn't been removed because of exception,
the second message is discarded
*/
Message<?> receive = discardChannel.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
}
@Test
@@ -409,9 +410,10 @@ public class AbstractCorrelatingMessageHandlerTests {
.build();
handler.handleMessage(message);
assertEquals(1, outputMessages.size());
assertThat(outputMessages.size()).isEqualTo(1);
assertEquals(1, TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size());
assertThat(TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size())
.isEqualTo(1);
Thread.sleep(100);
@@ -422,8 +424,9 @@ public class AbstractCorrelatingMessageHandlerTests {
Thread.sleep(50);
}
assertTrue(n < 200);
assertEquals(0, TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size());
assertThat(n < 200).isTrue();
assertThat(TestUtils.getPropertyValue(handler, "messageStore.groupIdToMessageGroup", Map.class).size())
.isEqualTo(0);
}
@Test
@@ -449,8 +452,8 @@ public class AbstractCorrelatingMessageHandlerTests {
groupStore.expireMessageGroups(0);
assertEquals(2, handler1DiscardChannel.getQueueSize());
assertEquals(1, handler2DiscardChannel.getQueueSize());
assertThat(handler1DiscardChannel.getQueueSize()).isEqualTo(2);
assertThat(handler2DiscardChannel.getQueueSize()).isEqualTo(1);
}
@Test
@@ -473,12 +476,12 @@ public class AbstractCorrelatingMessageHandlerTests {
Message<?> receive = outputChannel.receive(10_000);
assertNotNull(receive);
assertThat(receive).isNotNull();
assertEquals(2, receive.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID));
assertEquals(2, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertEquals(2, receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE));
assertTrue(receive.getHeaders().containsKey(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS));
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID)).isEqualTo(2);
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).isEqualTo(2);
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(2);
assertThat(receive.getHeaders().containsKey(IntegrationMessageHeaderAccessor.SEQUENCE_DETAILS)).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,10 +16,7 @@
package org.springframework.integration.aggregator;
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.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.Arrays;
@@ -133,11 +130,11 @@ public class AggregatingMessageGroupProcessorHeaderTests {
List<Message<?>> messages = Arrays.asList(message1, message2);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result).isNotNull();
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertNull(resultMessage.getHeaders().get("k1"));
assertNull(resultMessage.getHeaders().get("k2"));
assertThat(resultMessage.getHeaders().get("k1")).isNull();
assertThat(resultMessage.getHeaders().get("k2")).isNull();
headers1 = new HashMap<>();
headers1.put("k1", "foo");
@@ -156,8 +153,8 @@ public class AggregatingMessageGroupProcessorHeaderTests {
group = new SimpleMessageGroup(messages, 1);
result = processor.processMessageGroup(group);
resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertNull(resultMessage.getHeaders().get("k1"));
assertNull(resultMessage.getHeaders().get("k2"));
assertThat(resultMessage.getHeaders().get("k1")).isNull();
assertThat(resultMessage.getHeaders().get("k2")).isNull();
}
@@ -169,11 +166,11 @@ public class AggregatingMessageGroupProcessorHeaderTests {
List<Message<?>> messages = Collections.singletonList(message);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result).isNotNull();
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertEquals("value1", resultMessage.getHeaders().get("k1"));
assertEquals(2, resultMessage.getHeaders().get("k2"));
assertThat(resultMessage.getHeaders().get("k1")).isEqualTo("value1");
assertThat(resultMessage.getHeaders().get("k2")).isEqualTo(2);
}
private void twoMessagesWithoutConflicts(MessageGroupProcessor processor) {
@@ -185,11 +182,11 @@ public class AggregatingMessageGroupProcessorHeaderTests {
List<Message<?>> messages = Arrays.asList(message1, message2);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result).isNotNull();
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertEquals("value1", resultMessage.getHeaders().get("k1"));
assertEquals(2, resultMessage.getHeaders().get("k2"));
assertThat(resultMessage.getHeaders().get("k1")).isEqualTo("value1");
assertThat(resultMessage.getHeaders().get("k2")).isEqualTo(2);
}
private void twoMessagesWithConflicts(MessageGroupProcessor processor) {
@@ -204,11 +201,11 @@ public class AggregatingMessageGroupProcessorHeaderTests {
List<Message<?>> messages = Arrays.asList(message1, message2);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result).isNotNull();
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertNull(resultMessage.getHeaders().get("k1"));
assertEquals(123, resultMessage.getHeaders().get("k2"));
assertThat(resultMessage.getHeaders().get("k1")).isNull();
assertThat(resultMessage.getHeaders().get("k2")).isEqualTo(123);
}
private void missingValuesDoNotConflict(MessageGroupProcessor processor) {
@@ -235,17 +232,17 @@ public class AggregatingMessageGroupProcessorHeaderTests {
List<Message<?>> messages = Arrays.asList(message1, message2, message3);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result).isNotNull();
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertEquals("value1", resultMessage.getHeaders().get("only1"));
assertEquals("value2", resultMessage.getHeaders().get("only2"));
assertEquals("value3", resultMessage.getHeaders().get("only3"));
assertEquals("foo", resultMessage.getHeaders().get("commonTo1And2"));
assertEquals("bar", resultMessage.getHeaders().get("commonTo2And3"));
assertEquals(123, resultMessage.getHeaders().get("commonToAll"));
assertNull(resultMessage.getHeaders().get("conflictBetween1And2"));
assertNull(resultMessage.getHeaders().get("conflictBetween2And3"));
assertThat(resultMessage.getHeaders().get("only1")).isEqualTo("value1");
assertThat(resultMessage.getHeaders().get("only2")).isEqualTo("value2");
assertThat(resultMessage.getHeaders().get("only3")).isEqualTo("value3");
assertThat(resultMessage.getHeaders().get("commonTo1And2")).isEqualTo("foo");
assertThat(resultMessage.getHeaders().get("commonTo2And3")).isEqualTo("bar");
assertThat(resultMessage.getHeaders().get("commonToAll")).isEqualTo(123);
assertThat(resultMessage.getHeaders().get("conflictBetween1And2")).isNull();
assertThat(resultMessage.getHeaders().get("conflictBetween2And3")).isNull();
}
private void multipleValuesConflict(MessageGroupProcessor processor) {
@@ -264,11 +261,11 @@ public class AggregatingMessageGroupProcessorHeaderTests {
List<Message<?>> messages = Arrays.asList(message1, message2, message3);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result).isNotNull();
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertEquals("valueForAll", resultMessage.getHeaders().get("common"));
assertNull(resultMessage.getHeaders().get("conflict"));
assertThat(resultMessage.getHeaders().get("common")).isEqualTo("valueForAll");
assertThat(resultMessage.getHeaders().get("conflict")).isNull();
}
private static Message<?> correlatedMessage(Object correlationId, Integer sequenceSize,

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.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.lessThan;
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.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
@@ -132,8 +124,8 @@ public class AggregatorTests {
" (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
assertNotNull(result);
assertEquals(60000, result.size());
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(60000);
}
@Test
@@ -181,9 +173,9 @@ public class AggregatorTests {
" (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
assertNotNull(result);
assertEquals(120000, result.size());
assertThat(stopwatch.getTotalTimeSeconds(), lessThan(60.0)); // actually < 2.0, was many minutes
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(120000);
assertThat(stopwatch.getTotalTimeSeconds()).isLessThan(60.0); // actually < 2.0, was many minutes
}
@Test
@@ -251,8 +243,8 @@ public class AggregatorTests {
" (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
assertNotNull(result);
assertEquals(60000, result.size());
assertThat(result).isNotNull();
assertThat(result.size()).isEqualTo(60000);
}
@Test
@@ -272,8 +264,8 @@ public class AggregatorTests {
this.aggregator.handleMessage(message3);
Message<?> reply = replyChannel.receive(10000);
assertNotNull(reply);
assertEquals(reply.getPayload(), 105);
assertThat(reply).isNotNull();
assertThat(105).isEqualTo(reply.getPayload());
}
@Test
@@ -294,8 +286,8 @@ public class AggregatorTests {
this.aggregator.handleMessage(message3);
Message<?> reply = replyChannel.receive(10000);
assertNotNull(reply);
assertEquals(reply.getPayload(), 105);
assertThat(reply).isNotNull();
assertThat(105).isEqualTo(reply.getPayload());
}
@Test
@@ -311,15 +303,15 @@ public class AggregatorTests {
this.aggregator.handleMessage(message);
this.store.expireMessageGroups(-10000);
Message<?> reply = replyChannel.receive(0);
assertNull("No message should have been sent normally", reply);
assertThat(reply).as("No message should have been sent normally").isNull();
Message<?> discardedMessage = discardChannel.receive(1000);
assertNotNull("A message should have been discarded", discardedMessage);
assertEquals(message, discardedMessage);
assertEquals(1, expiryEvents.size());
assertSame(this.aggregator, expiryEvents.get(0).getSource());
assertEquals("ABC", this.expiryEvents.get(0).getGroupId());
assertEquals(1, this.expiryEvents.get(0).getMessageCount());
assertTrue(this.expiryEvents.get(0).isDiscarded());
assertThat(discardedMessage).as("A message should have been discarded").isNotNull();
assertThat(discardedMessage).isEqualTo(message);
assertThat(expiryEvents.size()).isEqualTo(1);
assertThat(expiryEvents.get(0).getSource()).isSameAs(this.aggregator);
assertThat(this.expiryEvents.get(0).getGroupId()).isEqualTo("ABC");
assertThat(this.expiryEvents.get(0).getMessageCount()).isEqualTo(1);
assertThat(this.expiryEvents.get(0).isDiscarded()).isTrue();
}
@Test
@@ -336,15 +328,15 @@ public class AggregatorTests {
this.aggregator.handleMessage(message);
this.store.expireMessageGroups(-10000);
Message<?> reply = replyChannel.receive(0);
assertNull("No message should have been sent normally", reply);
assertThat(reply).as("No message should have been sent normally").isNull();
Message<?> discardedMessage = discardChannel.receive(1000);
assertNotNull("A message should have been discarded", discardedMessage);
assertEquals(message, discardedMessage);
assertEquals(1, expiryEvents.size());
assertSame(this.aggregator, expiryEvents.get(0).getSource());
assertEquals("ABC", this.expiryEvents.get(0).getGroupId());
assertEquals(1, this.expiryEvents.get(0).getMessageCount());
assertTrue(this.expiryEvents.get(0).isDiscarded());
assertThat(discardedMessage).as("A message should have been discarded").isNotNull();
assertThat(discardedMessage).isEqualTo(message);
assertThat(expiryEvents.size()).isEqualTo(1);
assertThat(expiryEvents.get(0).getSource()).isSameAs(this.aggregator);
assertThat(this.expiryEvents.get(0).getGroupId()).isEqualTo("ABC");
assertThat(this.expiryEvents.get(0).getMessageCount()).isEqualTo(1);
assertThat(this.expiryEvents.get(0).isDiscarded()).isTrue();
}
@Test
@@ -357,16 +349,16 @@ public class AggregatorTests {
this.aggregator.handleMessage(message2);
this.store.expireMessageGroups(-10000);
Message<?> reply = replyChannel.receive(1000);
assertNotNull("A reply message should have been received", reply);
assertEquals(15, reply.getPayload());
assertEquals(1, expiryEvents.size());
assertSame(this.aggregator, expiryEvents.get(0).getSource());
assertEquals("ABC", this.expiryEvents.get(0).getGroupId());
assertEquals(2, this.expiryEvents.get(0).getMessageCount());
assertFalse(this.expiryEvents.get(0).isDiscarded());
assertThat(reply).as("A reply message should have been received").isNotNull();
assertThat(reply.getPayload()).isEqualTo(15);
assertThat(expiryEvents.size()).isEqualTo(1);
assertThat(expiryEvents.get(0).getSource()).isSameAs(this.aggregator);
assertThat(this.expiryEvents.get(0).getGroupId()).isEqualTo("ABC");
assertThat(this.expiryEvents.get(0).getMessageCount()).isEqualTo(2);
assertThat(this.expiryEvents.get(0).isDiscarded()).isFalse();
Message<?> message3 = createMessage(5, "ABC", 3, 3, replyChannel, null);
this.aggregator.handleMessage(message3);
assertEquals(1, this.store.getMessageGroup("ABC").size());
assertThat(this.store.getMessageGroup("ABC").size()).isEqualTo(1);
}
@Test
@@ -391,20 +383,20 @@ public class AggregatorTests {
this.aggregator.handleMessage(message2);
this.store.expireMessageGroups(-10000);
Message<?> reply = replyChannel.receive(1000);
assertNotNull("A reply message should have been received", reply);
assertEquals(15, reply.getPayload());
assertEquals(1, expiryEvents.size());
assertSame(this.aggregator, expiryEvents.get(0).getSource());
assertEquals("ABC", this.expiryEvents.get(0).getGroupId());
assertEquals(2, this.expiryEvents.get(0).getMessageCount());
assertFalse(this.expiryEvents.get(0).isDiscarded());
assertEquals(0, this.store.getMessageGroup("ABC").size());
assertThat(reply).as("A reply message should have been received").isNotNull();
assertThat(reply.getPayload()).isEqualTo(15);
assertThat(expiryEvents.size()).isEqualTo(1);
assertThat(expiryEvents.get(0).getSource()).isSameAs(this.aggregator);
assertThat(this.expiryEvents.get(0).getGroupId()).isEqualTo("ABC");
assertThat(this.expiryEvents.get(0).getMessageCount()).isEqualTo(2);
assertThat(this.expiryEvents.get(0).isDiscarded()).isFalse();
assertThat(this.store.getMessageGroup("ABC").size()).isEqualTo(0);
Message<?> message3 = createMessage(5, "ABC", 3, 3, lockCheckingChannel, null);
this.aggregator.handleMessage(message3);
assertEquals(0, this.store.getMessageGroup("ABC").size());
assertThat(this.store.getMessageGroup("ABC").size()).isEqualTo(0);
Message<?> discardedMessage = discardChannel.receive(1000);
assertNotNull("A message should have been discarded", discardedMessage);
assertSame(message3, discardedMessage);
assertThat(discardedMessage).as("A message should have been discarded").isNotNull();
assertThat(discardedMessage).isSameAs(message3);
}
@Test
@@ -430,20 +422,20 @@ public class AggregatorTests {
this.aggregator.handleMessage(message2);
this.store.expireMessageGroups(-10000);
Message<?> reply = replyChannel.receive(1000);
assertNotNull("A reply message should have been received", reply);
assertEquals(15, reply.getPayload());
assertEquals(1, expiryEvents.size());
assertSame(this.aggregator, expiryEvents.get(0).getSource());
assertEquals("ABC", this.expiryEvents.get(0).getGroupId());
assertEquals(2, this.expiryEvents.get(0).getMessageCount());
assertFalse(this.expiryEvents.get(0).isDiscarded());
assertEquals(0, this.store.getMessageGroup("ABC").size());
assertThat(reply).as("A reply message should have been received").isNotNull();
assertThat(reply.getPayload()).isEqualTo(15);
assertThat(expiryEvents.size()).isEqualTo(1);
assertThat(expiryEvents.get(0).getSource()).isSameAs(this.aggregator);
assertThat(this.expiryEvents.get(0).getGroupId()).isEqualTo("ABC");
assertThat(this.expiryEvents.get(0).getMessageCount()).isEqualTo(2);
assertThat(this.expiryEvents.get(0).isDiscarded()).isFalse();
assertThat(this.store.getMessageGroup("ABC").size()).isEqualTo(0);
Message<?> message3 = createMessage(5, "ABC", 3, 3, lockCheckingChannel, null);
this.aggregator.handleMessage(message3);
assertEquals(0, this.store.getMessageGroup("ABC").size());
assertThat(this.store.getMessageGroup("ABC").size()).isEqualTo(0);
Message<?> discardedMessage = discardChannel.receive(1000);
assertNotNull("A message should have been discarded", discardedMessage);
assertSame(message3, discardedMessage);
assertThat(discardedMessage).as("A message should have been discarded").isNotNull();
assertThat(discardedMessage).isSameAs(message3);
}
@Test
@@ -464,12 +456,12 @@ public class AggregatorTests {
aggregator.handleMessage(message2);
@SuppressWarnings("unchecked")
Message<Integer> reply1 = (Message<Integer>) replyChannel1.receive(1000);
assertNotNull(reply1);
assertThat(reply1.getPayload(), is(105));
assertThat(reply1).isNotNull();
assertThat(reply1.getPayload()).isEqualTo(105);
@SuppressWarnings("unchecked")
Message<Integer> reply2 = (Message<Integer>) replyChannel2.receive(1000);
assertNotNull(reply2);
assertThat(reply2.getPayload(), is(2431));
assertThat(reply2).isNotNull();
assertThat(reply2.getPayload()).isEqualTo(2431);
}
@Test
@@ -481,14 +473,14 @@ public class AggregatorTests {
this.aggregator.setDiscardChannel(discardChannel);
this.aggregator.handleMessage(createMessage(1, 1, 1, 1, replyChannel, null));
assertEquals(1, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(1);
this.aggregator.handleMessage(createMessage(3, 2, 1, 1, replyChannel, null));
assertEquals(3, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(3);
this.aggregator.handleMessage(createMessage(4, 3, 1, 1, replyChannel, null));
assertEquals(4, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(4);
// next message with same correllation ID is discarded
this.aggregator.handleMessage(createMessage(2, 1, 1, 1, replyChannel, null));
assertEquals(2, discardChannel.receive(1000).getPayload());
assertThat(discardChannel.receive(1000).getPayload()).isEqualTo(2);
}
@Test
@@ -500,16 +492,16 @@ public class AggregatorTests {
this.aggregator.setDiscardChannel(discardChannel);
this.aggregator.handleMessage(createMessage(1, 1, 1, 1, replyChannel, null));
assertEquals(1, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(1);
this.aggregator.handleMessage(createMessage(2, 2, 1, 1, replyChannel, null));
assertEquals(2, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(2);
this.aggregator.handleMessage(createMessage(3, 3, 1, 1, replyChannel, null));
assertEquals(3, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(3);
this.aggregator.handleMessage(createMessage(4, 4, 1, 1, replyChannel, null));
assertEquals(4, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(4);
this.aggregator.handleMessage(createMessage(5, 1, 1, 1, replyChannel, null));
assertEquals(5, replyChannel.receive(1000).getPayload());
assertNull(discardChannel.receive(0));
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(5);
assertThat(discardChannel.receive(0)).isNull();
}
@Test(expected = MessageHandlingException.class)
@@ -532,8 +524,8 @@ public class AggregatorTests {
this.aggregator.handleMessage(message4);
Message<?> reply = replyChannel.receive(10000);
assertNotNull("A message should be aggregated", reply);
assertThat((reply.getPayload()), is(105));
assertThat(reply).as("A message should be aggregated").isNotNull();
assertThat((reply.getPayload())).isEqualTo(105);
}
@Test
@@ -552,8 +544,8 @@ public class AggregatorTests {
this.aggregator.handleMessage(message2);
Message<?> reply = replyChannel.receive(10000);
assertNotNull("A message should be aggregated", reply);
assertThat((reply.getPayload()), is(105));
assertThat(reply).as("A message should be aggregated").isNotNull();
assertThat((reply.getPayload())).isEqualTo(105);
}
@@ -570,7 +562,7 @@ public class AggregatorTests {
private void checkLock(AbstractCorrelatingMessageHandler handler, String group, boolean expectedHeld) {
ReentrantLock lock = (ReentrantLock) TestUtils.getPropertyValue(handler, "lockRegistry", LockRegistry.class)
.obtain(UUIDConverter.getUUID(group).toString());
assertEquals(expectedHeld, lock.isHeldByCurrentThread());
assertThat(lock.isHeldByCurrentThread()).isEqualTo(expectedHeld);
}
private class MultiplyingProcessor implements MessageGroupProcessor {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-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.aggregator;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -39,7 +32,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -121,19 +113,19 @@ public class BarrierMessageHandlerTests {
Thread.sleep(100);
}
Map<?, ?> inProcess = TestUtils.getPropertyValue(handler, "inProcess", Map.class);
assertEquals(1, inProcess.size());
assertTrue("suspension did not appear in time", n < 100);
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNotNull(dupCorrelation.get());
assertThat(dupCorrelation.get().getMessage(), startsWith("Correlation key (foo) is already in use by"));
assertThat(inProcess.size()).isEqualTo(1);
assertThat(n < 100).as("suspension did not appear in time").isTrue();
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(dupCorrelation.get()).isNotNull();
assertThat(dupCorrelation.get().getMessage()).startsWith("Correlation key (foo) is already in use by");
handler.trigger(MessageBuilder.withPayload("bar").setCorrelationId("foo").build());
Message<?> received = outputChannel.receive(10000);
assertNotNull(received);
assertThat(received).isNotNull();
List<?> result = (List<?>) received.getPayload();
assertEquals("foo", result.get(0));
assertEquals("bar", result.get(1));
assertEquals(0, suspensions.size());
assertEquals(0, inProcess.size());
assertThat(result.get(0)).isEqualTo("foo");
assertThat(result.get(1)).isEqualTo("bar");
assertThat(suspensions.size()).isEqualTo(0);
assertThat(inProcess.size()).isEqualTo(0);
exec.shutdownNow();
}
@@ -151,14 +143,14 @@ public class BarrierMessageHandlerTests {
while (n++ < 100 && suspensions.size() == 0) {
Thread.sleep(100);
}
assertTrue("suspension did not appear in time", n < 100);
assertThat(n < 100).as("suspension did not appear in time").isTrue();
handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
Message<?> received = outputChannel.receive(10000);
assertNotNull(received);
assertThat(received).isNotNull();
List<?> result = (ArrayList<?>) received.getPayload();
assertEquals("foo", result.get(0));
assertEquals("bar", result.get(1));
assertEquals(0, suspensions.size());
assertThat(result.get(0)).isEqualTo("foo");
assertThat(result.get(1)).isEqualTo("bar");
assertThat(suspensions.size()).isEqualTo(0);
exec.shutdownNow();
}
@@ -179,22 +171,21 @@ public class BarrierMessageHandlerTests {
latch.countDown();
});
Map<?, ?> suspensions = TestUtils.getPropertyValue(handler, "suspensions", Map.class);
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("suspension not removed", 0, suspensions.size());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(suspensions.size()).as("suspension not removed").isEqualTo(0);
Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
final Message<String> triggerMessage = MessageBuilder.withPayload("bar").setCorrelationId("foo").build();
handler.trigger(triggerMessage);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger).error(captor.capture());
assertThat(captor.getValue(),
allOf(containsString("Suspending thread timed out or did not arrive within timeout for:"),
containsString("payload=bar")));
assertEquals(0, suspensions.size());
assertThat(captor.getValue()).contains("Suspending thread timed out or did not arrive within timeout for:")
.contains("payload=bar");
assertThat(suspensions.size()).isEqualTo(0);
Message<?> discard = discardChannel.receive(0);
assertSame(discard, triggerMessage);
assertThat(triggerMessage).isSameAs(discard);
handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
assertEquals(0, suspensions.size());
assertThat(suspensions.size()).isEqualTo(0);
exec.shutdownNow();
}
@@ -211,7 +202,7 @@ public class BarrierMessageHandlerTests {
fail("exception expected");
}
catch (Exception e) {
assertThat(e, Matchers.instanceOf(ReplyRequiredException.class));
assertThat(e).isInstanceOf(ReplyRequiredException.class);
}
}
@@ -239,12 +230,12 @@ public class BarrierMessageHandlerTests {
while (n++ < 100 && suspensions.size() == 0) {
Thread.sleep(100);
}
assertTrue("suspension did not appear in time", n < 100);
assertThat(n < 100).as("suspension did not appear in time").isTrue();
Exception exc = new RuntimeException();
handler.trigger(MessageBuilder.withPayload(exc).setCorrelationId("foo").build());
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertSame(exc, exception.get().getCause());
assertEquals(0, suspensions.size());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(exception.get().getCause()).isSameAs(exc);
assertThat(suspensions.size()).isEqualTo(0);
exec.shutdownNow();
}
@@ -255,12 +246,12 @@ public class BarrierMessageHandlerTests {
Message<?> suspending = MessageBuilder.withPayload("foo").setCorrelationId("foo").build();
this.in.send(suspending);
Message<?> out = this.out.receive(10000);
assertNotNull(out);
assertEquals("[foo, bar]", out.getPayload().toString());
assertThat(out).isNotNull();
assertThat(out.getPayload().toString()).isEqualTo("[foo, bar]");
Message<?> publisherMessage = this.publisherChannel.receive(10000);
assertNotNull(publisherMessage);
assertEquals("BAR", publisherMessage.getPayload());
assertThat(publisherMessage).isNotNull();
assertThat(publisherMessage.getPayload()).isEqualTo("BAR");
}
@Configuration

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,7 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
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.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -80,12 +75,12 @@ public class ConcurrentAggregatorTests {
this.taskExecutor.execute(new AggregatorTestTask(this.aggregator,
message3, latch));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(latch.getCount(), is(0L));
assertThat(latch.getCount()).isEqualTo(0L);
Message<?> reply = replyChannel.receive(2000);
assertNotNull(reply);
assertEquals(reply.getPayload(), 105);
assertThat(reply).isNotNull();
assertThat(105).isEqualTo(reply.getPayload());
}
@Test
@@ -106,8 +101,8 @@ public class ConcurrentAggregatorTests {
new AggregatorTestTask(this.aggregator, message2, latch).run();
new AggregatorTestTask(this.aggregator, message3, latch).run();
Message<?> reply = replyChannel.receive(1000);
assertNotNull(reply);
assertEquals("123456789", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("123456789");
}
@Test
@@ -122,16 +117,16 @@ public class ConcurrentAggregatorTests {
message, latch);
this.taskExecutor.execute(task);
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertEquals("Task should have completed within timeout", 0, latch
.getCount());
assertThat(latch
.getCount()).as("Task should have completed within timeout").isEqualTo(0);
Message<?> reply = replyChannel.receive(10);
assertNull("No message should have been sent normally", reply);
assertThat(reply).as("No message should have been sent normally").isNull();
this.store.expireMessageGroups(-10000);
Message<?> discardedMessage = discardChannel.receive(10000);
assertNotNull("A message should have been discarded", discardedMessage);
assertEquals(message, discardedMessage);
assertThat(discardedMessage).as("A message should have been discarded").isNotNull();
assertThat(discardedMessage).isEqualTo(message);
}
@Test
@@ -148,16 +143,15 @@ public class ConcurrentAggregatorTests {
this.taskExecutor.execute(task1);
this.taskExecutor.execute(task2);
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertEquals("handlers should have been invoked within time limit", 0,
latch.getCount());
assertThat(latch.getCount()).as("handlers should have been invoked within time limit").isEqualTo(0);
this.store.expireMessageGroups(-10000);
Message<?> reply = replyChannel.receive(1000);
assertNotNull("A reply message should have been received", reply);
assertEquals(15, reply.getPayload());
assertNull(task1.getException());
assertNull(task2.getException());
assertThat(reply).as("A reply message should have been received").isNotNull();
assertThat(reply.getPayload()).isEqualTo(15);
assertThat(task1.getException()).isNull();
assertThat(task2.getException()).isNull();
}
@Test
@@ -187,16 +181,16 @@ public class ConcurrentAggregatorTests {
this.taskExecutor.execute(new AggregatorTestTask(this.aggregator,
message4, latch));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
@SuppressWarnings("unchecked")
Message<Integer> reply1 = (Message<Integer>) replyChannel1.receive(1000);
assertNotNull(reply1);
assertThat(reply1.getPayload(), is(105));
assertThat(reply1).isNotNull();
assertThat(reply1.getPayload()).isEqualTo(105);
@SuppressWarnings("unchecked")
Message<Integer> reply2 = (Message<Integer>) replyChannel2.receive(1000);
assertNotNull(reply2);
assertThat(reply2.getPayload(), is(2431));
assertThat(reply2).isNotNull();
assertThat(reply2.getPayload()).isEqualTo(2431);
}
@Test
@@ -210,17 +204,17 @@ public class ConcurrentAggregatorTests {
this.aggregator.setDiscardChannel(discardChannel);
this.aggregator.handleMessage(createMessage(1, 1, 1, 1, replyChannel,
null));
assertEquals(1, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(1);
this.aggregator.handleMessage(createMessage(3, 2, 1, 1, replyChannel,
null));
assertEquals(3, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(3);
this.aggregator.handleMessage(createMessage(4, 3, 1, 1, replyChannel,
null));
assertEquals(4, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(4);
// next message with same correlation ID is discarded
this.aggregator.handleMessage(createMessage(2, 1, 1, 1, replyChannel,
null));
assertEquals(2, discardChannel.receive(1000).getPayload());
assertThat(discardChannel.receive(1000).getPayload()).isEqualTo(2);
}
@Test
@@ -234,20 +228,20 @@ public class ConcurrentAggregatorTests {
this.aggregator.setDiscardChannel(discardChannel);
this.aggregator.handleMessage(createMessage(1, 1, 1, 1, replyChannel,
null));
assertEquals(1, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(1);
this.aggregator.handleMessage(createMessage(2, 2, 1, 1, replyChannel,
null));
assertEquals(2, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(2);
this.aggregator.handleMessage(createMessage(3, 3, 1, 1, replyChannel,
null));
assertEquals(3, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(3);
this.aggregator.handleMessage(createMessage(4, 4, 1, 1, replyChannel,
null));
assertEquals(4, replyChannel.receive(1000).getPayload());
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(4);
this.aggregator.handleMessage(createMessage(5, 1, 1, 1, replyChannel,
null));
assertEquals(5, replyChannel.receive(1000).getPayload());
assertNull(discardChannel.receive(0));
assertThat(replyChannel.receive(1000).getPayload()).isEqualTo(5);
assertThat(discardChannel.receive(0)).isNull();
}
@Test(expected = MessageHandlingException.class)
@@ -277,11 +271,11 @@ public class ConcurrentAggregatorTests {
this.taskExecutor.execute(new AggregatorTestTask(this.aggregator,
message4, latch));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
Message<?> reply = replyChannel.receive(10000);
assertNotNull("A message should be aggregated", reply);
assertThat(reply.getPayload(), is(105));
assertThat(reply).as("A message should be aggregated").isNotNull();
assertThat(reply.getPayload()).isEqualTo(105);
}

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,7 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -69,7 +66,7 @@ public class CorrelatingMessageBarrierTests {
public void shouldPassMessage() {
Message<Object> message = testMessage();
barrier.handleMessage(message);
assertThat(barrier.receive(), is(message));
assertThat(barrier.receive()).isEqualTo(message);
}
@Test
@@ -78,10 +75,10 @@ public class CorrelatingMessageBarrierTests {
Message<Object> message2 = testMessage();
barrier.handleMessage(message);
verify(correlationStrategy).getCorrelationKey(message);
assertThat(barrier.receive(), is(notNullValue()));
assertThat(barrier.receive()).isNotNull();
barrier.handleMessage(message2);
assertThat(barrier.receive(), is(notNullValue()));
assertThat(barrier.receive(), is(nullValue()));
assertThat(barrier.receive()).isNotNull();
assertThat(barrier.receive()).isNull();
}
@Test(timeout = 10000)
@@ -103,10 +100,10 @@ public class CorrelatingMessageBarrierTests {
Thread.currentThread().interrupt();
}
assertThat((barrier.receive()), is(notNullValue()));
assertThat((barrier.receive())).isNotNull();
for (int i = 0; i < 199; i++) {
trackingReleaseStrategy.release("foo");
assertThat((barrier.receive()), is(notNullValue()));
assertThat((barrier.receive())).isNotNull();
}
exec.shutdownNow();
}

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,8 @@
package org.springframework.integration.aggregator;
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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doAnswer;
@@ -118,7 +117,7 @@ public class CorrelatingMessageHandlerTests {
fail("Expected MessageHandlingException");
}
catch (MessageHandlingException e) {
assertEquals(0, store.getMessageGroup(correlationKey).size());
assertThat(store.getMessageGroup(correlationKey).size()).isEqualTo(0);
}
verify(correlationStrategy).getCorrelationKey(message1);
@@ -154,9 +153,9 @@ public class CorrelatingMessageHandlerTests {
bothMessagesHandled.countDown();
});
assertTrue(bothMessagesHandled.await(10, TimeUnit.SECONDS));
assertThat(bothMessagesHandled.await(10, TimeUnit.SECONDS)).isTrue();
assertEquals(0, store.expireMessageGroups(10000));
assertThat(store.expireMessageGroups(10000)).isEqualTo(0);
exec.shutdownNow();
}

View File

@@ -16,7 +16,7 @@
package org.springframework.integration.aggregator;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Before;
@@ -47,7 +47,7 @@ public class CorrelationStrategyAdapterTests {
MethodInvokingCorrelationStrategy adapter =
new MethodInvokingCorrelationStrategy(new SimpleMessageCorrelator(), "getKey");
adapter.setBeanFactory(mock(BeanFactory.class));
assertEquals("b", adapter.getCorrelationKey(message));
assertThat(adapter.getCorrelationKey(message)).isEqualTo("b");
}
@Test
@@ -56,7 +56,7 @@ public class CorrelationStrategyAdapterTests {
new MethodInvokingCorrelationStrategy(new SimpleMessageCorrelator(),
ReflectionUtils.findMethod(SimpleMessageCorrelator.class, "getKey", Message.class));
adapter.setBeanFactory(mock(BeanFactory.class));
assertEquals("b", adapter.getCorrelationKey(message));
assertThat(adapter.getCorrelationKey(message)).isEqualTo("b");
}
@Test
@@ -64,7 +64,7 @@ public class CorrelationStrategyAdapterTests {
MethodInvokingCorrelationStrategy adapter =
new MethodInvokingCorrelationStrategy(new SimplePojoCorrelator(), "getKey");
adapter.setBeanFactory(mock(BeanFactory.class));
assertEquals("foo", adapter.getCorrelationKey(message));
assertThat(adapter.getCorrelationKey(message)).isEqualTo("foo");
}
@Test
@@ -72,7 +72,7 @@ public class CorrelationStrategyAdapterTests {
MethodInvokingCorrelationStrategy adapter =
new MethodInvokingCorrelationStrategy(new SimpleHeaderCorrelator(), "getKey");
adapter.setBeanFactory(mock(BeanFactory.class));
assertEquals("b", adapter.getCorrelationKey(message));
assertThat(adapter.getCorrelationKey(message)).isEqualTo("b");
}
@Test
@@ -80,7 +80,7 @@ public class CorrelationStrategyAdapterTests {
MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new MultiHeaderCorrelator(),
ReflectionUtils.findMethod(MultiHeaderCorrelator.class, "getKey", String.class, String.class));
adapter.setBeanFactory(mock(BeanFactory.class));
assertEquals("bd", adapter.getCorrelationKey(message));
assertThat(adapter.getCorrelationKey(message)).isEqualTo("bd");
}
private static class MultiHeaderCorrelator {

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,7 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Test;
@@ -65,8 +62,8 @@ public class ExpressionEvaluatingCorrelationStrategyTests {
strategy = new ExpressionEvaluatingCorrelationStrategy(expression);
strategy.setBeanFactory(mock(BeanFactory.class));
Object correlationKey = strategy.getCorrelationKey(new GenericMessage<String>("bla"));
assertThat(correlationKey, is(instanceOf(String.class)));
assertThat((String) correlationKey, is("b"));
assertThat(correlationKey).isInstanceOf(String.class);
assertThat((String) correlationKey).isEqualTo("b");
}
@Test
@@ -78,7 +75,7 @@ public class ExpressionEvaluatingCorrelationStrategyTests {
Message<?> message = MessageBuilder.withPayload("foo").setSequenceNumber(1).setSequenceSize(1).build();
inputChannel.send(message);
Message<?> reply = outputChannel.receive(0);
assertNotNull(reply);
assertThat(reply).isNotNull();
context.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,8 +16,7 @@
package org.springframework.integration.aggregator;
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 static org.mockito.Mockito.when;
@@ -69,9 +68,9 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
processor = new ExpressionEvaluatingMessageGroupProcessor("#root.size()");
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertEquals(5, resultMessage.getPayload());
assertThat(resultMessage.getPayload()).isEqualTo(5);
}
@Test
@@ -81,9 +80,9 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
processor.setBeanFactory(mock(BeanFactory.class));
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertEquals("bar", resultMessage.getHeaders().get("foo"));
assertThat(resultMessage.getHeaders().get("foo")).isEqualTo("bar");
}
@Test
@@ -92,16 +91,16 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
processor = new ExpressionEvaluatingMessageGroupProcessor("![payload]");
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertTrue(resultMessage.getPayload() instanceof Collection<?>);
assertThat(resultMessage.getPayload() instanceof Collection<?>).isTrue();
Collection<?> list = (Collection<?>) resultMessage.getPayload();
assertEquals(5, list.size());
assertTrue(list.contains(1));
assertTrue(list.contains(2));
assertTrue(list.contains(3));
assertTrue(list.contains(4));
assertTrue(list.contains(5));
assertThat(list.size()).isEqualTo(5);
assertThat(list.contains(1)).isTrue();
assertThat(list.contains(2)).isTrue();
assertThat(list.contains(3)).isTrue();
assertThat(list.contains(4)).isTrue();
assertThat(list.contains(5)).isTrue();
}
@Test
@@ -110,14 +109,14 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
processor = new ExpressionEvaluatingMessageGroupProcessor("?[payload>2].![payload]");
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertTrue(resultMessage.getPayload() instanceof Collection<?>);
assertThat(resultMessage.getPayload() instanceof Collection<?>).isTrue();
Collection<?> list = (Collection<?>) resultMessage.getPayload();
assertEquals(3, list.size());
assertTrue(list.contains(3));
assertTrue(list.contains(4));
assertTrue(list.contains(5));
assertThat(list.size()).isEqualTo(3);
assertThat(list.contains(3)).isTrue();
assertThat(list.contains(4)).isTrue();
assertThat(list.contains(5)).isTrue();
}
@Test
@@ -127,9 +126,9 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
getClass().getName()));
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof AbstractIntegrationMessageBuilder<?>);
assertThat(result instanceof AbstractIntegrationMessageBuilder<?>).isTrue();
Message<?> resultMessage = ((AbstractIntegrationMessageBuilder<?>) result).build();
assertEquals(3 + 4 + 5, resultMessage.getPayload());
assertThat(resultMessage.getPayload()).isEqualTo(3 + 4 + 5);
}

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.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Before;
@@ -52,21 +51,21 @@ public class ExpressionEvaluatingReleaseStrategyTests {
public void testCompletedWithSizeSpelEvaluated() {
strategy = new ExpressionEvaluatingReleaseStrategy("#root.size()==5");
strategy.setBeanFactory(mock(BeanFactory.class));
assertThat(strategy.canRelease(messages), is(true));
assertThat(strategy.canRelease(messages)).isTrue();
}
@Test
public void testCompletedWithFilterSpelEvaluated() {
strategy = new ExpressionEvaluatingReleaseStrategy("!messages.?[payload==5].empty");
strategy.setBeanFactory(mock(BeanFactory.class));
assertThat(strategy.canRelease(messages), is(true));
assertThat(strategy.canRelease(messages)).isTrue();
}
@Test
public void testCompletedWithFilterSpelReturnsNotCompleted() {
strategy = new ExpressionEvaluatingReleaseStrategy("!messages.?[payload==6].empty");
strategy.setBeanFactory(mock(BeanFactory.class));
assertThat(strategy.canRelease(messages), is(false));
assertThat(strategy.canRelease(messages)).isFalse();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 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.aggregator;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -34,7 +34,7 @@ public class HeaderAttributeCorrelationStrategyTests {
String testHeaderName = "header.for.test";
Message<?> message = MessageBuilder.withPayload("irrelevantData").setHeader(testHeaderName, testedHeaderValue).build();
HeaderAttributeCorrelationStrategy correlationStrategy = new HeaderAttributeCorrelationStrategy(testHeaderName);
assertEquals(testedHeaderValue, correlationStrategy.getCorrelationKey(message));
assertThat(correlationStrategy.getCorrelationKey(message)).isEqualTo(testedHeaderValue);
}

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.aggregator;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Comparator;
@@ -38,7 +38,7 @@ public class MessageSequenceComparatorTests {
.setSequenceNumber(1).build();
Message<String> message2 = MessageBuilder.withPayload("test2")
.setSequenceNumber(2).build();
assertEquals(-1, comparator.compare(message1, message2));
assertThat(comparator.compare(message1, message2)).isEqualTo(-1);
}
@Test
@@ -48,7 +48,7 @@ public class MessageSequenceComparatorTests {
.setSequenceNumber(3).build();
Message<String> message2 = MessageBuilder.withPayload("test2")
.setSequenceNumber(3).build();
assertEquals(0, comparator.compare(message1, message2));
assertThat(comparator.compare(message1, message2)).isEqualTo(0);
}
@Test
@@ -58,7 +58,7 @@ public class MessageSequenceComparatorTests {
.setSequenceNumber(5).build();
Message<String> message2 = MessageBuilder.withPayload("test2")
.setSequenceNumber(3).build();
assertEquals(1, comparator.compare(message1, message2));
assertThat(comparator.compare(message1, message2)).isEqualTo(1);
}
@Test
@@ -66,7 +66,7 @@ public class MessageSequenceComparatorTests {
Comparator<Message<?>> comparator = new MessageSequenceComparator();
Message<String> message1 = MessageBuilder.withPayload("test1").build();
Message<String> message2 = MessageBuilder.withPayload("test2").build();
assertEquals(0, comparator.compare(message1, message2));
assertThat(comparator.compare(message1, message2)).isEqualTo(0);
}
}

View File

@@ -16,12 +16,8 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
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.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -108,7 +104,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is(7));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo(7);
}
@Test
@@ -132,7 +128,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is(7));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo(7);
}
@Test
@@ -156,7 +152,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is(7));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo(7);
}
@Test
@@ -184,7 +180,8 @@ public class MethodInvokingMessageGroupProcessorTests {
messagesUpForProcessing.add(MessageBuilder.withPayload(3).setHeader("foo", Arrays.asList(101, 102)).build());
when(messageGroupMock.getMessages()).thenReturn(messagesUpForProcessing);
Object result = processor.processMessageGroup(messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is("[1, 2, 4, 3, 101, 102]"));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload())
.isEqualTo("[1, 2, 4, 3, 101, 102]");
}
@Test
@@ -217,7 +214,8 @@ public class MethodInvokingMessageGroupProcessorTests {
.build());
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is("[1, 2, 4, 3, 101, 102]"));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload())
.isEqualTo("[1, 2, 4, 3, 101, 102]");
}
@Test
@@ -242,7 +240,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is("[1, 2, 4]"));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo("[1, 2, 4]");
}
@Test
@@ -266,7 +264,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is(7));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo(7);
}
@Test
@@ -290,7 +288,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is(7));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo(7);
}
@@ -325,7 +323,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setConversionService(conversionService);
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is(7));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo(7);
}
@Test
@@ -358,7 +356,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), is(7));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isEqualTo(7);
}
@Test
@@ -388,7 +386,7 @@ public class MethodInvokingMessageGroupProcessorTests {
processor.setBeanFactory(mock(BeanFactory.class));
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload(), instanceOf(Iterator.class));
assertThat(((AbstractIntegrationMessageBuilder<?>) result).build().getPayload()).isInstanceOf(Iterator.class);
}
@Test
@@ -419,8 +417,8 @@ public class MethodInvokingMessageGroupProcessorTests {
when(this.messageGroupMock.getMessages()).thenReturn(this.messagesUpForProcessing);
Object result = processor.processMessageGroup(this.messageGroupMock);
Object payload = ((AbstractIntegrationMessageBuilder<?>) result).build().getPayload();
assertTrue(payload instanceof Integer);
assertEquals(7, payload);
assertThat(payload instanceof Integer).isTrue();
assertThat(payload).isEqualTo(7);
}
@@ -447,7 +445,7 @@ public class MethodInvokingMessageGroupProcessorTests {
SimpleMessageGroup group = new SimpleMessageGroup("FOO");
group.add(new GenericMessage<>("foo"));
group.add(new GenericMessage<>("bar"));
assertEquals("foo", aggregator.aggregatePayloads(group, null));
assertThat(aggregator.aggregatePayloads(group, null)).isEqualTo("foo");
}
@Test
@@ -468,7 +466,7 @@ public class MethodInvokingMessageGroupProcessorTests {
SimpleMessageGroup group = new SimpleMessageGroup("FOO");
group.add(MessageBuilder.withPayload("foo").setHeader("foo", "bar").build());
group.add(MessageBuilder.withPayload("bar").setHeader("foo", "bar").build());
assertEquals("foobar", processor.aggregatePayloads(group, processor.aggregateHeaders(group)));
assertThat(processor.aggregatePayloads(group, processor.aggregateHeaders(group))).isEqualTo("foobar");
}
@Test
@@ -489,7 +487,7 @@ public class MethodInvokingMessageGroupProcessorTests {
SimpleMessageGroup group = new SimpleMessageGroup("FOO");
group.add(MessageBuilder.withPayload("foo").setHeader("foo", "bar").build());
group.add(MessageBuilder.withPayload("bar").setHeader("foo", "bar").build());
assertEquals("foobar", aggregator.aggregatePayloads(group, aggregator.aggregateHeaders(group)));
assertThat(aggregator.aggregatePayloads(group, aggregator.aggregateHeaders(group))).isEqualTo("foobar");
}
@Test(expected = IllegalArgumentException.class)
@@ -535,7 +533,7 @@ public class MethodInvokingMessageGroupProcessorTests {
SimpleMessageGroup group = new SimpleMessageGroup("FOO");
group.add(new GenericMessage<>("foo"));
group.add(new GenericMessage<>("bar"));
assertEquals("foo", aggregator.aggregatePayloads(group, null));
assertThat(aggregator.aggregatePayloads(group, null)).isEqualTo("foo");
}
@Test(expected = IllegalArgumentException.class)
@@ -593,7 +591,7 @@ public class MethodInvokingMessageGroupProcessorTests {
Message<?> message = MessageBuilder.withPayload("proxy").setCorrelationId("abc").build();
input.send(message);
assertEquals("hello proxy", output.receive(0).getPayload());
assertThat(output.receive(0).getPayload()).isEqualTo("hello proxy");
}
@Test
@@ -615,7 +613,7 @@ public class MethodInvokingMessageGroupProcessorTests {
Message<?> message = MessageBuilder.withPayload("proxy").setCorrelationId("abc").build();
input.send(message);
assertEquals("hello proxy", output.receive(0).getPayload());
assertThat(output.receive(0).getPayload()).isEqualTo("hello proxy");
}

View File

@@ -16,8 +16,7 @@
package org.springframework.integration.aggregator;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
@@ -47,7 +46,7 @@ public class MethodInvokingReleaseStrategyTests {
MethodInvokingReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new AlwaysTrueReleaseStrategy(),
"checkCompleteness");
adapter.setBeanFactory(mock(BeanFactory.class));
assertTrue(adapter.canRelease(createListOfMessages(0)));
assertThat(adapter.canRelease(createListOfMessages(0))).isTrue();
}
@Test
@@ -55,7 +54,7 @@ public class MethodInvokingReleaseStrategyTests {
MethodInvokingReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new AlwaysFalseReleaseStrategy(),
"checkCompleteness");
adapter.setBeanFactory(mock(BeanFactory.class));
assertFalse(adapter.canRelease(createListOfMessages(0)));
assertThat(adapter.canRelease(createListOfMessages(0))).isFalse();
}
@Test
@@ -64,7 +63,7 @@ public class MethodInvokingReleaseStrategyTests {
@SuppressWarnings("unused")
public boolean checkCompletenessOnNonParameterizedListOfMessages(List<Message<?>> messages) {
assertTrue(messages.size() > 0);
assertThat(messages.size() > 0).isTrue();
return messages.size() >
new IntegrationMessageHeaderAccessor(messages.iterator().next()).getSequenceSize();
}
@@ -74,7 +73,7 @@ public class MethodInvokingReleaseStrategyTests {
"checkCompletenessOnNonParameterizedListOfMessages");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test
@@ -83,7 +82,7 @@ public class MethodInvokingReleaseStrategyTests {
@SuppressWarnings("unused")
public boolean checkCompletenessOnListOfMessagesParametrizedWithWildcard(List<Message<?>> messages) {
assertTrue(messages.size() > 0);
assertThat(messages.size() > 0).isTrue();
return messages.size() >
new IntegrationMessageHeaderAccessor(messages.iterator().next()).getSequenceSize();
}
@@ -93,7 +92,7 @@ public class MethodInvokingReleaseStrategyTests {
"checkCompletenessOnListOfMessagesParametrizedWithWildcard");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test
@@ -102,7 +101,7 @@ public class MethodInvokingReleaseStrategyTests {
@SuppressWarnings("unused")
public boolean checkCompletenessOnListOfMessagesParametrizedWithString(List<Message<String>> messages) {
assertTrue(messages.size() > 0);
assertThat(messages.size() > 0).isTrue();
return messages.size() > new IntegrationMessageHeaderAccessor(messages.iterator().next())
.getSequenceSize();
}
@@ -112,7 +111,7 @@ public class MethodInvokingReleaseStrategyTests {
"checkCompletenessOnListOfMessagesParametrizedWithString");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test
@@ -135,7 +134,7 @@ public class MethodInvokingReleaseStrategyTests {
"checkCompletenessOnListOfStrings");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test
@@ -158,7 +157,7 @@ public class MethodInvokingReleaseStrategyTests {
"checkCompletenessOnListOfStrings");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test(expected = IllegalStateException.class)
@@ -183,7 +182,7 @@ public class MethodInvokingReleaseStrategyTests {
new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "invalidParameterType");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test(expected = IllegalStateException.class)
@@ -240,7 +239,7 @@ public class MethodInvokingReleaseStrategyTests {
"listSubclassParameter");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test(expected = ConversionFailedException.class)
@@ -257,7 +256,7 @@ public class MethodInvokingReleaseStrategyTests {
new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "wrongReturnType");
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test(expected = IllegalArgumentException.class)
@@ -288,7 +287,7 @@ public class MethodInvokingReleaseStrategyTests {
TestReleaseStrategy.class.getMethod("listSubclassParameter", LinkedList.class));
adapter.setBeanFactory(mock(BeanFactory.class));
MessageGroup messages = createListOfMessages(3);
assertTrue(adapter.canRelease(messages));
assertThat(adapter.canRelease(messages)).isTrue();
}
@Test(expected = IllegalStateException.class)

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,13 +16,8 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
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.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.util.ArrayList;
@@ -80,12 +75,12 @@ public class ResequencerTests {
Message<?> reply1 = replyChannel.receive(0);
Message<?> reply2 = replyChannel.receive(0);
Message<?> reply3 = replyChannel.receive(0);
assertNotNull(reply1);
assertThat(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber(), is(1));
assertNotNull(reply2);
assertThat(new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber(), is(2));
assertNotNull(reply3);
assertThat(new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber(), is(3));
assertThat(reply1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber()).isEqualTo(1);
assertThat(reply2).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber()).isEqualTo(2);
assertThat(reply3).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber()).isEqualTo(3);
}
@Test
@@ -101,10 +96,10 @@ public class ResequencerTests {
Message<?> message3 = createMessage("789", "ABC", 3, 3, replyChannel);
this.resequencer.handleMessage(message3);
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNull();
this.resequencer.handleMessage(message1);
assertNotNull(replyChannel.receive(0));
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNotNull();
assertThat(replyChannel.receive(0)).isNull();
}
@Test
@@ -125,20 +120,20 @@ public class ResequencerTests {
Message<?> message5 = MessageBuilder.withPayload("5").setSequenceNumber(5).setReplyChannel(replyChannel).build();
this.resequencer.handleMessage(message3);
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNull();
this.resequencer.handleMessage(message1);
assertNotNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNotNull();
this.resequencer.handleMessage(message2);
assertNotNull(replyChannel.receive(0));
assertNotNull(replyChannel.receive(0));
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNotNull();
assertThat(replyChannel.receive(0)).isNotNull();
assertThat(replyChannel.receive(0)).isNull();
this.resequencer.handleMessage(message5);
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNull();
this.resequencer.handleMessage(message4);
assertNotNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNotNull();
}
@Test
@@ -154,12 +149,12 @@ public class ResequencerTests {
Message<?> reply1 = replyChannel.receive(0);
Message<?> reply2 = replyChannel.receive(0);
Message<?> reply3 = replyChannel.receive(0);
assertNotNull(reply1);
assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
assertNotNull(reply2);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
assertNotNull(reply3);
assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
assertThat(reply1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber()).isEqualTo(1);
assertThat(reply2).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber()).isEqualTo(2);
assertThat(reply3).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber()).isEqualTo(3);
}
@Test
@@ -179,19 +174,19 @@ public class ResequencerTests {
Message<?> reply2 = replyChannel.receive(0);
Message<?> reply3 = replyChannel.receive(0);
// only messages 1 and 2 should have been received by now
assertNotNull(reply1);
assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
assertNotNull(reply2);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
assertNull(reply3);
assertThat(reply1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber()).isEqualTo(1);
assertThat(reply2).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber()).isEqualTo(2);
assertThat(reply3).isNull();
// when sending the last message, the whole sequence must have been sent
this.resequencer.handleMessage(message4);
reply3 = replyChannel.receive(0);
Message<?> reply4 = replyChannel.receive(0);
assertNotNull(reply3);
assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
assertNotNull(reply4);
assertEquals(4, new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber());
assertThat(reply3).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber()).isEqualTo(3);
assertThat(reply4).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber()).isEqualTo(4);
}
@Test
@@ -210,7 +205,7 @@ public class ResequencerTests {
fail("Expected exception");
}
catch (MessagingException e) {
assertThat(e.getMessage(), containsString("out of capacity (2) for group 'ABC'"));
assertThat(e.getMessage()).contains("out of capacity (2) for group 'ABC'");
}
}
@@ -229,19 +224,19 @@ public class ResequencerTests {
Message<?> reply2 = replyChannel.receive(0);
Message<?> reply3 = replyChannel.receive(0);
// only messages 1 and 2 should have been received by now
assertNotNull(reply1);
assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
assertNotNull(reply2);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
assertNull(reply3);
assertThat(reply1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber()).isEqualTo(1);
assertThat(reply2).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber()).isEqualTo(2);
assertThat(reply3).isNull();
// when sending the last message, the whole sequence must have been sent
this.resequencer.handleMessage(message4);
reply3 = replyChannel.receive(0);
Message<?> reply4 = replyChannel.receive(0);
assertNotNull(reply3);
assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
assertNotNull(reply4);
assertEquals(4, new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber());
assertThat(reply3).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber()).isEqualTo(3);
assertThat(reply4).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber()).isEqualTo(4);
}
@Test
@@ -254,23 +249,23 @@ public class ResequencerTests {
this.resequencer.setDiscardChannel(discardChannel);
this.resequencer.handleMessage(message1);
this.resequencer.handleMessage(message2);
assertEquals(1, store.expireMessageGroups(-10000));
assertThat(store.expireMessageGroups(-10000)).isEqualTo(1);
Message<?> reply1 = discardChannel.receive(0);
Message<?> reply2 = discardChannel.receive(0);
Message<?> reply3 = discardChannel.receive(0);
// only messages 1 and 2 should have been received by now
assertNotNull(reply1);
assertNotNull(reply2);
assertNull(reply3);
assertThat(reply1).isNotNull();
assertThat(reply2).isNotNull();
assertThat(reply3).isNull();
ArrayList<Integer> sequence = new ArrayList<>(
Arrays.asList(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber(),
new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber()));
Collections.sort(sequence);
assertEquals("[1, 2]", sequence.toString());
assertThat(sequence.toString()).isEqualTo("[1, 2]");
// Once a group is expired, late messages are discarded immediately by default
this.resequencer.handleMessage(message3);
reply3 = discardChannel.receive(0);
assertNotNull(reply3);
assertThat(reply3).isNotNull();
}
@Test
@@ -287,9 +282,9 @@ public class ResequencerTests {
Message<?> discard1 = discardChannel.receive(0);
Message<?> discard2 = discardChannel.receive(0);
// message2 has been discarded because it came in with the wrong sequence size
assertNotNull(discard1);
assertEquals(1, new IntegrationMessageHeaderAccessor(discard1).getSequenceNumber());
assertNull(discard2);
assertThat(discard1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(discard1).getSequenceNumber()).isEqualTo(1);
assertThat(discard2).isNull();
}
@Test
@@ -302,7 +297,7 @@ public class ResequencerTests {
// this.resequencer.discardBarrier(this.resequencer.barriers.get("ABC"));
Message<?> reply1 = discardChannel.receive(0);
// No message has been received - the message has been rejected.
assertNull(reply1);
assertThat(reply1).isNull();
}
@Test
@@ -319,23 +314,23 @@ public class ResequencerTests {
Message<?> reply2 = replyChannel.receive(0);
Message<?> reply3 = replyChannel.receive(0);
// no messages should have been received yet
assertNull(reply1);
assertNull(reply2);
assertNull(reply3);
assertThat(reply1).isNull();
assertThat(reply2).isNull();
assertThat(reply3).isNull();
// after sending the last message, the whole sequence should have been sent
this.resequencer.handleMessage(message4);
reply1 = replyChannel.receive(0);
reply2 = replyChannel.receive(0);
reply3 = replyChannel.receive(0);
Message<?> reply4 = replyChannel.receive(0);
assertNotNull(reply1);
assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
assertNotNull(reply2);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
assertNotNull(reply3);
assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
assertNotNull(reply4);
assertEquals(4, new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber());
assertThat(reply1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber()).isEqualTo(1);
assertThat(reply2).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber()).isEqualTo(2);
assertThat(reply3).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber()).isEqualTo(3);
assertThat(reply4).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber()).isEqualTo(4);
}
@Test
@@ -344,7 +339,7 @@ public class ResequencerTests {
String correlationId = "ABC";
Message<?> message1 = createMessage("123", correlationId, 1, 1, replyChannel);
resequencer.handleMessage(message1);
assertEquals(0, store.getMessageGroup(correlationId).size());
assertThat(store.getMessageGroup(correlationId).size()).isEqualTo(0);
}
@Test
@@ -363,15 +358,15 @@ public class ResequencerTests {
this.resequencer.handleMessage(message3);
this.resequencer.handleMessage(message2);
Message<?> out1 = replyChannel.receive(10);
assertNull(out1);
assertThat(out1).isNull();
out1 = discardChannel.receive(10000);
assertNotNull(out1);
assertThat(out1).isNotNull();
Message<?> out2 = discardChannel.receive(10);
assertNotNull(out2);
assertThat(out2).isNotNull();
Message<?> message1 = createMessage("123", "ABC", 3, 1, null);
this.resequencer.handleMessage(message1);
Message<?> out3 = discardChannel.receive(0);
assertNotNull(out3);
assertThat(out3).isNotNull();
}
@Test
@@ -391,17 +386,17 @@ public class ResequencerTests {
this.resequencer.handleMessage(message3);
this.resequencer.handleMessage(message2);
Message<?> out1 = replyChannel.receive(0);
assertNull(out1);
assertThat(out1).isNull();
out1 = discardChannel.receive(10_000);
assertNotNull(out1);
assertThat(out1).isNotNull();
Message<?> out2 = discardChannel.receive(10_000);
assertNotNull(out2);
assertThat(out2).isNotNull();
Message<?> message1 = createMessage("123", "ABC", 3, 1, null);
this.resequencer.handleMessage(message1);
Message<?> out3 = discardChannel.receive(0);
assertNull(out3);
assertThat(out3).isNull();
out3 = discardChannel.receive(10_000);
assertNotNull(out3);
assertThat(out3).isNotNull();
}
private static Message<?> createMessage(String payload, Object correlationId, int sequenceSize, int sequenceNumber,

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,7 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -50,7 +48,7 @@ public class ResequencingMessageGroupProcessorTests {
messages.add(message3);
SimpleMessageGroup group = new SimpleMessageGroup(messages, "x");
List<Message> processedMessages = (List<Message>) processor.processMessageGroup(group);
assertThat(processedMessages, hasItems(message1, message2, message3));
assertThat(processedMessages).contains(message1, message2, message3);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -66,8 +64,8 @@ public class ResequencingMessageGroupProcessorTests {
messages.add(message3);
SimpleMessageGroup group = new SimpleMessageGroup(messages, "x");
List<Message> processedMessages = (List<Message>) processor.processMessageGroup(group);
assertThat(processedMessages, hasItems(message1));
assertThat(processedMessages.size(), is(1));
assertThat(processedMessages).contains(message1);
assertThat(processedMessages.size()).isEqualTo(1);
}
}

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.aggregator;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -39,7 +38,7 @@ public class SequenceSizeReleaseStrategyTests {
SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
messages.add(message);
SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
assertFalse(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isFalse();
}
@Test
@@ -50,13 +49,13 @@ public class SequenceSizeReleaseStrategyTests {
messages.add(message1);
messages.add(message2);
SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
}
@Test
public void testEmptyList() {
SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
assertTrue(releaseStrategy.canRelease(new SimpleMessageGroup("FOO")));
assertThat(releaseStrategy.canRelease(new SimpleMessageGroup("FOO"))).isTrue();
}
@Test
@@ -67,7 +66,7 @@ public class SequenceSizeReleaseStrategyTests {
Message<String> message = MessageBuilder.withPayload("test1").setSequenceSize(1).build();
messages.add(message);
messages.remove(message);
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
}
@Test
@@ -77,7 +76,7 @@ public class SequenceSizeReleaseStrategyTests {
SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
assertTrue(releaseStrategy.canRelease(groupWithFirstMessagesOfIncompleteSequence(messages)));
assertThat(releaseStrategy.canRelease(groupWithFirstMessagesOfIncompleteSequence(messages))).isTrue();
}
private SimpleMessageGroup groupWithFirstMessagesOfIncompleteSequence(SimpleMessageGroup messages) {
@@ -96,7 +95,7 @@ public class SequenceSizeReleaseStrategyTests {
boolean canRelease = releaseStrategy.canRelease(groupWithLastAndFirstMessagesOfIncompleteSequence());
assertTrue(canRelease);
assertThat(canRelease).isTrue();
}
private MessageGroup groupWithLastAndFirstMessagesOfIncompleteSequence() {
@@ -124,15 +123,15 @@ public class SequenceSizeReleaseStrategyTests {
Message<String> message5 = MessageBuilder.withPayload("test5").setSequenceSize(5).setSequenceNumber(5).build();
messages.add(message5);
assertFalse(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isFalse();
messages.add(message1);
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
messages.add(message2);
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
messages.add(message3);
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
messages.add(message4);
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).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.aggregator;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -38,7 +37,7 @@ public class TimeoutCountSequenceSizeReleaseStrategyTests {
SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
messages.add(message);
TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = new TimeoutCountSequenceSizeReleaseStrategy();
assertFalse(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isFalse();
}
@Test
@@ -50,7 +49,7 @@ public class TimeoutCountSequenceSizeReleaseStrategyTests {
TimeoutCountSequenceSizeReleaseStrategy releaseStrategy =
new TimeoutCountSequenceSizeReleaseStrategy(TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_THRESHOLD,
-100);
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
}
@Test
@@ -62,7 +61,7 @@ public class TimeoutCountSequenceSizeReleaseStrategyTests {
TimeoutCountSequenceSizeReleaseStrategy releaseStrategy =
new TimeoutCountSequenceSizeReleaseStrategy(1,
TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_TIMEOUT);
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
}
@Test
@@ -75,13 +74,13 @@ public class TimeoutCountSequenceSizeReleaseStrategyTests {
messages.add(message1);
messages.add(message2);
SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
assertTrue(releaseStrategy.canRelease(messages));
assertThat(releaseStrategy.canRelease(messages)).isTrue();
}
@Test
public void testEmptyList() {
SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
assertTrue(releaseStrategy.canRelease(new SimpleMessageGroup("FOO")));
assertThat(releaseStrategy.canRelease(new SimpleMessageGroup("FOO"))).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,7 +16,7 @@
package org.springframework.integration.aggregator.integration;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -57,7 +57,7 @@ public class AggregatorExpressionIntegrationTests {
Map<String, Object> headers = stubHeaders(i, 5, 1);
this.input.send(new GenericMessage<>(i, headers));
}
assertEquals("[0, 1, 2, 3, 4]", this.output.receive().getPayload());
assertThat(this.output.receive().getPayload()).isEqualTo("[0, 1, 2, 3, 4]");
}
private Map<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) {

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,7 @@
package org.springframework.integration.aggregator.integration;
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.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import java.util.Collections;
@@ -95,8 +90,8 @@ public class AggregatorIntegrationTests {
input.send(new GenericMessage<>(i, headers));
}
Message<?> receive = output.receive(10000);
assertNotNull(receive);
assertEquals(1 + 2 + 3 + 4, receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo(1 + 2 + 3 + 4);
}
@Test
@@ -105,21 +100,21 @@ public class AggregatorIntegrationTests {
Map<String, Object> headers = stubHeaders(i, 5, 1);
nonExpiringAggregatorInput.send(new GenericMessage<>(i, headers));
}
assertNotNull(output.receive(0));
assertThat(output.receive(0)).isNotNull();
assertNull(discard.receive(0));
assertThat(discard.receive(0)).isNull();
for (int i = 5; i < 10; i++) {
Map<String, Object> headers = stubHeaders(i, 5, 1);
nonExpiringAggregatorInput.send(new GenericMessage<>(i, headers));
}
assertNull(output.receive(0));
assertThat(output.receive(0)).isNull();
assertNotNull(discard.receive(0));
assertNotNull(discard.receive(0));
assertNotNull(discard.receive(0));
assertNotNull(discard.receive(0));
assertNotNull(discard.receive(0));
assertThat(discard.receive(0)).isNotNull();
assertThat(discard.receive(0)).isNotNull();
assertThat(discard.receive(0)).isNotNull();
assertThat(discard.receive(0)).isNotNull();
assertThat(discard.receive(0)).isNotNull();
}
@Test
@@ -128,17 +123,17 @@ public class AggregatorIntegrationTests {
Map<String, Object> headers = stubHeaders(i, 5, 1);
expiringAggregatorInput.send(new GenericMessage<>(i, headers));
}
assertNotNull(output.receive(0));
assertThat(output.receive(0)).isNotNull();
assertNull(discard.receive(0));
assertThat(discard.receive(0)).isNull();
for (int i = 5; i < 10; i++) {
Map<String, Object> headers = stubHeaders(i, 5, 1);
expiringAggregatorInput.send(new GenericMessage<>(i, headers));
}
assertNotNull(output.receive(0));
assertThat(output.receive(0)).isNotNull();
assertNull(discard.receive(0));
assertThat(discard.receive(0)).isNull();
}
@@ -155,9 +150,9 @@ public class AggregatorIntegrationTests {
while (n++ < 100 && mgs.getMessageGroupCount() > 0) {
Thread.sleep(100);
}
assertTrue("Group did not complete", n < 100);
assertNotNull(this.output.receive(10000));
assertNull(this.discard.receive(0));
assertThat(n < 100).as("Group did not complete").isTrue();
assertThat(this.output.receive(10000)).isNotNull();
assertThat(this.discard.receive(0)).isNull();
}
}
@@ -180,50 +175,50 @@ public class AggregatorIntegrationTests {
TestUtils.getPropertyValue(this.output, "queue", Queue.class).clear();
}
}
assertTrue("Group did not complete", n < 100);
assertThat(n < 100).as("Group did not complete").isTrue();
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(Collections.singletonList(1), receive.getPayload());
assertNull(this.discard.receive(0));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo(Collections.singletonList(1));
assertThat(this.discard.receive(0)).isNull();
}
@Test
public void testGroupTimeoutExpressionScheduling() {
// Since group-timeout-expression="size() >= 2 ? 100 : null". The first message won't be scheduled to 'forceComplete'
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<>(1, stubHeaders(1, 6, 1)));
assertNull(this.output.receive(0));
assertNull(this.discard.receive(0));
assertThat(this.output.receive(0)).isNull();
assertThat(this.discard.receive(0)).isNull();
// As far as 'group.size() >= 2' it will be scheduled to 'forceComplete'
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<>(2, stubHeaders(2, 6, 1)));
assertNull(this.output.receive(0));
assertThat(this.output.receive(0)).isNull();
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(2, ((Collection<?>) receive.getPayload()).size());
assertNull(this.discard.receive(0));
assertThat(receive).isNotNull();
assertThat(((Collection<?>) receive.getPayload()).size()).isEqualTo(2);
assertThat(this.discard.receive(0)).isNull();
// The same with these three messages
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<>(3, stubHeaders(3, 6, 1)));
assertNull(this.output.receive(0));
assertNull(this.discard.receive(0));
assertThat(this.output.receive(0)).isNull();
assertThat(this.discard.receive(0)).isNull();
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<>(4, stubHeaders(4, 6, 1)));
assertNull(this.output.receive(0));
assertNull(this.discard.receive(0));
assertThat(this.output.receive(0)).isNull();
assertThat(this.discard.receive(0)).isNull();
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<>(5, stubHeaders(5, 6, 1)));
assertNull(this.output.receive(0));
assertThat(this.output.receive(0)).isNull();
receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(3, ((Collection<?>) receive.getPayload()).size());
assertNull(this.discard.receive(0));
assertThat(receive).isNotNull();
assertThat(((Collection<?>) receive.getPayload()).size()).isEqualTo(3);
assertThat(this.discard.receive(0)).isNull();
// The last message in the sequence - normal release by provided 'ReleaseStrategy'
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<>(6, stubHeaders(6, 6, 1)));
receive = this.output.receive(10000);
assertNotNull(receive);
assertEquals(1, ((Collection<?>) receive.getPayload()).size());
assertNull(this.discard.receive(0));
assertThat(receive).isNotNull();
assertThat(((Collection<?>) receive.getPayload()).size()).isEqualTo(1);
assertThat(this.discard.receive(0)).isNull();
}
@Test
@@ -239,9 +234,9 @@ public class AggregatorIntegrationTests {
this.output.send(message);
this.zeroGroupTimeoutExpressionAggregatorInput.send(new GenericMessage<>(1, stubHeaders(1, 2, 1)));
ErrorMessage em = (ErrorMessage) this.errors.receive(10000);
assertNotNull(em);
assertThat(em.getPayload().getMessage().toLowerCase(),
containsString("failed to send message to channel 'output' within timeout: 10"));
assertThat(em).isNotNull();
assertThat(em.getPayload().getMessage().toLowerCase())
.contains("failed to send message to channel 'output' within timeout: 10");
}
finally {
this.output.purge(null);

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,7 @@
package org.springframework.integration.aggregator.integration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
@@ -56,19 +54,19 @@ public class AggregatorSupportedUseCasesTests {
for (int i = 0; i < 5; i++) {
defaultHandler.handleMessage(MessageBuilder.withPayload(i).setSequenceSize(5).setCorrelationId("A").setSequenceNumber(i).build());
}
assertEquals(5, ((List<?>) outputChannel.receive(0).getPayload()).size());
assertNull(discardChannel.receive(0));
assertEquals(0, store.getMessageGroup("A").getMessages().size());
assertThat(((List<?>) outputChannel.receive(0).getPayload()).size()).isEqualTo(5);
assertThat(discardChannel.receive(0)).isNull();
assertThat(store.getMessageGroup("A").getMessages().size()).isEqualTo(0);
// send another message with the same correlation id and see it in the discard channel
defaultHandler.handleMessage(MessageBuilder.withPayload("foo").setSequenceSize(5).setCorrelationId("A").setSequenceNumber(3).build());
assertNotNull(discardChannel.receive(0));
assertThat(discardChannel.receive(0)).isNotNull();
// expireMessageGroups from aggregator MessageStore and the messages should start accumulating again
store.expireMessageGroups(0);
defaultHandler.handleMessage(MessageBuilder.withPayload("foo").setSequenceSize(5).setCorrelationId("A").setSequenceNumber(3).build());
assertNull(discardChannel.receive(0));
assertEquals(1, store.getMessageGroup("A").getMessages().size());
assertThat(discardChannel.receive(0)).isNull();
assertThat(store.getMessageGroup("A").getMessages().size()).isEqualTo(1);
}
@Test
@@ -82,19 +80,19 @@ public class AggregatorSupportedUseCasesTests {
for (int i = 0; i < 5; i++) {
defaultHandler.handleMessage(MessageBuilder.withPayload(i).setCorrelationId("A").build());
}
assertEquals(5, ((List<?>) outputChannel.receive(0).getPayload()).size());
assertNull(discardChannel.receive(0));
assertEquals(0, store.getMessageGroup("A").getMessages().size());
assertThat(((List<?>) outputChannel.receive(0).getPayload()).size()).isEqualTo(5);
assertThat(discardChannel.receive(0)).isNull();
assertThat(store.getMessageGroup("A").getMessages().size()).isEqualTo(0);
// send another message with the same correlation id and see it in the discard channel
defaultHandler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("A").build());
assertNotNull(discardChannel.receive(0));
assertThat(discardChannel.receive(0)).isNotNull();
// expireMessageGroups from aggregator MessageStore and the messages should start accumulating again
store.expireMessageGroups(0);
defaultHandler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("A").build());
assertNull(discardChannel.receive(0));
assertEquals(1, store.getMessageGroup("A").getMessages().size());
assertThat(discardChannel.receive(0)).isNull();
assertThat(store.getMessageGroup("A").getMessages().size()).isEqualTo(1);
}
@Test
@@ -108,11 +106,11 @@ public class AggregatorSupportedUseCasesTests {
for (int i = 0; i < 5; i++) {
defaultHandler.handleMessage(MessageBuilder.withPayload(i).setCorrelationId("A").build());
}
assertEquals(1, ((List<?>) outputChannel.receive(0).getPayload()).size());
assertNotNull(discardChannel.receive(0));
assertNotNull(discardChannel.receive(0));
assertNotNull(discardChannel.receive(0));
assertNotNull(discardChannel.receive(0));
assertThat(((List<?>) outputChannel.receive(0).getPayload()).size()).isEqualTo(1);
assertThat(discardChannel.receive(0)).isNotNull();
assertThat(discardChannel.receive(0)).isNotNull();
assertThat(discardChannel.receive(0)).isNotNull();
assertThat(discardChannel.receive(0)).isNotNull();
}
@Test
@@ -127,9 +125,9 @@ public class AggregatorSupportedUseCasesTests {
for (int i = 0; i < 10; i++) {
defaultHandler.handleMessage(MessageBuilder.withPayload(i).setCorrelationId("A").build());
}
assertEquals(5, ((List<?>) outputChannel.receive(0).getPayload()).size());
assertEquals(5, ((List<?>) outputChannel.receive(0).getPayload()).size());
assertNull(discardChannel.receive(0));
assertThat(((List<?>) outputChannel.receive(0).getPayload()).size()).isEqualTo(5);
assertThat(((List<?>) outputChannel.receive(0).getPayload()).size()).isEqualTo(5);
assertThat(discardChannel.receive(0)).isNull();
}
@Test
@@ -144,10 +142,10 @@ public class AggregatorSupportedUseCasesTests {
for (int i = 0; i < 12; i++) {
defaultHandler.handleMessage(MessageBuilder.withPayload(i).setCorrelationId("A").build());
}
assertEquals(5, ((List<?>) outputChannel.receive(0).getPayload()).size());
assertEquals(5, ((List<?>) outputChannel.receive(0).getPayload()).size());
assertNull(discardChannel.receive(0));
assertEquals(2, store.getMessageGroup("A").getMessages().size());
assertThat(((List<?>) outputChannel.receive(0).getPayload()).size()).isEqualTo(5);
assertThat(((List<?>) outputChannel.receive(0).getPayload()).size()).isEqualTo(5);
assertThat(discardChannel.receive(0)).isNull();
assertThat(store.getMessageGroup("A").getMessages().size()).isEqualTo(2);
}
private class SampleSizeReleaseStrategy implements ReleaseStrategy {

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.aggregator.integration;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
@@ -55,8 +55,8 @@ public class AnnotationAggregatorTests {
@SuppressWarnings("unchecked")
Message<String> result = (Message<String>) output.receive();
String payload = result.getPayload();
assertTrue("Wrong payload: " + payload, payload.matches(".*payload.*?=a.*"));
assertTrue("Wrong payload: " + payload, payload.matches(".*payload.*?=b.*"));
assertThat(payload.matches(".*payload.*?=a.*")).as("Wrong payload: " + payload).isTrue();
assertThat(payload.matches(".*payload.*?=b.*")).as("Wrong payload: " + payload).isTrue();
}
@SuppressWarnings("unused")

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,7 @@
package org.springframework.integration.aggregator.integration;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.HashMap;
@@ -64,9 +61,9 @@ public class DefaultMessageAggregatorIntegrationTests {
this.input.send(new GenericMessage<>(i, headers));
}
Object payload = this.output.receive().getPayload();
assertThat(payload, is(instanceOf(List.class)));
assertTrue(payload + " doesn't contain all of {0,1,2,3,4}",
((List) payload).containsAll(Arrays.asList(0, 1, 2, 3, 4)));
assertThat(payload).isInstanceOf(List.class);
assertThat(((List) payload).containsAll(Arrays.asList(0, 1, 2, 3, 4)))
.as(payload + " doesn't contain all of {0,1,2,3,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,7 +16,7 @@
package org.springframework.integration.aggregator.integration;
import static org.junit.Assert.assertFalse;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.List;
@@ -58,7 +58,7 @@ public class MethodInvokingAggregatorReturningMessageTests {
List<String> payload = Collections.singletonList("test");
this.pojoInput.send(MessageBuilder.withPayload(payload).build());
Message<?> result = this.pojoOutput.receive();
assertFalse(Message.class.isAssignableFrom(result.getPayload().getClass()));
assertThat(Message.class.isAssignableFrom(result.getPayload().getClass())).isFalse();
}
@Test
@@ -66,7 +66,7 @@ public class MethodInvokingAggregatorReturningMessageTests {
List<String> payload = Collections.singletonList("test");
this.defaultInput.send(MessageBuilder.withPayload(payload).build());
Message<?> result = this.defaultOutput.receive();
assertFalse(Message.class.isAssignableFrom(result.getPayload().getClass()));
assertThat(Message.class.isAssignableFrom(result.getPayload().getClass())).isFalse();
}

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,11 +16,7 @@
package org.springframework.integration.aggregator.integration;
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 org.junit.Test;
import org.junit.runner.RunWith;
@@ -77,45 +73,45 @@ public class ResequencerIntegrationTests {
Message<?> message6 = MessageBuilder.withPayload("6").setCorrelationId("A").setSequenceNumber(6).build();
inputChannel.send(message3);
assertNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNull();
inputChannel.send(message1);
message1 = outputChannel.receive(0);
assertNotNull(message1);
assertEquals(1, new IntegrationMessageHeaderAccessor(message1).getSequenceNumber());
assertFalse(message1.getHeaders().containsKey("foo"));
assertThat(message1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(message1).getSequenceNumber()).isEqualTo(1);
assertThat(message1.getHeaders().containsKey("foo")).isFalse();
inputChannel.send(message2);
message2 = outputChannel.receive(0);
message3 = outputChannel.receive(0);
assertNotNull(message2);
assertNotNull(message3);
assertEquals(2, new IntegrationMessageHeaderAccessor(message2).getSequenceNumber());
assertTrue(message2.getHeaders().containsKey("foo"));
assertEquals(3, new IntegrationMessageHeaderAccessor(message3).getSequenceNumber());
assertFalse(message3.getHeaders().containsKey("foo"));
assertThat(message2).isNotNull();
assertThat(message3).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(message2).getSequenceNumber()).isEqualTo(2);
assertThat(message2.getHeaders().containsKey("foo")).isTrue();
assertThat(new IntegrationMessageHeaderAccessor(message3).getSequenceNumber()).isEqualTo(3);
assertThat(message3.getHeaders().containsKey("foo")).isFalse();
inputChannel.send(message5);
assertNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNull();
inputChannel.send(message6);
assertNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNull();
inputChannel.send(message4);
message4 = outputChannel.receive(0);
message5 = outputChannel.receive(0);
message6 = outputChannel.receive(0);
assertNotNull(message4);
assertNotNull(message5);
assertNotNull(message6);
assertEquals(4, new IntegrationMessageHeaderAccessor(message4).getSequenceNumber());
assertTrue(message4.getHeaders().containsKey("foo"));
assertEquals(5, new IntegrationMessageHeaderAccessor(message5).getSequenceNumber());
assertFalse(message5.getHeaders().containsKey("foo"));
assertEquals(6, new IntegrationMessageHeaderAccessor(message6).getSequenceNumber());
assertFalse(message6.getHeaders().containsKey("foo"));
assertThat(message4).isNotNull();
assertThat(message5).isNotNull();
assertThat(message6).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(message4).getSequenceNumber()).isEqualTo(4);
assertThat(message4.getHeaders().containsKey("foo")).isTrue();
assertThat(new IntegrationMessageHeaderAccessor(message5).getSequenceNumber()).isEqualTo(5);
assertThat(message5.getHeaders().containsKey("foo")).isFalse();
assertThat(new IntegrationMessageHeaderAccessor(message6).getSequenceNumber()).isEqualTo(6);
assertThat(message6.getHeaders().containsKey("foo")).isFalse();
assertEquals(0, store.getMessageGroup("A").getMessages().size());
assertThat(store.getMessageGroup("A").getMessages().size()).isEqualTo(0);
}
@Test
@@ -131,13 +127,13 @@ public class ResequencerIntegrationTests {
Message<?> message3 = MessageBuilder.withPayload("3").setCorrelationId("A").setSequenceNumber(3).build();
inputChannel.send(message3);
assertNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNull();
inputChannel.send(message1);
assertNotNull(outputChannel.receive(0));
assertThat(outputChannel.receive(0)).isNotNull();
inputChannel.send(message2);
assertNotNull(outputChannel.receive(0));
assertNotNull(outputChannel.receive(0));
assertEquals(0, store.getMessageGroup("A").getMessages().size());
assertThat(outputChannel.receive(0)).isNotNull();
assertThat(outputChannel.receive(0)).isNotNull();
assertThat(store.getMessageGroup("A").getMessages().size()).isEqualTo(0);
}
@Test
@@ -147,8 +143,8 @@ public class ResequencerIntegrationTests {
Message<?> message1 = MessageBuilder.withPayload("1").setCorrelationId("A").setSequenceNumber(1).build();
inputChannel.send(message1);
message1 = outputChannel.receive(0);
assertNotNull(message1);
assertEquals(1, new IntegrationMessageHeaderAccessor(message1).getSequenceNumber());
assertThat(message1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(message1).getSequenceNumber()).isEqualTo(1);
}
}

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,11 @@
package org.springframework.integration.aggregator.scenarios;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -99,7 +100,7 @@ public class AggregationResendTests {
}
while (null != replyMessage);
Assert.assertEquals(1, messageCount);
assertThat(messageCount).isEqualTo(1);
}
}

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,7 @@
package org.springframework.integration.aggregator.scenarios;
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.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -73,15 +70,15 @@ public class AggregatorReplyChannelTests {
}
private void verifyReply(Message<?> message) {
assertNull(this.output.receive(0));
assertThat(this.output.receive(0)).isNull();
this.input.send(message);
Message<?> result = this.output.receive(0);
assertNotNull(result);
assertTrue(result.getPayload() instanceof List);
assertThat(result).isNotNull();
assertThat(result.getPayload() instanceof List).isTrue();
List<?> resultList = (List<?>) result.getPayload();
assertEquals(2, resultList.size());
assertTrue(resultList.contains("foo"));
assertTrue(resultList.contains("bar"));
assertThat(resultList.size()).isEqualTo(2);
assertThat(resultList.contains("foo")).isTrue();
assertThat(resultList.contains("bar")).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.aggregator.scenarios;
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.ExecutorService;
@@ -92,7 +91,8 @@ public class AggregatorWithCustomReleaseStrategyTests {
});
}
assertTrue("Sends failed to complete: " + latch.getCount() + " remain", latch.await(120, TimeUnit.SECONDS));
assertThat(latch.await(120, TimeUnit.SECONDS)).as("Sends failed to complete: " + latch.getCount() + " remain")
.isTrue();
Message<?> message = resultChannel.receive(1000);
int counter = 0;
@@ -100,7 +100,7 @@ public class AggregatorWithCustomReleaseStrategyTests {
counter++;
message = resultChannel.receive(1000);
}
assertEquals(600, counter);
assertThat(counter).isEqualTo(600);
context.close();
}
@@ -127,14 +127,15 @@ public class AggregatorWithCustomReleaseStrategyTests {
});
}
assertTrue("Sends failed to complete: " + latch.getCount() + " remain", latch.await(60, TimeUnit.SECONDS));
assertThat(latch.await(60, TimeUnit.SECONDS)).as("Sends failed to complete: " + latch.getCount() + " remain")
.isTrue();
Message<?> message = resultChannel.receive(1000);
int counter = 0;
while (message != null && ++counter < 7200) {
message = resultChannel.receive(1000);
}
assertEquals(7200, counter);
assertThat(counter).isEqualTo(7200);
context.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,8 +16,7 @@
package org.springframework.integration.aggregator.scenarios;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.List;
@@ -55,16 +54,16 @@ public class NestedAggregationTests {
Arrays.asList("foo", "bar", "spam"),
Arrays.asList("bar", "foo")));
List<String> result = sendAndReceiveMessage(splitter, 2000, input);
assertNotNull("Expected result and got null", result);
assertEquals("[[foo, bar, spam], [bar, foo]]", result.toString());
assertThat(result).as("Expected result and got null").isNotNull();
assertThat(result.toString()).isEqualTo("[[foo, bar, spam], [bar, foo]]");
}
@Test
public void testAggregatorWithNestedRouter() {
Message<?> input = new GenericMessage<>(Arrays.asList("bar", "foo"));
List<String> result = sendAndReceiveMessage(router, 2000, input);
assertNotNull("Expected result and got null", result);
assertEquals("[[bar, foo], [bar, foo]]", result.toString());
assertThat(result).as("Expected result and got null").isNotNull();
assertThat(result.toString()).isEqualTo("[[bar, foo], [bar, foo]]");
}
private List<String> sendAndReceiveMessage(DirectChannel channel, int timeout, Message<?> input) {

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,7 @@
package org.springframework.integration.aggregator.scenarios;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
@@ -63,14 +61,14 @@ public class PartialSequencesWithGapsTests {
in.send(message(6, 6));
in.send(message(2, 6));
in.send(message(1, 6));
assertThat(new IntegrationMessageHeaderAccessor(received.poll()).getSequenceNumber(), is(1));
assertThat(new IntegrationMessageHeaderAccessor(received.poll()).getSequenceNumber(), is(2));
assertThat(new IntegrationMessageHeaderAccessor(received.poll()).getSequenceNumber()).isEqualTo(1);
assertThat(new IntegrationMessageHeaderAccessor(received.poll()).getSequenceNumber()).isEqualTo(2);
received.poll();
received.poll();
in.send(message(5, 6));
assertThat(received.poll(), is(nullValue()));
assertThat(received.poll()).isNull();
in.send(message(4, 6));
assertThat(received.poll(), is(nullValue()));
assertThat(received.poll()).isNull();
}
private Message<?> message(int sequenceNumber, int sequenceSize) {

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,8 @@
package org.springframework.integration.aop;
import org.junit.Assert;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -53,21 +54,21 @@ public class AnnotationConfigRegistrationTests {
@Test // INT-1200
public void verifyInterception() {
String name = this.testBean.setName("John", "Doe", 123);
Assert.assertNotNull(name);
assertThat(name).isNotNull();
Message<?> message = this.annotationConfigRegistrationTest.receive(0);
Assert.assertNotNull(message);
Assert.assertEquals("John DoeDoe", message.getPayload());
Assert.assertEquals(123, message.getHeaders().get("x"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("John DoeDoe");
assertThat(message.getHeaders().get("x")).isEqualTo(123);
}
@Test
public void defaultChannel() {
String result = this.testBean.exclaim("hello");
Assert.assertNotNull(result);
Assert.assertEquals("HELLO!!!", result);
assertThat(result).isNotNull();
assertThat(result).isEqualTo("HELLO!!!");
Message<?> message = this.defaultChannel.receive(0);
Assert.assertNotNull(message);
Assert.assertEquals("HELLO!!!", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("HELLO!!!");
}

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.aop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,32 +51,32 @@ public class MessagePublishingAnnotationUsageTests {
@Test
public void headerWithExplicitName() {
String name = this.testBean.defaultPayload("John", "Doe");
assertNotNull(name);
assertThat(name).isNotNull();
Message<?> message = this.channel.receive(1000);
assertNotNull(message);
assertEquals("John Doe", message.getPayload());
assertEquals("Doe", message.getHeaders().get("last"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("John Doe");
assertThat(message.getHeaders().get("last")).isEqualTo("Doe");
}
@Test
public void headerWithImplicitName() {
String name = this.testBean.defaultPayloadButExplicitAnnotation("John", "Doe");
assertNotNull(name);
assertThat(name).isNotNull();
Message<?> message = this.channel.receive(1000);
assertNotNull(message);
assertEquals("John Doe", message.getPayload());
assertEquals("Doe", message.getHeaders().get("lname"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("John Doe");
assertThat(message.getHeaders().get("lname")).isEqualTo("Doe");
}
@Test
public void payloadAsArgument() {
String name = this.testBean.argumentAsPayload("John", "Doe");
assertNotNull(name);
assertEquals("John Doe", name);
assertThat(name).isNotNull();
assertThat(name).isEqualTo("John Doe");
Message<?> message = this.channel.receive(1000);
assertNotNull(message);
assertEquals("John", message.getPayload());
assertEquals("Doe", message.getHeaders().get("lname"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("John");
assertThat(message.getHeaders().get("lname")).isEqualTo("Doe");
}

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.aop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Method;
import java.util.HashMap;
@@ -68,8 +67,8 @@ public class MessagePublishingInterceptorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("test-foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("test-foo");
}
@Test
@@ -96,10 +95,10 @@ public class MessagePublishingInterceptorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertEquals("foo", message.getHeaders().get("bar"));
assertEquals("oleg", message.getHeaders().get("name"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
assertThat(message.getHeaders().get("bar")).isEqualTo("foo");
assertThat(message.getHeaders().get("name")).isEqualTo("oleg");
}

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,8 @@
package org.springframework.integration.aop;
import org.junit.Assert;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,11 +47,11 @@ public class MessagePublishingInterceptorUsageTests {
@Test
public void demoMessagePublishingInterceptor() {
String name = this.testBean.setName("John", "Doe");
Assert.assertNotNull(name);
assertThat(name).isNotNull();
Message<?> message = this.channel.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals("John Doe", message.getPayload());
Assert.assertEquals("bar", message.getHeaders().get("foo"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("John Doe");
assertThat(message.getHeaders().get("foo")).isEqualTo("bar");
}

View File

@@ -16,10 +16,7 @@
package org.springframework.integration.aop;
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.assertj.core.api.Assertions.assertThat;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -52,8 +49,8 @@ public class MethodAnnotationPublisherMetadataSourceTests {
Method method = getMethod("methodWithChannelAndExplicitReturnAsPayload");
String channelName = source.getChannelName(method);
Expression payloadExpression = source.getExpressionForPayload(method);
assertEquals("foo", channelName);
assertEquals("#return", payloadExpression.getExpressionString());
assertThat(channelName).isEqualTo("foo");
assertThat(payloadExpression.getExpressionString()).isEqualTo("#return");
}
@Test
@@ -61,40 +58,40 @@ public class MethodAnnotationPublisherMetadataSourceTests {
Method method = getMethod("methodWithChannelAndEmptyPayloadAnnotation");
String channelName = source.getChannelName(method);
Expression payloadExpression = source.getExpressionForPayload(method);
assertEquals("foo", channelName);
assertEquals("#return", payloadExpression.getExpressionString());
assertThat(channelName).isEqualTo("foo");
assertThat(payloadExpression.getExpressionString()).isEqualTo("#return");
}
@Test
public void payloadButNoHeaders() {
Method method = getMethod("methodWithPayloadAnnotation", String.class, int.class);
String expressionString = source.getExpressionForPayload(method).getExpressionString();
assertEquals("testExpression1", expressionString);
assertThat(expressionString).isEqualTo("testExpression1");
Map<String, Expression> headerMap = source.getExpressionsForHeaders(method);
assertNotNull(headerMap);
assertEquals(0, headerMap.size());
assertThat(headerMap).isNotNull();
assertThat(headerMap.size()).isEqualTo(0);
}
@Test
public void payloadAndHeaders() {
Method method = getMethod("methodWithHeaderAnnotations", String.class, String.class, String.class);
String expressionString = source.getExpressionForPayload(method).getExpressionString();
assertEquals("testExpression2", expressionString);
assertThat(expressionString).isEqualTo("testExpression2");
Map<String, Expression> headerMap = source.getExpressionsForHeaders(method);
assertNotNull(headerMap);
assertEquals(2, headerMap.size());
assertEquals("#args[1]", headerMap.get("foo").getExpressionString());
assertEquals("#args[2]", headerMap.get("bar").getExpressionString());
assertThat(headerMap).isNotNull();
assertThat(headerMap.size()).isEqualTo(2);
assertThat(headerMap.get("foo").getExpressionString()).isEqualTo("#args[1]");
assertThat(headerMap.get("bar").getExpressionString()).isEqualTo("#args[2]");
}
@Test
public void expressionsAreConcurrentHashMap() {
assertThat("Expressions should be concurrent to allow startup",
ReflectionTestUtils.getField(source, "channels"), instanceOf(ConcurrentHashMap.class));
assertThat("Expressions should be concurrent to allow startup",
ReflectionTestUtils.getField(source, "payloadExpressions"), instanceOf(ConcurrentHashMap.class));
assertThat("Expressions should be concurrent to allow startup",
ReflectionTestUtils.getField(source, "headersExpressions"), instanceOf(ConcurrentHashMap.class));
assertThat(ReflectionTestUtils.getField(source, "channels"))
.as("Expressions should be concurrent to allow startup").isInstanceOf(ConcurrentHashMap.class);
assertThat(ReflectionTestUtils.getField(source, "payloadExpressions"))
.as("Expressions should be concurrent to allow startup").isInstanceOf(ConcurrentHashMap.class);
assertThat(ReflectionTestUtils.getField(source, "headersExpressions"))
.as("Expressions should be concurrent to allow startup").isInstanceOf(ConcurrentHashMap.class);
}
@Test
@@ -102,8 +99,8 @@ public class MethodAnnotationPublisherMetadataSourceTests {
Method method = getMethod("methodWithVoidReturnAndMethodNameAsPayload");
String channelName = source.getChannelName(method);
String payloadExpression = source.getExpressionForPayload(method).getExpressionString();
assertEquals("foo", channelName);
assertEquals("#method", payloadExpression);
assertThat(channelName).isEqualTo("foo");
assertThat(payloadExpression).isEqualTo("#method");
}
@Test(expected = IllegalArgumentException.class)
@@ -116,7 +113,7 @@ public class MethodAnnotationPublisherMetadataSourceTests {
public void voidReturnAndParameterPayloadAnnotation() {
Method method = getMethod("methodWithVoidReturnAndParameterPayloadAnnotation", String.class);
String payloadExpression = source.getExpressionForPayload(method).getExpressionString();
assertEquals("#args[0]", payloadExpression);
assertThat(payloadExpression).isEqualTo("#args[0]");
}
@Test(expected = IllegalArgumentException.class)
@@ -129,14 +126,14 @@ public class MethodAnnotationPublisherMetadataSourceTests {
public void explicitAnnotationAttributeOverride() {
Method method = getMethod("methodWithExplicitAnnotationAttributeOverride");
String channelName = source.getChannelName(method);
assertEquals("foo", channelName);
assertThat(channelName).isEqualTo("foo");
}
@Test
public void explicitAnnotationAttributeOverrideOnDeclaringClass() {
Method method = getMethodFromTestClass("methodWithAnnotationOnTheDeclaringClass");
String channelName = source.getChannelName(method);
assertEquals("bar", channelName);
assertThat(channelName).isEqualTo("bar");
}
private static Method getMethodFromTestClass(String name, Class<?>... params) {

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.aop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -60,8 +59,8 @@ public class PublisherAnnotationAdvisorTests {
TestVoidBean proxy = (TestVoidBean) pf.getProxy();
proxy.testVoidMethod("foo");
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -74,8 +73,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -88,8 +87,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -102,8 +101,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testMetaChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -116,8 +115,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testMetaChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -130,8 +129,8 @@ public class PublisherAnnotationAdvisorTests {
TestVoidBean proxy = (TestVoidBean) pf.getProxy();
proxy.testVoidMethod("foo");
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -144,8 +143,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -158,8 +157,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -172,8 +171,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testMetaChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
@Test
@@ -186,8 +185,8 @@ public class PublisherAnnotationAdvisorTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testMetaChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
}
interface TestBean {

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.aop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.After;
import org.junit.Before;
@@ -74,9 +73,9 @@ public class PublisherExpressionTests {
TestBean proxy = (TestBean) pf.getProxy();
proxy.test("123");
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("hellofoo", message.getPayload());
assertEquals("123", message.getHeaders().get("foo"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("hellofoo");
assertThat(message.getHeaders().get("foo")).isEqualTo("123");
}

View File

@@ -16,10 +16,7 @@
package org.springframework.integration.bus;
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.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.concurrent.CountDownLatch;
@@ -78,7 +75,7 @@ public class ApplicationContextMessageBusTests {
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
Message<?> result = targetChannel.receive(10000);
assertEquals("test", result.getPayload());
assertThat(result.getPayload()).isEqualTo("test");
context.close();
}
@@ -92,7 +89,7 @@ public class ApplicationContextMessageBusTests {
context.registerChannel("targetChannel", targetChannel);
context.refresh();
Message<?> result = targetChannel.receive(10);
assertNull(result);
assertThat(result).isNull();
context.close();
}
@@ -105,7 +102,7 @@ public class ApplicationContextMessageBusTests {
sourceChannel.send(new GenericMessage<>("test"));
PollableChannel targetChannel = (PollableChannel) context.getBean("targetChannel");
Message<?> result = targetChannel.receive(10000);
assertEquals("test", result.getPayload());
assertThat(result.getPayload()).isEqualTo("test");
context.close();
}
@@ -145,7 +142,7 @@ public class ApplicationContextMessageBusTests {
Message<?> message1 = outputChannel1.receive(10000);
Message<?> message2 = outputChannel2.receive(0);
context.close();
assertTrue("exactly one message should be null", message1 == null ^ message2 == null);
assertThat(message1 == null ^ message2 == null).as("exactly one message should be null").isTrue();
}
@Test
@@ -183,12 +180,12 @@ public class ApplicationContextMessageBusTests {
context.refresh();
inputChannel.send(new GenericMessage<String>("testing"));
latch.await(500, TimeUnit.MILLISECONDS);
assertEquals("both handlers should have been invoked", 0, latch.getCount());
assertThat(latch.getCount()).as("both handlers should have been invoked").isEqualTo(0);
Message<?> message1 = outputChannel1.receive(500);
Message<?> message2 = outputChannel2.receive(500);
context.close();
assertNotNull("both handlers should have replied to the message", message1);
assertNotNull("both handlers should have replied to the message", message2);
assertThat(message1).as("both handlers should have replied to the message").isNotNull();
assertThat(message2).as("both handlers should have replied to the message").isNotNull();
}
@Test
@@ -208,11 +205,11 @@ public class ApplicationContextMessageBusTests {
latch.await(2000, TimeUnit.MILLISECONDS);
Message<?> message = errorChannel.receive(5000);
context.close();
assertNull(outputChannel.receive(100));
assertNotNull("message should not be null", message);
assertTrue(message instanceof ErrorMessage);
assertThat(outputChannel.receive(100)).isNull();
assertThat(message).as("message should not be null").isNotNull();
assertThat(message instanceof ErrorMessage).isTrue();
Throwable exception = ((ErrorMessage) message).getPayload();
assertEquals("intentional test failure", exception.getCause().getMessage());
assertThat(exception.getCause().getMessage()).isEqualTo("intentional test failure");
}
@Test
@@ -235,7 +232,7 @@ public class ApplicationContextMessageBusTests {
context.refresh();
errorChannel.send(new ErrorMessage(new RuntimeException("test-exception")));
latch.await(1000, TimeUnit.MILLISECONDS);
assertEquals("handler should have received error message", 0, latch.getCount());
assertThat(latch.getCount()).as("handler should have received error message").isEqualTo(0);
context.close();
}

View File

@@ -16,7 +16,7 @@
package org.springframework.integration.bus;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.After;
import org.junit.Before;
@@ -73,7 +73,7 @@ public class DirectChannelSubscriptionTests {
context.refresh();
this.sourceChannel.send(new GenericMessage<>("foo"));
Message<?> response = this.targetChannel.receive();
assertEquals("foo!", response.getPayload());
assertThat(response.getPayload()).isEqualTo("foo!");
}
@Test
@@ -86,7 +86,7 @@ public class DirectChannelSubscriptionTests {
this.context.refresh();
this.sourceChannel.send(new GenericMessage<>("foo"));
Message<?> response = this.targetChannel.receive();
assertEquals("foo-from-annotated-endpoint", response.getPayload());
assertThat(response.getPayload()).isEqualTo("foo-from-annotated-endpoint");
}
@Test(expected = MessagingException.class)

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,8 +16,7 @@
package org.springframework.integration.channel;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@@ -61,23 +60,23 @@ public class CGLibProxyChannelTests {
@Test
public void testProxyDirect() {
assertTrue(AopUtils.isCglibProxy(this.directChannel));
assertThat(AopUtils.isCglibProxy(this.directChannel)).isTrue();
final AtomicReference<Message<?>> message = new AtomicReference<>();
this.directChannel.subscribe(m -> message.set(m));
this.directChannel.send(new GenericMessage<>("foo"));
assertNotNull(message.get());
assertThat(message.get()).isNotNull();
}
@Test
public void testProxyQueue() {
assertTrue(AopUtils.isCglibProxy(this.queueChannel));
assertThat(AopUtils.isCglibProxy(this.queueChannel)).isTrue();
this.queueChannel.send(new GenericMessage<>("foo"));
assertNotNull(this.queueChannel.receive(0));
assertThat(this.queueChannel.receive(0)).isNotNull();
}
@Test
public void testProxyExecutor() throws Exception {
assertTrue(AopUtils.isCglibProxy(this.executorChannel));
assertThat(AopUtils.isCglibProxy(this.executorChannel)).isTrue();
final AtomicReference<Message<?>> message = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
this.executorChannel.subscribe(m -> {
@@ -85,13 +84,13 @@ public class CGLibProxyChannelTests {
latch.countDown();
});
this.executorChannel.send(new GenericMessage<>("foo"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNotNull(message.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(message.get()).isNotNull();
}
@Test
public void testProxyPubSubWithExec() throws Exception {
assertTrue(AopUtils.isCglibProxy(this.publishSubscribeChannel));
assertThat(AopUtils.isCglibProxy(this.publishSubscribeChannel)).isTrue();
final AtomicReference<Message<?>> message = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
this.publishSubscribeChannel.subscribe(m -> {
@@ -99,8 +98,8 @@ public class CGLibProxyChannelTests {
latch.countDown();
});
this.publishSubscribeChannel.send(new GenericMessage<>("foo"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertNotNull(message.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(message.get()).isNotNull();
}
@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,9 +16,7 @@
package org.springframework.integration.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
@@ -40,8 +38,8 @@ public class ChannelPurgerTests {
channel.send(new GenericMessage<String>("test3"));
ChannelPurger purger = new ChannelPurger(channel);
List<Message<?>> purgedMessages = purger.purge();
assertEquals(3, purgedMessages.size());
assertNull(channel.receive(0));
assertThat(purgedMessages.size()).isEqualTo(3);
assertThat(channel.receive(0)).isNull();
}
@Test
@@ -52,8 +50,8 @@ public class ChannelPurgerTests {
channel.send(new GenericMessage<String>("test3"));
ChannelPurger purger = new ChannelPurger(message -> false, channel);
List<Message<?>> purgedMessages = purger.purge();
assertEquals(3, purgedMessages.size());
assertNull(channel.receive(0));
assertThat(purgedMessages.size()).isEqualTo(3);
assertThat(channel.receive(0)).isNull();
}
@Test
@@ -64,10 +62,10 @@ public class ChannelPurgerTests {
channel.send(new GenericMessage<String>("test3"));
ChannelPurger purger = new ChannelPurger(message -> true, channel);
List<Message<?>> purgedMessages = purger.purge();
assertEquals(0, purgedMessages.size());
assertNotNull(channel.receive(0));
assertNotNull(channel.receive(0));
assertNotNull(channel.receive(0));
assertThat(purgedMessages.size()).isEqualTo(0);
assertThat(channel.receive(0)).isNotNull();
assertThat(channel.receive(0)).isNotNull();
assertThat(channel.receive(0)).isNotNull();
}
@Test
@@ -78,11 +76,11 @@ public class ChannelPurgerTests {
channel.send(new GenericMessage<String>("test3"));
ChannelPurger purger = new ChannelPurger(message -> (message.getPayload().equals("test2")), channel);
List<Message<?>> purgedMessages = purger.purge();
assertEquals(2, purgedMessages.size());
assertThat(purgedMessages.size()).isEqualTo(2);
Message<?> message = channel.receive(0);
assertNotNull(message);
assertEquals("test2", message.getPayload());
assertNull(channel.receive(0));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("test2");
assertThat(channel.receive(0)).isNull();
}
@Test
@@ -95,9 +93,9 @@ public class ChannelPurgerTests {
channel2.send(new GenericMessage<String>("test2"));
ChannelPurger purger = new ChannelPurger(channel1, channel2);
List<Message<?>> purgedMessages = purger.purge();
assertEquals(4, purgedMessages.size());
assertNull(channel1.receive(0));
assertNull(channel2.receive(0));
assertThat(purgedMessages.size()).isEqualTo(4);
assertThat(channel1.receive(0)).isNull();
assertThat(channel2.receive(0)).isNull();
}
@Test
@@ -112,15 +110,15 @@ public class ChannelPurgerTests {
channel2.send(new GenericMessage<String>("test3"));
ChannelPurger purger = new ChannelPurger(message -> (message.getPayload().equals("test2")), channel1, channel2);
List<Message<?>> purgedMessages = purger.purge();
assertEquals(4, purgedMessages.size());
assertThat(purgedMessages.size()).isEqualTo(4);
Message<?> message1 = channel1.receive(0);
assertNotNull(message1);
assertEquals("test2", message1.getPayload());
assertNull(channel1.receive(0));
assertThat(message1).isNotNull();
assertThat(message1.getPayload()).isEqualTo("test2");
assertThat(channel1.receive(0)).isNull();
Message<?> message2 = channel2.receive(0);
assertNotNull(message2);
assertEquals("test2", message2.getPayload());
assertNull(channel2.receive(0));
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("test2");
assertThat(channel2.receive(0)).isNull();
}
@Test
@@ -133,11 +131,11 @@ public class ChannelPurgerTests {
channel2.send(new GenericMessage<String>("test2"));
ChannelPurger purger = new ChannelPurger(message -> true, channel1, channel2);
List<Message<?>> purgedMessages = purger.purge();
assertEquals(0, purgedMessages.size());
assertNotNull(channel1.receive(0));
assertNotNull(channel1.receive(0));
assertNotNull(channel2.receive(0));
assertNotNull(channel2.receive(0));
assertThat(purgedMessages.size()).isEqualTo(0);
assertThat(channel1.receive(0)).isNotNull();
assertThat(channel1.receive(0)).isNotNull();
assertThat(channel2.receive(0)).isNotNull();
assertThat(channel2.receive(0)).isNotNull();
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.channel;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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.Collections;
import java.util.Date;
@@ -63,7 +58,7 @@ public class DatatypeChannelTests {
@Test
public void supportedType() {
MessageChannel channel = createChannel(String.class);
assertTrue(channel.send(new GenericMessage<String>("test")));
assertThat(channel.send(new GenericMessage<String>("test"))).isTrue();
}
@Test(expected = MessageDeliveryException.class)
@@ -79,7 +74,7 @@ public class DatatypeChannelTests {
DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
converter.setConversionService(conversionService);
channel.setMessageConverter(converter);
assertTrue(channel.send(new GenericMessage<String>("123")));
assertThat(channel.send(new GenericMessage<String>("123"))).isTrue();
}
@Test(expected = MessageDeliveryException.class)
@@ -89,7 +84,7 @@ public class DatatypeChannelTests {
DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
converter.setConversionService(conversionService);
channel.setMessageConverter(converter);
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
assertThat(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))).isTrue();
}
@Test
@@ -105,8 +100,8 @@ public class DatatypeChannelTests {
DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
converter.setConversionService(conversionService);
channel.setMessageConverter(converter);
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
assertEquals(1, channel.receive().getPayload());
assertThat(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))).isTrue();
assertThat(channel.receive().getPayload()).isEqualTo(1);
}
@Test
@@ -135,10 +130,10 @@ public class DatatypeChannelTests {
context.refresh();
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
assertSame(context.getBean(ConversionService.class),
TestUtils.getPropertyValue(channel, "messageConverter.conversionService"));
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
assertEquals(1, channel.receive().getPayload());
assertThat(TestUtils.getPropertyValue(channel, "messageConverter.conversionService"))
.isSameAs(context.getBean(ConversionService.class));
assertThat(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))).isTrue();
assertThat(channel.receive().getPayload()).isEqualTo(1);
context.close();
}
@@ -174,16 +169,16 @@ public class DatatypeChannelTests {
context.refresh();
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
assertEquals(99, channel.receive().getPayload());
assertThat(channel.send(new GenericMessage<Boolean>(Boolean.TRUE))).isTrue();
assertThat(channel.receive().getPayload()).isEqualTo(99);
context.close();
}
@Test
public void multipleTypes() {
MessageChannel channel = createChannel(String.class, Integer.class);
assertTrue(channel.send(new GenericMessage<String>("test1")));
assertTrue(channel.send(new GenericMessage<Integer>(2)));
assertThat(channel.send(new GenericMessage<String>("test1"))).isTrue();
assertThat(channel.send(new GenericMessage<Integer>(2))).isTrue();
Exception exception = null;
try {
channel.send(new GenericMessage<Date>(new Date()));
@@ -191,13 +186,13 @@ public class DatatypeChannelTests {
catch (MessageDeliveryException e) {
exception = e;
}
assertNotNull(exception);
assertThat(exception).isNotNull();
}
@Test
public void subclassOfAcceptedType() {
MessageChannel channel = createChannel(RuntimeException.class);
assertTrue(channel.send(new ErrorMessage(new MessagingException("test"))));
assertThat(channel.send(new ErrorMessage(new MessagingException("test")))).isTrue();
}
@Test(expected = MessageDeliveryException.class)
@@ -215,12 +210,12 @@ public class DatatypeChannelTests {
DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
converter.setConversionService(conversionService);
channel.setMessageConverter(converter);
assertTrue(channel.send(new GenericMessage<String>("foo")));
assertThat(channel.send(new GenericMessage<String>("foo"))).isTrue();
Message<?> out = channel.receive(0);
assertThat(out.getPayload(), instanceOf(Bar.class));
assertTrue(channel.send(new GenericMessage<Integer>(42)));
assertThat(out.getPayload()).isInstanceOf(Bar.class);
assertThat(channel.send(new GenericMessage<Integer>(42))).isTrue();
out = channel.receive(0);
assertThat(out.getPayload(), instanceOf(Baz.class));
assertThat(out.getPayload()).isInstanceOf(Baz.class);
}

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.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -37,9 +36,10 @@ public class DirectChannelParserTests {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"directChannelParserTests.xml", DirectChannelParserTests.class);
Object channel = context.getBean("channel");
assertEquals(DirectChannel.class, channel.getClass());
assertThat(channel.getClass()).isEqualTo(DirectChannel.class);
DirectFieldAccessor dcAccessor = new DirectFieldAccessor(((DirectChannel) channel).getDispatcher());
assertTrue(dcAccessor.getPropertyValue("loadBalancingStrategy") instanceof RoundRobinLoadBalancingStrategy);
assertThat(dcAccessor.getPropertyValue("loadBalancingStrategy") instanceof RoundRobinLoadBalancingStrategy)
.isTrue();
context.close();
}

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.channel;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -64,19 +60,19 @@ public class DirectChannelTests {
ThreadNameExtractingTestTarget target = new ThreadNameExtractingTestTarget();
channel.subscribe(target);
GenericMessage<String> message = new GenericMessage<String>("test");
assertTrue(channel.send(message));
assertEquals(Thread.currentThread().getName(), target.threadName);
assertThat(channel.send(message)).isTrue();
assertThat(target.threadName).isEqualTo(Thread.currentThread().getName());
DirectFieldAccessor channelAccessor = new DirectFieldAccessor(channel);
UnicastingDispatcher dispatcher = (UnicastingDispatcher) channelAccessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
Object loadBalancingStrategy = dispatcherAccessor.getPropertyValue("loadBalancingStrategy");
assertTrue(loadBalancingStrategy instanceof RoundRobinLoadBalancingStrategy);
assertThat(loadBalancingStrategy instanceof RoundRobinLoadBalancingStrategy).isTrue();
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(2)).debug(captor.capture());
List<String> logs = captor.getAllValues();
assertEquals(2, logs.size());
assertThat(logs.get(0), startsWith("preSend"));
assertThat(logs.get(1), startsWith("postSend"));
assertThat(logs.size()).isEqualTo(2);
assertThat(logs.get(0)).startsWith("preSend");
assertThat(logs.get(1)).startsWith("postSend");
}
@Test
@@ -94,7 +90,7 @@ public class DirectChannelTests {
final AtomicInteger count = new AtomicInteger();
channel.subscribe(message -> count.incrementAndGet());
GenericMessage<String> message = new GenericMessage<String>("test");
assertTrue(channel.send(message));
assertThat(channel.send(message)).isTrue();
for (int i = 0; i < 10000000; i++) {
channel.send(message);
}
@@ -115,12 +111,12 @@ public class DirectChannelTests {
channel.subscribe(message -> count1.incrementAndGet());
channel.subscribe(message -> count2.getAndIncrement());
GenericMessage<String> message = new GenericMessage<String>("test");
assertTrue(channel.send(message));
assertThat(channel.send(message)).isTrue();
for (int i = 0; i < 10000000; i++) {
channel.send(message);
}
assertEquals(5000001, count1.get());
assertEquals(5000000, count2.get());
assertThat(count1.get()).isEqualTo(5000001);
assertThat(count2.get()).isEqualTo(5000000);
}
@Test
@@ -135,7 +131,7 @@ public class DirectChannelTests {
final AtomicInteger count = new AtomicInteger();
FixedSubscriberChannel channel = new FixedSubscriberChannel(message -> count.incrementAndGet());
GenericMessage<String> message = new GenericMessage<String>("test");
assertTrue(channel.send(message));
assertThat(channel.send(message)).isTrue();
for (int i = 0; i < 100000000; i++) {
channel.send(message, 0);
}
@@ -150,7 +146,7 @@ public class DirectChannelTests {
final GenericMessage<String> message = new GenericMessage<String>("test");
new Thread((Runnable) () -> channel.send(message), "test-thread").start();
latch.await(1000, TimeUnit.MILLISECONDS);
assertEquals("test-thread", target.threadName);
assertThat(target.threadName).isEqualTo("test-thread");
}
@Test // See INT-2434
@@ -166,40 +162,43 @@ public class DirectChannelTests {
Method method = ReflectionUtils.findMethod(ClassPathXmlApplicationContext.class, "obtainFreshBeanFactory");
method.setAccessible(true);
method.invoke(context);
assertFalse(context.containsBean("channelA"));
assertFalse(context.containsBean("channelB"));
assertTrue(context.containsBean("channelC"));
assertTrue(context.containsBean("channelD"));
assertThat(context.containsBean("channelA")).isFalse();
assertThat(context.containsBean("channelB")).isFalse();
assertThat(context.containsBean("channelC")).isTrue();
assertThat(context.containsBean("channelD")).isTrue();
context.refresh();
PublishSubscribeChannel channelEarly = context.getBean("channelEarly", PublishSubscribeChannel.class);
assertTrue(context.containsBean("channelA"));
assertTrue(context.containsBean("channelB"));
assertTrue(context.containsBean("channelC"));
assertTrue(context.containsBean("channelD"));
assertThat(context.containsBean("channelA")).isTrue();
assertThat(context.containsBean("channelB")).isTrue();
assertThat(context.containsBean("channelC")).isTrue();
assertThat(context.containsBean("channelD")).isTrue();
EventDrivenConsumer consumerA = context.getBean("serviceA", EventDrivenConsumer.class);
assertEquals(context.getBean("channelA"), TestUtils.getPropertyValue(consumerA, "inputChannel"));
assertEquals(context.getBean("channelB"), TestUtils.getPropertyValue(consumerA, "handler.outputChannel"));
assertThat(TestUtils.getPropertyValue(consumerA, "inputChannel")).isEqualTo(context.getBean("channelA"));
assertThat(TestUtils.getPropertyValue(consumerA, "handler.outputChannel"))
.isEqualTo(context.getBean("channelB"));
EventDrivenConsumer consumerB = context.getBean("serviceB", EventDrivenConsumer.class);
assertEquals(context.getBean("channelB"), TestUtils.getPropertyValue(consumerB, "inputChannel"));
assertEquals(context.getBean("channelC"), TestUtils.getPropertyValue(consumerB, "handler.outputChannel"));
assertThat(TestUtils.getPropertyValue(consumerB, "inputChannel")).isEqualTo(context.getBean("channelB"));
assertThat(TestUtils.getPropertyValue(consumerB, "handler.outputChannel"))
.isEqualTo(context.getBean("channelC"));
EventDrivenConsumer consumerC = context.getBean("serviceC", EventDrivenConsumer.class);
assertEquals(context.getBean("channelC"), TestUtils.getPropertyValue(consumerC, "inputChannel"));
assertEquals(context.getBean("channelD"), TestUtils.getPropertyValue(consumerC, "handler.outputChannel"));
assertThat(TestUtils.getPropertyValue(consumerC, "inputChannel")).isEqualTo(context.getBean("channelC"));
assertThat(TestUtils.getPropertyValue(consumerC, "handler.outputChannel"))
.isEqualTo(context.getBean("channelD"));
EventDrivenConsumer consumerD = context.getBean("serviceD", EventDrivenConsumer.class);
assertEquals(parentChannelA, TestUtils.getPropertyValue(consumerD, "inputChannel"));
assertEquals(parentChannelB, TestUtils.getPropertyValue(consumerD, "handler.outputChannel"));
assertThat(TestUtils.getPropertyValue(consumerD, "inputChannel")).isEqualTo(parentChannelA);
assertThat(TestUtils.getPropertyValue(consumerD, "handler.outputChannel")).isEqualTo(parentChannelB);
EventDrivenConsumer consumerE = context.getBean("serviceE", EventDrivenConsumer.class);
assertEquals(parentChannelB, TestUtils.getPropertyValue(consumerE, "inputChannel"));
assertThat(TestUtils.getPropertyValue(consumerE, "inputChannel")).isEqualTo(parentChannelB);
EventDrivenConsumer consumerF = context.getBean("serviceF", EventDrivenConsumer.class);
assertEquals(channelEarly, TestUtils.getPropertyValue(consumerF, "inputChannel"));
assertThat(TestUtils.getPropertyValue(consumerF, "inputChannel")).isEqualTo(channelEarly);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.channel;
import static org.hamcrest.Matchers.containsString;
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.Before;
import org.junit.Test;
@@ -63,8 +62,8 @@ public class DispatcherHasNoSubscribersTests {
fail("Exception expected");
}
catch (MessagingException e) {
assertThat(e.getMessage(),
containsString("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'."));
assertThat(e.getMessage())
.contains("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'.");
}
}
@@ -75,8 +74,8 @@ public class DispatcherHasNoSubscribersTests {
fail("Exception expected");
}
catch (MessagingException e) {
assertThat(e.getMessage(),
containsString("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'."));
assertThat(e.getMessage())
.contains("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'.");
}
}
@@ -89,8 +88,7 @@ public class DispatcherHasNoSubscribersTests {
fail("Exception expected");
}
catch (MessagingException e) {
assertThat(e.getMessage(),
containsString("Dispatcher has no subscribers for channel 'bar'."));
assertThat(e.getMessage()).contains("Dispatcher has no subscribers for channel 'bar'.");
}
}

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,7 @@
package org.springframework.integration.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -76,11 +74,11 @@ public class DispatchingChannelErrorHandlingTests {
channel.send(message);
this.waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessagingException.class, errorMessage.getPayload().getClass());
assertThat(errorMessage.getPayload().getClass()).isEqualTo(MessagingException.class);
MessagingException exceptionPayload = (MessagingException) errorMessage.getPayload();
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertSame(message, exceptionPayload.getFailedMessage());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
assertThat(exceptionPayload.getCause().getClass()).isEqualTo(UnsupportedOperationException.class);
assertThat(exceptionPayload.getFailedMessage()).isSameAs(message);
assertThat(resultHandler.lastThread).isNotSameAs(Thread.currentThread());
}
@Test
@@ -105,11 +103,11 @@ public class DispatchingChannelErrorHandlingTests {
channel.send(message);
this.waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessagingException.class, errorMessage.getPayload().getClass());
assertThat(errorMessage.getPayload().getClass()).isEqualTo(MessagingException.class);
MessagingException exceptionPayload = (MessagingException) errorMessage.getPayload();
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertSame(message, exceptionPayload.getFailedMessage());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
assertThat(exceptionPayload.getCause().getClass()).isEqualTo(UnsupportedOperationException.class);
assertThat(exceptionPayload.getFailedMessage()).isSameAs(message);
assertThat(resultHandler.lastThread).isNotSameAs(Thread.currentThread());
}

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.channel;
import static org.hamcrest.Matchers.equalTo;
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.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.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -65,12 +58,12 @@ public class ExecutorChannelTests {
CountDownLatch latch = new CountDownLatch(1);
TestHandler handler = new TestHandler(latch);
channel.subscribe(handler);
channel.send(new GenericMessage<String>("test"));
channel.send(new GenericMessage<>("test"));
latch.await(1000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertNotNull(handler.thread);
assertFalse(Thread.currentThread().equals(handler.thread));
assertEquals("test-1", handler.thread.getName());
assertThat(latch.getCount()).isEqualTo(0);
assertThat(handler.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler.thread)).isFalse();
assertThat(handler.thread.getName()).isEqualTo("test-1");
}
@Test
@@ -89,22 +82,22 @@ public class ExecutorChannelTests {
channel.subscribe(handler2);
channel.subscribe(handler3);
for (int i = 0; i < numberOfMessages; i++) {
channel.send(new GenericMessage<String>("test-" + i));
channel.send(new GenericMessage<>("test-" + i));
}
latch.await(3000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertNotNull(handler1.thread);
assertFalse(Thread.currentThread().equals(handler1.thread));
assertTrue(handler1.thread.getName().startsWith("test-"));
assertNotNull(handler2.thread);
assertFalse(Thread.currentThread().equals(handler2.thread));
assertTrue(handler2.thread.getName().startsWith("test-"));
assertNotNull(handler3.thread);
assertFalse(Thread.currentThread().equals(handler3.thread));
assertTrue(handler3.thread.getName().startsWith("test-"));
assertEquals(4, handler1.count.get());
assertEquals(4, handler2.count.get());
assertEquals(3, handler3.count.get());
assertThat(latch.getCount()).isEqualTo(0);
assertThat(handler1.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler1.thread)).isFalse();
assertThat(handler1.thread.getName().startsWith("test-")).isTrue();
assertThat(handler2.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler2.thread)).isFalse();
assertThat(handler2.thread.getName().startsWith("test-")).isTrue();
assertThat(handler3.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler3.thread)).isFalse();
assertThat(handler3.thread.getName().startsWith("test-")).isTrue();
assertThat(handler1.count.get()).isEqualTo(4);
assertThat(handler2.count.get()).isEqualTo(4);
assertThat(handler3.count.get()).isEqualTo(3);
exec.shutdownNow();
}
@@ -125,22 +118,22 @@ public class ExecutorChannelTests {
channel.subscribe(handler3);
handler2.shouldFail = true;
for (int i = 0; i < numberOfMessages; i++) {
channel.send(new GenericMessage<String>("test-" + i));
channel.send(new GenericMessage<>("test-" + i));
}
latch.await(3000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertNotNull(handler1.thread);
assertFalse(Thread.currentThread().equals(handler1.thread));
assertTrue(handler1.thread.getName().startsWith("test-"));
assertNotNull(handler2.thread);
assertFalse(Thread.currentThread().equals(handler2.thread));
assertTrue(handler2.thread.getName().startsWith("test-"));
assertNotNull(handler3.thread);
assertFalse(Thread.currentThread().equals(handler3.thread));
assertTrue(handler3.thread.getName().startsWith("test-"));
assertEquals(0, handler2.count.get());
assertEquals(4, handler1.count.get());
assertEquals(7, handler3.count.get());
assertThat(latch.getCount()).isEqualTo(0);
assertThat(handler1.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler1.thread)).isFalse();
assertThat(handler1.thread.getName().startsWith("test-")).isTrue();
assertThat(handler2.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler2.thread)).isFalse();
assertThat(handler2.thread.getName().startsWith("test-")).isTrue();
assertThat(handler3.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler3.thread)).isFalse();
assertThat(handler3.thread.getName().startsWith("test-")).isTrue();
assertThat(handler2.count.get()).isEqualTo(0);
assertThat(handler1.count.get()).isEqualTo(4);
assertThat(handler3.count.get()).isEqualTo(7);
exec.shutdownNow();
}
@@ -160,20 +153,20 @@ public class ExecutorChannelTests {
channel.subscribe(handler3);
handler1.shouldFail = true;
for (int i = 0; i < numberOfMessages; i++) {
channel.send(new GenericMessage<String>("test-" + i));
channel.send(new GenericMessage<>("test-" + i));
}
latch.await(3000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertNotNull(handler1.thread);
assertFalse(Thread.currentThread().equals(handler1.thread));
assertTrue(handler1.thread.getName().startsWith("test-"));
assertNotNull(handler2.thread);
assertFalse(Thread.currentThread().equals(handler2.thread));
assertTrue(handler2.thread.getName().startsWith("test-"));
assertNull(handler3.thread);
assertEquals(0, handler1.count.get());
assertEquals(0, handler3.count.get());
assertEquals(numberOfMessages, handler2.count.get());
assertThat(latch.getCount()).isEqualTo(0);
assertThat(handler1.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler1.thread)).isFalse();
assertThat(handler1.thread.getName().startsWith("test-")).isTrue();
assertThat(handler2.thread).isNotNull();
assertThat(Thread.currentThread().equals(handler2.thread)).isFalse();
assertThat(handler2.thread.getName().startsWith("test-")).isTrue();
assertThat(handler3.thread).isNull();
assertThat(handler1.count.get()).isEqualTo(0);
assertThat(handler3.count.get()).isEqualTo(0);
assertThat(handler2.count.get()).isEqualTo(numberOfMessages);
exec.shutdownNow();
}
@@ -191,8 +184,8 @@ public class ExecutorChannelTests {
channel.subscribe(handler);
channel.send(new GenericMessage<Object>("foo"));
verify(handler).handleMessage(expected);
assertEquals(1, interceptor.getCounter().get());
assertTrue(interceptor.wasAfterHandledInvoked());
assertThat(interceptor.getCounter().get()).isEqualTo(1);
assertThat(interceptor.wasAfterHandledInvoked()).isTrue();
}
@Test
@@ -201,7 +194,7 @@ public class ExecutorChannelTests {
channel.setBeanFactory(mock(BeanFactory.class));
channel.afterPropertiesSet();
Message<Object> message = new GenericMessage<Object>("foo");
Message<Object> message = new GenericMessage<>("foo");
MessageHandler handler = mock(MessageHandler.class);
IllegalStateException expected = new IllegalStateException("Fake exception");
@@ -213,25 +206,26 @@ public class ExecutorChannelTests {
channel.send(message);
}
catch (MessageDeliveryException actual) {
assertSame(expected, actual.getCause());
assertThat(actual.getCause()).isSameAs(expected);
}
verify(handler).handleMessage(message);
assertEquals(1, interceptor.getCounter().get());
assertTrue(interceptor.wasAfterHandledInvoked());
assertThat(interceptor.getCounter().get()).isEqualTo(1);
assertThat(interceptor.wasAfterHandledInvoked()).isTrue();
}
@Test
public void testEarlySubscribe() {
ExecutorChannel channel = new ExecutorChannel(mock(Executor.class));
try {
channel.subscribe(m -> { });
channel.subscribe(m -> {
});
channel.setBeanFactory(mock(BeanFactory.class));
channel.afterPropertiesSet();
fail("expected Exception");
}
catch (IllegalStateException e) {
assertThat(e.getMessage(), equalTo("You cannot subscribe() until the channel "
+ "bean is fully initialized by the framework. Do not subscribe in a @Bean definition"));
assertThat(e.getMessage()).isEqualTo("You cannot subscribe() until the channel "
+ "bean is fully initialized by the framework. Do not subscribe in a @Bean definition");
}
}
@@ -259,6 +253,7 @@ public class ExecutorChannelTests {
this.count.incrementAndGet();
this.latch.countDown();
}
}
private static class BeforeHandleInterceptor implements ExecutorChannelInterceptor {
@@ -287,14 +282,15 @@ public class ExecutorChannelTests {
@Override
public Message<?> beforeHandle(Message<?> message, MessageChannel channel, MessageHandler handler) {
assertNotNull(message);
assertThat(message).isNotNull();
this.counter.incrementAndGet();
return (this.messageToReturn != null ? this.messageToReturn : message);
}
@Override
public void afterMessageHandled(Message<?> message, MessageChannel channel, MessageHandler handler,
Exception ex) {
Exception ex) {
this.afterHandledInvoked = true;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 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,12 +16,9 @@
package org.springframework.integration.channel;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
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.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,8 +54,8 @@ public class FixedSubscriberChannelTests {
public void testHappyDay() {
this.in.send(new GenericMessage<String>("foo"));
Message<?> out = this.out.receive(0);
assertEquals("FOO", out.getPayload());
assertThat(this.in, instanceOf(FixedSubscriberChannel.class));
assertThat(out.getPayload()).isEqualTo("FOO");
assertThat(this.in).isInstanceOf(FixedSubscriberChannel.class);
}
@Test
@@ -70,10 +67,10 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(BeanCreationException.class));
assertThat(e.getCause(), instanceOf(BeanInstantiationException.class));
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
assertThat(e.getCause().getCause().getMessage(), Matchers.containsString("Cannot instantiate a"));
assertThat(e).isInstanceOf(BeanCreationException.class);
assertThat(e.getCause()).isInstanceOf(BeanInstantiationException.class);
assertThat(e.getCause().getCause()).isInstanceOf(IllegalArgumentException.class);
assertThat(e.getCause().getCause().getMessage()).contains("Cannot instantiate a");
}
if (context != null) {
context.close();
@@ -89,8 +86,8 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(BeanDefinitionParsingException.class));
assertThat(e.getMessage(), Matchers.containsString("Only one subscriber is allowed for a FixedSubscriberChannel."));
assertThat(e).isInstanceOf(BeanDefinitionParsingException.class);
assertThat(e.getMessage()).contains("Only one subscriber is allowed for a FixedSubscriberChannel.");
}
if (context != null) {
context.close();
@@ -106,8 +103,8 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), Matchers.containsString("Only one subscriber is allowed for a FixedSubscriberChannel."));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
assertThat(e.getMessage()).contains("Only one subscriber is allowed for a FixedSubscriberChannel.");
}
if (context != null) {
context.close();
@@ -123,8 +120,8 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(BeanDefinitionParsingException.class));
assertThat(e.getMessage(), Matchers.containsString("Cannot have interceptors when 'fixed-subscriber=\"true\"'"));
assertThat(e).isInstanceOf(BeanDefinitionParsingException.class);
assertThat(e.getMessage()).contains("Cannot have interceptors when 'fixed-subscriber=\"true\"'");
}
if (context != null) {
context.close();
@@ -140,8 +137,8 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(BeanDefinitionParsingException.class));
assertThat(e.getMessage(), Matchers.containsString("Cannot have 'datatype' when 'fixed-subscriber=\"true\"'"));
assertThat(e).isInstanceOf(BeanDefinitionParsingException.class);
assertThat(e.getMessage()).contains("Cannot have 'datatype' when 'fixed-subscriber=\"true\"'");
}
if (context != null) {
context.close();
@@ -157,8 +154,8 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(BeanDefinitionParsingException.class));
assertThat(e.getMessage(), Matchers.containsString("Cannot have 'message-converter' when 'fixed-subscriber=\"true\"'"));
assertThat(e).isInstanceOf(BeanDefinitionParsingException.class);
assertThat(e.getMessage()).contains("Cannot have 'message-converter' when 'fixed-subscriber=\"true\"'");
}
if (context != null) {
context.close();
@@ -174,8 +171,9 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(BeanDefinitionParsingException.class));
assertThat(e.getMessage(), Matchers.containsString("The 'fixed-subscriber' attribute is not allowed when a <queue/> child element is present."));
assertThat(e).isInstanceOf(BeanDefinitionParsingException.class);
assertThat(e.getMessage())
.contains("The 'fixed-subscriber' attribute is not allowed when a <queue/> child element is present.");
}
if (context != null) {
context.close();
@@ -191,8 +189,9 @@ public class FixedSubscriberChannelTests {
fail("Expected exception");
}
catch (Exception e) {
assertThat(e, instanceOf(BeanDefinitionParsingException.class));
assertThat(e.getMessage(), Matchers.containsString("The 'fixed-subscriber' attribute is not allowed when a <dispatcher/> child element is present."));
assertThat(e).isInstanceOf(BeanDefinitionParsingException.class);
assertThat(e.getMessage())
.contains("The 'fixed-subscriber' attribute is not allowed when a <dispatcher/> child element is present.");
}
if (context != null) {
context.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,8 +16,7 @@
package org.springframework.integration.channel;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
@@ -158,12 +157,12 @@ public class MixedDispatcherConfigurationScenarioTests {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
assertThat(allDone.await(10, TimeUnit.SECONDS)).isTrue();
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertTrue("not all messages were accepted", failed.get());
assertThat(failed.get()).as("not all messages were accepted").isTrue();
verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerB, times(0)).handleMessage(message);
verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add(any(Exception.class));
@@ -199,12 +198,12 @@ public class MixedDispatcherConfigurationScenarioTests {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
assertThat(allDone.await(10, TimeUnit.SECONDS)).isTrue();
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertTrue("not all messages were accepted", failed.get());
assertThat(failed.get()).as("not all messages were accepted").isTrue();
verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerB, times(0)).handleMessage(message);
verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add(any(Exception.class));
@@ -280,12 +279,12 @@ public class MixedDispatcherConfigurationScenarioTests {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
assertThat(allDone.await(10, TimeUnit.SECONDS)).isTrue();
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertTrue("not all messages were accepted", failed.get());
assertThat(failed.get()).as("not all messages were accepted").isTrue();
verify(handlerA, times(14)).handleMessage(message);
verify(handlerB, times(13)).handleMessage(message);
verify(handlerC, times(13)).handleMessage(message);
@@ -333,12 +332,12 @@ public class MixedDispatcherConfigurationScenarioTests {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
assertThat(allDone.await(10, TimeUnit.SECONDS)).isTrue();
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertTrue("not all messages were accepted", failed.get());
assertThat(failed.get()).as("not all messages were accepted").isTrue();
verify(handlerA, times(14)).handleMessage(message);
verify(handlerB, times(13)).handleMessage(message);
verify(handlerC, times(13)).handleMessage(message);
@@ -414,12 +413,12 @@ public class MixedDispatcherConfigurationScenarioTests {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
assertThat(allDone.await(10, TimeUnit.SECONDS)).isTrue();
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertFalse("not all messages were accepted", failed.get());
assertThat(failed.get()).as("not all messages were accepted").isFalse();
verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerB, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerC, never()).handleMessage(message);
@@ -458,7 +457,7 @@ public class MixedDispatcherConfigurationScenarioTests {
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
assertThat(allDone.await(10, TimeUnit.SECONDS)).isTrue();
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);

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.channel;
import static org.junit.Assert.assertEquals;
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.times;
@@ -73,21 +73,21 @@ public class P2pChannelTests {
MessageHandler handler1 = mock(MessageHandler.class);
channel.subscribe(handler1);
assertEquals(1, channel.getSubscriberCount());
assertEquals(String.format(log, 1), logs.remove(0));
assertThat(channel.getSubscriberCount()).isEqualTo(1);
assertThat(logs.remove(0)).isEqualTo(String.format(log, 1));
MessageHandler handler2 = mock(MessageHandler.class);
channel.subscribe(handler2);
assertEquals(2, channel.getSubscriberCount());
assertEquals(String.format(log, 2), logs.remove(0));
assertThat(channel.getSubscriberCount()).isEqualTo(2);
assertThat(logs.remove(0)).isEqualTo(String.format(log, 2));
channel.unsubscribe(handler1);
assertEquals(1, channel.getSubscriberCount());
assertEquals(String.format(log, 1), logs.remove(0));
assertThat(channel.getSubscriberCount()).isEqualTo(1);
assertThat(logs.remove(0)).isEqualTo(String.format(log, 1));
channel.unsubscribe(handler1);
assertEquals(1, channel.getSubscriberCount());
assertEquals(0, logs.size());
assertThat(channel.getSubscriberCount()).isEqualTo(1);
assertThat(logs.size()).isEqualTo(0);
channel.unsubscribe(handler2);
assertEquals(0, channel.getSubscriberCount());
assertEquals(String.format(log, 0), logs.remove(0));
assertThat(channel.getSubscriberCount()).isEqualTo(0);
assertThat(logs.remove(0)).isEqualTo(String.format(log, 0));
verify(logger, times(4)).info(Mockito.anyString());
}

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.channel;
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.util.Comparator;
import java.util.concurrent.CountDownLatch;
@@ -45,12 +41,12 @@ public class PriorityChannelTests {
@Test
public void testCapacityEnforced() {
PriorityChannel channel = new PriorityChannel(3);
assertTrue(channel.send(new GenericMessage<>("test1"), 0));
assertTrue(channel.send(new GenericMessage<>("test2"), 0));
assertTrue(channel.send(new GenericMessage<>("test3"), 0));
assertFalse(channel.send(new GenericMessage<>("test4"), 0));
assertThat(channel.send(new GenericMessage<>("test1"), 0)).isTrue();
assertThat(channel.send(new GenericMessage<>("test2"), 0)).isTrue();
assertThat(channel.send(new GenericMessage<>("test3"), 0)).isTrue();
assertThat(channel.send(new GenericMessage<>("test4"), 0)).isFalse();
channel.receive(0);
assertTrue(channel.send(new GenericMessage<>("test5")));
assertThat(channel.send(new GenericMessage<>("test5"))).isTrue();
}
@Test
@@ -60,7 +56,7 @@ public class PriorityChannelTests {
channel.send(new GenericMessage<>(i));
}
for (int i = 0; i < 1000; i++) {
assertEquals(i, channel.receive().getPayload());
assertThat(channel.receive().getPayload()).isEqualTo(i);
}
}
@@ -77,11 +73,11 @@ public class PriorityChannelTests {
channel.send(priority5);
channel.send(priority1);
channel.send(priority2);
assertEquals("test:10", channel.receive(0).getPayload());
assertEquals("test:7", channel.receive(0).getPayload());
assertEquals("test:0", channel.receive(0).getPayload());
assertEquals("test:-3", channel.receive(0).getPayload());
assertEquals("test:-99", channel.receive(0).getPayload());
assertThat(channel.receive(0).getPayload()).isEqualTo("test:10");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:7");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:0");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:-3");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:-99");
}
// although this test has no assertions it results in ConcurrentModificationException
@@ -110,11 +106,11 @@ public class PriorityChannelTests {
channel.send(messageE);
channel.send(messageD);
channel.send(messageB);
assertEquals("A", channel.receive(0).getPayload());
assertEquals("B", channel.receive(0).getPayload());
assertEquals("C", channel.receive(0).getPayload());
assertEquals("D", channel.receive(0).getPayload());
assertEquals("E", channel.receive(0).getPayload());
assertThat(channel.receive(0).getPayload()).isEqualTo("A");
assertThat(channel.receive(0).getPayload()).isEqualTo("B");
assertThat(channel.receive(0).getPayload()).isEqualTo("C");
assertThat(channel.receive(0).getPayload()).isEqualTo("D");
assertThat(channel.receive(0).getPayload()).isEqualTo("E");
}
@Test
@@ -149,14 +145,14 @@ public class PriorityChannelTests {
Object receivedSeven = channel.receive(0).getPayload();
Object receivedEight = channel.receive(0).getPayload();
assertEquals(7, receivedOne);
assertEquals(8, receivedTwo);
assertEquals(5, receivedThree);
assertEquals(6, receivedFour);
assertEquals(1, receivedFive);
assertEquals(2, receivedSix);
assertEquals(3, receivedSeven);
assertEquals(4, receivedEight);
assertThat(receivedOne).isEqualTo(7);
assertThat(receivedTwo).isEqualTo(8);
assertThat(receivedThree).isEqualTo(5);
assertThat(receivedFour).isEqualTo(6);
assertThat(receivedFive).isEqualTo(1);
assertThat(receivedSix).isEqualTo(2);
assertThat(receivedSeven).isEqualTo(3);
assertThat(receivedEight).isEqualTo(4);
}
@Test
@@ -187,13 +183,13 @@ public class PriorityChannelTests {
Object receivedSix = channel.receive(0).getPayload();
Object receivedSeven = channel.receive(0).getPayload();
assertEquals(4, receivedOne);
assertEquals(5, receivedTwo);
assertEquals(1, receivedThree);
assertEquals(2, receivedFour);
assertEquals(3, receivedFive);
assertEquals(6, receivedSix);
assertEquals(7, receivedSeven);
assertThat(receivedOne).isEqualTo(4);
assertThat(receivedTwo).isEqualTo(5);
assertThat(receivedThree).isEqualTo(1);
assertThat(receivedFour).isEqualTo(2);
assertThat(receivedFive).isEqualTo(3);
assertThat(receivedSix).isEqualTo(6);
assertThat(receivedSeven).isEqualTo(7);
}
@Test
@@ -205,9 +201,9 @@ public class PriorityChannelTests {
channel.send(lowPriority);
channel.send(highPriority);
channel.send(nullPriority);
assertEquals("test:5", channel.receive(0).getPayload());
assertEquals("test:NULL", channel.receive(0).getPayload());
assertEquals("test:-5", channel.receive(0).getPayload());
assertThat(channel.receive(0).getPayload()).isEqualTo("test:5");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:NULL");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:-5");
}
@Test
@@ -219,9 +215,9 @@ public class PriorityChannelTests {
channel.send(lowPriority);
channel.send(highPriority);
channel.send(nullPriority);
assertEquals("test:5", channel.receive(0).getPayload());
assertEquals("test:NULL", channel.receive(0).getPayload());
assertEquals("test:-5", channel.receive(0).getPayload());
assertThat(channel.receive(0).getPayload()).isEqualTo("test:5");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:NULL");
assertThat(channel.receive(0).getPayload()).isEqualTo("test:-5");
}
@Test
@@ -231,15 +227,15 @@ public class PriorityChannelTests {
ExecutorService executor = Executors.newSingleThreadScheduledExecutor();
channel.send(new GenericMessage<>("test-1"));
executor.execute(() -> sentSecondMessage.set(channel.send(new GenericMessage<>("test-2"), 10)));
assertFalse(sentSecondMessage.get());
assertThat(sentSecondMessage.get()).isFalse();
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
assertThat(executor.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
Message<?> message1 = channel.receive(10000);
assertNotNull(message1);
assertEquals("test-1", message1.getPayload());
assertFalse(sentSecondMessage.get());
assertNull(channel.receive(0));
assertThat(message1).isNotNull();
assertThat(message1.getPayload()).isEqualTo("test-1");
assertThat(sentSecondMessage.get()).isFalse();
assertThat(channel.receive(0)).isNull();
}
@Test
@@ -253,16 +249,16 @@ public class PriorityChannelTests {
sentSecondMessage.set(channel.send(new GenericMessage<>("test-2"), 3000));
latch.countDown();
});
assertFalse(sentSecondMessage.get());
assertThat(sentSecondMessage.get()).isFalse();
Thread.sleep(10);
Message<?> message1 = channel.receive();
assertNotNull(message1);
assertEquals("test-1", message1.getPayload());
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertTrue(sentSecondMessage.get());
assertThat(message1).isNotNull();
assertThat(message1.getPayload()).isEqualTo("test-1");
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(sentSecondMessage.get()).isTrue();
Message<?> message2 = channel.receive();
assertNotNull(message2);
assertEquals("test-2", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("test-2");
executor.shutdownNow();
}
@@ -273,17 +269,17 @@ public class PriorityChannelTests {
ExecutorService executor = Executors.newSingleThreadScheduledExecutor();
channel.send(new GenericMessage<String>("test-1"));
executor.execute(() -> sentSecondMessage.set(channel.send(new GenericMessage<>("test-2"), -1)));
assertFalse(sentSecondMessage.get());
assertThat(sentSecondMessage.get()).isFalse();
Thread.sleep(10);
Message<?> message1 = channel.receive(10000);
assertNotNull(message1);
assertEquals("test-1", message1.getPayload());
assertThat(message1).isNotNull();
assertThat(message1.getPayload()).isEqualTo("test-1");
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
assertTrue(sentSecondMessage.get());
assertThat(executor.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
assertThat(sentSecondMessage.get()).isTrue();
Message<?> message2 = channel.receive();
assertNotNull(message2);
assertEquals("test-2", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("test-2");
}

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.channel;
import static org.hamcrest.Matchers.equalTo;
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.util.concurrent.Executor;
@@ -44,8 +43,9 @@ public class PublishSubscribeChannelTests {
fail("expected Exception");
}
catch (IllegalStateException e) {
assertThat(e.getMessage(), equalTo("When providing an Executor, you cannot subscribe() until the channel "
+ "bean is fully initialized by the framework. Do not subscribe in a @Bean definition"));
assertThat(e.getMessage()).isEqualTo("When providing an Executor, you cannot subscribe() until the " +
"channel "
+ "bean is fully initialized by the framework. Do not subscribe in a @Bean definition");
}
}

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,7 @@
package org.springframework.integration.channel;
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 static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Mockito.spy;
@@ -60,7 +57,7 @@ public class QueueChannelTests {
}
});
channel.send(new GenericMessage<>("testing"));
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
exec.shutdownNow();
}
@@ -76,7 +73,7 @@ public class QueueChannelTests {
}
});
channel.send(new GenericMessage<>("testing"));
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
exec.shutdownNow();
}
@@ -92,7 +89,7 @@ public class QueueChannelTests {
}
});
channel.send(new GenericMessage<>("testing"));
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
assertThat(latch.await(10000, TimeUnit.MILLISECONDS)).isTrue();
exec.shutdownNow();
}
@@ -110,7 +107,7 @@ public class QueueChannelTests {
};
Runnable sendTask = () -> channel.send(new GenericMessage<>("testing"));
singleThreadExecutor.execute(receiveTask1);
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
singleThreadExecutor.execute(sendTask);
Runnable receiveTask2 = () -> {
Message<?> message = channel.receive(0);
@@ -119,7 +116,7 @@ public class QueueChannelTests {
}
};
singleThreadExecutor.execute(receiveTask2);
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
singleThreadExecutor.shutdownNow();
}
@@ -135,8 +132,8 @@ public class QueueChannelTests {
latch.countDown();
});
exec.shutdownNow();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertTrue(messageNull.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(messageNull.get()).isTrue();
}
@Test
@@ -151,8 +148,8 @@ public class QueueChannelTests {
latch.countDown();
});
exec.shutdownNow();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertTrue(messageNull.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(messageNull.get()).isTrue();
}
@Test
@@ -173,9 +170,9 @@ public class QueueChannelTests {
latch.countDown();
}
});
assertTrue(pollLatch.await(10, TimeUnit.SECONDS));
assertThat(pollLatch.await(10, TimeUnit.SECONDS)).isTrue();
channel.send(new GenericMessage<>("testing"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
exec.shutdownNow();
}
@@ -197,9 +194,9 @@ public class QueueChannelTests {
latch.countDown();
}
});
assertTrue(pollLatch.await(10, TimeUnit.SECONDS));
assertThat(pollLatch.await(10, TimeUnit.SECONDS)).isTrue();
channel.send(new GenericMessage<>("testing"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
exec.shutdownNow();
}
@@ -207,20 +204,20 @@ public class QueueChannelTests {
public void testImmediateSend() {
QueueChannel channel = new QueueChannel(3);
boolean result1 = channel.send(new GenericMessage<>("test-1"));
assertTrue(result1);
assertThat(result1).isTrue();
boolean result2 = channel.send(new GenericMessage<>("test-2"), 100);
assertTrue(result2);
assertThat(result2).isTrue();
boolean result3 = channel.send(new GenericMessage<>("test-3"), 0);
assertTrue(result3);
assertThat(result3).isTrue();
boolean result4 = channel.send(new GenericMessage<>("test-4"), 0);
assertFalse(result4);
assertThat(result4).isFalse();
}
@Test
public void testBlockingSendWithNoTimeout() throws Exception {
final QueueChannel channel = new QueueChannel(1);
boolean result1 = channel.send(new GenericMessage<>("test-1"));
assertTrue(result1);
assertThat(result1).isTrue();
final CountDownLatch latch = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
@@ -228,14 +225,14 @@ public class QueueChannelTests {
latch.countDown();
});
exec.shutdownNow();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
public void testBlockingSendWithTimeout() throws Exception {
final QueueChannel channel = new QueueChannel(1);
boolean result1 = channel.send(new GenericMessage<>("test-1"));
assertTrue(result1);
assertThat(result1).isTrue();
final CountDownLatch latch = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
@@ -243,7 +240,7 @@ public class QueueChannelTests {
latch.countDown();
});
exec.shutdownNow();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
@@ -252,21 +249,21 @@ public class QueueChannelTests {
GenericMessage<String> message1 = new GenericMessage<>("test1");
GenericMessage<String> message2 = new GenericMessage<>("test2");
GenericMessage<String> message3 = new GenericMessage<>("test3");
assertTrue(channel.send(message1));
assertTrue(channel.send(message2));
assertFalse(channel.send(message3, 0));
assertThat(channel.send(message1)).isTrue();
assertThat(channel.send(message2)).isTrue();
assertThat(channel.send(message3, 0)).isFalse();
List<Message<?>> clearedMessages = channel.clear();
assertNotNull(clearedMessages);
assertEquals(2, clearedMessages.size());
assertTrue(channel.send(message3));
assertThat(clearedMessages).isNotNull();
assertThat(clearedMessages.size()).isEqualTo(2);
assertThat(channel.send(message3)).isTrue();
}
@Test
public void testClearEmptyChannel() {
QueueChannel channel = new QueueChannel();
List<Message<?>> clearedMessages = channel.clear();
assertNotNull(clearedMessages);
assertEquals(0, clearedMessages.size());
assertThat(clearedMessages).isNotNull();
assertThat(clearedMessages.size()).isEqualTo(0);
}
@Test
@@ -280,13 +277,13 @@ public class QueueChannelTests {
.setExpirationDate(past).build();
Message<String> unexpiredMessage = MessageBuilder.withPayload("test2")
.setExpirationDate(future).build();
assertTrue(channel.send(expiredMessage, 0));
assertTrue(channel.send(unexpiredMessage, 0));
assertFalse(channel.send(new GenericMessage<>("atCapacity"), 0));
assertThat(channel.send(expiredMessage, 0)).isTrue();
assertThat(channel.send(unexpiredMessage, 0)).isTrue();
assertThat(channel.send(new GenericMessage<>("atCapacity"), 0)).isFalse();
List<Message<?>> purgedMessages = channel.purge(new UnexpiredMessageSelector());
assertNotNull(purgedMessages);
assertEquals(1, purgedMessages.size());
assertTrue(channel.send(new GenericMessage<>("roomAvailable"), 0));
assertThat(purgedMessages).isNotNull();
assertThat(purgedMessages.size()).isEqualTo(1);
assertThat(channel.send(new GenericMessage<>("roomAvailable"), 0)).isTrue();
}
@Rule

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,7 @@
package org.springframework.integration.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;
@@ -65,17 +63,17 @@ public class TransactionSynchronizationQueueChannelTests {
GenericMessage<String> sentMessage = new GenericMessage<>("hello");
this.queueChannel.send(sentMessage);
Message<?> message = this.good.receive(10000);
assertNotNull(message);
assertEquals("hello", message.getPayload());
assertSame(message, sentMessage);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("hello");
assertThat(sentMessage).isSameAs(message);
}
@Test
public void testRollback() throws Exception {
this.queueChannel.send(new GenericMessage<>("fail"));
Message<?> message = this.good.receive(10000);
assertNotNull(message);
assertEquals("retry:fail", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("retry:fail");
}
@Test
@@ -84,10 +82,10 @@ public class TransactionSynchronizationQueueChannelTests {
.setHeader("foo", "bar").build();
queueChannel2.send(sentMessage);
Message<?> message = good.receive(10000);
assertNotNull(message);
assertEquals("hello processed ok from queueChannel2", message.getPayload());
assertNotNull(message.getHeaders().get("foo"));
assertEquals("bar", message.getHeaders().get("foo"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("hello processed ok from queueChannel2");
assertThat(message.getHeaders().get("foo")).isNotNull();
assertThat(message.getHeaders().get("foo")).isEqualTo("bar");
}
public static class Service {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 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.channel.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,8 +40,8 @@ public class AutoGeneratedChannelTests {
@Test
public void checkConfig() {
Object input = context.getBean("input");
assertNotNull(input);
assertEquals(DirectChannel.class, input.getClass());
assertThat(input).isNotNull();
assertThat(input.getClass()).isEqualTo(DirectChannel.class);
}
}

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.channel.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,25 +43,25 @@ public class ChannelCapacityPlaceholderTests {
@Test
public void verifyCapacityValueChanges() {
QueueChannel channel = context.getBean("channel", QueueChannel.class);
assertNotNull(channel);
assertEquals(99, channel.getRemainingCapacity());
assertThat(channel).isNotNull();
assertThat(channel.getRemainingCapacity()).isEqualTo(99);
channel.send(MessageBuilder.withPayload("test1").build());
channel.send(MessageBuilder.withPayload("test2").build());
assertEquals(97, channel.getRemainingCapacity());
assertNotNull(channel.receive(0));
assertEquals(98, channel.getRemainingCapacity());
assertThat(channel.getRemainingCapacity()).isEqualTo(97);
assertThat(channel.receive(0)).isNotNull();
assertThat(channel.getRemainingCapacity()).isEqualTo(98);
}
@Test
public void testCapacityOnPriorityChannel() {
PriorityChannel channel = context.getBean("priorityChannel", PriorityChannel.class);
assertNotNull(channel);
assertEquals(99, channel.getRemainingCapacity());
assertThat(channel).isNotNull();
assertThat(channel.getRemainingCapacity()).isEqualTo(99);
channel.send(MessageBuilder.withPayload("test1").build());
channel.send(MessageBuilder.withPayload("test2").build());
assertEquals(97, channel.getRemainingCapacity());
assertNotNull(channel.receive(0));
assertEquals(98, channel.getRemainingCapacity());
assertThat(channel.getRemainingCapacity()).isEqualTo(97);
assertThat(channel.receive(0)).isNotNull();
assertThat(channel.getRemainingCapacity()).isEqualTo(98);
}
}

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.channel.config;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
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.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.Executor;
@@ -89,28 +81,28 @@ public class ChannelParserTests {
MessageChannel channel = (MessageChannel) context.getBean("capacityChannel");
for (int i = 0; i < 10; i++) {
boolean result = channel.send(new GenericMessage<String>("test"), 10);
assertTrue(result);
assertThat(result).isTrue();
}
assertFalse(channel.send(new GenericMessage<String>("test"), 3));
assertThat(channel.send(new GenericMessage<String>("test"), 3)).isFalse();
}
@Test
public void testDirectChannelByDefault() throws InterruptedException {
MessageChannel channel = (MessageChannel) context.getBean("defaultChannel");
assertThat(channel, instanceOf(DirectChannel.class));
assertThat(channel).isInstanceOf(DirectChannel.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
Object dispatcher = accessor.getPropertyValue("dispatcher");
assertThat(dispatcher, is(instanceOf(UnicastingDispatcher.class)));
assertThat(new DirectFieldAccessor(dispatcher).getPropertyValue("loadBalancingStrategy"),
is(instanceOf(RoundRobinLoadBalancingStrategy.class)));
assertThat(dispatcher).isInstanceOf(UnicastingDispatcher.class);
assertThat(new DirectFieldAccessor(dispatcher).getPropertyValue("loadBalancingStrategy"))
.isInstanceOf(RoundRobinLoadBalancingStrategy.class);
}
@Test
public void testExecutorChannel() throws InterruptedException {
MessageChannel channel = context.getBean("executorChannel", MessageChannel.class);
assertThat(channel, instanceOf(ExecutorChannel.class));
assertNotNull(TestUtils.getPropertyValue(channel, "messageConverter"));
assertNotNull(TestUtils.getPropertyValue(channel, "messageConverter.conversionService"));
assertThat(channel).isInstanceOf(ExecutorChannel.class);
assertThat(TestUtils.getPropertyValue(channel, "messageConverter")).isNotNull();
assertThat(TestUtils.getPropertyValue(channel, "messageConverter.conversionService")).isNotNull();
}
@Test
@@ -118,63 +110,63 @@ public class ChannelParserTests {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"ChannelParserTests-no-converter-context.xml", this.getClass());
MessageChannel channel = context.getBean("executorChannel", MessageChannel.class);
assertThat(channel, instanceOf(ExecutorChannel.class));
assertNotNull(TestUtils.getPropertyValue(channel, "messageConverter"));
assertNotNull(TestUtils.getPropertyValue(channel, "messageConverter.conversionService"));
assertThat(channel).isInstanceOf(ExecutorChannel.class);
assertThat(TestUtils.getPropertyValue(channel, "messageConverter")).isNotNull();
assertThat(TestUtils.getPropertyValue(channel, "messageConverter.conversionService")).isNotNull();
context.close();
}
@Test
public void channelWithFailoverDispatcherAttribute() throws Exception {
MessageChannel channel = (MessageChannel) context.getBean("channelWithFailover");
assertEquals(DirectChannel.class, channel.getClass());
assertThat(channel.getClass()).isEqualTo(DirectChannel.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
Object dispatcher = accessor.getPropertyValue("dispatcher");
assertThat(dispatcher, is(instanceOf(UnicastingDispatcher.class)));
assertNull(new DirectFieldAccessor(dispatcher).getPropertyValue("loadBalancingStrategy"));
assertThat(dispatcher).isInstanceOf(UnicastingDispatcher.class);
assertThat(new DirectFieldAccessor(dispatcher).getPropertyValue("loadBalancingStrategy")).isNull();
}
@Test
public void testPublishSubscribeChannel() throws InterruptedException {
MessageChannel channel = (MessageChannel) context.getBean("publishSubscribeChannel");
assertEquals(PublishSubscribeChannel.class, channel.getClass());
assertThat(channel.getClass()).isEqualTo(PublishSubscribeChannel.class);
}
@Test
public void testPublishSubscribeChannelWithTaskExecutorReference() throws InterruptedException {
MessageChannel channel = (MessageChannel) context.getBean("publishSubscribeChannelWithTaskExecutorRef");
assertEquals(PublishSubscribeChannel.class, channel.getClass());
assertThat(channel.getClass()).isEqualTo(PublishSubscribeChannel.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
accessor = new DirectFieldAccessor(accessor.getPropertyValue("dispatcher"));
Object executorProperty = accessor.getPropertyValue("executor");
assertNotNull(executorProperty);
assertEquals(ErrorHandlingTaskExecutor.class, executorProperty.getClass());
assertThat(executorProperty).isNotNull();
assertThat(executorProperty.getClass()).isEqualTo(ErrorHandlingTaskExecutor.class);
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executorProperty);
Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
Object executorBean = context.getBean("taskExecutor");
assertEquals(executorBean, innerExecutor);
assertThat(innerExecutor).isEqualTo(executorBean);
}
@Test
public void channelWithCustomQueue() {
Object customQueue = context.getBean("customQueue");
Object channelWithCustomQueue = context.getBean("channelWithCustomQueue");
assertEquals(QueueChannel.class, channelWithCustomQueue.getClass());
assertThat(channelWithCustomQueue.getClass()).isEqualTo(QueueChannel.class);
Object actualQueue = new DirectFieldAccessor(channelWithCustomQueue).getPropertyValue("queue");
assertSame(customQueue, actualQueue);
assertThat(actualQueue).isSameAs(customQueue);
}
@Test
public void testDatatypeChannelWithCorrectType() {
MessageChannel channel = (MessageChannel) context.getBean("integerChannel");
assertTrue(channel.send(new GenericMessage<Integer>(123)));
assertThat(channel.send(new GenericMessage<Integer>(123))).isTrue();
}
@Test(expected = MessageDeliveryException.class)
public void testDatatypeChannelWithIncorrectType() {
MessageChannel channel = (MessageChannel) context.getBean("integerChannel");
channel.send(new GenericMessage<String>("incorrect type"));
assertTrue(TestUtils.getPropertyValue(channel, "messageConverter") instanceof UselessMessageConverter);
assertThat(TestUtils.getPropertyValue(channel, "messageConverter") instanceof UselessMessageConverter).isTrue();
}
@Test
@@ -183,25 +175,25 @@ public class ChannelParserTests {
new ClassPathXmlApplicationContext("channelParserGlobalConverterTests.xml", getClass());
MessageChannel channel = context.getBean("integerChannel", MessageChannel.class);
context.close();
assertTrue(TestUtils.getPropertyValue(channel, "messageConverter") instanceof UselessMessageConverter);
assertThat(TestUtils.getPropertyValue(channel, "messageConverter") instanceof UselessMessageConverter).isTrue();
}
@Test
public void testDatatypeChannelWithAssignableSubTypes() {
MessageChannel channel = (MessageChannel) context.getBean("numberChannel");
assertTrue(channel.send(new GenericMessage<>(123)));
assertTrue(channel.send(new GenericMessage<>(123.45)));
assertTrue(channel.send(new GenericMessage<>(Boolean.TRUE)));
assertThat(TestUtils.getPropertyValue(channel, "messageConverter"),
instanceOf(DefaultDatatypeChannelMessageConverter.class));
assertNotNull(TestUtils.getPropertyValue(channel, "messageConverter.conversionService"));
assertThat(channel.send(new GenericMessage<>(123))).isTrue();
assertThat(channel.send(new GenericMessage<>(123.45))).isTrue();
assertThat(channel.send(new GenericMessage<>(Boolean.TRUE))).isTrue();
assertThat(TestUtils.getPropertyValue(channel, "messageConverter"))
.isInstanceOf(DefaultDatatypeChannelMessageConverter.class);
assertThat(TestUtils.getPropertyValue(channel, "messageConverter.conversionService")).isNotNull();
}
@Test
public void testMultipleDatatypeChannelWithCorrectTypes() {
MessageChannel channel = (MessageChannel) context.getBean("stringOrNumberChannel");
assertTrue(channel.send(new GenericMessage<>(123)));
assertTrue(channel.send(new GenericMessage<>("accepted type")));
assertThat(channel.send(new GenericMessage<>(123))).isTrue();
assertThat(channel.send(new GenericMessage<>("accepted type"))).isTrue();
}
@Test(expected = MessageDeliveryException.class)
@@ -216,12 +208,12 @@ public class ChannelParserTests {
new ClassPathXmlApplicationContext("channelInterceptorParserTests.xml", getClass());
PollableChannel channel = (PollableChannel) context.getBean("channelWithInterceptorRef");
TestChannelInterceptor interceptor = (TestChannelInterceptor) context.getBean("interceptor");
assertEquals(0, interceptor.getSendCount());
assertThat(interceptor.getSendCount()).isEqualTo(0);
channel.send(new GenericMessage<>("test"));
assertEquals(1, interceptor.getSendCount());
assertEquals(0, interceptor.getReceiveCount());
assertThat(interceptor.getSendCount()).isEqualTo(1);
assertThat(interceptor.getReceiveCount()).isEqualTo(0);
channel.receive();
assertEquals(1, interceptor.getReceiveCount());
assertThat(interceptor.getReceiveCount()).isEqualTo(1);
context.close();
}
@@ -232,7 +224,7 @@ public class ChannelParserTests {
PollableChannel channel = (PollableChannel) context.getBean("channelWithInterceptorInnerBean");
channel.send(new GenericMessage<String>("test"));
Message<?> transformed = channel.receive(1000);
assertEquals("TEST", transformed.getPayload());
assertThat(transformed.getPayload()).isEqualTo("TEST");
context.close();
}
@@ -248,9 +240,9 @@ public class ChannelParserTests {
Message<?> reply1 = channel.receive(0);
Message<?> reply2 = channel.receive(0);
Message<?> reply3 = channel.receive(0);
assertEquals("high", reply1.getPayload());
assertEquals("mid", reply2.getPayload());
assertEquals("low", reply3.getPayload());
assertThat(reply1.getPayload()).isEqualTo("high");
assertThat(reply2.getPayload()).isEqualTo("mid");
assertThat(reply3.getPayload()).isEqualTo("low");
}
@Test
@@ -264,10 +256,10 @@ public class ChannelParserTests {
Message<?> reply2 = channel.receive(0);
Message<?> reply3 = channel.receive(0);
Message<?> reply4 = channel.receive(0);
assertEquals("A", reply1.getPayload());
assertEquals("B", reply2.getPayload());
assertEquals("C", reply3.getPayload());
assertEquals("D", reply4.getPayload());
assertThat(reply1.getPayload()).isEqualTo("A");
assertThat(reply2.getPayload()).isEqualTo("B");
assertThat(reply3.getPayload()).isEqualTo("C");
assertThat(reply4.getPayload()).isEqualTo("D");
}
@Test
@@ -276,18 +268,18 @@ public class ChannelParserTests {
channel.send(new GenericMessage<>(3));
channel.send(new GenericMessage<>(2));
channel.send(new GenericMessage<>(1));
assertEquals(1, channel.receive(0).getPayload());
assertEquals(2, channel.receive(0).getPayload());
assertEquals(3, channel.receive(0).getPayload());
assertThat(channel.receive(0).getPayload()).isEqualTo(1);
assertThat(channel.receive(0).getPayload()).isEqualTo(2);
assertThat(channel.receive(0).getPayload()).isEqualTo(3);
boolean threwException = false;
try {
channel.send(new GenericMessage<>("wrong type"));
}
catch (MessageDeliveryException e) {
assertEquals("wrong type", e.getFailedMessage().getPayload());
assertThat(e.getFailedMessage().getPayload()).isEqualTo("wrong type");
threwException = true;
}
assertTrue(threwException);
assertThat(threwException).isTrue();
}
public static class TestInterceptor implements ChannelInterceptor {

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,7 @@
package org.springframework.integration.channel.config;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@@ -54,16 +51,16 @@ public class ChannelWithCustomQueueParserTests {
@Test
public void parseConfig() throws Exception {
assertNotNull(customQueueChannel);
assertThat(customQueueChannel).isNotNull();
}
@Test
public void queueTypeSet() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(customQueueChannel);
Object queue = accessor.getPropertyValue("queue");
assertNotNull(queue);
assertThat(queue, is(instanceOf(ArrayBlockingQueue.class)));
assertThat(((BlockingQueue<?>) queue).remainingCapacity(), is(2));
assertThat(queue).isNotNull();
assertThat(queue).isInstanceOf(ArrayBlockingQueue.class);
assertThat(((BlockingQueue<?>) queue).remainingCapacity()).isEqualTo(2);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 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,18 +16,12 @@
package org.springframework.integration.channel.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.Collection;
import java.util.Iterator;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -66,72 +60,73 @@ public class DispatchingChannelParserTests {
@Test
public void taskExecutorOnly() {
MessageChannel channel = channels.get("taskExecutorOnly");
assertEquals(ExecutorChannel.class, channel.getClass());
assertThat(channel.getClass()).isEqualTo(ExecutorChannel.class);
Object executor = getDispatcherProperty("executor", channel);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
assertSame(context.getBean("taskExecutor"),
new DirectFieldAccessor(executor).getPropertyValue("executor"));
assertTrue((Boolean) getDispatcherProperty("failover", channel));
assertEquals(RoundRobinLoadBalancingStrategy.class,
getDispatcherProperty("loadBalancingStrategy", channel).getClass());
assertThat(executor.getClass()).isEqualTo(ErrorHandlingTaskExecutor.class);
assertThat(new DirectFieldAccessor(executor).getPropertyValue("executor"))
.isSameAs(context.getBean("taskExecutor"));
assertThat((Boolean) getDispatcherProperty("failover", channel)).isTrue();
assertThat(getDispatcherProperty("loadBalancingStrategy", channel).getClass())
.isEqualTo(RoundRobinLoadBalancingStrategy.class);
}
@Test
public void failoverFalse() {
MessageChannel channel = channels.get("failoverFalse");
assertEquals(DirectChannel.class, channel.getClass());
assertFalse((Boolean) getDispatcherProperty("failover", channel));
assertEquals(RoundRobinLoadBalancingStrategy.class,
getDispatcherProperty("loadBalancingStrategy", channel).getClass());
assertThat(channel.getClass()).isEqualTo(DirectChannel.class);
assertThat((Boolean) getDispatcherProperty("failover", channel)).isFalse();
assertThat(getDispatcherProperty("loadBalancingStrategy", channel).getClass())
.isEqualTo(RoundRobinLoadBalancingStrategy.class);
}
@Test
public void failoverTrue() {
MessageChannel channel = channels.get("failoverTrue");
assertEquals(DirectChannel.class, channel.getClass());
assertTrue((Boolean) getDispatcherProperty("failover", channel));
assertEquals(RoundRobinLoadBalancingStrategy.class,
getDispatcherProperty("loadBalancingStrategy", channel).getClass());
assertThat(channel.getClass()).isEqualTo(DirectChannel.class);
assertThat((Boolean) getDispatcherProperty("failover", channel)).isTrue();
assertThat(getDispatcherProperty("loadBalancingStrategy", channel).getClass())
.isEqualTo(RoundRobinLoadBalancingStrategy.class);
}
@Test
public void loadBalancerDisabled() {
MessageChannel channel = channels.get("loadBalancerDisabled");
assertEquals(DirectChannel.class, channel.getClass());
assertTrue((Boolean) getDispatcherProperty("failover", channel));
assertNull(getDispatcherProperty("loadBalancingStrategy", channel));
assertThat(channel.getClass()).isEqualTo(DirectChannel.class);
assertThat((Boolean) getDispatcherProperty("failover", channel)).isTrue();
assertThat(getDispatcherProperty("loadBalancingStrategy", channel)).isNull();
}
@Test
public void loadBalancerDisabledAndTaskExecutor() {
MessageChannel channel = channels.get("loadBalancerDisabledAndTaskExecutor");
assertEquals(ExecutorChannel.class, channel.getClass());
assertTrue((Boolean) getDispatcherProperty("failover", channel));
assertNull(getDispatcherProperty("loadBalancingStrategy", channel));
assertThat(channel.getClass()).isEqualTo(ExecutorChannel.class);
assertThat((Boolean) getDispatcherProperty("failover", channel)).isTrue();
assertThat(getDispatcherProperty("loadBalancingStrategy", channel)).isNull();
Object executor = getDispatcherProperty("executor", channel);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
assertSame(context.getBean("taskExecutor"),
new DirectFieldAccessor(executor).getPropertyValue("executor"));
assertThat(executor.getClass()).isEqualTo(ErrorHandlingTaskExecutor.class);
assertThat(new DirectFieldAccessor(executor).getPropertyValue("executor"))
.isSameAs(context.getBean("taskExecutor"));
}
@Test
public void roundRobinLoadBalancerAndTaskExecutor() {
MessageChannel channel = channels.get("roundRobinLoadBalancerAndTaskExecutor");
assertEquals(ExecutorChannel.class, channel.getClass());
assertTrue((Boolean) getDispatcherProperty("failover", channel));
assertEquals(RoundRobinLoadBalancingStrategy.class,
getDispatcherProperty("loadBalancingStrategy", channel).getClass());
assertThat(channel.getClass()).isEqualTo(ExecutorChannel.class);
assertThat((Boolean) getDispatcherProperty("failover", channel)).isTrue();
assertThat(getDispatcherProperty("loadBalancingStrategy", channel).getClass())
.isEqualTo(RoundRobinLoadBalancingStrategy.class);
Object executor = getDispatcherProperty("executor", channel);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
assertSame(context.getBean("taskExecutor"),
new DirectFieldAccessor(executor).getPropertyValue("executor"));
assertThat(executor.getClass()).isEqualTo(ErrorHandlingTaskExecutor.class);
assertThat(new DirectFieldAccessor(executor).getPropertyValue("executor"))
.isSameAs(context.getBean("taskExecutor"));
}
@Test
public void loadBalancerRef() {
MessageChannel channel = channels.get("lbRefChannel");
LoadBalancingStrategy lbStrategy = TestUtils.getPropertyValue(channel, "dispatcher.loadBalancingStrategy", LoadBalancingStrategy.class);
assertTrue(lbStrategy instanceof SampleLoadBalancingStrategy);
LoadBalancingStrategy lbStrategy = TestUtils.getPropertyValue(channel, "dispatcher.loadBalancingStrategy",
LoadBalancingStrategy.class);
assertThat(lbStrategy instanceof SampleLoadBalancingStrategy).isTrue();
}
@Test
@@ -141,7 +136,7 @@ public class DispatchingChannelParserTests {
new ClassPathXmlApplicationContext("ChannelWithLoadBalancerRef-fail-config.xml", this.getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertThat(e.getMessage(), Matchers.containsString("'load-balancer' and 'load-balancer-ref' are mutually exclusive"));
assertThat(e.getMessage()).contains("'load-balancer' and 'load-balancer-ref' are mutually exclusive");
}
}

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.channel.config;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -35,7 +35,7 @@ public class RendezvousChannelParserTests {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"rendezvousChannelParserTests.xml", RendezvousChannelParserTests.class);
MessageChannel channel = (MessageChannel) context.getBean("channel");
assertEquals(RendezvousChannel.class, channel.getClass());
assertThat(channel.getClass()).isEqualTo(RendezvousChannel.class);
context.close();
}

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,7 @@
package org.springframework.integration.channel.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -67,10 +65,10 @@ public class ThreadLocalChannelParserTests {
simpleChannel.send(new GenericMessage<String>("crap"));
latch.countDown();
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("test", simpleChannel.receive(10).getPayload());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(simpleChannel.receive(10).getPayload()).isEqualTo("test");
// Message sent on another thread is not collected here
assertEquals(null, simpleChannel.receive(10));
assertThat(simpleChannel.receive(10)).isEqualTo(null);
}
@Test
@@ -91,24 +89,24 @@ public class ThreadLocalChannelParserTests {
otherThreadResults.add(channelWithInterceptor.receive(0));
latch.countDown();
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(2, otherThreadResults.size());
assertNull(otherThreadResults.get(0));
assertNull(otherThreadResults.get(1));
assertEquals("test-1.1", simpleChannel.receive(0).getPayload());
assertEquals("test-1.2", simpleChannel.receive(0).getPayload());
assertEquals("test-1.3", simpleChannel.receive(0).getPayload());
assertNull(simpleChannel.receive(0));
assertEquals("test-2.1", channelWithInterceptor.receive(0).getPayload());
assertEquals("test-2.2", channelWithInterceptor.receive(0).getPayload());
assertNull(channelWithInterceptor.receive(0));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(otherThreadResults.size()).isEqualTo(2);
assertThat(otherThreadResults.get(0)).isNull();
assertThat(otherThreadResults.get(1)).isNull();
assertThat(simpleChannel.receive(0).getPayload()).isEqualTo("test-1.1");
assertThat(simpleChannel.receive(0).getPayload()).isEqualTo("test-1.2");
assertThat(simpleChannel.receive(0).getPayload()).isEqualTo("test-1.3");
assertThat(simpleChannel.receive(0)).isNull();
assertThat(channelWithInterceptor.receive(0).getPayload()).isEqualTo("test-2.1");
assertThat(channelWithInterceptor.receive(0).getPayload()).isEqualTo("test-2.2");
assertThat(channelWithInterceptor.receive(0)).isNull();
}
@Test
public void testInterceptor() {
int before = interceptor.getSendCount();
channelWithInterceptor.send(new GenericMessage<String>("test"));
assertEquals(before + 1, interceptor.getSendCount());
assertThat(interceptor.getSendCount()).isEqualTo(before + 1);
}
}

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,7 @@
package org.springframework.integration.channel.interceptor;
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.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -31,7 +25,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
@@ -67,10 +60,10 @@ public class ChannelInterceptorTests {
channel.addInterceptor(interceptor);
channel.send(new GenericMessage<String>("test"));
Message<?> result = channel.receive(0);
assertNotNull(result);
assertEquals("test", result.getPayload());
assertEquals(1, result.getHeaders().get(PreSendReturnsMessageInterceptor.class.getSimpleName()));
assertTrue(interceptor.wasAfterCompletionInvoked());
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("test");
assertThat(result.getHeaders().get(PreSendReturnsMessageInterceptor.class.getSimpleName())).isEqualTo(1);
assertThat(interceptor.wasAfterCompletionInvoked()).isTrue();
}
@Test
@@ -79,16 +72,16 @@ public class ChannelInterceptorTests {
channel.addInterceptor(interceptor);
Message<?> message = new GenericMessage<String>("test");
channel.send(message);
assertEquals(1, interceptor.getCount());
assertThat(interceptor.getCount()).isEqualTo(1);
assertTrue(channel.removeInterceptor(interceptor));
assertThat(channel.removeInterceptor(interceptor)).isTrue();
channel.send(new GenericMessage<String>("TEST"));
assertEquals(1, interceptor.getCount());
assertThat(interceptor.getCount()).isEqualTo(1);
Message<?> result = channel.receive(0);
assertNotNull(result);
assertEquals("TEST", result.getPayload());
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("TEST");
}
@Test
@@ -98,16 +91,16 @@ public class ChannelInterceptorTests {
@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
assertNotNull(message);
assertNotNull(channel);
assertSame(ChannelInterceptorTests.this.channel, channel);
assertTrue(sent);
assertThat(message).isNotNull();
assertThat(channel).isNotNull();
assertThat(channel).isSameAs(ChannelInterceptorTests.this.channel);
assertThat(sent).isTrue();
invoked.set(true);
}
});
channel.send(new GenericMessage<String>("test"));
assertTrue(invoked.get());
assertThat(invoked.get()).isTrue();
}
@Test
@@ -119,9 +112,9 @@ public class ChannelInterceptorTests {
@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
assertNotNull(message);
assertNotNull(channel);
assertSame(singleItemChannel, channel);
assertThat(message).isNotNull();
assertThat(channel).isNotNull();
assertThat(channel).isSameAs(singleItemChannel);
if (sent) {
sentCounter.incrementAndGet();
}
@@ -129,19 +122,19 @@ public class ChannelInterceptorTests {
}
});
assertEquals(0, invokedCounter.get());
assertEquals(0, sentCounter.get());
assertThat(invokedCounter.get()).isEqualTo(0);
assertThat(sentCounter.get()).isEqualTo(0);
singleItemChannel.send(new GenericMessage<String>("test1"));
assertEquals(1, invokedCounter.get());
assertEquals(1, sentCounter.get());
assertThat(invokedCounter.get()).isEqualTo(1);
assertThat(sentCounter.get()).isEqualTo(1);
singleItemChannel.send(new GenericMessage<String>("test2"), 0);
assertEquals(2, invokedCounter.get());
assertEquals(1, sentCounter.get());
assertThat(invokedCounter.get()).isEqualTo(2);
assertThat(sentCounter.get()).isEqualTo(1);
assertNotNull(singleItemChannel.removeInterceptor(0));
assertThat(singleItemChannel.removeInterceptor(0)).isNotNull();
singleItemChannel.send(new GenericMessage<String>("test2"), 0);
assertEquals(2, invokedCounter.get());
assertEquals(1, sentCounter.get());
assertThat(invokedCounter.get()).isEqualTo(2);
assertThat(sentCounter.get()).isEqualTo(1);
}
@Test
@@ -161,10 +154,10 @@ public class ChannelInterceptorTests {
testChannel.send(MessageBuilder.withPayload("test").build());
}
catch (Exception ex) {
assertEquals("Simulated exception", ex.getCause().getMessage());
assertThat(ex.getCause().getMessage()).isEqualTo("Simulated exception");
}
assertTrue(interceptor1.wasAfterCompletionInvoked());
assertTrue(interceptor2.wasAfterCompletionInvoked());
assertThat(interceptor1.wasAfterCompletionInvoked()).isTrue();
assertThat(interceptor2.wasAfterCompletionInvoked()).isTrue();
}
@Test
@@ -178,10 +171,10 @@ public class ChannelInterceptorTests {
this.channel.send(MessageBuilder.withPayload("test").build());
}
catch (Exception ex) {
assertEquals("Simulated exception", ex.getCause().getMessage());
assertThat(ex.getCause().getMessage()).isEqualTo("Simulated exception");
}
assertTrue(interceptor1.wasAfterCompletionInvoked());
assertFalse(interceptor2.wasAfterCompletionInvoked());
assertThat(interceptor1.wasAfterCompletionInvoked()).isTrue();
assertThat(interceptor2.wasAfterCompletionInvoked()).isFalse();
}
@Test
@@ -191,9 +184,9 @@ public class ChannelInterceptorTests {
Message<?> message = new GenericMessage<String>("test");
channel.send(message);
Message<?> result = channel.receive(0);
assertEquals(1, interceptor.getCounter().get());
assertNotNull(result);
assertTrue(interceptor.wasAfterCompletionInvoked());
assertThat(interceptor.getCounter().get()).isEqualTo(1);
assertThat(result).isNotNull();
assertThat(interceptor.wasAfterCompletionInvoked()).isTrue();
}
@Test
@@ -202,8 +195,8 @@ public class ChannelInterceptorTests {
Message<?> message = new GenericMessage<String>("test");
channel.send(message);
Message<?> result = channel.receive(0);
assertEquals(1, PreReceiveReturnsFalseInterceptor.counter.get());
assertNull(result);
assertThat(PreReceiveReturnsFalseInterceptor.counter.get()).isEqualTo(1);
assertThat(result).isNull();
}
@Test
@@ -213,19 +206,19 @@ public class ChannelInterceptorTests {
@Override
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
assertNotNull(channel);
assertSame(ChannelInterceptorTests.this.channel, channel);
assertThat(channel).isNotNull();
assertThat(channel).isSameAs(ChannelInterceptorTests.this.channel);
messageCount.incrementAndGet();
return message;
}
});
channel.receive(0);
assertEquals(0, messageCount.get());
assertThat(messageCount.get()).isEqualTo(0);
channel.send(new GenericMessage<String>("test"));
Message<?> result = channel.receive(0);
assertNotNull(result);
assertEquals(1, messageCount.get());
assertThat(result).isNotNull();
assertThat(messageCount.get()).isEqualTo(1);
}
@Test
@@ -240,10 +233,10 @@ public class ChannelInterceptorTests {
channel.receive(0);
}
catch (Exception ex) {
assertEquals("Simulated exception", ex.getMessage());
assertThat(ex.getMessage()).isEqualTo("Simulated exception");
}
assertTrue(interceptor1.wasAfterCompletionInvoked());
assertFalse(interceptor2.wasAfterCompletionInvoked());
assertThat(interceptor1.wasAfterCompletionInvoked()).isTrue();
assertThat(interceptor2.wasAfterCompletionInvoked()).isFalse();
}
@Test
@@ -253,10 +246,10 @@ public class ChannelInterceptorTests {
ChannelInterceptorAware channel = ac.getBean("input", AbstractMessageChannel.class);
List<ChannelInterceptor> interceptors = channel.getChannelInterceptors();
ChannelInterceptor channelInterceptor = interceptors.get(0);
assertThat(channelInterceptor, Matchers.instanceOf(PreSendReturnsMessageInterceptor.class));
assertThat(channelInterceptor).isInstanceOf(PreSendReturnsMessageInterceptor.class);
String foo = ((PreSendReturnsMessageInterceptor) channelInterceptor).getFoo();
assertTrue(StringUtils.hasText(foo));
assertEquals("foo", foo);
assertThat(StringUtils.hasText(foo)).isTrue();
assertThat(foo).isEqualTo("foo");
ac.close();
}
@@ -281,16 +274,16 @@ public class ChannelInterceptorTests {
channel.send(new GenericMessage<>("foo"));
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
channel.addInterceptor(new TestExecutorInterceptor());
channel.send(new GenericMessage<>("foo"));
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertEquals(2, messages.size());
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(messages.size()).isEqualTo(2);
assertEquals("foo", messages.get(0).getPayload());
assertEquals("FOO", messages.get(1).getPayload());
assertThat(messages.get(0).getPayload()).isEqualTo("foo");
assertThat(messages.get(1).getPayload()).isEqualTo("FOO");
testApplicationContext.close();
}
@@ -304,7 +297,7 @@ public class ChannelInterceptorTests {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
assertNotNull(message);
assertThat(message).isNotNull();
return MessageBuilder.fromMessage(message)
.setHeader(this.getClass().getSimpleName(), counter.incrementAndGet())
.build();
@@ -343,7 +336,7 @@ public class ChannelInterceptorTests {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
assertNotNull(message);
assertThat(message).isNotNull();
counter.incrementAndGet();
return null;
}
@@ -376,7 +369,7 @@ public class ChannelInterceptorTests {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
assertNotNull(message);
assertThat(message).isNotNull();
counter.incrementAndGet();
if (this.exceptionToRaise != null) {
throw this.exceptionToRaise;

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,9 +16,7 @@
package org.springframework.integration.channel.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -59,10 +57,10 @@ public class GlobalChannelInterceptorSubElementTests {
public void testWiretapSubElement() {
this.inputA.send(new GenericMessage<String>("hello"));
Message<?> result = this.wiretapChannel.receive(100);
assertNotNull(result);
assertEquals("hello", result.getPayload());
assertNull(this.wiretapChannel.receive(1));
assertNull(this.wiretap1.receive(1));
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("hello");
assertThat(this.wiretapChannel.receive(1)).isNull();
assertThat(this.wiretap1.receive(1)).isNull();
}
}

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.channel.interceptor;
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.ArrayList;
import java.util.List;
@@ -76,60 +72,60 @@ public class GlobalChannelInterceptorTests {
ChannelInterceptor[] interceptors = channel.getChannelInterceptors()
.toArray(new ChannelInterceptor[channel.getChannelInterceptors().size()]);
if (channelName.equals("inputA")) { // 328741
assertTrue(interceptors.length == 10);
assertEquals("interceptor-three", interceptors[0].toString());
assertEquals("interceptor-two", interceptors[1].toString());
assertEquals("interceptor-eight", interceptors[2].toString());
assertEquals("interceptor-seven", interceptors[3].toString());
assertEquals("interceptor-five", interceptors[4].toString());
assertEquals("interceptor-six", interceptors[5].toString());
assertEquals("interceptor-ten", interceptors[6].toString());
assertEquals("interceptor-eleven", interceptors[7].toString());
assertEquals("interceptor-four", interceptors[8].toString());
assertEquals("interceptor-one", interceptors[9].toString());
assertThat(interceptors.length == 10).isTrue();
assertThat(interceptors[0].toString()).isEqualTo("interceptor-three");
assertThat(interceptors[1].toString()).isEqualTo("interceptor-two");
assertThat(interceptors[2].toString()).isEqualTo("interceptor-eight");
assertThat(interceptors[3].toString()).isEqualTo("interceptor-seven");
assertThat(interceptors[4].toString()).isEqualTo("interceptor-five");
assertThat(interceptors[5].toString()).isEqualTo("interceptor-six");
assertThat(interceptors[6].toString()).isEqualTo("interceptor-ten");
assertThat(interceptors[7].toString()).isEqualTo("interceptor-eleven");
assertThat(interceptors[8].toString()).isEqualTo("interceptor-four");
assertThat(interceptors[9].toString()).isEqualTo("interceptor-one");
}
else if (channelName.equals("inputB")) {
assertTrue(interceptors.length == 6);
assertEquals("interceptor-three", interceptors[0].toString());
assertEquals("interceptor-two", interceptors[1].toString());
assertEquals("interceptor-ten", interceptors[2].toString());
assertEquals("interceptor-eleven", interceptors[3].toString());
assertEquals("interceptor-four", interceptors[4].toString());
assertEquals("interceptor-one", interceptors[5].toString());
assertThat(interceptors.length == 6).isTrue();
assertThat(interceptors[0].toString()).isEqualTo("interceptor-three");
assertThat(interceptors[1].toString()).isEqualTo("interceptor-two");
assertThat(interceptors[2].toString()).isEqualTo("interceptor-ten");
assertThat(interceptors[3].toString()).isEqualTo("interceptor-eleven");
assertThat(interceptors[4].toString()).isEqualTo("interceptor-four");
assertThat(interceptors[5].toString()).isEqualTo("interceptor-one");
}
else if (channelName.equals("foo")) {
assertTrue(interceptors.length == 6);
assertEquals("interceptor-two", interceptors[0].toString());
assertEquals("interceptor-five", interceptors[1].toString());
assertEquals("interceptor-ten", interceptors[2].toString());
assertEquals("interceptor-eleven", interceptors[3].toString());
assertEquals("interceptor-four", interceptors[4].toString());
assertEquals("interceptor-one", interceptors[5].toString());
assertThat(interceptors.length == 6).isTrue();
assertThat(interceptors[0].toString()).isEqualTo("interceptor-two");
assertThat(interceptors[1].toString()).isEqualTo("interceptor-five");
assertThat(interceptors[2].toString()).isEqualTo("interceptor-ten");
assertThat(interceptors[3].toString()).isEqualTo("interceptor-eleven");
assertThat(interceptors[4].toString()).isEqualTo("interceptor-four");
assertThat(interceptors[5].toString()).isEqualTo("interceptor-one");
}
else if (channelName.equals("bar")) {
assertTrue(interceptors.length == 4);
assertEquals("interceptor-eight", interceptors[0].toString());
assertEquals("interceptor-seven", interceptors[1].toString());
assertEquals("interceptor-ten", interceptors[2].toString());
assertEquals("interceptor-eleven", interceptors[3].toString());
assertThat(interceptors.length == 4).isTrue();
assertThat(interceptors[0].toString()).isEqualTo("interceptor-eight");
assertThat(interceptors[1].toString()).isEqualTo("interceptor-seven");
assertThat(interceptors[2].toString()).isEqualTo("interceptor-ten");
assertThat(interceptors[3].toString()).isEqualTo("interceptor-eleven");
}
else if (channelName.equals("baz")) {
assertTrue(interceptors.length == 2);
assertEquals("interceptor-ten", interceptors[0].toString());
assertEquals("interceptor-eleven", interceptors[1].toString());
assertThat(interceptors.length == 2).isTrue();
assertThat(interceptors[0].toString()).isEqualTo("interceptor-ten");
assertThat(interceptors[1].toString()).isEqualTo("interceptor-eleven");
}
else if (channelName.equals("inputWithProxy")) {
assertTrue(interceptors.length == 6);
assertThat(interceptors.length == 6).isTrue();
}
else if (channelName.equals("test")) {
assertNotNull(interceptors);
assertTrue(interceptors.length == 2);
assertThat(interceptors).isNotNull();
assertThat(interceptors.length == 2).isTrue();
List<String> interceptorNames = new ArrayList<String>();
for (ChannelInterceptor interceptor : interceptors) {
interceptorNames.add(interceptor.toString());
}
assertTrue(interceptorNames.contains("interceptor-ten"));
assertTrue(interceptorNames.contains("interceptor-eleven"));
assertThat(interceptorNames.contains("interceptor-ten")).isTrue();
assertThat(interceptorNames.contains("interceptor-eleven")).isTrue();
}
}
}
@@ -142,8 +138,8 @@ public class GlobalChannelInterceptorTests {
for (ChannelInterceptor interceptor : channelInterceptors) {
interceptorNames.add(interceptor.toString());
}
assertTrue(interceptorNames.contains("interceptor-ten"));
assertTrue(interceptorNames.contains("interceptor-eleven"));
assertThat(interceptorNames.contains("interceptor-ten")).isTrue();
assertThat(interceptorNames.contains("interceptor-eleven")).isTrue();
}
@Test
@@ -154,9 +150,9 @@ public class GlobalChannelInterceptorTests {
List<ChannelInterceptor> channelInterceptors = testChannel.getChannelInterceptors();
assertEquals(2, channelInterceptors.size());
assertThat(channelInterceptors.get(0), instanceOf(SampleInterceptor.class));
assertThat(channelInterceptors.get(0), instanceOf(SampleInterceptor.class));
assertThat(channelInterceptors.size()).isEqualTo(2);
assertThat(channelInterceptors.get(0)).isInstanceOf(SampleInterceptor.class);
assertThat(channelInterceptors.get(0)).isInstanceOf(SampleInterceptor.class);
}
public static class SampleInterceptor implements ChannelInterceptor {

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,7 @@
package org.springframework.integration.channel.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -73,7 +71,7 @@ public class GlobalWireTapTests {
Message<?> message = new GenericMessage<String>("hello");
this.channel.send(message);
Message<?> wireTapMessage = this.wiretapSingle.receive(100);
assertNotNull(wireTapMessage);
assertThat(wireTapMessage).isNotNull();
// There should be 5 messages on this channel:
// 'channel', 'output', 'wiretapSingle', and too for 'unnamedGlobalWireTaps'.
@@ -81,15 +79,15 @@ public class GlobalWireTapTests {
int msgCount = 0;
while (wireTapMessage != null) {
msgCount++;
assertEquals(wireTapMessage.getPayload(), message.getPayload());
assertThat(message.getPayload()).isEqualTo(wireTapMessage.getPayload());
wireTapMessage = this.wiretapAll.receive(100);
}
assertEquals(5, msgCount);
assertThat(msgCount).isEqualTo(5);
assertNull(this.wiretapAll2.receive(1));
assertThat(this.wiretapAll2.receive(1)).isNull();
assertEquals(4, this.channel.getChannelInterceptors().size());
assertThat(this.channel.getChannelInterceptors().size()).isEqualTo(4);
}
@Test
@@ -99,18 +97,18 @@ public class GlobalWireTapTests {
//This time no message on wiretapSingle
Message<?> wireTapMessage = wiretapSingle.receive(100);
assertNull(wireTapMessage);
assertThat(wireTapMessage).isNull();
//There should be two messages on this channel. One for 'channel' and one for 'output'
wireTapMessage = wiretapAll.receive(100);
int msgCount = 0;
while (wireTapMessage != null) {
msgCount++;
assertEquals(wireTapMessage.getPayload(), message.getPayload());
assertThat(message.getPayload()).isEqualTo(wireTapMessage.getPayload());
wireTapMessage = wiretapAll.receive(100);
}
assertEquals(2, msgCount);
assertThat(msgCount).isEqualTo(2);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 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,10 +16,7 @@
package org.springframework.integration.channel.interceptor;
import static org.hamcrest.Matchers.anyOf;
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 java.util.List;
@@ -57,17 +54,17 @@ public class ImplicitConsumerChannelTests {
public void testImplicit() {
// used to fail to load AC (no channel 'bar')
List<ChannelInterceptor> barInterceptors = bar.getChannelInterceptors();
assertEquals(2, barInterceptors.size());
assertThat(barInterceptors.get(0), anyOf(instanceOf(Interceptor1.class), instanceOf(Interceptor2.class)));
assertThat(barInterceptors.get(1), anyOf(instanceOf(Interceptor1.class), instanceOf(Interceptor2.class)));
assertThat(barInterceptors.size()).isEqualTo(2);
assertThat(barInterceptors.get(0)).isInstanceOfAny(Interceptor1.class, Interceptor2.class);
assertThat(barInterceptors.get(1)).isInstanceOfAny(Interceptor1.class, Interceptor2.class);
List<ChannelInterceptor> fooInterceptors = foo.getChannelInterceptors();
assertEquals(2, fooInterceptors.size());
assertThat(fooInterceptors.get(0), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor2.class)));
assertThat(fooInterceptors.get(1), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor2.class)));
assertThat(fooInterceptors.size()).isEqualTo(2);
assertThat(fooInterceptors.get(0)).isInstanceOfAny(WireTap.class, Interceptor2.class);
assertThat(fooInterceptors.get(1)).isInstanceOfAny(WireTap.class, Interceptor2.class);
List<ChannelInterceptor> bazInterceptors = baz.getChannelInterceptors();
assertEquals(2, bazInterceptors.size());
assertThat(bazInterceptors.get(0), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor1.class)));
assertThat(bazInterceptors.get(1), anyOf(instanceOf(WireTap.class), instanceOf(Interceptor1.class)));
assertThat(bazInterceptors.size()).isEqualTo(2);
assertThat(bazInterceptors.get(0)).isInstanceOfAny(WireTap.class, Interceptor1.class);
assertThat(bazInterceptors.get(1)).isInstanceOfAny(WireTap.class, Interceptor1.class);
}
public static class Interceptor1 implements ChannelInterceptor, VetoCapableInterceptor {

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.channel.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.atomic.AtomicInteger;
@@ -42,7 +41,7 @@ public class MessageSelectingInterceptorTests {
MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector);
QueueChannel channel = new QueueChannel();
channel.addInterceptor(interceptor);
assertTrue(channel.send(new GenericMessage<>("test1")));
assertThat(channel.send(new GenericMessage<>("test1"))).isTrue();
}
@Test(expected = MessageDeliveryException.class)
@@ -63,8 +62,8 @@ public class MessageSelectingInterceptorTests {
MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2);
QueueChannel channel = new QueueChannel();
channel.addInterceptor(interceptor);
assertTrue(channel.send(new GenericMessage<>("test1")));
assertEquals(2, counter.get());
assertThat(channel.send(new GenericMessage<>("test1"))).isTrue();
assertThat(counter.get()).isEqualTo(2);
}
@Test
@@ -85,8 +84,8 @@ public class MessageSelectingInterceptorTests {
catch (MessageDeliveryException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
assertEquals(2, counter.get());
assertThat(exceptionThrown).isTrue();
assertThat(counter.get()).isEqualTo(2);
}

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.channel.interceptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -42,10 +40,10 @@ public class WireTapTests {
mainChannel.addInterceptor(new WireTap(secondaryChannel));
mainChannel.send(new GenericMessage<>("testing"));
Message<?> original = mainChannel.receive(0);
assertNotNull(original);
assertThat(original).isNotNull();
Message<?> intercepted = secondaryChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
assertThat(intercepted).isNotNull();
assertThat(intercepted).isEqualTo(original);
}
@Test
@@ -55,9 +53,9 @@ public class WireTapTests {
mainChannel.addInterceptor(new WireTap(secondaryChannel, new TestSelector(false)));
mainChannel.send(new GenericMessage<>("testing"));
Message<?> original = mainChannel.receive(0);
assertNotNull(original);
assertThat(original).isNotNull();
Message<?> intercepted = secondaryChannel.receive(0);
assertNull(intercepted);
assertThat(intercepted).isNull();
}
@Test
@@ -67,10 +65,10 @@ public class WireTapTests {
mainChannel.addInterceptor(new WireTap(secondaryChannel, new TestSelector(true)));
mainChannel.send(new GenericMessage<>("testing"));
Message<?> original = mainChannel.receive(0);
assertNotNull(original);
assertThat(original).isNotNull();
Message<?> intercepted = secondaryChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
assertThat(intercepted).isNotNull();
assertThat(intercepted).isEqualTo(original);
}
@Test(expected = IllegalArgumentException.class)
@@ -83,14 +81,14 @@ public class WireTapTests {
QueueChannel mainChannel = new QueueChannel();
QueueChannel secondaryChannel = new QueueChannel();
mainChannel.addInterceptor(new WireTap(secondaryChannel));
assertNull(secondaryChannel.receive(0));
assertThat(secondaryChannel.receive(0)).isNull();
Message<?> message = new GenericMessage<>("testing");
mainChannel.send(message);
Message<?> original = mainChannel.receive(0);
Message<?> intercepted = secondaryChannel.receive(0);
assertNotNull(original);
assertNotNull(intercepted);
assertEquals(original, intercepted);
assertThat(original).isNotNull();
assertThat(intercepted).isNotNull();
assertThat(intercepted).isEqualTo(original);
}
@Test
@@ -106,9 +104,9 @@ public class WireTapTests {
Message<?> intercepted = secondaryChannel.receive(0);
Object originalAttribute = original.getHeaders().get(headerName);
Object interceptedAttribute = intercepted.getHeaders().get(headerName);
assertNotNull(originalAttribute);
assertNotNull(interceptedAttribute);
assertEquals(originalAttribute, interceptedAttribute);
assertThat(originalAttribute).isNotNull();
assertThat(interceptedAttribute).isNotNull();
assertThat(interceptedAttribute).isEqualTo(originalAttribute);
}
@Test

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,13 +16,7 @@
package org.springframework.integration.channel.reactive;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.isOneOf;
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.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -88,14 +82,14 @@ public class FluxMessageChannelTests {
for (int i = 0; i < 9; i++) {
Message<?> receive = replyChannel.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), isOneOf("0", "1", "2", "3", "4", "6", "7", "8", "9"));
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isIn("0", "1", "2", "3", "4", "6", "7", "8", "9");
}
assertNull(replyChannel.receive(0));
assertThat(replyChannel.receive(0)).isNull();
Message<?> error = this.errorChannel.receive(0);
assertNotNull(error);
assertEquals(5, ((MessagingException) error.getPayload()).getFailedMessage().getPayload());
assertThat(error).isNotNull();
assertThat(((MessagingException) error.getPayload()).getFailedMessage().getPayload()).isEqualTo(5);
}
@Test
@@ -112,8 +106,8 @@ public class FluxMessageChannelTests {
this.queueChannel.send(new GenericMessage<>("foo"));
this.queueChannel.send(new GenericMessage<>("bar"));
assertTrue(done.await(10, TimeUnit.SECONDS));
assertThat(results, contains("FOO", "BAR"));
assertThat(done.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(results).containsExactly("FOO", "BAR");
}
@Test
@@ -134,9 +128,9 @@ public class FluxMessageChannelTests {
flowRegistration.getInputChannel().send(new GenericMessage<>("foo"));
assertTrue(finishLatch.await(10, TimeUnit.SECONDS));
assertThat(finishLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertTrue(TestUtils.getPropertyValue(flux, "publishers", Map.class).isEmpty());
assertThat(TestUtils.getPropertyValue(flux, "publishers", Map.class).isEmpty()).isTrue();
flowRegistration.destroy();
}

View File

@@ -16,13 +16,8 @@
package org.springframework.integration.channel.reactive;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
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.BDDMockito.willAnswer;
import static org.mockito.Mockito.mock;
@@ -37,7 +32,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -92,9 +86,9 @@ public class ReactiveStreamsConsumerTests {
testChannel.send(testMessage);
}
catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("doesn't have subscribers to accept messages"));
assertThat(e).isInstanceOf(MessageDeliveryException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("doesn't have subscribers to accept messages");
}
reactiveConsumer.start();
@@ -102,8 +96,8 @@ public class ReactiveStreamsConsumerTests {
Message<?> testMessage2 = new GenericMessage<>("test2");
testChannel.send(testMessage2);
assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
assertThat(result, Matchers.<Message<?>>contains(testMessage, testMessage2));
assertThat(stopLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(result).containsExactly(testMessage, testMessage2);
}
@@ -138,7 +132,7 @@ public class ReactiveStreamsConsumerTests {
subscription.request(1);
Message<?> message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
assertThat(message).isSameAs(testMessage);
reactiveConsumer.stop();
@@ -147,7 +141,7 @@ public class ReactiveStreamsConsumerTests {
fail("MessageDeliveryException");
}
catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e).isInstanceOf(MessageDeliveryException.class);
}
reactiveConsumer.start();
@@ -159,12 +153,12 @@ public class ReactiveStreamsConsumerTests {
testChannel.send(testMessage);
message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
assertThat(message).isSameAs(testMessage);
verify(testSubscriber, never()).onError(any(Throwable.class));
verify(testSubscriber, never()).onComplete();
assertTrue(messages.isEmpty());
assertThat(messages.isEmpty()).isTrue();
}
@Test
@@ -198,7 +192,7 @@ public class ReactiveStreamsConsumerTests {
subscription.request(1);
Message<?> message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
assertThat(message).isSameAs(testMessage);
reactiveConsumer.stop();
@@ -217,15 +211,15 @@ public class ReactiveStreamsConsumerTests {
testChannel.send(testMessage2);
message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage, message);
assertThat(message).isSameAs(testMessage);
message = messages.poll(10, TimeUnit.SECONDS);
assertSame(testMessage2, message);
assertThat(message).isSameAs(testMessage2);
verify(testSubscriber, never()).onError(any(Throwable.class));
verify(testSubscriber, never()).onComplete();
assertTrue(messages.isEmpty());
assertThat(messages.isEmpty()).isTrue();
}
@Test
@@ -257,9 +251,9 @@ public class ReactiveStreamsConsumerTests {
testChannel.send(testMessage);
}
catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("doesn't have subscribers to accept messages"));
assertThat(e).isInstanceOf(MessageDeliveryException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("doesn't have subscribers to accept messages");
}
endpointFactoryBean.start();
@@ -269,9 +263,9 @@ public class ReactiveStreamsConsumerTests {
testChannel.send(testMessage2);
testChannel.send(testMessage2);
assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
assertThat(result.size(), equalTo(3));
assertThat(result, Matchers.<Message<?>>contains(testMessage, testMessage2, testMessage2));
assertThat(stopLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(result.size()).isEqualTo(3);
assertThat(result).containsExactly(testMessage, testMessage2, testMessage2);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-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,25 +16,14 @@
package org.springframework.integration.channel.registry;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.lessThan;
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.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -65,6 +54,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 3.0
*
*/
@@ -105,13 +96,13 @@ public class HeaderChannelRegistryTests {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.input);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("foo"));
assertNotNull(reply);
assertEquals("echo:foo", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:foo");
String stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
assertThat(TestUtils.getPropertyValue(
TestUtils.getPropertyValue(registry, "channels", Map.class)
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis(),
lessThan(61000L));
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis())
.isLessThan(61000L);
}
@Test
@@ -119,13 +110,13 @@ public class HeaderChannelRegistryTests {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.inputTtl);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("ttl"));
assertNotNull(reply);
assertEquals("echo:ttl", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:ttl");
String stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
assertThat(TestUtils.getPropertyValue(
TestUtils.getPropertyValue(registry, "channels", Map.class)
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis(),
greaterThan(100000L));
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis())
.isGreaterThan(100000L);
}
@Test
@@ -136,36 +127,36 @@ public class HeaderChannelRegistryTests {
.setHeader("channelTTL", 180000)
.build();
Message<?> reply = template.sendAndReceive(requestMessage);
assertNotNull(reply);
assertEquals("echo:ttl", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:ttl");
String stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
assertThat(TestUtils.getPropertyValue(
TestUtils.getPropertyValue(registry, "channels", Map.class)
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis(),
allOf(greaterThan(160000L), lessThan(181000L)));
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis())
.isGreaterThan(160000L).isLessThan(181000L);
// Now for Elvis...
reply = template.sendAndReceive(new GenericMessage<String>("ttl"));
assertNotNull(reply);
assertEquals("echo:ttl", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:ttl");
stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
assertThat(TestUtils.getPropertyValue(
TestUtils.getPropertyValue(registry, "channels", Map.class)
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis(),
greaterThan(220000L));
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis())
.isGreaterThan(220000L);
}
@Test
public void testReplaceGatewayWithNoReplyChannel() {
String reply = this.gatewayNoReplyChannel.exchange("foo");
assertNotNull(reply);
assertEquals("echo:foo", reply);
assertThat(reply).isNotNull();
assertThat(reply).isEqualTo("echo:foo");
}
@Test
public void testReplaceGatewayWithExplicitReplyChannel() {
String reply = this.gatewayExplicitReplyChannel.exchange("foo");
assertNotNull(reply);
assertEquals("echo:foo", reply);
assertThat(reply).isNotNull();
assertThat(reply).isEqualTo("echo:foo");
}
/**
@@ -177,10 +168,10 @@ public class HeaderChannelRegistryTests {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.inputPolled);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("bar"));
assertNotNull(reply);
assertTrue(reply instanceof ErrorMessage);
assertNotNull(((ErrorMessage) reply).getOriginalMessage());
assertThat(reply.getPayload(), not(instanceOf(MessagingExceptionWrapper.class)));
assertThat(reply).isNotNull();
assertThat(reply instanceof ErrorMessage).isTrue();
assertThat(((ErrorMessage) reply).getOriginalMessage()).isNotNull();
assertThat(reply.getPayload()).isNotInstanceOf(MessagingExceptionWrapper.class);
}
@Test
@@ -191,8 +182,8 @@ public class HeaderChannelRegistryTests {
.build();
this.input.send(requestMessage);
Message<?> reply = alreadyAString.receive(0);
assertNotNull(reply);
assertEquals("echo:foo", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:foo");
}
@Test
@@ -204,7 +195,7 @@ public class HeaderChannelRegistryTests {
fail("expected exception");
}
catch (Exception e) {
assertThat(e.getMessage(), Matchers.containsString("no output-channel or replyChannel"));
assertThat(e.getMessage()).contains("no output-channel or replyChannel");
}
}
@@ -217,7 +208,7 @@ public class HeaderChannelRegistryTests {
while (n++ < 100 && registry.channelNameToChannel(id) != null) {
Thread.sleep(100);
}
assertNull(registry.channelNameToChannel(id));
assertThat(registry.channelNameToChannel(id)).isNull();
registry.stop();
}
@@ -226,8 +217,8 @@ public class HeaderChannelRegistryTests {
BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver();
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.getBean(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME,
HeaderChannelRegistry.class))
.thenReturn(mock(HeaderChannelRegistry.class));
HeaderChannelRegistry.class))
.thenReturn(mock(HeaderChannelRegistry.class));
doAnswer(invocation -> {
throw new NoSuchBeanDefinitionException("bar");
}).when(beanFactory).getBean("foo", MessageChannel.class);
@@ -237,8 +228,8 @@ public class HeaderChannelRegistryTests {
fail("Expected exception");
}
catch (DestinationResolutionException e) {
assertThat(e.getMessage(),
Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory."));
assertThat(e.getMessage()).contains("failed to look up MessageChannel with name 'foo' in the BeanFactory" +
".");
}
}
@@ -255,9 +246,9 @@ public class HeaderChannelRegistryTests {
fail("Expected exception");
}
catch (DestinationResolutionException e) {
assertThat(e.getMessage(),
Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory " +
"(and there is no HeaderChannelRegistry present)."));
assertThat(e.getMessage()).contains("failed to look up MessageChannel with name 'foo' in the BeanFactory" +
" " +
"(and there is no HeaderChannelRegistry present).");
}
}
@@ -267,12 +258,12 @@ public class HeaderChannelRegistryTests {
MessageChannel channel = new DirectChannel();
String foo = (String) registry.channelToChannelName(channel);
Map<?, ?> map = TestUtils.getPropertyValue(registry, "channels", Map.class);
assertEquals(1, map.size());
assertSame(channel, registry.channelNameToChannel(foo));
assertEquals(1, map.size());
assertThat(map.size()).isEqualTo(1);
assertThat(registry.channelNameToChannel(foo)).isSameAs(channel);
assertThat(map.size()).isEqualTo(1);
registry.setRemoveOnGet(true);
assertSame(channel, registry.channelNameToChannel(foo));
assertEquals(0, map.size());
assertThat(registry.channelNameToChannel(foo)).isSameAs(channel);
assertThat(map.size()).isEqualTo(0);
}
@@ -280,10 +271,14 @@ public class HeaderChannelRegistryTests {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
assertThat(requestMessage.getHeaders().getReplyChannel(),
Matchers.anyOf(instanceOf(String.class), Matchers.nullValue()));
assertThat(requestMessage.getHeaders().getErrorChannel(),
Matchers.anyOf(instanceOf(String.class), Matchers.nullValue()));
assertThat(requestMessage.getHeaders().getReplyChannel())
.satisfiesAnyOf(
replyChannel -> assertThat(replyChannel).isInstanceOf(String.class),
replyChannel -> assertThat(replyChannel).isNull());
assertThat(requestMessage.getHeaders().getErrorChannel())
.satisfiesAnyOf(
errorChannel -> assertThat(errorChannel).isInstanceOf(String.class),
errorChannel -> assertThat(errorChannel).isNull());
if (requestMessage.getPayload().equals("bar")) {
throw new RuntimeException("intentional");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-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.codec.kryo;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.HashMap;
@@ -49,7 +49,7 @@ public class CompositeCodecTests {
SomeClassWithNoDefaultConstructors foo2 = this.codec.decode(
this.codec.encode(foo),
SomeClassWithNoDefaultConstructors.class);
assertEquals(foo, foo2);
assertThat(foo2).isEqualTo(foo);
}
static class SomeClassWithNoDefaultConstructors {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-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.codec.kryo;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
@@ -35,7 +35,7 @@ public class FileKryoRegistrarTests {
PojoCodec pc = new PojoCodec(new FileKryoRegistrar());
File file = new File("/foo/bar");
File file2 = pc.decode(pc.encode(file), File.class);
assertEquals(file, file2);
assertThat(file2).isEqualTo(file);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-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.codec.kryo;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -26,10 +26,13 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.assertj.core.data.Offset;
import org.junit.Test;
/**
* @author David Turanski
* @author Artem Bilan
*
* @since 4.2
*/
public class KryoCodecTests {
@@ -43,7 +46,7 @@ public class KryoCodecTests {
codec.encode(str, bos);
String s2 = codec.decode(bos.toByteArray(), String.class);
assertEquals(str, s2);
assertThat(s2).isEqualTo(str);
}
@Test
@@ -58,7 +61,7 @@ public class KryoCodecTests {
FileInputStream fis = new FileInputStream(file);
String s2 = codec.decode(fis, String.class);
file.delete();
assertEquals(str, s2);
assertThat(s2).isEqualTo(str);
}
@Test
@@ -68,7 +71,7 @@ public class KryoCodecTests {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
codec.encode(foo, bos);
Object foo2 = codec.decode(bos.toByteArray(), SomeClassWithNoDefaultConstructors.class);
assertEquals(foo, foo2);
assertThat(foo2).isEqualTo(foo);
}
@Test
@@ -78,36 +81,36 @@ public class KryoCodecTests {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
codec.encode(true, bos);
boolean b = codec.decode(bos.toByteArray(), Boolean.class);
assertEquals(true, b);
assertThat(b).isEqualTo(true);
b = codec.decode(bos.toByteArray(), boolean.class);
assertEquals(true, b);
assertThat(b).isEqualTo(true);
bos = new ByteArrayOutputStream();
codec.encode(3.14159, bos);
double d = codec.decode(bos.toByteArray(), double.class);
assertEquals(3.14159, d, 0.00001);
assertThat(d).isCloseTo(3.14159, Offset.offset(0.00001));
bos = new ByteArrayOutputStream();
codec.encode(3.14159, bos);
d = codec.decode(bos.toByteArray(), Double.class);
assertEquals(3.14159, d, 0.00001);
assertThat(d).isCloseTo(3.14159, Offset.offset(0.00001));
}
@Test
public void testMapSerialization() throws IOException {
PojoCodec codec = new PojoCodec();
Map<String, Integer> map = new HashMap<String, Integer>();
Map<String, Integer> map = new HashMap<>();
map.put("one", 1);
map.put("two", 2);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
codec.encode(map, bos);
Map<?, ?> m2 = (Map<?, ?>) codec.decode(bos.toByteArray(), HashMap.class);
assertEquals(2, m2.size());
assertEquals(1, m2.get("one"));
assertEquals(2, m2.get("two"));
assertThat(m2.size()).isEqualTo(2);
assertThat(m2.get("one")).isEqualTo(1);
assertThat(m2.get("two")).isEqualTo(2);
}
@Test
@@ -120,8 +123,8 @@ public class KryoCodecTests {
codec.encode(foo, bos);
Foo foo2 = codec.decode(bos.toByteArray(), Foo.class);
assertEquals(1, foo2.get("one"));
assertEquals(2, foo2.get("two"));
assertThat(foo2.get("one")).isEqualTo(1);
assertThat(foo2.get("two")).isEqualTo(2);
}
static class SomeClassWithNoDefaultConstructors {
@@ -158,7 +161,7 @@ public class KryoCodecTests {
private Map<Object, Object> map;
Foo() {
map = new HashMap<Object, Object>();
this.map = new HashMap<>();
}
public void put(Object key, Object value) {

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,24 +16,14 @@
package org.springframework.integration.config;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsString;
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.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 java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -92,14 +82,15 @@ public class AggregatorParserTests {
outboundMessages.forEach(input::send);
assertEquals("One and only one message must have been aggregated", 1,
aggregatorBean.getAggregatedMessages().size());
assertThat(aggregatorBean.getAggregatedMessages().size())
.as("One and only one message must have been aggregated").isEqualTo(1);
Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");
assertEquals("The aggregated message payload is not correct", "123456789", aggregatedMessage.getPayload());
assertThat(aggregatedMessage.getPayload()).as("The aggregated message payload is not correct")
.isEqualTo("123456789");
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
Object handler = context.getBean("aggregatorWithReference.handler");
assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
assertTrue(TestUtils.getPropertyValue(handler, "releaseLockBeforeSend", Boolean.class));
assertThat(TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")).isSameAs(mbf);
assertThat(TestUtils.getPropertyValue(handler, "releaseLockBeforeSend", Boolean.class)).isTrue();
}
@Test
@@ -114,10 +105,10 @@ public class AggregatorParserTests {
outboundMessages.forEach(input::send);
assertEquals(3, output.getQueueSize());
assertThat(output.getQueueSize()).isEqualTo(3);
output.purge(null);
assertFalse(TestUtils.getPropertyValue(context.getBean("aggregatorWithMGPReference.handler"),
"releaseLockBeforeSend", Boolean.class));
assertThat(TestUtils.getPropertyValue(context.getBean("aggregatorWithMGPReference.handler"),
"releaseLockBeforeSend", Boolean.class)).isFalse();
}
@Test
@@ -132,7 +123,7 @@ public class AggregatorParserTests {
outboundMessages.forEach(input::send);
assertEquals(3, output.getQueueSize());
assertThat(output.getQueueSize()).isEqualTo(3);
output.purge(null);
}
@@ -149,12 +140,12 @@ public class AggregatorParserTests {
outboundMessages.forEach(input::send);
assertEquals("The aggregated message payload is not correct", "[123]", aggregatedMessage.get().getPayload()
.toString());
assertThat(aggregatedMessage.get().getPayload()
.toString()).as("The aggregated message payload is not correct").isEqualTo("[123]");
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
Object handler = context.getBean("aggregatorWithExpressions.handler");
assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
assertTrue(TestUtils.getPropertyValue(handler, "expireGroupsUponTimeout", Boolean.class));
assertThat(TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")).isSameAs(mbf);
assertThat(TestUtils.getPropertyValue(handler, "expireGroupsUponTimeout", Boolean.class)).isTrue();
}
@Test
@@ -165,40 +156,46 @@ public class AggregatorParserTests {
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
Object consumer = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertThat(consumer, is(instanceOf(AggregatingMessageHandler.class)));
assertThat(consumer).isInstanceOf(AggregatingMessageHandler.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
Object handlerMethods = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(accessor
.getPropertyValue("outputProcessor")).getPropertyValue("processor")).getPropertyValue("delegate"))
.getPropertyValue("handlerMethods");
assertNull(handlerMethods);
assertThat(handlerMethods).isNull();
Object handlerMethod = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(accessor
.getPropertyValue("outputProcessor")).getPropertyValue("processor")).getPropertyValue("delegate"))
.getPropertyValue("handlerMethod");
assertTrue(handlerMethod.toString().contains("createSingleMessageFromGroup"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate ReleaseStrategy instance",
releaseStrategy, accessor.getPropertyValue("releaseStrategy"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate CorrelationStrategy instance",
correlationStrategy, accessor.getPropertyValue("correlationStrategy"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate output channel",
outputChannel, accessor.getPropertyValue("outputChannel"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate discard channel",
discardChannel, accessor.getPropertyValue("discardChannel"));
assertEquals("The AggregatorEndpoint is not set with the appropriate timeout value", 86420000L,
TestUtils.getPropertyValue(consumer, "messagingTemplate.sendTimeout"));
assertEquals(
"The AggregatorEndpoint is not configured with the appropriate 'send partial results on timeout' flag",
true, accessor.getPropertyValue("sendPartialResultOnExpiry"));
assertFalse(TestUtils.getPropertyValue(consumer, "expireGroupsUponTimeout", Boolean.class));
assertTrue(TestUtils.getPropertyValue(consumer, "expireGroupsUponCompletion", Boolean.class));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "minimumTimeoutForEmptyGroups"));
assertEquals("456", TestUtils.getPropertyValue(consumer, "groupTimeoutExpression", Expression.class)
.getExpressionString());
assertSame(this.context.getBean(LockRegistry.class), TestUtils.getPropertyValue(consumer, "lockRegistry"));
assertSame(this.context.getBean("scheduler"), TestUtils.getPropertyValue(consumer, "taskScheduler"));
assertSame(this.context.getBean("store"), TestUtils.getPropertyValue(consumer, "messageStore"));
assertEquals(5, TestUtils.getPropertyValue(consumer, "order"));
assertNotNull(TestUtils.getPropertyValue(consumer, "forceReleaseAdviceChain"));
assertFalse(TestUtils.getPropertyValue(consumer, "popSequence", Boolean.class));
assertThat(handlerMethod.toString().contains("createSingleMessageFromGroup")).isTrue();
assertThat(accessor.getPropertyValue("releaseStrategy"))
.as("The AggregatorEndpoint is not injected with the appropriate ReleaseStrategy instance")
.isEqualTo(releaseStrategy);
assertThat(accessor.getPropertyValue("correlationStrategy"))
.as("The AggregatorEndpoint is not injected with the appropriate CorrelationStrategy instance")
.isEqualTo(correlationStrategy);
assertThat(accessor.getPropertyValue("outputChannel"))
.as("The AggregatorEndpoint is not injected with the appropriate output channel")
.isEqualTo(outputChannel);
assertThat(accessor.getPropertyValue("discardChannel"))
.as("The AggregatorEndpoint is not injected with the appropriate discard channel")
.isEqualTo(discardChannel);
assertThat(TestUtils.getPropertyValue(consumer, "messagingTemplate.sendTimeout"))
.as("The AggregatorEndpoint is not set with the appropriate timeout value").isEqualTo(86420000L);
assertThat(accessor.getPropertyValue("sendPartialResultOnExpiry"))
.as("The AggregatorEndpoint is not configured with the appropriate 'send partial results on timeout' " +
"flag")
.isEqualTo(true);
assertThat(TestUtils.getPropertyValue(consumer, "expireGroupsUponTimeout", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(consumer, "expireGroupsUponCompletion", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(consumer, "minimumTimeoutForEmptyGroups")).isEqualTo(123L);
assertThat(TestUtils.getPropertyValue(consumer, "groupTimeoutExpression", Expression.class)
.getExpressionString()).isEqualTo("456");
assertThat(TestUtils.getPropertyValue(consumer, "lockRegistry"))
.isSameAs(this.context.getBean(LockRegistry.class));
assertThat(TestUtils.getPropertyValue(consumer, "taskScheduler")).isSameAs(this.context.getBean("scheduler"));
assertThat(TestUtils.getPropertyValue(consumer, "messageStore")).isSameAs(this.context.getBean("store"));
assertThat(TestUtils.getPropertyValue(consumer, "order")).isEqualTo(5);
assertThat(TestUtils.getPropertyValue(consumer, "forceReleaseAdviceChain")).isNotNull();
assertThat(TestUtils.getPropertyValue(consumer, "popSequence", Boolean.class)).isFalse();
}
@Test
@@ -211,10 +208,10 @@ public class AggregatorParserTests {
outboundMessages.forEach(input::send);
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
Message<?> response = outputChannel.receive(10);
Assert.assertEquals(6L, response.getPayload());
assertThat(response.getPayload()).isEqualTo(6L);
Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
Object handler = context.getBean("aggregatorWithReferenceAndMethod.handler");
assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
assertThat(TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")).isSameAs(mbf);
}
@Test
@@ -224,7 +221,7 @@ public class AggregatorParserTests {
fail("Expected exception");
}
catch (BeanCreationException e) {
assertThat(e.getMessage(), containsString("Adder] has no eligible methods"));
assertThat(e.getMessage()).contains("Adder] has no eligible methods");
}
}
@@ -235,7 +232,7 @@ public class AggregatorParserTests {
fail("Expected exception");
}
catch (BeanCreationException e) {
assertThat(e.getMessage(), containsString("No bean named 'testReleaseStrategy' available"));
assertThat(e.getMessage()).contains("No bean named 'testReleaseStrategy' available");
}
}
@@ -246,23 +243,23 @@ public class AggregatorParserTests {
EventDrivenConsumer endpoint = this.context.getBean("aggregatorWithPojoReleaseStrategy", EventDrivenConsumer.class);
ReleaseStrategy releaseStrategy =
TestUtils.getPropertyValue(endpoint, "handler.releaseStrategy", ReleaseStrategy.class);
Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy);
assertThat(releaseStrategy instanceof MethodInvokingReleaseStrategy).isTrue();
MessagingMethodInvokerHelper<Long> methodInvokerHelper =
TestUtils.getPropertyValue(releaseStrategy, "adapter.delegate", MessagingMethodInvokerHelper.class);
Object handlerMethods = TestUtils.getPropertyValue(methodInvokerHelper, "handlerMethods");
assertNull(handlerMethods);
assertThat(handlerMethods).isNull();
Object handlerMethod = TestUtils.getPropertyValue(methodInvokerHelper, "handlerMethod");
assertTrue(handlerMethod.toString().contains("checkCompleteness"));
assertThat(handlerMethod.toString().contains("checkCompleteness")).isTrue();
input.send(createMessage(1L, "correlationId", 4, 0, null));
input.send(createMessage(2L, "correlationId", 4, 1, null));
input.send(createMessage(3L, "correlationId", 4, 2, null));
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
Message<?> reply = outputChannel.receive(0);
Assert.assertNull(reply);
assertThat(reply).isNull();
input.send(createMessage(5L, "correlationId", 4, 3, null));
reply = outputChannel.receive(0);
Assert.assertNotNull(reply);
assertEquals(11L, reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo(11L);
}
@Test // see INT-2011
@@ -271,23 +268,23 @@ public class AggregatorParserTests {
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("aggregatorWithPojoReleaseStrategyAsCollection");
ReleaseStrategy releaseStrategy = (ReleaseStrategy) new DirectFieldAccessor(new DirectFieldAccessor(endpoint)
.getPropertyValue("handler")).getPropertyValue("releaseStrategy");
Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy);
assertThat(releaseStrategy instanceof MethodInvokingReleaseStrategy).isTrue();
DirectFieldAccessor releaseStrategyAccessor = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(releaseStrategy)
.getPropertyValue("adapter")).getPropertyValue("delegate"));
Object handlerMethods = releaseStrategyAccessor.getPropertyValue("handlerMethods");
assertNull(handlerMethods);
assertThat(handlerMethods).isNull();
Object handlerMethod = releaseStrategyAccessor.getPropertyValue("handlerMethod");
assertTrue(handlerMethod.toString().contains("checkCompleteness"));
assertThat(handlerMethod.toString().contains("checkCompleteness")).isTrue();
input.send(createMessage(1L, "correlationId", 4, 0, null));
input.send(createMessage(2L, "correlationId", 4, 1, null));
input.send(createMessage(3L, "correlationId", 4, 2, null));
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
Message<?> reply = outputChannel.receive(0);
Assert.assertNull(reply);
assertThat(reply).isNull();
input.send(createMessage(5L, "correlationId", 4, 3, null));
reply = outputChannel.receive(0);
Assert.assertNotNull(reply);
assertEquals(11L, reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo(11L);
}
@Test
@@ -297,7 +294,7 @@ public class AggregatorParserTests {
fail("Expected exception");
}
catch (BeanCreationException e) {
assertThat(e.getMessage(), containsString("TestReleaseStrategy] has no eligible methods"));
assertThat(e.getMessage()).contains("TestReleaseStrategy] has no eligible methods");
}
}
@@ -306,15 +303,17 @@ public class AggregatorParserTests {
EventDrivenConsumer aggregatorConsumer = (EventDrivenConsumer) context.getBean("aggregatorWithExpressionsAndPojoAggregator");
AggregatingMessageHandler aggregatingMessageHandler = (AggregatingMessageHandler) TestUtils.getPropertyValue(aggregatorConsumer, "handler");
MethodInvokingMessageGroupProcessor messageGroupProcessor = (MethodInvokingMessageGroupProcessor) TestUtils.getPropertyValue(aggregatingMessageHandler, "outputProcessor");
Object messageGroupProcessorTargetObject = TestUtils.getPropertyValue(messageGroupProcessor, "processor.delegate.targetObject");
assertSame(context.getBean("aggregatorBean"), messageGroupProcessorTargetObject);
Object messageGroupProcessorTargetObject = TestUtils.getPropertyValue(messageGroupProcessor, "processor" +
".delegate.targetObject");
assertThat(messageGroupProcessorTargetObject).isSameAs(context.getBean("aggregatorBean"));
ReleaseStrategy releaseStrategy = (ReleaseStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "releaseStrategy");
CorrelationStrategy correlationStrategy = (CorrelationStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "correlationStrategy");
Long minimumTimeoutForEmptyGroups = TestUtils.getPropertyValue(aggregatingMessageHandler, "minimumTimeoutForEmptyGroups", Long.class);
Long minimumTimeoutForEmptyGroups = TestUtils.getPropertyValue(aggregatingMessageHandler,
"minimumTimeoutForEmptyGroups", Long.class);
assertTrue(ExpressionEvaluatingReleaseStrategy.class.equals(releaseStrategy.getClass()));
assertTrue(ExpressionEvaluatingCorrelationStrategy.class.equals(correlationStrategy.getClass()));
assertEquals(60000L, minimumTimeoutForEmptyGroups.longValue());
assertThat(ExpressionEvaluatingReleaseStrategy.class.equals(releaseStrategy.getClass())).isTrue();
assertThat(ExpressionEvaluatingCorrelationStrategy.class.equals(correlationStrategy.getClass())).isTrue();
assertThat(minimumTimeoutForEmptyGroups.longValue()).isEqualTo(60000L);
}
@Test
@@ -323,8 +322,8 @@ public class AggregatorParserTests {
new ClassPathXmlApplicationContext("aggregatorParserFailTests.xml", this.getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertThat(e.getMessage(), containsString(
"Exactly one of the 'release-strategy' or 'release-strategy-expression' attribute is allowed."));
assertThat(e.getMessage())
.contains("Exactly one of the 'release-strategy' or 'release-strategy-expression' attribute is allowed.");
}
}

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,10 @@
package org.springframework.integration.config;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -97,9 +95,9 @@ public class AggregatorWithCorrelationStrategyTests {
private void receiveAndCompare(PollableChannel outputChannel, String... expectedValues) {
Message<?> message = outputChannel.receive(500);
Assert.assertNotNull(message);
assertThat(message).isNotNull();
for (String expectedValue : expectedValues) {
assertThat((String) message.getPayload(), containsString(expectedValue));
assertThat((String) message.getPayload()).contains(expectedValue);
}
}

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.config;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,15 +58,16 @@ public class AggregatorWithMessageStoreParserTests {
@DirtiesContext
public void testAggregation() {
input.send(createMessage("123", "id1", 3, 1, null));
assertEquals(1, messageGroupStore.getMessageGroup("id1").size());
assertThat(messageGroupStore.getMessageGroup("id1").size()).isEqualTo(1);
input.send(createMessage("789", "id1", 3, 3, null));
assertEquals(2, messageGroupStore.getMessageGroup("id1").size());
assertThat(messageGroupStore.getMessageGroup("id1").size()).isEqualTo(2);
input.send(createMessage("456", "id1", 3, 2, null));
assertEquals("One and only one message should have been aggregated", 1, aggregatorBean
.getAggregatedMessages().size());
assertThat(aggregatorBean
.getAggregatedMessages().size()).as("One and only one message should have been aggregated")
.isEqualTo(1);
Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");
assertEquals("The aggregated message payload is not correct", "123456789", aggregatedMessage
.getPayload());
assertThat(aggregatedMessage
.getPayload()).as("The aggregated message payload is not correct").isEqualTo("123456789");
}
@@ -74,15 +75,16 @@ public class AggregatorWithMessageStoreParserTests {
@DirtiesContext
public void testExpiry() {
input.send(createMessage("123", "id1", 3, 1, null));
assertEquals(1, messageGroupStore.getMessageGroup("id1").size());
assertThat(messageGroupStore.getMessageGroup("id1").size()).isEqualTo(1);
input.send(createMessage("456", "id1", 3, 2, null));
assertEquals(2, messageGroupStore.getMessageGroup("id1").size());
assertThat(messageGroupStore.getMessageGroup("id1").size()).isEqualTo(2);
this.controlBusChannel.send(new GenericMessage<Object>("@messageStore.expireMessageGroups(-10000)"));
assertEquals("One and only one message should have been aggregated", 1, aggregatorBean
.getAggregatedMessages().size());
assertThat(aggregatorBean
.getAggregatedMessages().size()).as("One and only one message should have been aggregated")
.isEqualTo(1);
Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");
assertEquals("The aggregated message payload is not correct", "123456", aggregatedMessage
.getPayload());
assertThat(aggregatedMessage
.getPayload()).as("The aggregated message payload is not correct").isEqualTo("123456");
}

Some files were not shown because too many files have changed in this diff Show More