Migrate tests to AssertJ

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

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

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,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");
}

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,15 +16,8 @@
package org.springframework.integration.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.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.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -34,8 +27,6 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,9 +49,9 @@ import org.springframework.integration.handler.LoggingHandler;
import org.springframework.integration.handler.MessageHandlerChain;
import org.springframework.integration.handler.ReplyRequiredException;
import org.springframework.integration.handler.ServiceActivatingHandler;
import org.springframework.integration.message.MessageMatcher;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.json.JsonObjectMapper;
import org.springframework.integration.test.predicate.MessagePredicate;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.transformer.MessageTransformingHandler;
import org.springframework.integration.transformer.ObjectToMapTransformer;
@@ -174,18 +165,13 @@ public class ChainParserTests {
public static Message<?> successMessage = MessageBuilder.withPayload("success").build();
@Factory
public static Matcher<Message<?>> sameExceptImmutableHeaders(Message<?> expected) {
return new MessageMatcher(expected);
}
@Test
public void chainWithAcceptingFilter() {
Message<?> message = MessageBuilder.withPayload("test").build();
this.filterInput.send(message);
Message<?> reply = this.output.receive(1000);
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("foo");
}
@Test
@@ -193,7 +179,7 @@ public class ChainParserTests {
Message<?> message = MessageBuilder.withPayload(123).build();
this.filterInput.send(message);
Message<?> reply = this.output.receive(0);
assertNull(reply);
assertThat(reply).isNull();
}
@Test
@@ -201,11 +187,11 @@ public class ChainParserTests {
Message<?> message = MessageBuilder.withPayload(123).build();
this.headerEnricherInput.send(message);
Message<?> reply = this.replyOutput.receive(1000);
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
assertEquals("ABC", new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
assertEquals("XYZ", reply.getHeaders().get("testValue"));
assertEquals(123, reply.getHeaders().get("testRef"));
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("foo");
assertThat(new IntegrationMessageHeaderAccessor(reply).getCorrelationId()).isEqualTo("ABC");
assertThat(reply.getHeaders().get("testValue")).isEqualTo("XYZ");
assertThat(reply.getHeaders().get("testRef")).isEqualTo(123);
}
@Test
@@ -213,8 +199,8 @@ public class ChainParserTests {
Message<?> message = MessageBuilder.withPayload("test").build();
this.pollableInput1.send(message);
Message<?> reply = this.output.receive(3000);
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("foo");
}
@Test
@@ -222,76 +208,76 @@ public class ChainParserTests {
Message<?> message = MessageBuilder.withPayload("test").build();
this.pollableInput2.send(message);
Message<?> reply = this.output.receive(3000);
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("foo");
}
@Test
public void chainHandlerBean() throws Exception {
public void chainHandlerBean() {
Message<?> message = MessageBuilder.withPayload("test").build();
this.beanInput.send(message);
Message<?> reply = this.output.receive(3000);
assertNotNull(reply);
assertThat(reply, sameExceptImmutableHeaders(successMessage));
assertThat(reply).isNotNull();
assertThat(reply).matches(new MessagePredicate(successMessage));
}
@SuppressWarnings("rawtypes")
@Test
public void chainNestingAndAggregation() throws Exception {
public void chainNestingAndAggregation() {
Message<?> message = MessageBuilder.withPayload("test").setCorrelationId(1).setSequenceSize(1).build();
this.aggregatorInput.send(message);
Message reply = this.output.receive(3000);
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("foo");
}
@Test
public void chainWithPayloadTypeRouter() throws Exception {
public void chainWithPayloadTypeRouter() {
Message<?> message1 = MessageBuilder.withPayload("test").build();
Message<?> message2 = MessageBuilder.withPayload(123).build();
this.payloadTypeRouterInput.send(message1);
this.payloadTypeRouterInput.send(message2);
Message<?> reply1 = this.strings.receive(1000);
Message<?> reply2 = this.numbers.receive(1000);
assertNotNull(reply1);
assertNotNull(reply2);
assertEquals("test", reply1.getPayload());
assertEquals(123, reply2.getPayload());
assertThat(reply1).isNotNull();
assertThat(reply2).isNotNull();
assertThat(reply1.getPayload()).isEqualTo("test");
assertThat(reply2.getPayload()).isEqualTo(123);
}
@Test // INT-2315
public void chainWithHeaderValueRouter() throws Exception {
public void chainWithHeaderValueRouter() {
Message<?> message1 = MessageBuilder.withPayload("test").setHeader("routingHeader", "strings").build();
Message<?> message2 = MessageBuilder.withPayload(123).setHeader("routingHeader", "numbers").build();
this.headerValueRouterInput.send(message1);
this.headerValueRouterInput.send(message2);
Message<?> reply1 = this.strings.receive(1000);
Message<?> reply2 = this.numbers.receive(1000);
assertNotNull(reply1);
assertNotNull(reply2);
assertEquals("test", reply1.getPayload());
assertEquals(123, reply2.getPayload());
assertThat(reply1).isNotNull();
assertThat(reply2).isNotNull();
assertThat(reply1.getPayload()).isEqualTo("test");
assertThat(reply2.getPayload()).isEqualTo(123);
}
@Test // INT-2315
public void chainWithHeaderValueRouterWithMapping() throws Exception {
public void chainWithHeaderValueRouterWithMapping() {
Message<?> message1 = MessageBuilder.withPayload("test").setHeader("routingHeader", "isString").build();
Message<?> message2 = MessageBuilder.withPayload(123).setHeader("routingHeader", "isNumber").build();
this.headerValueRouterWithMappingInput.send(message1);
this.headerValueRouterWithMappingInput.send(message2);
Message<?> reply1 = this.strings.receive(0);
Message<?> reply2 = this.numbers.receive(0);
assertNotNull(reply1);
assertNotNull(reply2);
assertEquals("test", reply1.getPayload());
assertEquals(123, reply2.getPayload());
assertThat(reply1).isNotNull();
assertThat(reply2).isNotNull();
assertThat(reply1.getPayload()).isEqualTo("test");
assertThat(reply2.getPayload()).isEqualTo(123);
}
@Test // INT-1165
public void chainWithSendTimeout() {
long sendTimeout = TestUtils.getPropertyValue(this.chainWithSendTimeout, "messagingTemplate.sendTimeout",
Long.class);
assertEquals(9876, sendTimeout);
assertThat(sendTimeout).isEqualTo(9876);
}
@Test //INT-1622
@@ -299,19 +285,19 @@ public class ChainParserTests {
Message<?> message = MessageBuilder.withPayload("test").build();
this.claimCheckInput.send(message);
Message<?> reply = this.claimCheckOutput.receive(0);
assertEquals(message.getPayload(), reply.getPayload());
assertThat(reply.getPayload()).isEqualTo(message.getPayload());
}
@Test //INT-2275
public void chainWithOutboundChannelAdapter() {
this.outboundChannelAdapterChannel.send(successMessage);
assertSame(successMessage, testConsumer.getLastMessage());
assertThat(testConsumer.getLastMessage()).isSameAs(successMessage);
}
@Test //INT-2275, INT-2958
public void chainWithLoggingChannelAdapter() {
Log logger = mock(Log.class);
final AtomicReference<String> log = new AtomicReference<String>();
final AtomicReference<String> log = new AtomicReference<>();
when(logger.isWarnEnabled()).thenReturn(true);
doAnswer(invocation -> {
log.set(invocation.getArgument(0));
@@ -321,13 +307,13 @@ public class ChainParserTests {
@SuppressWarnings("unchecked")
List<MessageHandler> handlers = TestUtils.getPropertyValue(this.logChain, "handlers", List.class);
MessageHandler handler = handlers.get(2);
assertTrue(handler instanceof LoggingHandler);
assertThat(handler instanceof LoggingHandler).isTrue();
DirectFieldAccessor dfa = new DirectFieldAccessor(handler);
dfa.setPropertyValue("messageLogger", logger);
this.loggingChannelAdapterChannel.send(MessageBuilder.withPayload(new byte[] { 116, 101, 115, 116 }).build());
assertNotNull(log.get());
assertEquals("TEST", log.get());
assertThat(log.get()).isNotNull();
assertThat(log.get()).isEqualTo("TEST");
}
@Test(expected = BeanCreationException.class) //INT-2275
@@ -338,9 +324,9 @@ public class ChainParserTests {
fail("BeanCreationException is expected!");
}
catch (BeansException e) {
assertEquals(IllegalArgumentException.class, e.getCause().getClass());
assertTrue(e.getMessage().contains("output channel was provided"));
assertTrue(e.getMessage().contains("does not implement the MessageProducer"));
assertThat(e.getCause().getClass()).isEqualTo(IllegalArgumentException.class);
assertThat(e.getMessage()).contains("output channel was provided");
assertThat(e.getMessage()).contains("does not implement the MessageProducer");
throw e;
}
}
@@ -350,100 +336,134 @@ public class ChainParserTests {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"ChainParserSmartLifecycleAttributesTest.xml", this.getClass());
AbstractEndpoint chainEndpoint = ctx.getBean("chain", AbstractEndpoint.class);
assertEquals(false, chainEndpoint.isAutoStartup());
assertEquals(256, chainEndpoint.getPhase());
assertThat(chainEndpoint.isAutoStartup()).isEqualTo(false);
assertThat(chainEndpoint.getPhase()).isEqualTo(256);
MessageHandlerChain handlerChain = ctx.getBean("chain.handler", MessageHandlerChain.class);
assertEquals(3000L, TestUtils.getPropertyValue(handlerChain, "messagingTemplate.sendTimeout"));
assertEquals(false, TestUtils.getPropertyValue(handlerChain, "running"));
assertThat(TestUtils.getPropertyValue(handlerChain, "messagingTemplate.sendTimeout")).isEqualTo(3000L);
assertThat(TestUtils.getPropertyValue(handlerChain, "running")).isEqualTo(false);
//INT-3108
MessageHandler serviceActivator = ctx.getBean("chain$child.sa-within-chain.handler", MessageHandler.class);
assertTrue(TestUtils.getPropertyValue(serviceActivator, "requiresReply", Boolean.class));
assertThat(TestUtils.getPropertyValue(serviceActivator, "requiresReply", Boolean.class)).isTrue();
ctx.close();
}
@Test
public void testInt2755SubComponentsIdSupport() {
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1.handler"));
assertTrue(this.beanFactory.containsBean("filterChain$child.filterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("filterChain$child.serviceActivatorWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.aggregatorWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.filterWithinNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain$child.filterWithinDoubleNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.aggregatorWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain$child.filterWithinNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("payloadTypeRouterChain$child.payloadTypeRouterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("headerValueRouterChain$child.headerValueRouterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckInWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckOutWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("outboundChain$child.outboundChannelAdapterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("logChain$child.transformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("logChain$child.loggingChannelAdapterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.splitterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.resequencerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.enricherWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.headerFilterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadSerializingTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadDeserializingTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.gatewayWithinChain.handler"));
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1.handler")).isTrue();
assertThat(this.beanFactory.containsBean("filterChain$child.filterWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("filterChain$child.serviceActivatorWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("aggregatorChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("aggregatorChain$child.aggregatorWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("aggregatorChain$child.nestedChain.handler")).isTrue();
assertThat(this.beanFactory
.containsBean("aggregatorChain$child.nestedChain$child.filterWithinNestedChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain.handler"))
.isTrue();
assertThat(this.beanFactory
.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain$child" +
".filterWithinDoubleNestedChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("aggregatorChain2.handler")).isTrue();
assertThat(this.beanFactory.containsBean("aggregatorChain2$child.aggregatorWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain.handler")).isTrue();
assertThat(this.beanFactory
.containsBean("aggregatorChain2$child.nestedChain$child.filterWithinNestedChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("payloadTypeRouterChain$child.payloadTypeRouterWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("headerValueRouterChain$child.headerValueRouterWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckInWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckOutWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("outboundChain$child.outboundChannelAdapterWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("logChain$child.transformerWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("logChain$child.loggingChannelAdapterWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1$child.splitterWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1$child.resequencerWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1$child.enricherWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1$child.headerFilterWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory
.containsBean("subComponentsIdSupport1$child.payloadSerializingTransformerWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory
.containsBean("subComponentsIdSupport1$child.payloadDeserializingTransformerWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1$child.gatewayWithinChain.handler")).isTrue();
//INT-3117
GatewayProxyFactoryBean gatewayProxyFactoryBean = this.beanFactory.getBean("&subComponentsIdSupport1$child.gatewayWithinChain.handler",
GatewayProxyFactoryBean gatewayProxyFactoryBean = this.beanFactory.getBean("&subComponentsIdSupport1$child" +
".gatewayWithinChain.handler",
GatewayProxyFactoryBean.class);
assertEquals("strings", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestChannelName"));
assertEquals("numbers", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyChannelName"));
assertEquals(1000L, TestUtils
.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestTimeout", Expression.class).getValue());
assertEquals(100L, TestUtils
.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyTimeout", Expression.class).getValue());
assertThat(TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestChannelName"))
.isEqualTo("strings");
assertThat(TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyChannelName")).isEqualTo(
"numbers");
assertThat(TestUtils
.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestTimeout", Expression.class).getValue())
.isEqualTo(1000L);
assertThat(TestUtils
.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyTimeout", Expression.class).getValue())
.isEqualTo(100L);
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToStringTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler"));
assertThat(this.beanFactory
.containsBean("subComponentsIdSupport1$child.objectToStringTransformerWithinChain.handler")).isTrue();
assertThat(this.beanFactory
.containsBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler")).isTrue();
Object transformerHandler = this.beanFactory.getBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler");
Object transformerHandler = this.beanFactory.getBean(
"subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler");
Object transformer = TestUtils.getPropertyValue(transformerHandler, "transformer");
assertThat(transformer, instanceOf(ObjectToMapTransformer.class));
assertFalse(TestUtils.getPropertyValue(transformer, "shouldFlattenKeys", Boolean.class));
assertSame(this.beanFactory.getBean(JsonObjectMapper.class),
TestUtils.getPropertyValue(transformer, "jsonObjectMapper"));
assertThat(transformer).isInstanceOf(ObjectToMapTransformer.class);
assertThat(TestUtils.getPropertyValue(transformer, "shouldFlattenKeys", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(transformer, "jsonObjectMapper"))
.isSameAs(this.beanFactory.getBean(JsonObjectMapper.class));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.mapToObjectTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.controlBusWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.routerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("exceptionTypeRouterChain$child.exceptionTypeRouterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("recipientListRouterChain$child.recipientListRouterWithinChain.handler"));
assertThat(this.beanFactory
.containsBean("subComponentsIdSupport1$child.mapToObjectTransformerWithinChain.handler")).isTrue();
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1$child.controlBusWithinChain.handler"))
.isTrue();
assertThat(this.beanFactory.containsBean("subComponentsIdSupport1$child.routerWithinChain.handler")).isTrue();
assertThat(this.beanFactory
.containsBean("exceptionTypeRouterChain$child.exceptionTypeRouterWithinChain.handler")).isTrue();
assertThat(this.beanFactory
.containsBean("recipientListRouterChain$child.recipientListRouterWithinChain.handler")).isTrue();
MessageHandlerChain chain = this.beanFactory.getBean("headerEnricherChain.handler", MessageHandlerChain.class);
List<?> handlers = TestUtils.getPropertyValue(chain, "handlers", List.class);
assertTrue(handlers.get(0) instanceof MessageTransformingHandler);
assertEquals("headerEnricherChain$child.headerEnricherWithinChain", TestUtils.getPropertyValue(handlers.get(0), "componentName"));
assertEquals("headerEnricherChain$child.headerEnricherWithinChain.handler", TestUtils.getPropertyValue(handlers.get(0), "beanName"));
assertTrue(this.beanFactory.containsBean("headerEnricherChain$child.headerEnricherWithinChain.handler"));
assertThat(handlers.get(0) instanceof MessageTransformingHandler).isTrue();
assertThat(TestUtils.getPropertyValue(handlers.get(0), "componentName"))
.isEqualTo("headerEnricherChain$child.headerEnricherWithinChain");
assertThat(TestUtils.getPropertyValue(handlers.get(0), "beanName"))
.isEqualTo("headerEnricherChain$child.headerEnricherWithinChain.handler");
assertThat(this.beanFactory.containsBean("headerEnricherChain$child.headerEnricherWithinChain.handler"))
.isTrue();
assertTrue(handlers.get(1) instanceof ServiceActivatingHandler);
assertEquals("headerEnricherChain$child#1", TestUtils.getPropertyValue(handlers.get(1), "componentName"));
assertEquals("headerEnricherChain$child#1.handler", TestUtils.getPropertyValue(handlers.get(1), "beanName"));
assertFalse(this.beanFactory.containsBean("headerEnricherChain$child#1.handler"));
assertThat(handlers.get(1) instanceof ServiceActivatingHandler).isTrue();
assertThat(TestUtils.getPropertyValue(handlers.get(1), "componentName"))
.isEqualTo("headerEnricherChain$child#1");
assertThat(TestUtils.getPropertyValue(handlers.get(1), "beanName"))
.isEqualTo("headerEnricherChain$child#1.handler");
assertThat(this.beanFactory.containsBean("headerEnricherChain$child#1.handler")).isFalse();
}
@Test
public void testInt2755SubComponentException() {
GenericMessage<String> testMessage = new GenericMessage<String>("test");
GenericMessage<String> testMessage = new GenericMessage<>("test");
try {
this.chainReplyRequiredChannel.send(testMessage);
fail("Expected ReplyRequiredException");
}
catch (Exception e) {
assertTrue(e instanceof ReplyRequiredException);
assertTrue(e.getMessage().contains("'chainReplyRequired$child.transformerReplyRequired'"));
assertThat(e instanceof ReplyRequiredException).isTrue();
assertThat(e.getMessage().contains("'chainReplyRequired$child.transformerReplyRequired'")).isTrue();
}
try {
@@ -451,8 +471,9 @@ public class ChainParserTests {
fail("Expected MessageRejectedException");
}
catch (Exception e) {
assertTrue(e instanceof MessageRejectedException);
assertTrue(e.getMessage().contains("chainMessageRejectedException$child.filterMessageRejectedException"));
assertThat(e instanceof MessageRejectedException).isTrue();
assertThat(e.getMessage().contains("chainMessageRejectedException$child.filterMessageRejectedException"))
.isTrue();
}
}
@@ -463,13 +484,13 @@ public class ChainParserTests {
Message<String> message = MessageBuilder.withPayload("foo").setHeader("myReplyChannel", replyChannel).build();
this.chainWithNoOutputChannel.send(message);
Message<?> receive = replyChannel.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
message = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build();
Message<String> message2 = MessageBuilder.withPayload("bar").setHeader("myMessage", message).build();
this.chainWithTransformNoOutputChannel.send(message2);
receive = replyChannel.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
}
public static class StubHandler extends AbstractReplyProducingMessageHandler {
@@ -486,6 +507,7 @@ public class ChainParserTests {
public String aggregate(List<String> strings) {
return StringUtils.collectionToCommaDelimitedString(strings);
}
}
public static class FooPojo {

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,16 +16,9 @@
package org.springframework.integration.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.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 org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -81,16 +74,16 @@ public class ChannelAdapterParserTests {
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertEquals(-1, ((SourcePollingChannelAdapter) adapter).getPhase());
assertThat(adapter).isNotNull();
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
assertThat(((SourcePollingChannelAdapter) adapter).getPhase()).isEqualTo(-1);
this.applicationContext.start();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertEquals("source test", testBean.getMessage());
assertThat(message).isNotNull();
assertThat(testBean.getMessage()).isEqualTo("source test");
this.applicationContext.stop();
message = channel.receive(100);
assertNull(message);
assertThat(message).isNull();
}
@Test
@@ -100,63 +93,63 @@ public class ChannelAdapterParserTests {
// TestBean testBean = (TestBean) this.applicationContextInner.getBean("testBean");
// testBean.store("source test");
Object adapter = this.applicationContextInner.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
this.applicationContextInner.start();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertThat(message).isNotNull();
//assertEquals("source test", testBean.getMessage());
this.applicationContextInner.stop();
message = channel.receive(100);
assertNull(message);
assertThat(message).isNull();
}
@Test
public void targetOnly() {
String beanName = "outboundWithImplicitChannel";
Object channel = this.applicationContext.getBean(beanName);
assertTrue(channel instanceof DirectChannel);
assertThat(channel instanceof DirectChannel).isTrue();
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
assertNotNull(channelResolver.resolveDestination(beanName));
assertThat(channelResolver.resolveDestination(beanName)).isNotNull();
Object adapter = this.applicationContext.getBean(beanName + ".adapter");
assertNotNull(adapter);
assertTrue(adapter instanceof EventDrivenConsumer);
assertFalse(((EventDrivenConsumer) adapter).isAutoStartup());
assertEquals(-1, ((EventDrivenConsumer) adapter).getPhase());
assertThat(adapter).isNotNull();
assertThat(adapter instanceof EventDrivenConsumer).isTrue();
assertThat(((EventDrivenConsumer) adapter).isAutoStartup()).isFalse();
assertThat(((EventDrivenConsumer) adapter).getPhase()).isEqualTo(-1);
TestConsumer consumer = (TestConsumer) this.applicationContext.getBean("consumer");
assertNull(consumer.getLastMessage());
assertThat(consumer.getLastMessage()).isNull();
Message<?> message = new GenericMessage<String>("test");
try {
((MessageChannel) channel).send(message);
fail("MessageDispatchingException is expected.");
}
catch (Exception e) {
assertThat(e, Matchers.instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), Matchers.instanceOf(MessageDispatchingException.class));
assertThat(e).isInstanceOf(MessageDeliveryException.class);
assertThat(e.getCause()).isInstanceOf(MessageDispatchingException.class);
}
((EventDrivenConsumer) adapter).start();
((MessageChannel) channel).send(message);
assertNotNull(consumer.getLastMessage());
assertEquals(message, consumer.getLastMessage());
assertThat(consumer.getLastMessage()).isNotNull();
assertThat(consumer.getLastMessage()).isEqualTo(message);
}
@Test
public void methodInvokingConsumer() {
String beanName = "methodInvokingConsumer";
Object channel = this.applicationContext.getBean(beanName);
assertTrue(channel instanceof DirectChannel);
assertThat(channel instanceof DirectChannel).isTrue();
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
assertNotNull(channelResolver.resolveDestination(beanName));
assertThat(channelResolver.resolveDestination(beanName)).isNotNull();
Object adapter = this.applicationContext.getBean(beanName + ".adapter");
assertNotNull(adapter);
assertTrue(adapter instanceof EventDrivenConsumer);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof EventDrivenConsumer).isTrue();
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
assertNull(testBean.getMessage());
assertThat(testBean.getMessage()).isNull();
Message<?> message = new GenericMessage<String>("consumer test");
assertTrue(((MessageChannel) channel).send(message));
assertNotNull(testBean.getMessage());
assertEquals("consumer test", testBean.getMessage());
assertThat(((MessageChannel) channel).send(message)).isTrue();
assertThat(testBean.getMessage()).isNotNull();
assertThat(testBean.getMessage()).isEqualTo("consumer test");
}
@Test
@@ -166,18 +159,18 @@ public class ChannelAdapterParserTests {
public void expressionConsumer() {
String beanName = "expressionConsumer";
Object channel = this.applicationContext.getBean(beanName);
assertTrue(channel instanceof DirectChannel);
assertThat(channel instanceof DirectChannel).isTrue();
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
assertNotNull(channelResolver.resolveDestination(beanName));
assertThat(channelResolver.resolveDestination(beanName)).isNotNull();
Object adapter = this.applicationContext.getBean(beanName + ".adapter");
assertNotNull(adapter);
assertTrue(adapter instanceof EventDrivenConsumer);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof EventDrivenConsumer).isTrue();
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
assertNull(testBean.getMessage());
assertThat(testBean.getMessage()).isNull();
Message<?> message = new GenericMessage<String>("consumer test expression");
assertTrue(((MessageChannel) channel).send(message));
assertNotNull(testBean.getMessage());
assertEquals("consumer test expression", testBean.getMessage());
assertThat(((MessageChannel) channel).send(message)).isTrue();
assertThat(testBean.getMessage()).isNotNull();
assertThat(testBean.getMessage()).isEqualTo("consumer test expression");
}
@Test
@@ -187,12 +180,12 @@ public class ChannelAdapterParserTests {
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
((SourcePollingChannelAdapter) adapter).start();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertEquals("source test", testBean.getMessage());
assertThat(message).isNotNull();
assertThat(testBean.getMessage()).isEqualTo("source test");
((SourcePollingChannelAdapter) adapter).stop();
}
@@ -203,16 +196,16 @@ public class ChannelAdapterParserTests {
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
((SourcePollingChannelAdapter) adapter).start();
Message<?> message = channel.receive(10000);
((SourcePollingChannelAdapter) adapter).stop();
assertNotNull(message);
assertEquals("source test", testBean.getMessage());
assertEquals("source test", message.getPayload());
assertEquals("ABC", message.getHeaders().get("foo"));
assertEquals(123, message.getHeaders().get("bar"));
assertThat(message).isNotNull();
assertThat(testBean.getMessage()).isEqualTo("source test");
assertThat(message.getPayload()).isEqualTo("source test");
assertThat(message.getHeaders().get("foo")).isEqualTo("ABC");
assertThat(message.getHeaders().get("bar")).isEqualTo(123);
}
@Test
@@ -222,10 +215,10 @@ public class ChannelAdapterParserTests {
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
Message<?> message = channel.receive(100);
assertNull(message);
assertThat(message).isNull();
}
@Test
@@ -235,15 +228,15 @@ public class ChannelAdapterParserTests {
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
((SourcePollingChannelAdapter) adapter).start();
Message<?> message = channel.receive(10000);
assertNotNull(message);
assertEquals("source test", testBean.getMessage());
assertThat(message).isNotNull();
assertThat(testBean.getMessage()).isEqualTo("source test");
((SourcePollingChannelAdapter) adapter).stop();
message = channel.receive(100);
assertNull(message);
assertThat(message).isNull();
}
@Test
@@ -253,12 +246,12 @@ public class ChannelAdapterParserTests {
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
testBean.store("source test");
Object adapter = this.applicationContext.getBean(beanName);
assertNotNull(adapter);
assertTrue(adapter instanceof SourcePollingChannelAdapter);
assertThat(adapter).isNotNull();
assertThat(adapter instanceof SourcePollingChannelAdapter).isTrue();
this.applicationContext.start();
Message<?> message = channel.receive(1000);
assertNotNull(message);
assertEquals("source test", testBean.getMessage());
assertThat(message).isNotNull();
assertThat(testBean.getMessage()).isEqualTo("source test");
this.applicationContext.stop();
}
@@ -274,9 +267,9 @@ public class ChannelAdapterParserTests {
SourcePollingChannelAdapter adapter =
this.applicationContext.getBean(beanName, SourcePollingChannelAdapter.class);
assertNotNull(adapter);
assertThat(adapter).isNotNull();
long sendTimeout = TestUtils.getPropertyValue(adapter, "messagingTemplate.sendTimeout", Long.class);
assertEquals(999, sendTimeout);
assertThat(sendTimeout).isEqualTo(999);
}
@Test(expected = BeanDefinitionParsingException.class)
@@ -292,11 +285,11 @@ public class ChannelAdapterParserTests {
for (int i = 0; i < 10; i++) {
Message<?> message = channel1.receive(5000);
assertNotNull(message);
assertEquals(i + 1, message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo(i + 1);
message = channel2.receive(5000);
assertNotNull(message);
assertEquals(i + 1, message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo(i + 1);
}
}
@@ -305,14 +298,14 @@ public class ChannelAdapterParserTests {
PollableChannel channel = this.applicationContext.getBean("messageSourceRefChannel", PollableChannel.class);
Message<?> message = channel.receive(5000);
assertNotNull(message);
assertEquals("test", message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("test");
MessageSource<?> testMessageSource = this.applicationContext.getBean("testMessageSource", MessageSource.class);
SourcePollingChannelAdapter adapterWithMessageSourceRef =
this.applicationContext.getBean("adapterWithMessageSourceRef", SourcePollingChannelAdapter.class);
MessageSource<?> source = TestUtils.getPropertyValue(adapterWithMessageSourceRef, "source", MessageSource.class);
assertSame(testMessageSource, source);
assertThat(source).isSameAs(testMessageSource);
}
public static class SampleBean {

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.config;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.TimeUnit;
@@ -79,21 +76,22 @@ public class ChannelWithMessageStoreParserTests {
input.send(createMessage("123", "id1", 3, 1, null));
handler.getLatch().await(100, TimeUnit.MILLISECONDS);
assertEquals("The message payload is not correct", "123", handler.getMessageString());
assertThat(handler.getMessageString()).as("The message payload is not correct").isEqualTo("123");
// The group id for buffered messages is the channel name
assertEquals(1, messageGroupStore.getMessageGroup("messageStore:output").size());
assertThat(messageGroupStore.getMessageGroup("messageStore:output").size()).isEqualTo(1);
Message<?> result = output.receive(100);
assertEquals("hello", result.getPayload());
assertEquals(0, messageGroupStore.getMessageGroup(BASE_PACKAGE + ".store:output").size());
assertThat(result.getPayload()).isEqualTo("hello");
assertThat(messageGroupStore.getMessageGroup(BASE_PACKAGE + ".store:output").size()).isEqualTo(0);
}
@Test
@DirtiesContext
public void testPriorityMessageStore() {
assertSame(this.priorityMessageStore, TestUtils.getPropertyValue(this.priorityChannel, "queue.messageGroupStore"));
assertThat(this.priorityChannel, instanceOf(PriorityChannel.class));
assertThat(TestUtils.getPropertyValue(this.priorityChannel, "queue.messageGroupStore"))
.isSameAs(this.priorityMessageStore);
assertThat(this.priorityChannel).isInstanceOf(PriorityChannel.class);
}
private static <T> Message<T> createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber,

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,8 +16,7 @@
package org.springframework.integration.config;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -37,7 +36,7 @@ public class CorrelationStrategyInvalidConfigurationTests {
CorrelationStrategyInvalidConfigurationTests.class).close();
}
catch (BeanCreationException e) {
assertThat(e.getMessage(), containsString("MessageCountReleaseStrategy] has no eligible methods"));
assertThat(e.getMessage()).contains("MessageCountReleaseStrategy] has no eligible methods");
}
}

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.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.concurrent.TimeUnit;
@@ -42,10 +40,10 @@ public class EndpointParserTests {
context.start();
MessageChannel channel = (MessageChannel) context.getBean("endpointParserTestInput");
TestHandler handler = (TestHandler) context.getBean("testHandler");
assertNull(handler.getMessageString());
assertThat(handler.getMessageString()).isNull();
channel.send(new GenericMessage<>("test"));
assertTrue(handler.getLatch().await(10000, TimeUnit.MILLISECONDS));
assertEquals("test", handler.getMessageString());
assertThat(handler.getLatch().await(10000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(handler.getMessageString()).isEqualTo("test");
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,11 +16,7 @@
package org.springframework.integration.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.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -97,8 +93,8 @@ public class FilterParserTests {
@Test
public void adviseDiscard() {
assertFalse(TestUtils.getPropertyValue(this.advised, "postProcessWithinAdvice", Boolean.class));
assertTrue(TestUtils.getPropertyValue(this.notAdvised, "postProcessWithinAdvice", Boolean.class));
assertThat(TestUtils.getPropertyValue(this.advised, "postProcessWithinAdvice", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(this.notAdvised, "postProcessWithinAdvice", Boolean.class)).isTrue();
}
@Test
@@ -106,38 +102,38 @@ public class FilterParserTests {
adviceCalled = 0;
adapterInput.send(new GenericMessage<>("test"));
Message<?> reply = adapterOutput.receive(0);
assertNotNull(reply);
assertEquals("test", reply.getPayload());
assertEquals(1, adviceCalled);
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("test");
assertThat(adviceCalled).isEqualTo(1);
}
@Test
public void filterWithSelectorAdapterRejects() {
adapterInput.send(new GenericMessage<>(""));
Message<?> reply = adapterOutput.receive(0);
assertNull(reply);
assertThat(reply).isNull();
}
@Test
public void filterWithSelectorImplementationAccepts() {
implementationInput.send(new GenericMessage<>("test"));
Message<?> reply = implementationOutput.receive(0);
assertNotNull(reply);
assertEquals("test", reply.getPayload());
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("test");
}
@Test
public void filterWithSelectorImplementationRejects() {
implementationInput.send(new GenericMessage<>(""));
Message<?> reply = implementationOutput.receive(0);
assertNull(reply);
assertThat(reply).isNull();
}
@Test
public void exceptionThrowingFilterAccepts() {
exceptionInput.send(new GenericMessage<>("test"));
Message<?> reply = implementationOutput.receive(0);
assertNotNull(reply);
assertThat(reply).isNotNull();
}
@Test(expected = MessageRejectedException.class)
@@ -149,9 +145,9 @@ public class FilterParserTests {
public void filterWithDiscardChannel() {
discardInput.send(new GenericMessage<>(""));
Message<?> discard = discardOutput.receive(0);
assertNotNull(discard);
assertEquals("", discard.getPayload());
assertNull(adapterOutput.receive(0));
assertThat(discard).isNotNull();
assertThat(discard.getPayload()).isEqualTo("");
assertThat(adapterOutput.receive(0)).isNull();
}
@Test(expected = MessageRejectedException.class)
@@ -164,9 +160,9 @@ public class FilterParserTests {
exception = e;
}
Message<?> discard = discardAndExceptionOutput.receive(0);
assertNotNull(discard);
assertEquals("", discard.getPayload());
assertNull(adapterOutput.receive(0));
assertThat(discard).isNotNull();
assertThat(discard.getPayload()).isEqualTo("");
assertThat(adapterOutput.receive(0)).isNull();
throw exception;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,8 @@
package org.springframework.integration.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
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.UUID;
import java.util.concurrent.atomic.AtomicLong;
@@ -50,13 +47,13 @@ public class IdGeneratorConfigurerTests {
context.registerBeanDefinition("foo", new RootBeanDefinition(MyIdGenerator.class));
context.refresh();
MessageHeaders headers = new MessageHeaders(null);
assertEquals(1, headers.getId().getMostSignificantBits());
assertEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(2);
context.close();
headers = new MessageHeaders(null);
assertNotEquals(1, headers.getId().getMostSignificantBits());
assertNotEquals(2, headers.getId().getLeastSignificantBits());
assertNull(TestUtils.getPropertyValue(headers, "idGenerator"));
assertThat(headers.getId().getMostSignificantBits()).isNotEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isNotEqualTo(2);
assertThat(TestUtils.getPropertyValue(headers, "idGenerator")).isNull();
}
@Test
@@ -69,7 +66,7 @@ public class IdGeneratorConfigurerTests {
// multiple beans are ignored with warning
MessageHeaders headers = new MessageHeaders(null);
assertNull(TestUtils.getPropertyValue(headers, "idGenerator"));
assertThat(TestUtils.getPropertyValue(headers, "idGenerator")).isNull();
context.close();
}
@@ -81,7 +78,7 @@ public class IdGeneratorConfigurerTests {
context.refresh();
MessageHeaders headers = new MessageHeaders(null);
assertNull(TestUtils.getPropertyValue(headers, "idGenerator"));
assertThat(TestUtils.getPropertyValue(headers, "idGenerator")).isNull();
context.close();
}
@@ -93,8 +90,8 @@ public class IdGeneratorConfigurerTests {
context.registerBeanDefinition("foo", new RootBeanDefinition(MyIdGenerator.class));
context.refresh();
MessageHeaders headers = new MessageHeaders(null);
assertEquals(1, headers.getId().getMostSignificantBits());
assertEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(2);
GenericApplicationContext context2 = new GenericApplicationContext();
context2.registerBeanDefinition("bfpp", new RootBeanDefinition(DefaultConfiguringBeanFactoryPostProcessor.class));
@@ -105,10 +102,10 @@ public class IdGeneratorConfigurerTests {
context2.close();
headers = new MessageHeaders(null);
assertNotEquals(1, headers.getId().getMostSignificantBits());
assertNotEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isNotEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isNotEqualTo(2);
assertNull(TestUtils.getPropertyValue(headers, "idGenerator"));
assertThat(TestUtils.getPropertyValue(headers, "idGenerator")).isNull();
}
@Test
@@ -118,8 +115,8 @@ public class IdGeneratorConfigurerTests {
context.registerBeanDefinition("foo", new RootBeanDefinition(MyIdGenerator.class));
context.refresh();
MessageHeaders headers = new MessageHeaders(null);
assertEquals(1, headers.getId().getMostSignificantBits());
assertEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(2);
GenericApplicationContext context2 = new GenericApplicationContext();
context2.registerBeanDefinition("bfpp", new RootBeanDefinition(DefaultConfiguringBeanFactoryPostProcessor.class));
@@ -129,16 +126,16 @@ public class IdGeneratorConfigurerTests {
context.close();
// we should still use the custom strategy
headers = new MessageHeaders(null);
assertEquals(1, headers.getId().getMostSignificantBits());
assertEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(2);
context2.close();
// back to default
headers = new MessageHeaders(null);
assertNotEquals(1, headers.getId().getMostSignificantBits());
assertNotEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isNotEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isNotEqualTo(2);
assertNull(TestUtils.getPropertyValue(headers, "idGenerator"));
assertThat(TestUtils.getPropertyValue(headers, "idGenerator")).isNull();
}
@Test
@@ -148,8 +145,8 @@ public class IdGeneratorConfigurerTests {
context.registerBeanDefinition("foo", new RootBeanDefinition(MyIdGenerator.class));
context.refresh();
MessageHeaders headers = new MessageHeaders(null);
assertEquals(1, headers.getId().getMostSignificantBits());
assertEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(2);
GenericApplicationContext context2 = new GenericApplicationContext();
context2.registerBeanDefinition("bfpp", new RootBeanDefinition(DefaultConfiguringBeanFactoryPostProcessor.class));
@@ -159,8 +156,8 @@ public class IdGeneratorConfigurerTests {
fail("Expected exception");
}
catch (BeanDefinitionStoreException e) {
assertEquals("'MessageHeaders.idGenerator' has already been set and can not be set again",
e.getMessage());
assertThat(e.getMessage())
.isEqualTo("'MessageHeaders.idGenerator' has already been set and can not be set again");
}
context.close();
@@ -174,7 +171,7 @@ public class IdGeneratorConfigurerTests {
context.registerBeanDefinition("foo", new RootBeanDefinition(JdkIdGenerator.class));
context.refresh();
MessageHeaders headers = new MessageHeaders(null);
assertSame(context.getBean(IdGenerator.class), TestUtils.getPropertyValue(headers, "idGenerator"));
assertThat(TestUtils.getPropertyValue(headers, "idGenerator")).isSameAs(context.getBean(IdGenerator.class));
context.close();
}
@@ -187,19 +184,19 @@ public class IdGeneratorConfigurerTests {
context.refresh();
IdGenerator idGenerator = context.getBean(IdGenerator.class);
MessageHeaders headers = new MessageHeaders(null);
assertEquals(0, headers.getId().getMostSignificantBits());
assertEquals(1, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(0);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(1);
headers = new MessageHeaders(null);
assertEquals(0, headers.getId().getMostSignificantBits());
assertEquals(2, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(0);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(2);
AtomicLong bottomBits = TestUtils.getPropertyValue(idGenerator, "bottomBits", AtomicLong.class);
bottomBits.set(0xffffffff);
headers = new MessageHeaders(null);
assertEquals(1, headers.getId().getMostSignificantBits());
assertEquals(0, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(0);
headers = new MessageHeaders(null);
assertEquals(1, headers.getId().getMostSignificantBits());
assertEquals(1, headers.getId().getLeastSignificantBits());
assertThat(headers.getId().getMostSignificantBits()).isEqualTo(1);
assertThat(headers.getId().getLeastSignificantBits()).isEqualTo(1);
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,9 @@
package org.springframework.integration.config;
import org.hamcrest.Matchers;
import org.junit.Rule;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -27,27 +26,29 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Dave Syer
* @author Manuel Jordan
* @author Artem Bilan
*
* @since 4.3
*/
public class InvalidPriorityChannelParserTests {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void testMessageStoreAndCapacityIllegal() throws Exception {
this.exception.expect(BeanDefinitionParsingException.class);
this.exception.expectMessage(Matchers.containsString("'capacity' attribute is not allowed"));
new ClassPathXmlApplicationContext("InvalidPriorityChannelWithMessageStoreAndCapacityParserTests.xml",
getClass()).close();
public void testMessageStoreAndCapacityIllegal() {
assertThatThrownBy(() ->
new ClassPathXmlApplicationContext("InvalidPriorityChannelWithMessageStoreAndCapacityParserTests.xml",
getClass()))
.isInstanceOf(BeanDefinitionParsingException.class)
.hasMessageContaining("'capacity' attribute is not allowed");
}
@Test
public void testComparatorAndMessageStoreIllegal() throws Exception {
this.exception.expect(BeanDefinitionParsingException.class);
this.exception.expectMessage(Matchers.containsString("The 'message-store' attribute is not allowed"));
new ClassPathXmlApplicationContext("InvalidPriorityChannelWithComparatorAndMessageStoreParserTests.xml",
getClass()).close();
public void testComparatorAndMessageStoreIllegal() {
assertThatThrownBy(() ->
new ClassPathXmlApplicationContext(
"InvalidPriorityChannelWithComparatorAndMessageStoreParserTests.xml",
getClass()))
.isInstanceOf(BeanDefinitionParsingException.class)
.hasMessageContaining("The 'message-store' attribute is not allowed");
}
}

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,9 @@
package org.springframework.integration.config;
import org.hamcrest.Matchers;
import org.junit.Rule;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -31,31 +30,32 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*/
public class InvalidQueueChannelParserTests {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void testMessageStoreAndCapacityIllegal() throws Exception {
this.exception.expect(BeanDefinitionParsingException.class);
this.exception.expectMessage(Matchers.containsString("'capacity' attribute is not allowed"));
new ClassPathXmlApplicationContext("InvalidQueueChannelWithMessageStoreAndCapacityParserTests.xml",
getClass()).close();
public void testMessageStoreAndCapacityIllegal() {
assertThatThrownBy(() ->
new ClassPathXmlApplicationContext("InvalidQueueChannelWithMessageStoreAndCapacityParserTests.xml",
getClass()))
.isInstanceOf(BeanDefinitionParsingException.class)
.hasMessageContaining("'capacity' attribute is not allowed");
}
@Test
public void testRefAndCapacityIllegal() throws Exception {
this.exception.expect(BeanDefinitionParsingException.class);
this.exception.expectMessage(Matchers.containsString("'capacity' attribute is not allowed"));
new ClassPathXmlApplicationContext("InvalidQueueChannelWithRefAndCapacityParserTests.xml", getClass())
.close();
public void testRefAndCapacityIllegal() {
assertThatThrownBy(() ->
new ClassPathXmlApplicationContext("InvalidQueueChannelWithRefAndCapacityParserTests.xml",
getClass()))
.isInstanceOf(BeanDefinitionParsingException.class)
.hasMessageContaining("'capacity' attribute is not allowed");
}
@Test
public void testRefAndMessageStoreIllegal() throws Exception {
this.exception.expect(BeanDefinitionParsingException.class);
this.exception.expectMessage(Matchers.containsString("'message-store' attribute is not allowed"));
new ClassPathXmlApplicationContext("InvalidQueueChannelWithRefAndMessageStoreParserTests.xml", getClass())
.close();
public void testRefAndMessageStoreIllegal() {
assertThatThrownBy(() ->
new ClassPathXmlApplicationContext("InvalidQueueChannelWithRefAndMessageStoreParserTests.xml",
getClass()))
.isInstanceOf(BeanDefinitionParsingException.class)
.hasMessageContaining("The 'message-store' attribute is not allowed " +
"when providing a 'ref' to a custom queue.");
}
}

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,8 +16,7 @@
package org.springframework.integration.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -45,7 +44,7 @@ public class MessageBusParserTests {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"messageBusWithErrorChannel.xml", this.getClass());
BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver(context);
assertEquals(context.getBean("errorChannel"), resolver.resolveDestination("errorChannel"));
assertThat(resolver.resolveDestination("errorChannel")).isEqualTo(context.getBean("errorChannel"));
context.close();
}
@@ -54,7 +53,7 @@ public class MessageBusParserTests {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"messageBusWithDefaults.xml", this.getClass());
BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver(context);
assertEquals(context.getBean("errorChannel"), resolver.resolveDestination("errorChannel"));
assertThat(resolver.resolveDestination("errorChannel")).isEqualTo(context.getBean("errorChannel"));
context.close();
}
@@ -67,10 +66,10 @@ public class MessageBusParserTests {
DirectFieldAccessor accessor = new DirectFieldAccessor(multicaster);
Object taskExecutor = accessor.getPropertyValue("taskExecutor");
if (SpringVersion.getVersion().startsWith("2")) {
assertEquals(SyncTaskExecutor.class, taskExecutor.getClass());
assertThat(taskExecutor.getClass()).isEqualTo(SyncTaskExecutor.class);
}
else {
assertNull(taskExecutor);
assertThat(taskExecutor).isNull();
}
context.close();
}
@@ -85,10 +84,10 @@ public class MessageBusParserTests {
DirectFieldAccessor accessor = new DirectFieldAccessor(multicaster);
Object taskExecutor = accessor.getPropertyValue("taskExecutor");
if (SpringVersion.getVersion().startsWith("2")) {
assertEquals(SyncTaskExecutor.class, taskExecutor.getClass());
assertThat(taskExecutor.getClass()).isEqualTo(SyncTaskExecutor.class);
}
else {
assertNull(taskExecutor);
assertThat(taskExecutor).isNull();
}
context.close();
}
@@ -102,7 +101,7 @@ public class MessageBusParserTests {
context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
DirectFieldAccessor accessor = new DirectFieldAccessor(multicaster);
Object taskExecutor = accessor.getPropertyValue("taskExecutor");
assertEquals(ThreadPoolTaskExecutor.class, taskExecutor.getClass());
assertThat(taskExecutor.getClass()).isEqualTo(ThreadPoolTaskExecutor.class);
context.close();
}
@@ -111,7 +110,7 @@ public class MessageBusParserTests {
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
"messageBusWithTaskScheduler.xml", this.getClass());
TaskScheduler scheduler = (TaskScheduler) context.getBean("taskScheduler");
assertEquals(StubTaskScheduler.class, scheduler.getClass());
assertThat(scheduler.getClass()).isEqualTo(StubTaskScheduler.class);
context.close();
}
@@ -120,7 +119,7 @@ public class MessageBusParserTests {
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
"messageBusWithTaskScheduler.xml", this.getClass());
TaskScheduler scheduler = (TaskScheduler) context.getBean("taskScheduler");
assertEquals(scheduler, IntegrationContextUtils.getTaskScheduler(context));
assertThat(IntegrationContextUtils.getTaskScheduler(context)).isEqualTo(scheduler);
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,12 +16,7 @@
package org.springframework.integration.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 java.util.concurrent.Executor;
@@ -60,11 +55,11 @@ public class PublishSubscribeChannelParserTests {
dispatcher.addHandler(message -> { });
dispatcher.dispatch(new GenericMessage<>("foo"));
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
assertNull(dispatcherAccessor.getPropertyValue("executor"));
assertFalse((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures"));
assertTrue((Boolean) dispatcherAccessor.getPropertyValue("applySequence"));
assertThat(dispatcherAccessor.getPropertyValue("executor")).isNull();
assertThat((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures")).isFalse();
assertThat((Boolean) dispatcherAccessor.getPropertyValue("applySequence")).isTrue();
Object mbf = this.context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
assertSame(mbf, dispatcherAccessor.getPropertyValue("messageBuilderFactory"));
assertThat(dispatcherAccessor.getPropertyValue("messageBuilderFactory")).isSameAs(mbf);
}
@Test
@@ -74,7 +69,7 @@ public class PublishSubscribeChannelParserTests {
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher)
accessor.getPropertyValue("dispatcher");
assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("ignoreFailures"));
assertThat((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("ignoreFailures")).isTrue();
}
@Test
@@ -84,7 +79,7 @@ public class PublishSubscribeChannelParserTests {
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher)
accessor.getPropertyValue("dispatcher");
assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("applySequence"));
assertThat((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("applySequence")).isTrue();
}
@Test
@@ -96,11 +91,11 @@ public class PublishSubscribeChannelParserTests {
accessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
assertNotNull(executor);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
assertThat(executor).isNotNull();
assertThat(executor.getClass()).isEqualTo(ErrorHandlingTaskExecutor.class);
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
assertEquals(context.getBean("pool"), innerExecutor);
assertThat(innerExecutor).isEqualTo(context.getBean("pool"));
}
@Test
@@ -111,13 +106,13 @@ public class PublishSubscribeChannelParserTests {
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher)
accessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
assertTrue((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures"));
assertThat((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures")).isTrue();
Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
assertNotNull(executor);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
assertThat(executor).isNotNull();
assertThat(executor.getClass()).isEqualTo(ErrorHandlingTaskExecutor.class);
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
assertEquals(this.context.getBean("pool"), innerExecutor);
assertThat(innerExecutor).isEqualTo(this.context.getBean("pool"));
}
@Test
@@ -128,13 +123,13 @@ public class PublishSubscribeChannelParserTests {
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher)
accessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
assertTrue((Boolean) dispatcherAccessor.getPropertyValue("applySequence"));
assertThat((Boolean) dispatcherAccessor.getPropertyValue("applySequence")).isTrue();
Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
assertNotNull(executor);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
assertThat(executor).isNotNull();
assertThat(executor.getClass()).isEqualTo(ErrorHandlingTaskExecutor.class);
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
assertEquals(this.context.getBean("pool"), innerExecutor);
assertThat(innerExecutor).isEqualTo(this.context.getBean("pool"));
}
@Test
@@ -143,8 +138,8 @@ public class PublishSubscribeChannelParserTests {
this.context.getBean("channelWithErrorHandler", PublishSubscribeChannel.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
ErrorHandler errorHandler = (ErrorHandler) accessor.getPropertyValue("errorHandler");
assertNotNull(errorHandler);
assertEquals(this.context.getBean("testErrorHandler"), errorHandler);
assertThat(errorHandler).isNotNull();
assertThat(errorHandler).isEqualTo(this.context.getBean("testErrorHandler"));
}
}

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,12 +16,8 @@
package org.springframework.integration.config;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
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 java.util.Collection;
@@ -52,10 +48,10 @@ public class ReleaseStrategyFactoryBeanTests {
fail("IllegalStateException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("Target object of type " +
assertThat(e).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("Target object of type " +
"[class org.springframework.integration.config.ReleaseStrategyFactoryBeanTests$Foo] " +
"has no eligible methods for handling Messages."));
"has no eligible methods for handling Messages.");
}
}
@@ -67,10 +63,10 @@ public class ReleaseStrategyFactoryBeanTests {
factory.setMethodName("doRelease2");
factory.afterPropertiesSet();
ReleaseStrategy delegate = factory.getObject();
assertThat(delegate, instanceOf(MethodInvokingReleaseStrategy.class));
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.targetObject", Bar.class), is(bar));
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.handlerMethod.expressionString"),
equalTo("#target.doRelease2(messages)"));
assertThat(delegate).isInstanceOf(MethodInvokingReleaseStrategy.class);
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.targetObject", Bar.class)).isEqualTo(bar);
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.handlerMethod.expressionString"))
.isEqualTo("#target.doRelease2(messages)");
}
@Test
@@ -80,8 +76,8 @@ public class ReleaseStrategyFactoryBeanTests {
factory.setTarget(bar);
factory.afterPropertiesSet();
ReleaseStrategy delegate = factory.getObject();
assertThat(delegate, instanceOf(MethodInvokingReleaseStrategy.class));
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.targetObject", Bar.class), is(bar));
assertThat(delegate).isInstanceOf(MethodInvokingReleaseStrategy.class);
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.targetObject", Bar.class)).isEqualTo(bar);
}
@Test
@@ -89,7 +85,7 @@ public class ReleaseStrategyFactoryBeanTests {
ReleaseStrategyFactoryBean factory = new ReleaseStrategyFactoryBean();
factory.afterPropertiesSet();
ReleaseStrategy delegate = factory.getObject();
assertThat(delegate, instanceOf(SimpleSequenceSizeReleaseStrategy.class));
assertThat(delegate).isInstanceOf(SimpleSequenceSizeReleaseStrategy.class);
}
@Test
@@ -99,7 +95,7 @@ public class ReleaseStrategyFactoryBeanTests {
factory.setTarget(foo);
factory.afterPropertiesSet();
ReleaseStrategy delegate = factory.getObject();
assertThat(delegate, instanceOf(SimpleSequenceSizeReleaseStrategy.class));
assertThat(delegate).isInstanceOf(SimpleSequenceSizeReleaseStrategy.class);
}
@Test
@@ -109,7 +105,7 @@ public class ReleaseStrategyFactoryBeanTests {
factory.setTarget(baz);
factory.afterPropertiesSet();
ReleaseStrategy delegate = factory.getObject();
assertThat(delegate, is(baz));
assertThat(delegate).isEqualTo(baz);
}
@Test
@@ -120,10 +116,10 @@ public class ReleaseStrategyFactoryBeanTests {
factory.setMethodName("doRelease2");
factory.afterPropertiesSet();
ReleaseStrategy delegate = factory.getObject();
assertThat(delegate, instanceOf(MethodInvokingReleaseStrategy.class));
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.targetObject", Baz.class), is(baz));
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.handlerMethod.expressionString"),
equalTo("#target.doRelease2(messages)"));
assertThat(delegate).isInstanceOf(MethodInvokingReleaseStrategy.class);
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.targetObject", Baz.class)).isEqualTo(baz);
assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.handlerMethod.expressionString"))
.isEqualTo("#target.doRelease2(messages)");
}
public class Foo {

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.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.integration.test.util.TestUtils.getPropertyValue;
import java.util.List;
@@ -66,15 +63,18 @@ public class ResequencerParserTests {
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("defaultResequencer");
ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler",
ResequencingMessageHandler.class);
assertNull(getPropertyValue(resequencer, "outputChannel"));
assertTrue(getPropertyValue(resequencer, "discardChannel") instanceof NullChannel);
assertEquals("The ResequencerEndpoint is not set with the appropriate timeout value", -1L, getPropertyValue(
resequencer, "messagingTemplate.sendTimeout"));
assertEquals(
"The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag",
false, getPropertyValue(resequencer, "sendPartialResultOnExpiry"));
assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag",
false, getPropertyValue(resequencer, "releasePartialSequences"));
assertThat(getPropertyValue(resequencer, "outputChannel")).isNull();
assertThat(getPropertyValue(resequencer, "discardChannel") instanceof NullChannel).isTrue();
assertThat(getPropertyValue(
resequencer, "messagingTemplate.sendTimeout"))
.as("The ResequencerEndpoint is not set with the appropriate timeout value").isEqualTo(-1L);
assertThat(getPropertyValue(resequencer, "sendPartialResultOnExpiry"))
.as("The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' " +
"flag")
.isEqualTo(false);
assertThat(getPropertyValue(resequencer, "releasePartialSequences"))
.as("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag")
.isEqualTo(false);
}
@Test
@@ -84,18 +84,23 @@ public class ResequencerParserTests {
MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler",
ResequencingMessageHandler.class);
assertEquals("The ResequencerEndpoint is not injected with the appropriate output channel", outputChannel,
getPropertyValue(resequencer, "outputChannel"));
assertEquals("The ResequencerEndpoint is not injected with the appropriate discard channel", discardChannel,
getPropertyValue(resequencer, "discardChannel"));
assertEquals("The ResequencerEndpoint is not set with the appropriate timeout value", 86420000L,
getPropertyValue(resequencer, "messagingTemplate.sendTimeout"));
assertEquals(
"The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag",
true, getPropertyValue(resequencer, "sendPartialResultOnExpiry"));
assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag",
true, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
assertEquals(60000L, getPropertyValue(resequencer, "minimumTimeoutForEmptyGroups", Long.class).longValue());
assertThat(getPropertyValue(resequencer, "outputChannel"))
.as("The ResequencerEndpoint is not injected with the appropriate output channel")
.isEqualTo(outputChannel);
assertThat(getPropertyValue(resequencer, "discardChannel"))
.as("The ResequencerEndpoint is not injected with the appropriate discard channel")
.isEqualTo(discardChannel);
assertThat(getPropertyValue(resequencer, "messagingTemplate.sendTimeout"))
.as("The ResequencerEndpoint is not set with the appropriate timeout value").isEqualTo(86420000L);
assertThat(getPropertyValue(resequencer, "sendPartialResultOnExpiry"))
.as("The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' " +
"flag")
.isEqualTo(true);
assertThat(getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"))
.as("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag")
.isEqualTo(true);
assertThat(getPropertyValue(resequencer, "minimumTimeoutForEmptyGroups", Long.class).longValue())
.isEqualTo(60000L);
}
@Test
@@ -104,38 +109,44 @@ public class ResequencerParserTests {
.getBean("resequencerWithCorrelationStrategyRefOnly");
ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler",
ResequencingMessageHandler.class);
assertEquals("The ResequencerEndpoint is not configured with the appropriate CorrelationStrategy", context
.getBean("testCorrelationStrategy"), getPropertyValue(resequencer, "correlationStrategy"));
assertThat(getPropertyValue(resequencer, "correlationStrategy"))
.as("The ResequencerEndpoint is not configured with the appropriate CorrelationStrategy")
.isEqualTo(context
.getBean("testCorrelationStrategy"));
}
@Test
public void testReleaseStrategyRefOnly() throws Exception {
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithReleaseStrategyRefOnly");
ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
assertEquals("The ResequencerEndpoint is not configured with the appropriate ReleaseStrategy",
context.getBean("testReleaseStrategy"), getPropertyValue(resequencer, "releaseStrategy"));
assertFalse(TestUtils.getPropertyValue(resequencer, "expireGroupsUponTimeout", Boolean.class));
ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler",
ResequencingMessageHandler.class);
assertThat(getPropertyValue(resequencer, "releaseStrategy"))
.as("The ResequencerEndpoint is not configured with the appropriate ReleaseStrategy")
.isEqualTo(context.getBean("testReleaseStrategy"));
assertThat(TestUtils.getPropertyValue(resequencer, "expireGroupsUponTimeout", Boolean.class)).isFalse();
}
@Test
public void testReleaseStrategyRefAndMethod() throws Exception {
EventDrivenConsumer endpoint = (EventDrivenConsumer) context
.getBean("resequencerWithReleaseStrategyRefAndMethod");
ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler",
ResequencingMessageHandler.class);
Object releaseStrategyBean = context.getBean("testReleaseStrategyPojo");
assertTrue("Release strategy is not of the expected type",
releaseStrategyBean instanceof TestReleaseStrategyPojo);
assertThat(releaseStrategyBean instanceof TestReleaseStrategyPojo)
.as("Release strategy is not of the expected type").isTrue();
TestReleaseStrategyPojo expectedReleaseStrategy = (TestReleaseStrategyPojo) releaseStrategyBean;
int currentInvocationCount = expectedReleaseStrategy.invocationCount;
ReleaseStrategy effectiveReleaseStrategy = (ReleaseStrategy) getPropertyValue(resequencer, "releaseStrategy");
assertTrue("The release strategy is expected to be a MethodInvokingReleaseStrategy",
effectiveReleaseStrategy instanceof MethodInvokingReleaseStrategy);
assertThat(effectiveReleaseStrategy instanceof MethodInvokingReleaseStrategy)
.as("The release strategy is expected to be a MethodInvokingReleaseStrategy").isTrue();
effectiveReleaseStrategy.canRelease(new SimpleMessageGroup("test"));
assertEquals("The ResequencerEndpoint was not invoked the expected number of times;",
currentInvocationCount + 1, expectedReleaseStrategy.invocationCount);
assertTrue(TestUtils.getPropertyValue(resequencer, "expireGroupsUponTimeout", Boolean.class));
assertThat(expectedReleaseStrategy.invocationCount)
.as("The ResequencerEndpoint was not invoked the expected number of times;")
.isEqualTo(currentInvocationCount + 1);
assertThat(TestUtils.getPropertyValue(resequencer, "expireGroupsUponTimeout", Boolean.class)).isTrue();
}
@Test
@@ -143,8 +154,9 @@ public class ResequencerParserTests {
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("completelyDefinedResequencer");
ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler",
ResequencingMessageHandler.class);
assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag",
true, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
assertThat(getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"))
.as("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag")
.isEqualTo(true);
}
@Test
@@ -154,10 +166,11 @@ public class ResequencerParserTests {
ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler",
ResequencingMessageHandler.class);
Object correlationStrategy = getPropertyValue(resequencer, "correlationStrategy");
assertEquals("The ResequencerEndpoint is not configured with a CorrelationStrategy adapter",
MethodInvokingCorrelationStrategy.class, correlationStrategy.getClass());
assertThat(correlationStrategy.getClass())
.as("The ResequencerEndpoint is not configured with a CorrelationStrategy adapter")
.isEqualTo(MethodInvokingCorrelationStrategy.class);
MethodInvokingCorrelationStrategy adapter = (MethodInvokingCorrelationStrategy) correlationStrategy;
assertEquals("foo", adapter.getCorrelationKey(MessageBuilder.withPayload("not important").build()));
assertThat(adapter.getCorrelationKey(MessageBuilder.withPayload("not important").build())).isEqualTo("foo");
}
@SuppressWarnings("unused")

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.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;
@@ -56,21 +55,21 @@ public class ResequencerWithMessageStoreParserTests {
public void testResequence() {
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));
Message<?> message1 = output.receive(500);
Message<?> message2 = output.receive(500);
Message<?> message3 = output.receive(500);
assertNotNull(message1);
assertEquals(1, new IntegrationMessageHeaderAccessor(message1).getSequenceNumber());
assertNotNull(message2);
assertEquals(2, new IntegrationMessageHeaderAccessor(message2).getSequenceNumber());
assertNotNull(message3);
assertEquals(3, new IntegrationMessageHeaderAccessor(message3).getSequenceNumber());
assertThat(message1).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(message1).getSequenceNumber()).isEqualTo(1);
assertThat(message2).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(message2).getSequenceNumber()).isEqualTo(2);
assertThat(message3).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(message3).getSequenceNumber()).isEqualTo(3);
}

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.config;
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;
@@ -62,21 +60,21 @@ public class RouterFactoryBeanDelegationTests {
public void checkResolutionRequiredConfiguredOnTargetRouter() {
@SuppressWarnings("unchecked")
boolean resolutionRequired = (Boolean) new DirectFieldAccessor(router).getPropertyValue("resolutionRequired");
assertTrue("The 'resolutionRequired' property should be 'true'", resolutionRequired);
assertThat(resolutionRequired).as("The 'resolutionRequired' property should be 'true'").isTrue();
}
@Test
public void routeWithMappedType() {
input.send(new GenericMessage<>("test"));
assertNull(discard.receive(0));
assertNotNull(strings.receive(0));
assertThat(discard.receive(0)).isNull();
assertThat(strings.receive(0)).isNotNull();
}
@Test
public void routeWithUnmappedType() {
input.send(new GenericMessage<>(123));
assertNull(strings.receive(0));
assertNotNull(discard.receive(0));
assertThat(strings.receive(0)).isNull();
assertThat(discard.receive(0)).isNotNull();
}
}

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.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
@@ -53,11 +52,11 @@ public class SelectorChainParserTests {
MessageSelector selector2 = (MessageSelector) context.getBean("selector2");
MessageSelectorChain chain = (MessageSelectorChain) context.getBean("selectorChain");
List<MessageSelector> selectors = this.getSelectors(chain);
assertEquals(VotingStrategy.ALL, this.getStrategy(chain));
assertEquals(selector1, selectors.get(0));
assertEquals(selector2, selectors.get(1));
assertTrue(chain.accept(new GenericMessage<>("test")));
assertTrue(this.context.containsBean("pojoSelector"));
assertThat(this.getStrategy(chain)).isEqualTo(VotingStrategy.ALL);
assertThat(selectors.get(0)).isEqualTo(selector1);
assertThat(selectors.get(1)).isEqualTo(selector2);
assertThat(chain.accept(new GenericMessage<>("test"))).isTrue();
assertThat(this.context.containsBean("pojoSelector")).isTrue();
}
@Test
@@ -69,30 +68,30 @@ public class SelectorChainParserTests {
MessageSelector selector5 = (MessageSelector) context.getBean("selector5");
MessageSelector selector6 = (MessageSelector) context.getBean("selector6");
MessageSelectorChain chain1 = (MessageSelectorChain) context.getBean("nestedSelectorChain");
assertEquals(VotingStrategy.MAJORITY, this.getStrategy(chain1));
assertThat(this.getStrategy(chain1)).isEqualTo(VotingStrategy.MAJORITY);
List<MessageSelector> selectorList1 = this.getSelectors(chain1);
assertEquals(selector1, selectorList1.get(0));
assertTrue(selectorList1.get(1) instanceof MessageSelectorChain);
assertThat(selectorList1.get(0)).isEqualTo(selector1);
assertThat(selectorList1.get(1) instanceof MessageSelectorChain).isTrue();
MessageSelectorChain chain2 = (MessageSelectorChain) selectorList1.get(1);
assertEquals(VotingStrategy.ALL, this.getStrategy(chain2));
assertThat(this.getStrategy(chain2)).isEqualTo(VotingStrategy.ALL);
List<MessageSelector> selectorList2 = this.getSelectors(chain2);
assertEquals(selector2, selectorList2.get(0));
assertTrue(selectorList2.get(1) instanceof MessageSelectorChain);
assertThat(selectorList2.get(0)).isEqualTo(selector2);
assertThat(selectorList2.get(1) instanceof MessageSelectorChain).isTrue();
MessageSelectorChain chain3 = (MessageSelectorChain) selectorList2.get(1);
assertEquals(VotingStrategy.ANY, this.getStrategy(chain3));
assertThat(this.getStrategy(chain3)).isEqualTo(VotingStrategy.ANY);
List<MessageSelector> selectorList3 = this.getSelectors(chain3);
assertEquals(selector3, selectorList3.get(0));
assertEquals(selector4, selectorList3.get(1));
assertEquals(selector5, selectorList2.get(2));
assertTrue(selectorList1.get(2) instanceof MessageSelectorChain);
assertThat(selectorList3.get(0)).isEqualTo(selector3);
assertThat(selectorList3.get(1)).isEqualTo(selector4);
assertThat(selectorList2.get(2)).isEqualTo(selector5);
assertThat(selectorList1.get(2) instanceof MessageSelectorChain).isTrue();
MessageSelectorChain chain4 = (MessageSelectorChain) selectorList1.get(2);
assertEquals(VotingStrategy.MAJORITY_OR_TIE, this.getStrategy(chain4));
assertThat(this.getStrategy(chain4)).isEqualTo(VotingStrategy.MAJORITY_OR_TIE);
List<MessageSelector> selectorList4 = this.getSelectors(chain4);
assertEquals(selector6, selectorList4.get(0));
assertTrue(chain1.accept(new GenericMessage<>("test1")));
assertTrue(chain2.accept(new GenericMessage<>("test2")));
assertTrue(chain3.accept(new GenericMessage<>("test3")));
assertTrue(chain4.accept(new GenericMessage<>("test4")));
assertThat(selectorList4.get(0)).isEqualTo(selector6);
assertThat(chain1.accept(new GenericMessage<>("test1"))).isTrue();
assertThat(chain2.accept(new GenericMessage<>("test2"))).isTrue();
assertThat(chain3.accept(new GenericMessage<>("test3"))).isTrue();
assertThat(chain4.accept(new GenericMessage<>("test4"))).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.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -53,13 +52,13 @@ public class ServiceActivatorAnnotationPostProcessorTests {
context.refresh();
SimpleServiceActivatorAnnotationTestBean testBean =
context.getBean("testBean", SimpleServiceActivatorAnnotationTestBean.class);
assertEquals(1, latch.getCount());
assertNull(testBean.getMessageText());
assertThat(latch.getCount()).isEqualTo(1);
assertThat(testBean.getMessageText()).isNull();
MessageChannel testChannel = (MessageChannel) context.getBean("testChannel");
testChannel.send(new GenericMessage<>("test-123"));
latch.await(1000, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
assertEquals("test-123", testBean.getMessageText());
assertThat(latch.getCount()).isEqualTo(0);
assertThat(testBean.getMessageText()).isEqualTo("test-123");
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,9 +16,7 @@
package org.springframework.integration.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.any;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.BDDMockito.willAnswer;
@@ -92,8 +90,8 @@ public class SourcePollingChannelAdapterFactoryBeanTests {
context.registerEndpoint("testPollingEndpoint", factoryBean.getObject());
context.refresh();
Message<?> message = outputChannel.receive(5000);
assertEquals("test", message.getPayload());
assertTrue("adviceChain was not applied", adviceApplied.get());
assertThat(message.getPayload()).isEqualTo("test");
assertThat(adviceApplied.get()).as("adviceChain was not applied").isTrue();
context.close();
}
@@ -133,9 +131,9 @@ public class SourcePollingChannelAdapterFactoryBeanTests {
context.registerEndpoint("testPollingEndpoint", factoryBean.getObject());
context.refresh();
Message<?> message = outputChannel.receive(5000);
assertEquals("test", message.getPayload());
assertEquals(1, count.get());
assertTrue("adviceChain was not applied", adviceApplied.get());
assertThat(message.getPayload()).isEqualTo("test");
assertThat(count.get()).isEqualTo(1);
assertThat(adviceApplied.get()).as("adviceChain was not applied").isTrue();
context.close();
}
@@ -183,7 +181,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests {
pollingChannelAdapter.start();
assertTrue(startLatch.await(10, TimeUnit.SECONDS));
assertThat(startLatch.await(10, TimeUnit.SECONDS)).isTrue();
pollingChannelAdapter.stop();
taskScheduler.shutdown();
@@ -215,8 +213,8 @@ public class SourcePollingChannelAdapterFactoryBeanTests {
pollingChannelAdapter.start();
Message<?> receive = outputChannel.receive(10_000);
assertNotNull(receive);
assertEquals(true, receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo(true);
pollingChannelAdapter.stop();
}

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.config;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,7 +41,7 @@ public class TopLevelSelectorParserTests {
@Test
public void topLevelSelector() {
MessageSelector selector = (MessageSelector) context.getBean("selector");
assertTrue(selector.accept(new GenericMessage<String>("test")));
assertThat(selector.accept(new GenericMessage<String>("test"))).isTrue();
}
}

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,11 +16,7 @@
package org.springframework.integration.config;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
@@ -71,41 +67,41 @@ public class WireTapParserTests {
@Test
public void simpleWireTap() {
assertNull(wireTapChannel.receive(0));
assertThat(wireTapChannel.receive(0)).isNull();
Message<?> original = new GenericMessage<String>("test");
noSelectors.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
assertThat(intercepted).isNotNull();
assertThat(intercepted).isEqualTo(original);
}
@Test
public void simpleWireTapWithIdAndSelectorExpression() {
assertThat(TestUtils.getPropertyValue(wireTap, "selector"), instanceOf(ExpressionEvaluatingSelector.class));
assertThat(TestUtils.getPropertyValue(wireTap, "selector")).isInstanceOf(ExpressionEvaluatingSelector.class);
Message<?> original = new GenericMessage<String>("test");
withId.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
assertThat(intercepted).isNotNull();
assertThat(intercepted).isEqualTo(original);
}
@Test
public void wireTapWithAcceptingSelector() {
assertNull(wireTapChannel.receive(0));
assertThat(wireTapChannel.receive(0)).isNull();
Message<?> original = new GenericMessage<String>("test");
accepting.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNotNull(intercepted);
assertEquals(original, intercepted);
assertThat(intercepted).isNotNull();
assertThat(intercepted).isEqualTo(original);
}
@Test
public void wireTapWithRejectingSelector() {
assertNull(wireTapChannel.receive(0));
assertThat(wireTapChannel.receive(0)).isNull();
Message<?> original = new GenericMessage<String>("test");
rejecting.send(original);
Message<?> intercepted = wireTapChannel.receive(0);
assertNull(intercepted);
assertThat(intercepted).isNull();
}
@Test
@@ -125,9 +121,9 @@ public class WireTapParserTests {
otherTimeoutCount++;
}
}
assertEquals(4, defaultTimeoutCount);
assertEquals(1, expectedTimeoutCount);
assertEquals(0, otherTimeoutCount);
assertThat(defaultTimeoutCount).isEqualTo(4);
assertThat(expectedTimeoutCount).isEqualTo(1);
assertThat(otherTimeoutCount).isEqualTo(0);
}
}

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,16 +16,11 @@
package org.springframework.integration.config.annotation;
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.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.integration.test.util.TestUtils.getPropertyValue;
import java.lang.reflect.Method;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
@@ -53,11 +48,12 @@ public class AggregatorAnnotationTests {
new String[] { "classpath:/org/springframework/integration/config/annotation/testAnnotatedAggregator.xml" });
final String endpointName = "endpointWithDefaultAnnotation";
MessageHandler aggregator = this.getAggregator(context, endpointName);
assertTrue(getPropertyValue(aggregator, "releaseStrategy") instanceof SimpleSequenceSizeReleaseStrategy);
assertNull(getPropertyValue(aggregator, "outputChannel"));
assertTrue(getPropertyValue(aggregator, "discardChannel") instanceof NullChannel);
assertEquals(-1L, getPropertyValue(aggregator, "messagingTemplate.sendTimeout"));
assertEquals(false, getPropertyValue(aggregator, "sendPartialResultOnExpiry"));
assertThat(getPropertyValue(aggregator, "releaseStrategy") instanceof SimpleSequenceSizeReleaseStrategy)
.isTrue();
assertThat(getPropertyValue(aggregator, "outputChannel")).isNull();
assertThat(getPropertyValue(aggregator, "discardChannel") instanceof NullChannel).isTrue();
assertThat(getPropertyValue(aggregator, "messagingTemplate.sendTimeout")).isEqualTo(-1L);
assertThat(getPropertyValue(aggregator, "sendPartialResultOnExpiry")).isEqualTo(false);
context.close();
}
@@ -67,11 +63,12 @@ public class AggregatorAnnotationTests {
new String[] { "classpath:/org/springframework/integration/config/annotation/testAnnotatedAggregator.xml" });
final String endpointName = "endpointWithCustomizedAnnotation";
MessageHandler aggregator = this.getAggregator(context, endpointName);
assertTrue(getPropertyValue(aggregator, "releaseStrategy") instanceof SimpleSequenceSizeReleaseStrategy);
assertEquals("outputChannel", getPropertyValue(aggregator, "outputChannelName"));
assertEquals("discardChannel", getPropertyValue(aggregator, "discardChannelName"));
assertEquals(98765432L, getPropertyValue(aggregator, "messagingTemplate.sendTimeout"));
assertEquals(true, getPropertyValue(aggregator, "sendPartialResultOnExpiry"));
assertThat(getPropertyValue(aggregator, "releaseStrategy") instanceof SimpleSequenceSizeReleaseStrategy)
.isTrue();
assertThat(getPropertyValue(aggregator, "outputChannelName")).isEqualTo("outputChannel");
assertThat(getPropertyValue(aggregator, "discardChannelName")).isEqualTo("discardChannel");
assertThat(getPropertyValue(aggregator, "messagingTemplate.sendTimeout")).isEqualTo(98765432L);
assertThat(getPropertyValue(aggregator, "sendPartialResultOnExpiry")).isEqualTo(true);
context.close();
}
@@ -82,14 +79,14 @@ public class AggregatorAnnotationTests {
final String endpointName = "endpointWithDefaultAnnotationAndCustomReleaseStrategy";
MessageHandler aggregator = this.getAggregator(context, endpointName);
Object releaseStrategy = getPropertyValue(aggregator, "releaseStrategy");
Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy);
assertThat(releaseStrategy instanceof MethodInvokingReleaseStrategy).isTrue();
MethodInvokingReleaseStrategy releaseStrategyAdapter = (MethodInvokingReleaseStrategy) releaseStrategy;
Object handlerMethods = new DirectFieldAccessor(releaseStrategyAdapter)
.getPropertyValue("adapter.delegate.handlerMethods");
assertNull(handlerMethods);
assertThat(handlerMethods).isNull();
Object handlerMethod = new DirectFieldAccessor(releaseStrategyAdapter)
.getPropertyValue("adapter.delegate.handlerMethod");
assertTrue(handlerMethod.toString().contains("completionChecker"));
assertThat(handlerMethod.toString().contains("completionChecker")).isTrue();
context.close();
}
@@ -100,18 +97,19 @@ public class AggregatorAnnotationTests {
final String endpointName = "endpointWithCorrelationStrategy";
MessageHandler aggregator = this.getAggregator(context, endpointName);
Object correlationStrategy = getPropertyValue(aggregator, "correlationStrategy");
Assert.assertTrue(correlationStrategy instanceof MethodInvokingCorrelationStrategy);
assertThat(correlationStrategy instanceof MethodInvokingCorrelationStrategy).isTrue();
MethodInvokingCorrelationStrategy releaseStrategyAdapter = (MethodInvokingCorrelationStrategy) correlationStrategy;
DirectFieldAccessor processorAccessor = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(releaseStrategyAdapter)
.getPropertyValue("processor")).getPropertyValue("delegate"));
Object targetObject = processorAccessor.getPropertyValue("targetObject");
assertSame(context.getBean(endpointName), targetObject);
assertNull(processorAccessor.getPropertyValue("handlerMethods"));
assertThat(targetObject).isSameAs(context.getBean(endpointName));
assertThat(processorAccessor.getPropertyValue("handlerMethods")).isNull();
Object handlerMethod = processorAccessor.getPropertyValue("handlerMethod");
assertNotNull(handlerMethod);
assertThat(handlerMethod).isNotNull();
DirectFieldAccessor handlerMethodAccessor = new DirectFieldAccessor(handlerMethod);
Method completionCheckerMethod = (Method) handlerMethodAccessor.getPropertyValue("invocableHandlerMethod.method");
assertEquals("correlate", completionCheckerMethod.getName());
Method completionCheckerMethod = (Method) handlerMethodAccessor.getPropertyValue(
"invocableHandlerMethod.method");
assertThat(completionCheckerMethod.getName()).isEqualTo("correlate");
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,9 +16,7 @@
package org.springframework.integration.config.annotation;
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 org.junit.Before;
import org.junit.Test;
@@ -83,21 +81,21 @@ public class AnnotatedEndpointActivationTests {
public void sendAndReceive() {
this.input.send(new GenericMessage<>("foo"));
Message<?> message = this.output.receive(100);
assertNotNull(message);
assertEquals("foo: 1", message.getPayload());
assertEquals(1, count);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo: 1");
assertThat(count).isEqualTo(1);
assertTrue(this.applicationContext.containsBean("annotatedEndpoint.process.serviceActivator"));
assertTrue(this.applicationContext.containsBean("annotatedEndpoint2.process.serviceActivator"));
assertThat(this.applicationContext.containsBean("annotatedEndpoint.process.serviceActivator")).isTrue();
assertThat(this.applicationContext.containsBean("annotatedEndpoint2.process.serviceActivator")).isTrue();
}
@Test
public void sendAndReceiveAsync() {
this.inputAsync.send(new GenericMessage<>("foo"));
Message<?> message = this.outputAsync.receive(100);
assertNotNull(message);
assertEquals("foo", message.getPayload());
assertTrue(this.applicationContext.containsBean("annotatedEndpoint3.process.serviceActivator"));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo");
assertThat(this.applicationContext.containsBean("annotatedEndpoint3.process.serviceActivator")).isTrue();
}
@Test
@@ -105,9 +103,9 @@ public class AnnotatedEndpointActivationTests {
MessageChannel input = this.applicationContext.getBean("inputImplicit", MessageChannel.class);
input.send(new GenericMessage<>("foo"));
Message<?> message = this.output.receive(100);
assertNotNull(message);
assertEquals("foo: 1", message.getPayload());
assertEquals(1, count);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo: 1");
assertThat(count).isEqualTo(1);
}
@Test(expected = MessageDeliveryException.class)
@@ -124,9 +122,9 @@ public class AnnotatedEndpointActivationTests {
applicationContext.start();
this.input.send(new GenericMessage<>("foo"));
Message<?> message = this.output.receive(100);
assertNotNull(message);
assertEquals("foo: 1", message.getPayload());
assertEquals(1, count);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo("foo: 1");
assertThat(count).isEqualTo(1);
}
@MessageEndpoint

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