diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java index 727a7c682d..2c298941f0 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java @@ -21,7 +21,9 @@ 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.mockito.BDDMockito.willAnswer; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -34,6 +36,7 @@ import java.util.concurrent.TimeUnit; import org.junit.AfterClass; import org.junit.ClassRule; import org.junit.Test; +import org.mockito.Mockito; import org.springframework.amqp.core.AmqpReplyTimeoutException; import org.springframework.amqp.core.MessageListener; @@ -43,6 +46,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; +import org.springframework.amqp.rabbit.support.CorrelationData; import org.springframework.amqp.support.AmqpHeaders; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; @@ -58,6 +62,8 @@ import org.springframework.util.concurrent.SettableListenableFuture; /** * @author Gary Russell + * @author Artem Bilan + * * @since 4.3 * */ @@ -66,10 +72,6 @@ public class AsyncAmqpGatewayTests { @ClassRule public static BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues("asyncQ1", "asyncRQ1"); -// @Rule -// public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration", -// "org.springframework.amqp"); - @AfterClass public static void tearDown() { brokerRunning.removeTestQueues(); @@ -89,6 +91,11 @@ public class AsyncAmqpGatewayTests { AsyncRabbitTemplate asyncTemplate = spy(new AsyncRabbitTemplate(template, container)); asyncTemplate.setEnableConfirms(true); asyncTemplate.setMandatory(true); + + willAnswer(Mockito.CALLS_REAL_METHODS) + .given(asyncTemplate) + .confirm(any(CorrelationData.class), anyBoolean(), anyString()); + asyncTemplate.start(); SimpleMessageListenerContainer receiver = new SimpleMessageListenerContainer(ccf); @@ -120,14 +127,12 @@ public class AsyncAmqpGatewayTests { returnChannel.setBeanName("returns"); QueueChannel ackChannel = new QueueChannel(); ackChannel.setBeanName("acks"); - QueueChannel nackChannel = new QueueChannel(); - nackChannel.setBeanName("nacks"); QueueChannel errorChannel = new QueueChannel(); errorChannel.setBeanName("errors"); gateway.setOutputChannel(outputChannel); gateway.setReturnChannel(returnChannel); gateway.setConfirmAckChannel(ackChannel); - gateway.setConfirmNackChannel(nackChannel); + gateway.setConfirmNackChannel(ackChannel); gateway.setConfirmCorrelationExpressionString("#this"); gateway.setExchangeName(""); gateway.setRoutingKey("asyncQ1"); @@ -150,6 +155,7 @@ public class AsyncAmqpGatewayTests { // timeout asyncTemplate.setReceiveTimeout(100); + receiver.setMessageListener(new MessageListener() { @Override @@ -158,7 +164,7 @@ public class AsyncAmqpGatewayTests { }); gateway.handleMessage(message); - assertNull(errorChannel.receive(1000)); + assertNull(errorChannel.receive(10)); ack = ackChannel.receive(10000); assertNotNull(ack); @@ -169,7 +175,7 @@ public class AsyncAmqpGatewayTests { assertThat(received, instanceOf(ErrorMessage.class)); ErrorMessage error = (ErrorMessage) received; assertThat(error.getPayload(), instanceOf(MessagingException.class)); - assertThat(((MessagingException) error.getPayload()).getCause(), instanceOf(AmqpReplyTimeoutException.class)); + assertThat(error.getPayload().getCause(), instanceOf(AmqpReplyTimeoutException.class)); asyncTemplate.setReceiveTimeout(30000); receiver.setMessageListener(messageListener); ack = ackChannel.receive(10000); @@ -213,7 +219,7 @@ public class AsyncAmqpGatewayTests { gateway.handleMessage(message); - ack = nackChannel.receive(10000); + ack = ackChannel.receive(10000); assertNotNull(ack); assertEquals("foo", ack.getPayload()); assertEquals("nacknack", ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM_NACK_CAUSE)); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java index 94ede31110..eaf1919b00 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java @@ -30,7 +30,6 @@ import java.util.Properties; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.test.util.TestUtils; @@ -41,13 +40,16 @@ import org.springframework.messaging.PollableChannel; * @author Oleg Zhurakousky * @author Iwein Fuld * @author Gunnar Hillert + * @author Artem Bilan */ public class FileMessageHistoryTests { @Test public void testMessageHistory() throws Exception { - ApplicationContext context = new ClassPathXmlApplicationContext("file-message-history-context.xml", this.getClass()); + ClassPathXmlApplicationContext context = + new ClassPathXmlApplicationContext("file-message-history-context.xml", getClass()); + TemporaryFolder input = context.getBean(TemporaryFolder.class); File file = input.newFile("FileMessageHistoryTest.txt"); BufferedWriter out = new BufferedWriter(new FileWriter(file)); @@ -55,12 +57,15 @@ public class FileMessageHistoryTests { out.close(); PollableChannel outChannel = context.getBean("outChannel", PollableChannel.class); - Message message = outChannel.receive(1000); + Message message = outChannel.receive(10000); assertThat(message, is(notNullValue())); MessageHistory history = MessageHistory.read(message); assertThat(history, is(notNullValue())); Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "fileAdapter", 0); assertNotNull(componentHistoryRecord); assertEquals("file:inbound-channel-adapter", componentHistoryRecord.get("type")); + + context.close(); } + } diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java index ed11cc36e7..381a017605 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java @@ -241,17 +241,17 @@ public class JdbcMessageStoreTests { @Test public void testAddAndRemoveMessagesFromMessageGroup() throws Exception { String groupId = "X"; - messageStore.setRemoveBatchSize(10); + this.messageStore.setRemoveBatchSize(10); List> messages = new ArrayList>(); for (int i = 0; i < 25; i++) { Message message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build(); messages.add(message); } - messageStore.addMessagesToGroup(groupId, messages.toArray(new Message[messages.size()])); - MessageGroup group = messageStore.getMessageGroup(groupId); + this.messageStore.addMessagesToGroup(groupId, messages.toArray(new Message[messages.size()])); + MessageGroup group = this.messageStore.getMessageGroup(groupId); assertEquals(25, group.size()); - messageStore.removeMessagesFromGroup(groupId, messages); - group = messageStore.getMessageGroup(groupId); + this.messageStore.removeMessagesFromGroup(groupId, messages); + group = this.messageStore.getMessageGroup(groupId); assertEquals(0, group.size()); } diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageGroupStoreTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageGroupStoreTests.java index 67e1d6d585..f1f8ab913d 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageGroupStoreTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageGroupStoreTests.java @@ -89,7 +89,7 @@ public class ConfigurableMongoDbMessageGroupStoreTests extends AbstractMongoDbMe performLazyLoadEagerTest(watch, sequenceSize, false); - System. out .println(watch.prettyPrint()); // checkstyle +// System. out .println(watch.prettyPrint()); // checkstyle } private void performLazyLoadEagerTest(StopWatch watch, int sequenceSize, boolean lazyLoad) {