diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategyTests.java index ac4e1e6593..4c6ee875a5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/ExpressionEvaluatingReleaseStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -24,8 +24,8 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.store.SimpleMessageGroup; +import org.springframework.messaging.support.GenericMessage; /** * @author Alex Peters @@ -49,21 +49,21 @@ public class ExpressionEvaluatingReleaseStrategyTests { } @Test - public void testCompletedWithSizeSpelEvaluated() throws Exception { + public void testCompletedWithSizeSpelEvaluated() { strategy = new ExpressionEvaluatingReleaseStrategy("#root.size()==5"); strategy.setBeanFactory(mock(BeanFactory.class)); assertThat(strategy.canRelease(messages), is(true)); } @Test - public void testCompletedWithFilterSpelEvaluated() throws Exception { + public void testCompletedWithFilterSpelEvaluated() { strategy = new ExpressionEvaluatingReleaseStrategy("!messages.?[payload==5].empty"); strategy.setBeanFactory(mock(BeanFactory.class)); assertThat(strategy.canRelease(messages), is(true)); } @Test - public void testCompletedWithFilterSpelReturnsNotCompleted() throws Exception { + public void testCompletedWithFilterSpelReturnsNotCompleted() { strategy = new ExpressionEvaluatingReleaseStrategy("!messages.?[payload==6].empty"); strategy.setBeanFactory(mock(BeanFactory.class)); assertThat(strategy.canRelease(messages), is(false)); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MessageSequenceComparatorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MessageSequenceComparatorTests.java index 55d278d7da..044adbe1e8 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MessageSequenceComparatorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MessageSequenceComparatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -22,8 +22,8 @@ import java.util.Comparator; import org.junit.Test; -import org.springframework.messaging.Message; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; /** * @author Mark Fisher diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/SequenceSizeReleaseStrategyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/SequenceSizeReleaseStrategyTests.java index 373bf7e293..196e908ac2 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/SequenceSizeReleaseStrategyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/SequenceSizeReleaseStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 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. @@ -20,14 +20,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.springframework.messaging.Message; + import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.SimpleMessageGroup; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; /** * @author Mark Fisher * @author Iwein Fuld + * @author Artem Bilan */ public class SequenceSizeReleaseStrategyTests { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/TimeoutCountSequenceSizeReleaseStrategyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/TimeoutCountSequenceSizeReleaseStrategyTests.java index dad3cb6ea0..4eb2815a7c 100755 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/TimeoutCountSequenceSizeReleaseStrategyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/TimeoutCountSequenceSizeReleaseStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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. @@ -20,12 +20,14 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.springframework.messaging.Message; + import org.springframework.integration.store.SimpleMessageGroup; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; /** * @author Dave Syer + * @author Artme Bilan */ public class TimeoutCountSequenceSizeReleaseStrategyTests { @@ -45,7 +47,9 @@ public class TimeoutCountSequenceSizeReleaseStrategyTests { .setSequenceSize(2).build(); SimpleMessageGroup messages = new SimpleMessageGroup("FOO"); messages.add(message); - TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = new TimeoutCountSequenceSizeReleaseStrategy(TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_THRESHOLD, -100); + TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = + new TimeoutCountSequenceSizeReleaseStrategy(TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_THRESHOLD, + -100); assertTrue(releaseStrategy.canRelease(messages)); } @@ -55,7 +59,9 @@ public class TimeoutCountSequenceSizeReleaseStrategyTests { .setSequenceSize(2).build(); SimpleMessageGroup messages = new SimpleMessageGroup("FOO"); messages.add(message); - TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = new TimeoutCountSequenceSizeReleaseStrategy(1, TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_TIMEOUT); + TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = + new TimeoutCountSequenceSizeReleaseStrategy(1, + TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_TIMEOUT); assertTrue(releaseStrategy.canRelease(messages)); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/AggregatorExpressionIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/AggregatorExpressionIntegrationTests.java index eef2c5b274..51f6467ff3 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/AggregatorExpressionIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/AggregatorExpressionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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. @@ -23,12 +23,13 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.IntegrationMessageHeaderAccessor; -import org.springframework.messaging.support.GenericMessage; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -36,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Iwein Fuld * @author Alex Peters * @author Oleg Zhurakousky + * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -50,16 +52,16 @@ public class AggregatorExpressionIntegrationTests { private PollableChannel output; @Test//(timeout=5000) - public void testVanillaAggregation() throws Exception { + public void testVanillaAggregation() { for (int i = 0; i < 5; i++) { Map headers = stubHeaders(i, 5, 1); - input.send(new GenericMessage(i, headers)); + this.input.send(new GenericMessage<>(i, headers)); } - assertEquals("[0, 1, 2, 3, 4]", output.receive().getPayload()); + assertEquals("[0, 1, 2, 3, 4]", this.output.receive().getPayload()); } private Map stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) { - Map headers = new HashMap(); + Map headers = new HashMap<>(); headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber); headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, sequenceSize); headers.put(IntegrationMessageHeaderAccessor.CORRELATION_ID, correllationId); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java index 671e825863..b15f168d08 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/DefaultMessageAggregatorIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -28,12 +28,13 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.IntegrationMessageHeaderAccessor; -import org.springframework.messaging.support.GenericMessage; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -41,6 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Alex Peters * @author Iwein Fuld * @author Gunnar Hillert + * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -56,12 +58,12 @@ public class DefaultMessageAggregatorIntegrationTests { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test(timeout = 10000) - public void testAggregation() throws Exception { + public void testAggregation() { for (int i = 0; i < 5; i++) { Map headers = stubHeaders(i, 5, 1); - input.send(new GenericMessage(i, headers)); + this.input.send(new GenericMessage<>(i, headers)); } - Object payload = output.receive().getPayload(); + 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))); @@ -69,7 +71,7 @@ public class DefaultMessageAggregatorIntegrationTests { private Map stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) { - Map headers = new HashMap(); + Map headers = new HashMap<>(); headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber); headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, sequenceSize); headers.put(IntegrationMessageHeaderAccessor.CORRELATION_ID, correllationId); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/MethodInvokingAggregatorReturningMessageTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/MethodInvokingAggregatorReturningMessageTests.java index 7378ae14fd..785d3b37f6 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/MethodInvokingAggregatorReturningMessageTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/MethodInvokingAggregatorReturningMessageTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -23,16 +23,18 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.Message; import org.springframework.integration.channel.DirectChannel; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.PollableChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -54,16 +56,16 @@ public class MethodInvokingAggregatorReturningMessageTests { @Test // INT-1107 public void messageReturningPojoAggregatorResultIsNotWrappedInAnotherMessage() { List payload = Collections.singletonList("test"); - pojoInput.send(MessageBuilder.withPayload(payload).build()); - Message result = pojoOutput.receive(); + this.pojoInput.send(MessageBuilder.withPayload(payload).build()); + Message result = this.pojoOutput.receive(); assertFalse(Message.class.isAssignableFrom(result.getPayload().getClass())); } @Test public void defaultAggregatorResultIsNotWrappedInAnotherMessage() { List payload = Collections.singletonList("test"); - defaultInput.send(MessageBuilder.withPayload(payload).build()); - Message result = defaultOutput.receive(); + this.defaultInput.send(MessageBuilder.withPayload(payload).build()); + Message result = this.defaultOutput.receive(); assertFalse(Message.class.isAssignableFrom(result.getPayload().getClass())); } @@ -75,6 +77,7 @@ public class MethodInvokingAggregatorReturningMessageTests { List payload = Collections.singletonList("foo"); return MessageBuilder.withPayload(payload).setHeader("bar", 123).build(); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregationResendTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregationResendTests.java index 1c69c0405b..3f73305318 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregationResendTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregationResendTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -20,16 +20,15 @@ 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; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.Message; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -38,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * * @author Iwein Fuld * @author Gunnar Hillert + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -62,8 +62,8 @@ public class AggregationResendTests { */ @Test @Ignore // timeout is no longer supported - public void testAggregatorWithoutExplicitTimeoutReturnsOnlyOneMessage() throws Exception { - sendMessage(input_for_aggregator_with_explicit_timeout, 2000); + public void testAggregatorWithoutExplicitTimeoutReturnsOnlyOneMessage() { + sendMessage(this.input_for_aggregator_with_explicit_timeout, 2000); } /** @@ -76,17 +76,17 @@ public class AggregationResendTests { */ @Test @Ignore // disabling from normal testing, should be the same behavior whether explicit or default - public void testAggregatorWithTimeoutReturnsOnlyOneMessage() throws Exception { - sendMessage(input_for_aggregator_without_explicit_timeout, 62000); + public void testAggregatorWithTimeoutReturnsOnlyOneMessage() { + sendMessage(this.input_for_aggregator_without_explicit_timeout, 62000); } private void sendMessage(DirectChannel channel, int waitSeconds) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add("foo"); list.add("bar"); list.add("baz"); - reply.purge(null); + this.reply.purge(null); channel.send(MessageBuilder.withPayload(list).setReplyChannel(reply).build()); Message replyMessage; @@ -96,8 +96,10 @@ public class AggregationResendTests { if (null != replyMessage) { messageCount++; } - } while (null != replyMessage); + } + while (null != replyMessage); Assert.assertEquals(1, messageCount); } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorReplyChannelTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorReplyChannelTests.java index bb61efef3e..8ad93418be 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorReplyChannelTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorReplyChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -29,15 +29,17 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artme Bilan + * * @since 2.0 */ @ContextConfiguration @@ -50,30 +52,30 @@ public class AggregatorReplyChannelTests { @Autowired private volatile PollableChannel output; - private final List list = new ArrayList(); + private final List list = new ArrayList<>(); @Before public void setupList() { - list.add("foo"); - list.add("bar"); + this.list.add("foo"); + this.list.add("bar"); } @Test public void replyChannelHeader() { - this.verifyReply(MessageBuilder.withPayload(list).setReplyChannel(output).build()); + verifyReply(MessageBuilder.withPayload(list).setReplyChannel(output).build()); } @Test // INT-1095 public void replyChannelNameHeader() { - this.verifyReply(MessageBuilder.withPayload(list).setReplyChannelName("output").build()); + verifyReply(MessageBuilder.withPayload(list).setReplyChannelName("output").build()); } private void verifyReply(Message message) { - assertNull(output.receive(0)); - input.send(message); - Message result = output.receive(0); + assertNull(this.output.receive(0)); + this.input.send(message); + Message result = this.output.receive(0); assertNotNull(result); assertTrue(result.getPayload() instanceof List); List resultList = (List) result.getPayload(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/NestedAggregationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/NestedAggregationTests.java index 5f68743852..02080affd5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/NestedAggregationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/NestedAggregationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -24,17 +24,19 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.channel.DirectChannel; -import org.springframework.messaging.support.GenericMessage; -import org.springframework.messaging.Message; import org.springframework.integration.core.MessagingTemplate; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * * @author Dave Syer + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -47,25 +49,25 @@ public class NestedAggregationTests { DirectChannel router; @Test - public void testAggregatorWithNestedSplitter() throws Exception { - @SuppressWarnings("unchecked") - Message input = new GenericMessage>>(Arrays.asList(Arrays.asList("foo", "bar", "spam"), - Arrays.asList("bar", "foo"))); + public void testAggregatorWithNestedSplitter() { + Message input = new GenericMessage<>( + Arrays.asList( + Arrays.asList("foo", "bar", "spam"), + Arrays.asList("bar", "foo"))); List result = sendAndReceiveMessage(splitter, 2000, input); assertNotNull("Expected result and got null", result); assertEquals("[[foo, bar, spam], [bar, foo]]", result.toString()); } @Test - public void testAggregatorWithNestedRouter() throws Exception { - Message input = new GenericMessage>(Arrays.asList("bar", "foo")); + public void testAggregatorWithNestedRouter() { + Message input = new GenericMessage<>(Arrays.asList("bar", "foo")); List result = sendAndReceiveMessage(router, 2000, input); assertNotNull("Expected result and got null", result); assertEquals("[[bar, foo], [bar, foo]]", result.toString()); } private List sendAndReceiveMessage(DirectChannel channel, int timeout, Message input) { - MessagingTemplate messagingTemplate = new MessagingTemplate(); messagingTemplate.setReceiveTimeout(timeout); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests.java index 4eb1e5e24a..eac9f552aa 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/AnnotationConfigRegistrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,22 +17,23 @@ package org.springframework.integration.aop; import org.junit.Assert; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.annotation.Publisher; +import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.Message; import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.integration.annotation.Publisher; -import org.springframework.integration.channel.QueueChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -51,9 +52,9 @@ public class AnnotationConfigRegistrationTests { @Test // INT-1200 public void verifyInterception() { - String name = testBean.setName("John", "Doe", 123); + String name = this.testBean.setName("John", "Doe", 123); Assert.assertNotNull(name); - Message message = annotationConfigRegistrationTest.receive(0); + Message message = this.annotationConfigRegistrationTest.receive(0); Assert.assertNotNull(message); Assert.assertEquals("John DoeDoe", message.getPayload()); Assert.assertEquals(123, message.getHeaders().get("x")); @@ -61,10 +62,10 @@ public class AnnotationConfigRegistrationTests { @Test public void defaultChannel() { - String result = testBean.exclaim("hello"); + String result = this.testBean.exclaim("hello"); Assert.assertNotNull(result); Assert.assertEquals("HELLO!!!", result); - Message message = defaultChannel.receive(0); + Message message = this.defaultChannel.receive(0); Assert.assertNotNull(message); Assert.assertEquals("HELLO!!!", message.getPayload()); } @@ -82,6 +83,7 @@ public class AnnotationConfigRegistrationTests { public String exclaim(String s) { return s.toUpperCase() + "!!!"; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingAnnotationUsageTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingAnnotationUsageTests.java index f0518c5619..7c73581d75 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingAnnotationUsageTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingAnnotationUsageTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -23,17 +23,19 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.annotation.Publisher; +import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.Message; import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.integration.annotation.Publisher; -import org.springframework.integration.channel.QueueChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky * @author Mark Fisher + * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -49,9 +51,9 @@ public class MessagePublishingAnnotationUsageTests { @Test public void headerWithExplicitName() { - String name = testBean.defaultPayload("John", "Doe"); + String name = this.testBean.defaultPayload("John", "Doe"); assertNotNull(name); - Message message = channel.receive(1000); + Message message = this.channel.receive(1000); assertNotNull(message); assertEquals("John Doe", message.getPayload()); assertEquals("Doe", message.getHeaders().get("last")); @@ -59,9 +61,9 @@ public class MessagePublishingAnnotationUsageTests { @Test public void headerWithImplicitName() { - String name = testBean.defaultPayloadButExplicitAnnotation("John", "Doe"); + String name = this.testBean.defaultPayloadButExplicitAnnotation("John", "Doe"); assertNotNull(name); - Message message = channel.receive(1000); + Message message = this.channel.receive(1000); assertNotNull(message); assertEquals("John Doe", message.getPayload()); assertEquals("Doe", message.getHeaders().get("lname")); @@ -69,10 +71,10 @@ public class MessagePublishingAnnotationUsageTests { @Test public void payloadAsArgument() { - String name = testBean.argumentAsPayload("John", "Doe"); + String name = this.testBean.argumentAsPayload("John", "Doe"); assertNotNull(name); assertEquals("John Doe", name); - Message message = channel.receive(1000); + Message message = this.channel.receive(1000); assertNotNull(message); assertEquals("John", message.getPayload()); assertEquals("Doe", message.getHeaders().get("lname")); @@ -96,6 +98,7 @@ public class MessagePublishingAnnotationUsageTests { public String argumentAsPayload(@Payload String fname, @Header String lname) { return fname + " " + lname; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorUsageTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorUsageTests.java index 45853fbaa7..031a10a597 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorUsageTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorUsageTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,18 +17,20 @@ package org.springframework.integration.aop; import org.junit.Assert; - import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.Message; import org.springframework.integration.channel.QueueChannel; +import org.springframework.messaging.Message; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -43,9 +45,9 @@ public class MessagePublishingInterceptorUsageTests { @Test public void demoMessagePublishingInterceptor() { - String name = testBean.setName("John", "Doe"); + String name = this.testBean.setName("John", "Doe"); Assert.assertNotNull(name); - Message message = channel.receive(1000); + Message message = this.channel.receive(1000); Assert.assertNotNull(message); Assert.assertEquals("John Doe", message.getPayload()); Assert.assertEquals("bar", message.getHeaders().get("foo")); @@ -57,6 +59,7 @@ public class MessagePublishingInterceptorUsageTests { public String setName(String fname, String lname) { return fname + " " + lname; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherExpressionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherExpressionTests.java index 3b5d2feb18..be476963fa 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherExpressionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -19,23 +19,26 @@ package org.springframework.integration.aop; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.context.support.StaticApplicationContext; import org.springframework.expression.EvaluationContext; -import org.springframework.messaging.handler.annotation.Header; -import org.springframework.messaging.handler.annotation.Payload; import org.springframework.integration.annotation.Publisher; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.messaging.Message; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.messaging.handler.annotation.Payload; /** * @author Mark Fisher * @author Gary Russell + * @author Artme Bilan + * * @since 2.0 */ public class PublisherExpressionTests { @@ -45,21 +48,26 @@ public class PublisherExpressionTests { @Before public void setup() throws Exception { - context.registerSingleton("testChannel", QueueChannel.class); + this.context.registerSingleton("testChannel", QueueChannel.class); IntegrationEvaluationContextFactoryBean factory = new IntegrationEvaluationContextFactoryBean(); - factory.setApplicationContext(context); + factory.setApplicationContext(this.context); factory.afterPropertiesSet(); EvaluationContext ec = factory.getObject(); - context.getBeanFactory().registerSingleton(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, ec); - context.getBeanFactory().registerSingleton("foo", "foo"); + this.context.getBeanFactory() + .registerSingleton(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, ec); + this.context.getBeanFactory().registerSingleton("foo", "foo"); } + @After + public void tearDown() { + this.context.close(); + } @Test // INT-1139 public void returnValue() { PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(); - advisor.setBeanFactory(context); - QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class); + advisor.setBeanFactory(this.context); + QueueChannel testChannel = this.context.getBean("testChannel", QueueChannel.class); advisor.setDefaultChannelName("testChannel"); ProxyFactory pf = new ProxyFactory(new TestBeanImpl()); pf.addAdvisor(advisor); @@ -73,7 +81,9 @@ public class PublisherExpressionTests { interface TestBean { + String test(String sku); + } @@ -85,6 +95,7 @@ public class PublisherExpressionTests { public String test(@Header("foo") String foo) { return "hello"; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/bus/DirectChannelSubscriptionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/bus/DirectChannelSubscriptionTests.java index db0473fcd7..4949d442ae 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/bus/DirectChannelSubscriptionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/bus/DirectChannelSubscriptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -18,27 +18,29 @@ package org.springframework.integration.bus; import static org.junit.Assert.assertEquals; +import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessagingException; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor; import org.springframework.integration.context.IntegrationContextUtils; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.handler.ServiceActivatingHandler; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.test.util.TestUtils.TestApplicationContext; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessagingException; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher + * @author Artem Bilan */ public class DirectChannelSubscriptionTests { @@ -51,8 +53,13 @@ public class DirectChannelSubscriptionTests { @Before public void setupChannels() { - context.registerChannel("sourceChannel", sourceChannel); - context.registerChannel("targetChannel", targetChannel); + this.context.registerChannel("sourceChannel", this.sourceChannel); + this.context.registerChannel("targetChannel", this.targetChannel); + } + + @After + public void tearDown() { + this.context.close(); } @@ -60,8 +67,8 @@ public class DirectChannelSubscriptionTests { public void sendAndReceiveForRegisteredEndpoint() { TestApplicationContext context = TestUtils.createTestApplicationContext(); ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "handle"); - serviceActivator.setOutputChannel(targetChannel); - EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, serviceActivator); + serviceActivator.setOutputChannel(this.targetChannel); + EventDrivenConsumer endpoint = new EventDrivenConsumer(this.sourceChannel, serviceActivator); context.registerEndpoint("testEndpoint", endpoint); context.refresh(); this.sourceChannel.send(new GenericMessage("foo")); @@ -73,20 +80,21 @@ public class DirectChannelSubscriptionTests { @Test public void sendAndReceiveForAnnotatedEndpoint() { MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(); - postProcessor.setBeanFactory(context.getBeanFactory()); + postProcessor.setBeanFactory(this.context.getBeanFactory()); postProcessor.afterPropertiesSet(); TestEndpoint endpoint = new TestEndpoint(); postProcessor.postProcessAfterInitialization(endpoint, "testEndpoint"); - context.refresh(); - this.sourceChannel.send(new GenericMessage("foo")); + this.context.refresh(); + this.sourceChannel.send(new GenericMessage<>("foo")); Message response = this.targetChannel.receive(); assertEquals("foo-from-annotated-endpoint", response.getPayload()); - context.stop(); + this.context.stop(); } @Test(expected = MessagingException.class) public void exceptionThrownFromRegisteredEndpoint() { AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { + @Override public Object handleRequestMessage(Message message) { throw new RuntimeException("intentional test failure"); @@ -94,31 +102,31 @@ public class DirectChannelSubscriptionTests { }; handler.setOutputChannel(targetChannel); EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, handler); - context.registerEndpoint("testEndpoint", endpoint); - context.refresh(); + this.context.registerEndpoint("testEndpoint", endpoint); + this.context.refresh(); try { - this.sourceChannel.send(new GenericMessage("foo")); + this.sourceChannel.send(new GenericMessage<>("foo")); } finally { - context.stop(); + this.context.stop(); } } @Test(expected = MessagingException.class) public void exceptionThrownFromAnnotatedEndpoint() { QueueChannel errorChannel = new QueueChannel(); - context.registerChannel(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, errorChannel); + this.context.registerChannel(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, errorChannel); MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(); - postProcessor.setBeanFactory(context.getBeanFactory()); + postProcessor.setBeanFactory(this.context.getBeanFactory()); postProcessor.afterPropertiesSet(); FailingTestEndpoint endpoint = new FailingTestEndpoint(); postProcessor.postProcessAfterInitialization(endpoint, "testEndpoint"); - context.refresh(); + this.context.refresh(); try { this.sourceChannel.send(new GenericMessage("foo")); } finally { - context.stop(); + this.context.stop(); } } @@ -126,8 +134,9 @@ public class DirectChannelSubscriptionTests { static class TestBean { public Message handle(Message message) { - return new GenericMessage(message.getPayload() + "!"); + return new GenericMessage<>(message.getPayload() + "!"); } + } @@ -136,8 +145,9 @@ public class DirectChannelSubscriptionTests { @ServiceActivator(inputChannel = "sourceChannel", outputChannel = "targetChannel") public Message handle(Message message) { - return new GenericMessage(message.getPayload() + "-from-annotated-endpoint"); + return new GenericMessage<>(message.getPayload() + "-from-annotated-endpoint"); } + } @@ -148,6 +158,7 @@ public class DirectChannelSubscriptionTests { public Message handle(Message message) { throw new RuntimeException("intentional test failure"); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/TestSource.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/TestSource.java deleted file mode 100644 index badd4460b2..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/TestSource.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.channel.config; - -import org.springframework.messaging.Message; -import org.springframework.integration.core.MessageSource; -import org.springframework.messaging.support.GenericMessage; - -/** - * @author Mark Fisher - */ -public class TestSource implements MessageSource { - - private final String text; - - - public TestSource(String text) { - this.text = text; - } - - public Message receive() { - return new GenericMessage(this.text); - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/TestTransformer.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/TestTransformer.java index b791a11daf..6f6d5d8154 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/config/TestTransformer.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/config/TestTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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,13 @@ package org.springframework.integration.channel.config; -import org.springframework.messaging.Message; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.transformer.Transformer; +import org.springframework.messaging.Message; /** * @author Mark Fisher + * @author Artem Bilan */ public class TestTransformer implements Transformer { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java index 802c1660d9..0dfd2c5154 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/MessageSelectingInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -22,14 +22,16 @@ import static org.junit.Assert.assertTrue; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; + import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.MessageSelector; -import org.springframework.messaging.support.GenericMessage; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; +import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher + * @author Artem Bilan */ public class MessageSelectingInterceptorTests { @@ -40,7 +42,7 @@ public class MessageSelectingInterceptorTests { MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector); QueueChannel channel = new QueueChannel(); channel.addInterceptor(interceptor); - assertTrue(channel.send(new GenericMessage("test1"))); + assertTrue(channel.send(new GenericMessage<>("test1"))); } @Test(expected = MessageDeliveryException.class) @@ -50,7 +52,7 @@ public class MessageSelectingInterceptorTests { MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector); QueueChannel channel = new QueueChannel(); channel.addInterceptor(interceptor); - channel.send(new GenericMessage("test1")); + channel.send(new GenericMessage<>("test1")); } @Test @@ -61,7 +63,7 @@ public class MessageSelectingInterceptorTests { MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2); QueueChannel channel = new QueueChannel(); channel.addInterceptor(interceptor); - assertTrue(channel.send(new GenericMessage("test1"))); + assertTrue(channel.send(new GenericMessage<>("test1"))); assertEquals(2, counter.get()); } @@ -73,11 +75,12 @@ public class MessageSelectingInterceptorTests { MessageSelector selector2 = new TestMessageSelector(false, counter); MessageSelector selector3 = new TestMessageSelector(false, counter); MessageSelector selector4 = new TestMessageSelector(true, counter); - MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2, selector3, selector4); + MessageSelectingInterceptor interceptor = + new MessageSelectingInterceptor(selector1, selector2, selector3, selector4); QueueChannel channel = new QueueChannel(); channel.addInterceptor(interceptor); try { - channel.send(new GenericMessage("test1")); + channel.send(new GenericMessage<>("test1")); } catch (MessageDeliveryException e) { exceptionThrown = true; @@ -104,6 +107,7 @@ public class MessageSelectingInterceptorTests { this.counter.incrementAndGet(); return this.shouldAccept; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java index ac388d0be8..aa322da428 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -22,12 +22,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; -import org.springframework.messaging.Message; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.MessageSelector; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.integration.support.MessageBuilder; /** * @author Mark Fisher @@ -40,7 +40,7 @@ public class WireTapTests { QueueChannel mainChannel = new QueueChannel(); QueueChannel secondaryChannel = new QueueChannel(); mainChannel.addInterceptor(new WireTap(secondaryChannel)); - mainChannel.send(new GenericMessage("testing")); + mainChannel.send(new GenericMessage<>("testing")); Message original = mainChannel.receive(0); assertNotNull(original); Message intercepted = secondaryChannel.receive(0); @@ -53,7 +53,7 @@ public class WireTapTests { QueueChannel mainChannel = new QueueChannel(); QueueChannel secondaryChannel = new QueueChannel(); mainChannel.addInterceptor(new WireTap(secondaryChannel, new TestSelector(false))); - mainChannel.send(new GenericMessage("testing")); + mainChannel.send(new GenericMessage<>("testing")); Message original = mainChannel.receive(0); assertNotNull(original); Message intercepted = secondaryChannel.receive(0); @@ -65,7 +65,7 @@ public class WireTapTests { QueueChannel mainChannel = new QueueChannel(); QueueChannel secondaryChannel = new QueueChannel(); mainChannel.addInterceptor(new WireTap(secondaryChannel, new TestSelector(true))); - mainChannel.send(new GenericMessage("testing")); + mainChannel.send(new GenericMessage<>("testing")); Message original = mainChannel.receive(0); assertNotNull(original); Message intercepted = secondaryChannel.receive(0); @@ -84,7 +84,7 @@ public class WireTapTests { QueueChannel secondaryChannel = new QueueChannel(); mainChannel.addInterceptor(new WireTap(secondaryChannel)); assertNull(secondaryChannel.receive(0)); - Message message = new GenericMessage("testing"); + Message message = new GenericMessage<>("testing"); mainChannel.send(message); Message original = mainChannel.receive(0); Message intercepted = secondaryChannel.receive(0); @@ -130,6 +130,7 @@ public class WireTapTests { public boolean accept(Message message) { return this.shouldAccept; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java index 033b3f3a97..cc0040b32f 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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,31 +16,33 @@ package org.springframework.integration.config; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.integration.aggregator.ReleaseStrategy; -import org.springframework.integration.aggregator.CorrelationStrategy; -import org.springframework.integration.annotation.Aggregator; -import org.springframework.messaging.PollableChannel; -import org.springframework.integration.store.MessageGroup; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; import java.util.List; -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.containsString; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.integration.aggregator.CorrelationStrategy; +import org.springframework.integration.aggregator.ReleaseStrategy; +import org.springframework.integration.annotation.Aggregator; +import org.springframework.integration.store.MessageGroup; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Marius Bogoevici * @author Iwein Fuld * @author Gunnar Hillert + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -139,7 +141,7 @@ public class AggregatorWithCorrelationStrategyTests { @Aggregator public String concatenate(List payloads) { - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); for (Object payload : payloads) { buffer.append(payload.toString()); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java index 1218173d09..7acfd28ca4 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -24,17 +24,18 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.MessageRejectedException; import org.springframework.integration.core.MessageSelector; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.filter.MessageFilter; import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StringUtils; @@ -42,42 +43,54 @@ import org.springframework.util.StringUtils; /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class FilterParserTests { - @Autowired @Qualifier("adapterInput") + @Autowired + @Qualifier("adapterInput") MessageChannel adapterInput; - @Autowired @Qualifier("adapterOutput") + @Autowired + @Qualifier("adapterOutput") PollableChannel adapterOutput; - @Autowired @Qualifier("implementationInput") + @Autowired + @Qualifier("implementationInput") MessageChannel implementationInput; - @Autowired @Qualifier("implementationOutput") + @Autowired + @Qualifier("implementationOutput") PollableChannel implementationOutput; - @Autowired @Qualifier("exceptionInput") + @Autowired + @Qualifier("exceptionInput") MessageChannel exceptionInput; - @Autowired @Qualifier("discardInput") + @Autowired + @Qualifier("discardInput") MessageChannel discardInput; - @Autowired @Qualifier("discardOutput") + @Autowired + @Qualifier("discardOutput") PollableChannel discardOutput; - @Autowired @Qualifier("discardAndExceptionInput") + @Autowired + @Qualifier("discardAndExceptionInput") MessageChannel discardAndExceptionInput; - @Autowired @Qualifier("discardAndExceptionOutput") + @Autowired + @Qualifier("discardAndExceptionOutput") PollableChannel discardAndExceptionOutput; - @Autowired @Qualifier("advised.handler") + @Autowired + @Qualifier("advised.handler") MessageFilter advised; - @Autowired @Qualifier("notAdvised.handler") + @Autowired + @Qualifier("notAdvised.handler") MessageFilter notAdvised; private static volatile int adviceCalled; @@ -91,7 +104,7 @@ public class FilterParserTests { @Test public void filterWithSelectorAdapterAccepts() { adviceCalled = 0; - adapterInput.send(new GenericMessage("test")); + adapterInput.send(new GenericMessage<>("test")); Message reply = adapterOutput.receive(0); assertNotNull(reply); assertEquals("test", reply.getPayload()); @@ -100,14 +113,14 @@ public class FilterParserTests { @Test public void filterWithSelectorAdapterRejects() { - adapterInput.send(new GenericMessage("")); + adapterInput.send(new GenericMessage<>("")); Message reply = adapterOutput.receive(0); assertNull(reply); } @Test public void filterWithSelectorImplementationAccepts() { - implementationInput.send(new GenericMessage("test")); + implementationInput.send(new GenericMessage<>("test")); Message reply = implementationOutput.receive(0); assertNotNull(reply); assertEquals("test", reply.getPayload()); @@ -115,26 +128,26 @@ public class FilterParserTests { @Test public void filterWithSelectorImplementationRejects() { - implementationInput.send(new GenericMessage("")); + implementationInput.send(new GenericMessage<>("")); Message reply = implementationOutput.receive(0); assertNull(reply); } @Test public void exceptionThrowingFilterAccepts() { - exceptionInput.send(new GenericMessage("test")); + exceptionInput.send(new GenericMessage<>("test")); Message reply = implementationOutput.receive(0); assertNotNull(reply); } @Test(expected = MessageRejectedException.class) public void exceptionThrowingFilterRejects() { - exceptionInput.send(new GenericMessage("")); + exceptionInput.send(new GenericMessage<>("")); } @Test public void filterWithDiscardChannel() { - discardInput.send(new GenericMessage("")); + discardInput.send(new GenericMessage<>("")); Message discard = discardOutput.receive(0); assertNotNull(discard); assertEquals("", discard.getPayload()); @@ -145,7 +158,7 @@ public class FilterParserTests { public void filterWithDiscardChannelAndException() throws Exception { Exception exception = null; try { - discardAndExceptionInput.send(new GenericMessage("")); + discardAndExceptionInput.send(new GenericMessage<>("")); } catch (Exception e) { exception = e; @@ -163,6 +176,7 @@ public class FilterParserTests { public boolean hasText(String s) { return StringUtils.hasText(s); } + } @@ -174,6 +188,7 @@ public class FilterParserTests { } return false; } + } public static class FooFilter extends AbstractRequestHandlerAdvice { @@ -185,4 +200,5 @@ public class FilterParserTests { } } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java index 5c657d4c7e..4a043db884 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -26,49 +26,55 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.integration.router.AbstractMappingMessageRouter; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.integration.router.AbstractMappingMessageRouter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class RouterFactoryBeanDelegationTests { - @Autowired @Qualifier("input") + @Autowired + @Qualifier("input") private MessageChannel input; - @Autowired @Qualifier("strings") + @Autowired + @Qualifier("strings") private PollableChannel strings; - @Autowired @Qualifier("discard") + @Autowired + @Qualifier("discard") private PollableChannel discard; - @Autowired @Qualifier("org.springframework.integration.config.RouterFactoryBean#0") + @Autowired + @Qualifier("org.springframework.integration.config.RouterFactoryBean#0") private AbstractMappingMessageRouter router; @Test public void checkResolutionRequiredConfiguredOnTargetRouter() { + @SuppressWarnings("unchecked") boolean resolutionRequired = (Boolean) new DirectFieldAccessor(router).getPropertyValue("resolutionRequired"); assertTrue("The 'resolutionRequired' property should be 'true'", resolutionRequired); } @Test public void routeWithMappedType() { - input.send(new GenericMessage("test")); + input.send(new GenericMessage<>("test")); assertNull(discard.receive(0)); assertNotNull(strings.receive(0)); } @Test public void routeWithUnmappedType() { - input.send(new GenericMessage(123)); + input.send(new GenericMessage<>(123)); assertNull(strings.receive(0)); assertNotNull(discard.receive(0)); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests-context.xml index 783010b44f..7a5f7c28d4 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests-context.xml @@ -39,16 +39,16 @@ - + - + - + - + - + - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java index 43fb980a5f..6ef9a533ca 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -27,17 +27,18 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.messaging.Message; import org.springframework.integration.core.MessageSelector; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.selector.MessageSelectorChain; import org.springframework.integration.selector.MessageSelectorChain.VotingStrategy; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Iwein Fuld + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -55,7 +56,7 @@ public class SelectorChainParserTests { assertEquals(VotingStrategy.ALL, this.getStrategy(chain)); assertEquals(selector1, selectors.get(0)); assertEquals(selector2, selectors.get(1)); - assertTrue(chain.accept(new GenericMessage("test"))); + assertTrue(chain.accept(new GenericMessage<>("test"))); assertTrue(this.context.containsBean("pojoSelector")); } @@ -88,10 +89,10 @@ public class SelectorChainParserTests { assertEquals(VotingStrategy.MAJORITY_OR_TIE, this.getStrategy(chain4)); List 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"))); + assertTrue(chain1.accept(new GenericMessage<>("test1"))); + assertTrue(chain2.accept(new GenericMessage<>("test2"))); + assertTrue(chain3.accept(new GenericMessage<>("test3"))); + assertTrue(chain4.accept(new GenericMessage<>("test4"))); } @@ -105,15 +106,12 @@ public class SelectorChainParserTests { return (VotingStrategy) new DirectFieldAccessor(chain).getPropertyValue("votingStrategy"); } - public static class StubMessageSelector implements MessageSelector { + public static class StubPojoSelector { + public boolean accept(Message message) { return true; } + } - public static class StubPojoSelector { - public boolean accept(Message message) { - return true; - } - } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ServiceActivatorAnnotationPostProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ServiceActivatorAnnotationPostProcessorTests.java index 8c1b30efa0..ced53628bc 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/ServiceActivatorAnnotationPostProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ServiceActivatorAnnotationPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -25,17 +25,18 @@ import java.util.concurrent.TimeUnit; import org.junit.Test; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.test.util.TestUtils.TestApplicationContext; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher + * @author Artem Bilan */ public class ServiceActivatorAnnotationPostProcessorTests { @@ -50,15 +51,16 @@ public class ServiceActivatorAnnotationPostProcessorTests { beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(latch); context.registerBeanDefinition("testBean", beanDefinition); context.refresh(); - SimpleServiceActivatorAnnotationTestBean testBean = (SimpleServiceActivatorAnnotationTestBean) context.getBean("testBean"); + SimpleServiceActivatorAnnotationTestBean testBean = + context.getBean("testBean", SimpleServiceActivatorAnnotationTestBean.class); assertEquals(1, latch.getCount()); assertNull(testBean.getMessageText()); MessageChannel testChannel = (MessageChannel) context.getBean("testChannel"); - testChannel.send(new GenericMessage("test-123")); + testChannel.send(new GenericMessage<>("test-123")); latch.await(1000, TimeUnit.MILLISECONDS); assertEquals(0, latch.getCount()); assertEquals("test-123", testBean.getMessageText()); - context.stop(); + context.close(); } @@ -79,6 +81,7 @@ public class ServiceActivatorAnnotationPostProcessorTests { public String getMessageText() { return this.messageText; } + } @@ -94,6 +97,7 @@ public class ServiceActivatorAnnotationPostProcessorTests { this.messageText = messageText; this.countDown(); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java index b518e86f06..dc79eb9db0 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -19,9 +19,9 @@ 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.mockito.BDDMockito.willAnswer; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.BDDMockito.willAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -77,7 +77,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests { factoryBean.setOutputChannel(outputChannel); factoryBean.setSource(() -> new GenericMessage<>("test")); PollerMetadata pollerMetadata = new PollerMetadata(); - List adviceChain = new ArrayList(); + List adviceChain = new ArrayList<>(); final AtomicBoolean adviceApplied = new AtomicBoolean(false); adviceChain.add((MethodInterceptor) invocation -> { adviceApplied.set(true); @@ -94,6 +94,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests { Message message = outputChannel.receive(5000); assertEquals("test", message.getPayload()); assertTrue("adviceChain was not applied", adviceApplied.get()); + context.close(); } @Test @@ -106,7 +107,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests { factoryBean.setOutputChannel(outputChannel); factoryBean.setSource(() -> new GenericMessage<>("test")); PollerMetadata pollerMetadata = new PollerMetadata(); - List adviceChain = new ArrayList(); + List adviceChain = new ArrayList<>(); final AtomicBoolean adviceApplied = new AtomicBoolean(false); adviceChain.add((MethodInterceptor) invocation -> { adviceApplied.set(true); @@ -135,6 +136,7 @@ public class SourcePollingChannelAdapterFactoryBeanTests { assertEquals("test", message.getPayload()); assertEquals(1, count.get()); assertTrue("adviceChain was not applied", adviceApplied.get()); + context.close(); } @Test diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/StubMessageSelector.java b/spring-integration-core/src/test/java/org/springframework/integration/config/StubMessageSelector.java index 3d470a1a7e..ea20d4c70c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/StubMessageSelector.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/StubMessageSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,12 @@ package org.springframework.integration.config; import org.springframework.beans.factory.BeanNameAware; -import org.springframework.messaging.Message; import org.springframework.integration.core.MessageSelector; +import org.springframework.messaging.Message; /** * @author Mark Fisher + * @author Artem Bilan */ public class StubMessageSelector implements MessageSelector, BeanNameAware { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/TestHandler.java b/spring-integration-core/src/test/java/org/springframework/integration/config/TestHandler.java index 91b161793b..110d84601b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/TestHandler.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/TestHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -18,11 +18,12 @@ package org.springframework.integration.config; import java.util.concurrent.CountDownLatch; -import org.springframework.messaging.Message; import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.messaging.Message; /** * @author Mark Fisher + * @author Artem Bilan */ public class TestHandler { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/TestSelector.java b/spring-integration-core/src/test/java/org/springframework/integration/config/TestSelector.java index d3389ce157..c2cbc76732 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/TestSelector.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/TestSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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,12 @@ package org.springframework.integration.config; -import org.springframework.messaging.Message; import org.springframework.integration.core.MessageSelector; +import org.springframework.messaging.Message; /** * @author Mark Fisher + * @author Artem Bilan */ public class TestSelector implements MessageSelector { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/TestSource.java b/spring-integration-core/src/test/java/org/springframework/integration/config/TestSource.java index 2525423853..abdb29e2ad 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/TestSource.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/TestSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,18 @@ package org.springframework.integration.config; -import org.springframework.messaging.Message; import org.springframework.integration.core.MessageSource; +import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher + * @author Artem Bilan */ public class TestSource implements MessageSource { public Message receive() { - return new GenericMessage("test"); + return new GenericMessage<>("test"); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java index 0d25f1dc24..b86f3e9526 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -29,20 +29,20 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.Message; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.SubscribableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Iwein Fuld * @author Mark Fisher + * @author Artem Bilan */ - @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class MessagingAnnotationPostProcessorAopIntegrationTests { @@ -57,12 +57,12 @@ public class MessagingAnnotationPostProcessorAopIntegrationTests { @Test - public void parseConfig() throws Exception { - assertThat(input, notNullValue()); + public void parseConfig() { + assertThat(this.input, notNullValue()); } @Test - public void sendMessage() throws Exception { + public void sendMessage() { input.send(MessageBuilder.withPayload(new AtomicInteger(0)).build()); Message reply = output.receive(1000); assertEquals(111, ((Integer) reply.getPayload()).intValue()); @@ -76,6 +76,7 @@ public class MessagingAnnotationPostProcessorAopIntegrationTests { public void addOneHundred(Message message) { ((AtomicInteger) message.getPayload()).addAndGet(100); } + } @@ -86,6 +87,7 @@ public class MessagingAnnotationPostProcessorAopIntegrationTests { public void addTen(AtomicInteger n) { n.addAndGet(10); } + } @@ -96,6 +98,7 @@ public class MessagingAnnotationPostProcessorAopIntegrationTests { public int addOne(AtomicInteger n) { return n.addAndGet(1); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java index 824ed919c5..b0ab5d7fae 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ClaimCheckParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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,9 @@ package org.springframework.integration.config.xml; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.util.UUID; @@ -28,15 +28,15 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.store.MessageStore; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.transformer.ClaimCheckInTransformer; import org.springframework.integration.transformer.ClaimCheckOutTransformer; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -44,6 +44,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Mark Fisher * @author Oleg Zhurakousky * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusChainTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusChainTests.java index ee48ef2c8c..cbc651f532 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusChainTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusChainTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 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. @@ -23,18 +23,20 @@ import java.util.Date; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -48,7 +50,10 @@ public class ControlBusChainTests { @Test public void testDefaultEvaluationContext() { - Message message = MessageBuilder.withPayload("@service.convert('aardvark')+headers.foo").setHeader("foo", "bar").build(); + Message message = + MessageBuilder.withPayload("@service.convert('aardvark')+headers.foo") + .setHeader("foo", "bar") + .build(); this.input.send(message); assertEquals("catbar", output.receive(0).getPayload()); assertNull(output.receive(0)); @@ -61,12 +66,15 @@ public class ControlBusChainTests { public String convert(String input) { return "cat"; } + } public static class AdapterService { + public Message receive() { - return new GenericMessage(new Date().toString()); + return new GenericMessage<>(new Date().toString()); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusExplicitPollerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusExplicitPollerTests.java index d03567a9d5..a20ad78a36 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusExplicitPollerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusExplicitPollerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -21,21 +21,24 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.jmx.export.annotation.ManagedOperation; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; /** * @author Dave Syer + * @author Artem Bilan + * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) +@DirtiesContext public class ControlBusExplicitPollerTests { @Autowired @@ -46,7 +49,10 @@ public class ControlBusExplicitPollerTests { @Test public void testDefaultEvaluationContext() { - Message message = MessageBuilder.withPayload("@service.convert('aardvark')+headers.foo").setHeader("foo", "bar").build(); + Message message = + MessageBuilder.withPayload("@service.convert('aardvark')+headers.foo") + .setHeader("foo", "bar") + .build(); this.input.send(message); assertEquals("catbar", output.receive(1000).getPayload()); assertNull(output.receive(0)); @@ -59,6 +65,7 @@ public class ControlBusExplicitPollerTests { public String convert(String input) { return "cat"; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusPollerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusPollerTests.java index 38acf71be6..45fbcf8c11 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusPollerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ControlBusPollerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -21,20 +21,23 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; /** * @author Dave Syer + * @author Artem Bilan + * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) +@DirtiesContext public class ControlBusPollerTests { @Autowired @@ -45,15 +48,21 @@ public class ControlBusPollerTests { @Test public void testDefaultEvaluationContext() { - Message message = MessageBuilder.withPayload("@service.convert('aardvark')+headers.foo").setHeader("foo", "bar").build(); + Message message = + MessageBuilder.withPayload("@service.convert('aardvark')+headers.foo") + .setHeader("foo", "bar") + .build(); this.input.send(message); assertEquals("catbar", output.receive(1000).getPayload()); assertNull(output.receive(0)); } public static class Service { + public String convert(String input) { return "cat"; } + } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ConverterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ConverterParserTests.java index 78b59d6a59..5a46fa9b51 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ConverterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ConverterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -21,14 +21,15 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.convert.converter.Converter; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -160,7 +161,7 @@ public class ConverterParserTests { } - public static class TestBean1 { + public static class TestBean1 { private String text; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDefaultConfigurationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDefaultConfigurationTests.java index 3f30db4d7a..632a270587 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDefaultConfigurationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDefaultConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -19,11 +19,14 @@ package org.springframework.integration.config.xml; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell + * @author Artem Bilan + * * @since 2.2 * */ @@ -36,4 +39,5 @@ public class DispatcherMaxSubscribersDefaultConfigurationTests extends Dispatche doTestUnicast(Integer.MAX_VALUE, Integer.MAX_VALUE, 123, Integer.MAX_VALUE, 234); doTestMulticast(Integer.MAX_VALUE, 2); } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests.java index 8ef8b23bab..d766f9fc60 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -19,11 +19,14 @@ package org.springframework.integration.config.xml; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell + * @author Artem Bilan + * * @since 2.2 * */ @@ -36,4 +39,5 @@ public class DispatcherMaxSubscribersDontOverrideDefaultTests extends Dispatcher doTestUnicast(Integer.MAX_VALUE, Integer.MAX_VALUE, 123, Integer.MAX_VALUE, 234); doTestMulticast(Integer.MAX_VALUE, 2); } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersTests.java index bb31ddfbfa..a8442da2ce 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -19,12 +19,13 @@ package org.springframework.integration.config.xml; import static org.junit.Assert.assertEquals; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.MessageChannel; /** * @author Gary Russell * @author Artem Bilan + * * @since 2.2 * */ @@ -59,7 +60,8 @@ public abstract class DispatcherMaxSubscribersTests { } protected void doTestUnicast(int val1, int val2, int val3, int val4, int val5) { - Integer autoCreateMax = TestUtils.getPropertyValue(autoCreateChannel, "dispatcher.maxSubscribers", Integer.class); + Integer autoCreateMax = + TestUtils.getPropertyValue(autoCreateChannel, "dispatcher.maxSubscribers", Integer.class); assertEquals(val1, autoCreateMax.intValue()); Integer defaultMax = TestUtils.getPropertyValue(defaultChannel, "dispatcher.maxSubscribers", Integer.class); assertEquals(val1, defaultMax.intValue()); @@ -69,7 +71,8 @@ public abstract class DispatcherMaxSubscribersTests { assertEquals(val3, explicitMax.intValue()); Integer execMax = TestUtils.getPropertyValue(executorChannel, "dispatcher.maxSubscribers", Integer.class); assertEquals(val4, execMax.intValue()); - Integer explicitExecMax = TestUtils.getPropertyValue(explicitExecutorChannel, "dispatcher.maxSubscribers", Integer.class); + Integer explicitExecMax = + TestUtils.getPropertyValue(explicitExecutorChannel, "dispatcher.maxSubscribers", Integer.class); assertEquals(val5, explicitExecMax.intValue()); } @@ -80,7 +83,9 @@ public abstract class DispatcherMaxSubscribersTests { Integer explicitMax = TestUtils.getPropertyValue( TestUtils.getPropertyValue(pubSubExplicitChannel, "dispatcher"), "maxSubscribers", Integer.class); assertEquals(val2, explicitMax.intValue()); - Integer explicitMin = TestUtils.getPropertyValue(pubSubExplicitChannel, "dispatcher.minSubscribers", Integer.class); + Integer explicitMin = + TestUtils.getPropertyValue(pubSubExplicitChannel, "dispatcher.minSubscribers", Integer.class); assertEquals(1, explicitMin.intValue()); } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTests2.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTests2.java index c4b150eab9..1d9807d6af 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTests2.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTests2.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 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. @@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.integration.test.util.TestUtils; @@ -29,6 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Gunnar Hillert + * @author Artem Bilan * * @since 2.1 */ diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTestsWithoutRequestChannel.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTestsWithoutRequestChannel.java index a7de83cff7..ce7734899b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTestsWithoutRequestChannel.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserTestsWithoutRequestChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 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. @@ -24,22 +24,25 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.expression.Expression; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.transformer.ContentEnricher; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan + * * @since 2.1 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -67,7 +70,8 @@ public class EnricherParserTestsWithoutRequestChannel { assertEquals(false, accessor.getPropertyValue("shouldClonePayload")); assertNull(accessor.getPropertyValue("requestPayloadExpression")); - Map propertyExpressions = (Map) accessor.getPropertyValue("propertyExpressions"); + Map propertyExpressions = + (Map) accessor.getPropertyValue("propertyExpressions"); for (Map.Entry e : propertyExpressions.entrySet()) { if ("name".equals(e.getKey().getExpressionString())) { assertEquals("payload.name", e.getValue().getExpressionString()); @@ -76,7 +80,8 @@ public class EnricherParserTestsWithoutRequestChannel { assertEquals("42", e.getValue().getExpressionString()); } else { - throw new IllegalStateException("expected 'name' and 'age' only, not: " + e.getKey().getExpressionString()); + throw new IllegalStateException( + "expected 'name' and 'age' only, not: " + e.getKey().getExpressionString()); } } } @@ -126,6 +131,7 @@ public class EnricherParserTestsWithoutRequestChannel { copy.setAge(this.age); return copy; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserWithRequestPayloadExpressionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserWithRequestPayloadExpressionTests.java index b8321677a6..c3a5e2070d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserWithRequestPayloadExpressionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/EnricherParserWithRequestPayloadExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,31 +17,33 @@ package org.springframework.integration.config.xml; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.expression.Expression; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.PollableChannel; -import org.springframework.messaging.SubscribableChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.transformer.ContentEnricher; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.SubscribableChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan * @since 2.1 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -68,7 +70,8 @@ public class EnricherParserWithRequestPayloadExpressionTests { Expression requestPayloadExpression = (Expression) accessor.getPropertyValue("requestPayloadExpression"); assertEquals("payload.age", requestPayloadExpression.getExpressionString()); - Map propertyExpressions = (Map) accessor.getPropertyValue("propertyExpressions"); + Map propertyExpressions = + (Map) accessor.getPropertyValue("propertyExpressions"); for (Map.Entry e : propertyExpressions.entrySet()) { if ("name".equals(e.getKey().getExpressionString())) { assertEquals("'Name as SpEL'", e.getValue().getExpressionString()); @@ -77,7 +80,8 @@ public class EnricherParserWithRequestPayloadExpressionTests { assertEquals("payload.sourceName", e.getValue().getExpressionString()); } else { - throw new IllegalStateException("expected 'name' and 'age' only, not: " + e.getKey().getExpressionString()); + throw new IllegalStateException( + "expected 'name' and 'age' only, not: " + e.getKey().getExpressionString()); } } } @@ -86,6 +90,7 @@ public class EnricherParserWithRequestPayloadExpressionTests { public void integrationTest() { SubscribableChannel requests = context.getBean("requests", SubscribableChannel.class); requests.subscribe(new AbstractReplyProducingMessageHandler() { + @Override protected Object handleRequestMessage(Message requestMessage) { @@ -124,6 +129,7 @@ public class EnricherParserWithRequestPayloadExpressionTests { public String getSourceName() { return sourceName; } + } @@ -155,6 +161,7 @@ public class EnricherParserWithRequestPayloadExpressionTests { copy.setAge(this.age); return copy; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorChannelAutoCreationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorChannelAutoCreationTests.java index a285af70c5..77cb468dfa 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorChannelAutoCreationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorChannelAutoCreationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -22,14 +22,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.PublishSubscribeChannel; +import org.springframework.messaging.MessageChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky - * + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorMessageExceptionTypeRouterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorMessageExceptionTypeRouterParserTests.java index 6232bb1f04..45117a5111 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorMessageExceptionTypeRouterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/ErrorMessageExceptionTypeRouterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,22 +16,23 @@ package org.springframework.integration.config.xml; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.Matchers.instanceOf; +import static org.junit.Assert.assertThat; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.ErrorMessage; -import org.springframework.integration.channel.QueueChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky * @author Gunnar Hillert - * + * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -53,12 +54,13 @@ public class ErrorMessageExceptionTypeRouterParserTests { public void validateExceptionTypeRouterConfig() { inputChannel.send(new ErrorMessage(new NullPointerException())); - assertTrue(npeChannel.receive(1000).getPayload() instanceof NullPointerException); + assertThat(npeChannel.receive(1000).getPayload(), instanceOf(NullPointerException.class)); inputChannel.send(new ErrorMessage(new IllegalArgumentException())); - assertTrue(illegalChannel.receive(1000).getPayload() instanceof IllegalArgumentException); + assertThat(illegalChannel.receive(1000).getPayload(), instanceOf(IllegalArgumentException.class)); inputChannel.send(new ErrorMessage(new RuntimeException())); - assertTrue(defaultChannel.receive(1000).getPayload() instanceof RuntimeException); + assertThat(defaultChannel.receive(1000).getPayload(), instanceOf(RuntimeException.class)); } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherMethodInvokingTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherMethodInvokingTests.java index b86849b6b3..57ec9aad83 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherMethodInvokingTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherMethodInvokingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -27,15 +27,17 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -69,11 +71,12 @@ public class HeaderEnricherMethodInvokingTests { } public Map enrich() { - Map headers = new HashMap(); + Map headers = new HashMap<>(); headers.put("foo", 123); headers.put("bar", "ABC"); return headers; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherOverwriteTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherOverwriteTests.java index c1b65cc3d2..9002ac7860 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherOverwriteTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherOverwriteTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -22,21 +22,24 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.integration.channel.QueueChannel; -import org.springframework.messaging.support.GenericMessage; +import org.springframework.integration.core.MessagingTemplate; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.core.MessagingTemplate; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -49,8 +52,10 @@ public class HeaderEnricherOverwriteTests { @Test public void replyChannelExplicitOverwriteTrue() { - MessageChannel inputChannel = context.getBean("replyChannelExplicitOverwriteTrueInput", MessageChannel.class); - PollableChannel replyChannel = context.getBean("replyChannelExplicitOverwriteTrueOutput", PollableChannel.class); + MessageChannel inputChannel = + this.context.getBean("replyChannelExplicitOverwriteTrueInput", MessageChannel.class); + PollableChannel replyChannel = + this.context.getBean("replyChannelExplicitOverwriteTrueOutput", PollableChannel.class); QueueChannel replyChannelToOverwrite = new QueueChannel(); Message message = MessageBuilder.withPayload("test").setReplyChannel(replyChannelToOverwrite).build(); inputChannel.send(message); @@ -63,7 +68,8 @@ public class HeaderEnricherOverwriteTests { @Test public void replyChannelExplicitOverwriteFalse() { - MessageChannel inputChannel = context.getBean("replyChannelExplicitOverwriteFalseInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("replyChannelExplicitOverwriteFalseInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build(); inputChannel.send(message); @@ -75,10 +81,12 @@ public class HeaderEnricherOverwriteTests { @Test public void replyChannelExplicitOverwriteFalseButNoExistingHeader() { - MessageChannel inputChannel = context.getBean( - "replyChannelExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); - PollableChannel replyChannel = context.getBean( - "replyChannelExplicitOverwriteFalseButNoExistingHeaderOutput", PollableChannel.class); + MessageChannel inputChannel = + this.context.getBean( + "replyChannelExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); + PollableChannel replyChannel = + this.context.getBean( + "replyChannelExplicitOverwriteFalseButNoExistingHeaderOutput", PollableChannel.class); Message message = MessageBuilder.withPayload("test").build(); inputChannel.send(message); Message result = replyChannel.receive(0); @@ -89,8 +97,10 @@ public class HeaderEnricherOverwriteTests { @Test public void replyChannelDefaultOverwriteTrue() { - MessageChannel inputChannel = context.getBean("replyChannelDefaultOverwriteTrueInput", MessageChannel.class); - PollableChannel replyChannel = context.getBean("replyChannelDefaultOverwriteTrueOutput", PollableChannel.class); + MessageChannel inputChannel = + this.context.getBean("replyChannelDefaultOverwriteTrueInput", MessageChannel.class); + PollableChannel replyChannel = + this.context.getBean("replyChannelDefaultOverwriteTrueOutput", PollableChannel.class); QueueChannel replyChannelToOverwrite = new QueueChannel(); Message message = MessageBuilder.withPayload("test").setReplyChannel(replyChannelToOverwrite).build(); inputChannel.send(message); @@ -103,7 +113,8 @@ public class HeaderEnricherOverwriteTests { @Test public void replyChannelDefaultOverwriteFalse() { - MessageChannel inputChannel = context.getBean("replyChannelDefaultOverwriteFalseInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("replyChannelDefaultOverwriteFalseInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build(); inputChannel.send(message); @@ -115,7 +126,9 @@ public class HeaderEnricherOverwriteTests { @Test public void replyChannelDefaultOverwriteTrueButExplicitOverwriteFalse() { - MessageChannel inputChannel = context.getBean("replyChannelDefaultOverwriteTrueButExplicitOverwriteFalseInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("replyChannelDefaultOverwriteTrueButExplicitOverwriteFalseInput", + MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build(); inputChannel.send(message); @@ -127,10 +140,12 @@ public class HeaderEnricherOverwriteTests { @Test public void replyChannelDefaultOverwriteFalseButNoExistingHeader() { - MessageChannel inputChannel = context.getBean( - "replyChannelDefaultOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); - PollableChannel replyChannel = context.getBean( - "replyChannelDefaultOverwriteFalseButNoExistingHeaderOutput", PollableChannel.class); + MessageChannel inputChannel = + this.context.getBean( + "replyChannelDefaultOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); + PollableChannel replyChannel = + this.context.getBean( + "replyChannelDefaultOverwriteFalseButNoExistingHeaderOutput", PollableChannel.class); Message message = MessageBuilder.withPayload("test").build(); inputChannel.send(message); Message result = replyChannel.receive(0); @@ -141,7 +156,7 @@ public class HeaderEnricherOverwriteTests { @Test public void priorityExplicitOverwriteTrue() { - MessageChannel channel = context.getBean("priorityExplicitOverwriteTrueInput", MessageChannel.class); + MessageChannel channel = this.context.getBean("priorityExplicitOverwriteTrueInput", MessageChannel.class); MessagingTemplate template = new MessagingTemplate(); template.setDefaultDestination(channel); Message result = template.sendAndReceive(new GenericMessage("test")); @@ -151,7 +166,7 @@ public class HeaderEnricherOverwriteTests { @Test public void priorityExplicitOverwriteFalse() { - MessageChannel input = context.getBean("priorityExplicitOverwriteFalseInput", MessageChannel.class); + MessageChannel input = this.context.getBean("priorityExplicitOverwriteFalseInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -165,7 +180,7 @@ public class HeaderEnricherOverwriteTests { @Test public void customExplicitOverwriteTrue() { - MessageChannel inputChannel = context.getBean("customExplicitOverwriteTrueInput", MessageChannel.class); + MessageChannel inputChannel = this.context.getBean("customExplicitOverwriteTrueInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -180,7 +195,7 @@ public class HeaderEnricherOverwriteTests { @Test public void customExplicitOverwriteFalse() { - MessageChannel inputChannel = context.getBean("customExplicitOverwriteFalseInput", MessageChannel.class); + MessageChannel inputChannel = this.context.getBean("customExplicitOverwriteFalseInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -195,7 +210,8 @@ public class HeaderEnricherOverwriteTests { @Test public void customExplicitOverwriteFalseButNoExistingHeader() { - MessageChannel inputChannel = context.getBean("customExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("customExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -209,7 +225,8 @@ public class HeaderEnricherOverwriteTests { @Test public void expressionExplicitOverwriteTrue() { - MessageChannel inputChannel = context.getBean("expressionExplicitOverwriteTrueInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("expressionExplicitOverwriteTrueInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -224,7 +241,8 @@ public class HeaderEnricherOverwriteTests { @Test public void expressionExplicitOverwriteFalse() { - MessageChannel inputChannel = context.getBean("expressionExplicitOverwriteFalseInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("expressionExplicitOverwriteFalseInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -239,7 +257,8 @@ public class HeaderEnricherOverwriteTests { @Test public void expressionExplicitOverwriteFalseButNoExistingHeader() { - MessageChannel inputChannel = context.getBean("expressionExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("expressionExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -253,7 +272,7 @@ public class HeaderEnricherOverwriteTests { @Test public void beanExplicitOverwriteTrue() { - MessageChannel inputChannel = context.getBean("beanExplicitOverwriteTrueInput", MessageChannel.class); + MessageChannel inputChannel = this.context.getBean("beanExplicitOverwriteTrueInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -268,7 +287,7 @@ public class HeaderEnricherOverwriteTests { @Test public void beanExplicitOverwriteFalse() { - MessageChannel inputChannel = context.getBean("beanExplicitOverwriteFalseInput", MessageChannel.class); + MessageChannel inputChannel = this.context.getBean("beanExplicitOverwriteFalseInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -283,7 +302,8 @@ public class HeaderEnricherOverwriteTests { @Test public void beanExplicitOverwriteFalseButNoExistingHeader() { - MessageChannel inputChannel = context.getBean("beanExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); + MessageChannel inputChannel = + this.context.getBean("beanExplicitOverwriteFalseButNoExistingHeaderInput", MessageChannel.class); QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload("test") .setReplyChannel(replyChannel) @@ -307,6 +327,7 @@ public class HeaderEnricherOverwriteTests { public String text() { return this.text; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/InboundChannelAdapterExpressionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/InboundChannelAdapterExpressionTests.java index 2400000305..e551f831af 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/InboundChannelAdapterExpressionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/InboundChannelAdapterExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -24,6 +24,7 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -39,6 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -51,7 +53,8 @@ public class InboundChannelAdapterExpressionTests { @Test public void fixedDelay() { - SourcePollingChannelAdapter adapter = context.getBean("fixedDelayProducer", SourcePollingChannelAdapter.class); + SourcePollingChannelAdapter adapter = + this.context.getBean("fixedDelayProducer", SourcePollingChannelAdapter.class); assertFalse(adapter.isAutoStartup()); DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class); @@ -59,14 +62,15 @@ public class InboundChannelAdapterExpressionTests { DirectFieldAccessor triggerAccessor = new DirectFieldAccessor(trigger); assertEquals(1234L, triggerAccessor.getPropertyValue("period")); assertEquals(Boolean.FALSE, triggerAccessor.getPropertyValue("fixedRate")); - assertEquals(context.getBean("fixedDelayChannel"), adapterAccessor.getPropertyValue("outputChannel")); + assertEquals(this.context.getBean("fixedDelayChannel"), adapterAccessor.getPropertyValue("outputChannel")); Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class); assertEquals("'fixedDelayTest'", expression.getExpressionString()); } @Test public void fixedRate() { - SourcePollingChannelAdapter adapter = context.getBean("fixedRateProducer", SourcePollingChannelAdapter.class); + SourcePollingChannelAdapter adapter = + this.context.getBean("fixedRateProducer", SourcePollingChannelAdapter.class); assertFalse(adapter.isAutoStartup()); DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class); @@ -74,33 +78,35 @@ public class InboundChannelAdapterExpressionTests { DirectFieldAccessor triggerAccessor = new DirectFieldAccessor(trigger); assertEquals(5678L, triggerAccessor.getPropertyValue("period")); assertEquals(Boolean.TRUE, triggerAccessor.getPropertyValue("fixedRate")); - assertEquals(context.getBean("fixedRateChannel"), adapterAccessor.getPropertyValue("outputChannel")); + assertEquals(this.context.getBean("fixedRateChannel"), adapterAccessor.getPropertyValue("outputChannel")); Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class); assertEquals("'fixedRateTest'", expression.getExpressionString()); } @Test public void cron() { - SourcePollingChannelAdapter adapter = context.getBean("cronProducer", SourcePollingChannelAdapter.class); + SourcePollingChannelAdapter adapter = + this.context.getBean("cronProducer", SourcePollingChannelAdapter.class); assertFalse(adapter.isAutoStartup()); DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class); assertEquals(CronTrigger.class, trigger.getClass()); assertEquals("7 6 5 4 3 ?", new DirectFieldAccessor(new DirectFieldAccessor( trigger).getPropertyValue("sequenceGenerator")).getPropertyValue("expression")); - assertEquals(context.getBean("cronChannel"), adapterAccessor.getPropertyValue("outputChannel")); + assertEquals(this.context.getBean("cronChannel"), adapterAccessor.getPropertyValue("outputChannel")); Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class); assertEquals("'cronTest'", expression.getExpressionString()); } @Test public void triggerRef() { - SourcePollingChannelAdapter adapter = context.getBean("triggerRefProducer", SourcePollingChannelAdapter.class); + SourcePollingChannelAdapter adapter = + this.context.getBean("triggerRefProducer", SourcePollingChannelAdapter.class); assertTrue(adapter.isAutoStartup()); DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class); - assertEquals(context.getBean("customTrigger"), trigger); - assertEquals(context.getBean("triggerRefChannel"), adapterAccessor.getPropertyValue("outputChannel")); + assertEquals(this.context.getBean("customTrigger"), trigger); + assertEquals(this.context.getBean("triggerRefChannel"), adapterAccessor.getPropertyValue("outputChannel")); Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class); assertEquals("'triggerRefTest'", expression.getExpressionString()); } @@ -108,9 +114,11 @@ public class InboundChannelAdapterExpressionTests { @Test @SuppressWarnings("unchecked") public void headerExpressions() { - SourcePollingChannelAdapter adapter = context.getBean("headerExpressionsProducer", SourcePollingChannelAdapter.class); + SourcePollingChannelAdapter adapter = + this.context.getBean("headerExpressionsProducer", SourcePollingChannelAdapter.class); assertFalse(adapter.isAutoStartup()); - Map headerExpressions = TestUtils.getPropertyValue(adapter, "source.headerExpressions", Map.class); + Map headerExpressions = + TestUtils.getPropertyValue(adapter, "source.headerExpressions", Map.class); assertEquals(2, headerExpressions.size()); assertEquals("6 * 7", headerExpressions.get("foo").getExpressionString()); assertEquals("x", headerExpressions.get("bar").getExpressionString()); @@ -120,10 +128,10 @@ public class InboundChannelAdapterExpressionTests { @Test public void testInt2867InnerExpression() { - SourcePollingChannelAdapter adapter = context.getBean("expressionElement", SourcePollingChannelAdapter.class); + SourcePollingChannelAdapter adapter = + this.context.getBean("expressionElement", SourcePollingChannelAdapter.class); Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class); assertEquals("'Hello World!'", expression.getExpressionString()); - } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/MethodInvokingSelectorParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/MethodInvokingSelectorParserTests.java index e85819470e..eb3263208a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/MethodInvokingSelectorParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/MethodInvokingSelectorParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.integration.config.xml; import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.util.List; @@ -27,16 +26,17 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.Message; import org.springframework.integration.core.MessageSelector; import org.springframework.integration.filter.MethodInvokingSelector; import org.springframework.integration.selector.MessageSelectorChain; +import org.springframework.messaging.Message; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Iwein Fuld * @author Gunnar Hillert + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -48,16 +48,18 @@ public class MethodInvokingSelectorParserTests { @SuppressWarnings("unchecked") @Test - public void configOK() throws Exception { + public void configOK() { DirectFieldAccessor accessor = new DirectFieldAccessor(chain); List selectors = (List) accessor.getPropertyValue("selectors"); - assertThat(selectors.get(0), is(instanceOf(MethodInvokingSelector.class))); + assertThat(selectors.get(0), instanceOf(MethodInvokingSelector.class)); } public static class TestFilter { + public boolean accept(Message m) { return true; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/NestedChainParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/NestedChainParserTests.java index 6e437666da..d1dabf21b4 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/NestedChainParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/NestedChainParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2018 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. @@ -27,13 +27,14 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.messaging.MessageHandler; import org.springframework.integration.handler.MessageHandlerChain; +import org.springframework.messaging.MessageHandler; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -56,8 +57,10 @@ public class NestedChainParserTests { public void handlersAreNotSame() { ParentTestBean bean1 = context.getBean("concreteParent1", ParentTestBean.class); ParentTestBean bean2 = context.getBean("concreteParent2", ParentTestBean.class); - List handlerList1 = (List) new DirectFieldAccessor(bean1.chain).getPropertyValue("handlers"); - List handlerList2 = (List) new DirectFieldAccessor(bean2.chain).getPropertyValue("handlers"); + List handlerList1 = + (List) new DirectFieldAccessor(bean1.chain).getPropertyValue("handlers"); + List handlerList2 = + (List) new DirectFieldAccessor(bean2.chain).getPropertyValue("handlers"); MessageHandler handler1 = handlerList1.get(0); MessageHandler handler2 = handlerList2.get(0); assertNotSame(handler1, handler2); @@ -71,6 +74,7 @@ public class NestedChainParserTests { public void setChain(MessageHandlerChain chain) { this.chain = chain; } + } @@ -79,6 +83,7 @@ public class NestedChainParserTests { public String echo(String s) { return s; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PNamespaceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PNamespaceTests.java index 9bed35c4a6..bea917a44e 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PNamespaceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PNamespaceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,13 @@ package org.springframework.integration.config.xml; +import static org.junit.Assert.assertEquals; + import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.aggregator.AggregatingMessageHandler; @@ -28,12 +31,11 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; - /** * Validates the "p:namespace" is working for inner "bean" definition within SI components. * * @author Oleg Zhurakousky + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -62,28 +64,28 @@ public class PNamespaceTests { @Test public void testPNamespaceServiceActivator() { - TestBean bean = prepare(serviceActivator); + TestBean bean = prepare(serviceActivator); assertEquals("paris", bean.getFname()); assertEquals("hilton", bean.getLname()); } @Test public void testPNamespaceSplitter() { - TestBean bean = prepare(splitter); + TestBean bean = prepare(splitter); assertEquals("paris", bean.getFname()); assertEquals("hilton", bean.getLname()); } @Test public void testPNamespaceRouter() { - TestBean bean = prepare(router); + TestBean bean = prepare(router); assertEquals("paris", bean.getFname()); assertEquals("hilton", bean.getLname()); } @Test public void testPNamespaceTransformer() { - TestBean bean = prepare(transformer); + TestBean bean = prepare(transformer); assertEquals("paris", bean.getFname()); assertEquals("hilton", bean.getLname()); } @@ -93,7 +95,8 @@ public class PNamespaceTests { List handlers = (List) TestUtils.getPropertyValue(sampleChain, "handler.handlers"); AggregatingMessageHandler handler = (AggregatingMessageHandler) handlers.get(0); SampleAggregator aggregator = - (SampleAggregator) TestUtils.getPropertyValue(handler, "outputProcessor.processor.delegate.targetObject"); + (SampleAggregator) TestUtils + .getPropertyValue(handler, "outputProcessor.processor.delegate.targetObject"); assertEquals("Bill", aggregator.getName()); } @@ -105,7 +108,9 @@ public class PNamespaceTests { public interface InboundGateway { + String echo(); + } @@ -138,11 +143,16 @@ public class PNamespaceTests { public String toString() { return fname + lname; } + } public static class SampleAggregator { + private String name; - public SampleAggregator() { } + + public SampleAggregator() { + } + public String getName() { return name; } @@ -150,5 +160,7 @@ public class PNamespaceTests { public void setName(String name) { this.name = name; } + } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/SyslogTransformerParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/SyslogTransformerParserTests.java index e94293b17c..e50c3b0399 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/SyslogTransformerParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/SyslogTransformerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2018 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. @@ -25,11 +25,12 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.transformer.SyslogToMapTransformer; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.integration.transformer.SyslogToMapTransformer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -37,6 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Gary Russell * @author Artem Bilan * @author Karol Dowbecki + * * @since 2.2 * */ @@ -52,7 +54,7 @@ public class SyslogTransformerParserTests { @Test public void testMap() { - toMapChannel.send(new GenericMessage("<157>JUL 26 22:08:35 WEBERN TESTING[70729]: TEST SYSLOG MESSAGE")); + toMapChannel.send(new GenericMessage<>("<157>JUL 26 22:08:35 WEBERN TESTING[70729]: TEST SYSLOG MESSAGE")); Map map = (Map) out.receive(1000).getPayload(); assertNotNull(map); assertEquals(6, map.size()); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/propertyplaceholder/PropertyPlaceholderTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/propertyplaceholder/PropertyPlaceholderTests.java index 80c0b1322a..44f46859f0 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/propertyplaceholder/PropertyPlaceholderTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/propertyplaceholder/PropertyPlaceholderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -18,26 +18,30 @@ package org.springframework.integration.config.xml.propertyplaceholder; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * * @author Iwein Fuld - * + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class PropertyPlaceholderTests { @Test - public void context() throws Exception { + public void context() { //parsing and instantiating is enough } public static class SanityCheck { + public SanityCheck(Integer i) { //this will throw an exception if the placeholder isn't replaced } + } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryExceptionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryExceptionTests.java index 4657e84bd2..4a789529dd 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryExceptionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -25,20 +25,22 @@ import java.util.List; import org.junit.Ignore; import org.junit.Test; -import org.springframework.messaging.support.GenericMessage; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; +import org.springframework.messaging.support.GenericMessage; /** * @author Iwein Fuld * @author Gunnar Hillert + * @author Artem Bilan */ public class AggregateMessageDeliveryExceptionTests { - private Message message = new GenericMessage("foo"); + private Message message = new GenericMessage<>("foo"); - private AggregateMessageDeliveryException exception = new AggregateMessageDeliveryException(message, - "something went wrong", exceptionsList()); + private AggregateMessageDeliveryException exception = + new AggregateMessageDeliveryException(this.message, "something went wrong", exceptionsList()); private MessageDeliveryException firstProblem; @@ -67,7 +69,7 @@ public class AggregateMessageDeliveryExceptionTests { @Test public void shouldShowFirstOriginalExceptionInCause() { - assertThat((MessageDeliveryException) exception.getCause(), is(firstProblem)); + assertThat(this.exception.getCause(), is(this.firstProblem)); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/FailOverDispatcherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/FailOverDispatcherTests.java index eb154c93b1..a80a9db77d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/FailOverDispatcherTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dispatcher/FailOverDispatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -25,16 +25,18 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; + import org.springframework.integration.MessageRejectedException; import org.springframework.integration.handler.ServiceActivatingHandler; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.message.TestHandlers; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandler; +import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher + * @author Artem Bilan */ public class FailOverDispatcherTests { @@ -43,7 +45,7 @@ public class FailOverDispatcherTests { UnicastingDispatcher dispatcher = new UnicastingDispatcher(); final CountDownLatch latch = new CountDownLatch(1); dispatcher.addHandler(createConsumer(TestHandlers.countDownHandler(latch))); - dispatcher.dispatch(new GenericMessage("test")); + dispatcher.dispatch(new GenericMessage<>("test")); latch.await(500, TimeUnit.MILLISECONDS); assertEquals(0, latch.getCount()); } @@ -56,7 +58,7 @@ public class FailOverDispatcherTests { final AtomicInteger counter2 = new AtomicInteger(); dispatcher.addHandler(createConsumer(TestHandlers.countingCountDownHandler(counter1, latch))); dispatcher.addHandler(createConsumer(TestHandlers.countingCountDownHandler(counter2, latch))); - dispatcher.dispatch(new GenericMessage("test")); + dispatcher.dispatch(new GenericMessage<>("test")); latch.await(500, TimeUnit.MILLISECONDS); assertEquals(0, latch.getCount()); assertEquals("only 1 handler should have received the message", 1, counter1.get() + counter2.get()); @@ -70,7 +72,7 @@ public class FailOverDispatcherTests { dispatcher.addHandler(target); dispatcher.addHandler(target); try { - dispatcher.dispatch(new GenericMessage("test")); + dispatcher.dispatch(new GenericMessage<>("test")); } catch (Exception e) { // ignore @@ -90,7 +92,7 @@ public class FailOverDispatcherTests { dispatcher.addHandler(target3); dispatcher.removeHandler(target2); try { - dispatcher.dispatch(new GenericMessage("test")); + dispatcher.dispatch(new GenericMessage<>("test")); } catch (Exception e) { // ignore @@ -109,7 +111,7 @@ public class FailOverDispatcherTests { dispatcher.addHandler(target2); dispatcher.addHandler(target3); try { - dispatcher.dispatch(new GenericMessage("test1")); + dispatcher.dispatch(new GenericMessage<>("test1")); } catch (Exception e) { // ignore @@ -117,7 +119,7 @@ public class FailOverDispatcherTests { assertEquals(3, counter.get()); dispatcher.removeHandler(target2); try { - dispatcher.dispatch(new GenericMessage("test2")); + dispatcher.dispatch(new GenericMessage<>("test2")); } catch (Exception e) { // ignore @@ -125,7 +127,7 @@ public class FailOverDispatcherTests { assertEquals(5, counter.get()); dispatcher.removeHandler(target1); try { - dispatcher.dispatch(new GenericMessage("test3")); + dispatcher.dispatch(new GenericMessage<>("test3")); } catch (Exception e) { // ignore @@ -140,14 +142,14 @@ public class FailOverDispatcherTests { MessageHandler target = new CountingTestEndpoint(counter, false); dispatcher.addHandler(target); try { - dispatcher.dispatch(new GenericMessage("test1")); + dispatcher.dispatch(new GenericMessage<>("test1")); } catch (Exception e) { // ignore } assertEquals(1, counter.get()); dispatcher.removeHandler(target); - dispatcher.dispatch(new GenericMessage("test2")); + dispatcher.dispatch(new GenericMessage<>("test2")); } @Test @@ -160,7 +162,7 @@ public class FailOverDispatcherTests { dispatcher.addHandler(target1); dispatcher.addHandler(target2); dispatcher.addHandler(target3); - assertTrue(dispatcher.dispatch(new GenericMessage("test"))); + assertTrue(dispatcher.dispatch(new GenericMessage<>("test"))); assertEquals("only the first target should have been invoked", 1, counter.get()); } @@ -174,7 +176,7 @@ public class FailOverDispatcherTests { dispatcher.addHandler(target1); dispatcher.addHandler(target2); dispatcher.addHandler(target3); - assertTrue(dispatcher.dispatch(new GenericMessage("test"))); + assertTrue(dispatcher.dispatch(new GenericMessage<>("test"))); assertEquals("first two targets should have been invoked", 2, counter.get()); } @@ -189,7 +191,7 @@ public class FailOverDispatcherTests { dispatcher.addHandler(target2); dispatcher.addHandler(target3); try { - assertFalse(dispatcher.dispatch(new GenericMessage("test"))); + assertFalse(dispatcher.dispatch(new GenericMessage<>("test"))); } catch (Exception e) { // ignore @@ -220,6 +222,7 @@ public class FailOverDispatcherTests { throw new MessageRejectedException(message, "intentional test failure"); } } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ProducerAndConsumerAutoStartupTests.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ProducerAndConsumerAutoStartupTests.java index 9fd71e3ce5..e486f160c9 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ProducerAndConsumerAutoStartupTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ProducerAndConsumerAutoStartupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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.endpoint; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; @@ -31,16 +25,23 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; /** * @author Mark Fisher * @author Iwein Fuld * @author Artem Bilan - * @since 2.0.0 + * + * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) +@DirtiesContext public class ProducerAndConsumerAutoStartupTests { @Autowired @@ -52,7 +53,7 @@ public class ProducerAndConsumerAutoStartupTests { @Test public void test() throws Exception { - List received = new ArrayList(); + List received = new ArrayList<>(); for (int i = 0; i < 3; i++) { received.add(this.consumer.poll(10000)); } @@ -67,7 +68,7 @@ public class ProducerAndConsumerAutoStartupTests { private final AtomicInteger count = new AtomicInteger(); - public Integer next() throws InterruptedException { + public Integer next() { if (this.count.get() > 2) { //prevent message overload return null; @@ -80,7 +81,7 @@ public class ProducerAndConsumerAutoStartupTests { static class Consumer { - private final BlockingQueue numbers = new LinkedBlockingQueue(); + private final BlockingQueue numbers = new LinkedBlockingQueue<>(); public void receive(Integer number) { this.numbers.add(number); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/annotation/MessageParameterAnnotatedEndpoint.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/annotation/MessageParameterAnnotatedEndpoint.java index e7e5068c9b..4ef456479f 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/annotation/MessageParameterAnnotatedEndpoint.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/annotation/MessageParameterAnnotatedEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,20 +16,21 @@ package org.springframework.integration.endpoint.annotation; -import org.springframework.messaging.Message; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher + * @author Artem Bilan */ @MessageEndpoint public class MessageParameterAnnotatedEndpoint { @ServiceActivator(inputChannel = "inputChannel", outputChannel = "outputChannel") public Message sayHello(Message message) { - return new GenericMessage("hello " + message.getPayload()); + return new GenericMessage<>("hello " + message.getPayload()); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayWithPayloadExpressionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayWithPayloadExpressionTests.java index 70ddaff475..1b114da8d7 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayWithPayloadExpressionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayWithPayloadExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -23,14 +23,16 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; -import org.springframework.messaging.handler.annotation.Payload; import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.handler.annotation.Payload; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.0 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -48,28 +50,28 @@ public class GatewayWithPayloadExpressionTests { @Test - public void simpleExpression() throws Exception { + public void simpleExpression() { gateway.send1("foo"); Message result = input.receive(0); assertEquals("foobar", result.getPayload()); } @Test - public void beanResolvingExpression() throws Exception { + public void beanResolvingExpression() { gateway.send2("foo"); Message result = input.receive(0); assertEquals(324, result.getPayload()); } @Test - public void payloadAnnotationExpression() throws Exception { + public void payloadAnnotationExpression() { annotatedGateway.send("foo", "bar"); Message result = input.receive(0); assertEquals("foobar", result.getPayload()); } @Test - public void noArgMethodWithPayloadExpression() throws Exception { + public void noArgMethodWithPayloadExpression() { gateway.send3(); Message result = input.receive(0); assertEquals("send3", result.getPayload()); @@ -83,6 +85,7 @@ public class GatewayWithPayloadExpressionTests { void send2(String value); void send3(); + } @@ -103,6 +106,7 @@ public class GatewayWithPayloadExpressionTests { } return sum; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultiMethodGatewayConfigTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultiMethodGatewayConfigTests.java index f25eb9b8d2..ad3cbd7c20 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultiMethodGatewayConfigTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultiMethodGatewayConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.integration.gateway; import org.junit.Assert; - import org.junit.Test; import org.junit.runner.RunWith; @@ -29,7 +28,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky * @author Gunnar Hillert - * @since 2.0.M1 + * @author Artem Bilan + * + * @since 2.0 */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -41,7 +42,7 @@ public class MultiMethodGatewayConfigTests { @Test public void validateGatewayMethods() { - TestGateway gateway = (TestGateway) applicationContext.getBean("myGateway"); + TestGateway gateway = this.applicationContext.getBean("myGateway", TestGateway.class); String parentClassName = "org.springframework.integration.gateway.MultiMethodGatewayConfigTests"; Assert.assertEquals(gateway.echo("oleg"), parentClassName + "$TestBeanA:oleg"); @@ -53,27 +54,37 @@ public class MultiMethodGatewayConfigTests { public static class TestBeanA { + public String echo(String str) { return this.getClass().getName() + ":" + str; } + } public static class TestBeanB { + public String echo(String str) { return this.getClass().getName() + ":" + str; } + } public static class TestBeanC { + public String echo(String str) { return this.getClass().getName() + ":" + str; } + } public interface TestGateway { + String echo(String str); + String echoViaDefault(String str); + String echoUpperCase(String str); + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultipleEndpointGatewayTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultipleEndpointGatewayTests.java index 7f08f0fb25..cb1d826ecf 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultipleEndpointGatewayTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MultipleEndpointGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -18,16 +18,17 @@ package org.springframework.integration.gateway; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.Message; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky - * + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -46,6 +47,7 @@ public class MultipleEndpointGatewayTests { gatewayA.echo("echoAsMessageChannel"); // there is nothing to assert. Successful execution of the above is all we care in this test } + @Test public void gatewayWithDefaultReplyChannel() { gatewayB.echo("echoAsMessageChannelIgnoreDefOutChannel"); @@ -59,15 +61,21 @@ public class MultipleEndpointGatewayTests { } public interface SampleGateway { + Object echo(Object value); + } public static class SampleEchoService { + public Object echo(Object value) { return "R:" + value; } + public Message echoAsMessage(Object value) { return MessageBuilder.withPayload("R:" + value).build(); } + } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/CollectionAndArrayTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/CollectionAndArrayTests.java index 3ba0015f71..10eeec0274 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/CollectionAndArrayTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/CollectionAndArrayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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,13 @@ package org.springframework.integration.handler; +import static org.hamcrest.CoreMatchers.instanceOf; +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.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.instanceOf; import java.util.Arrays; import java.util.HashSet; @@ -31,15 +31,17 @@ import java.util.Set; import org.junit.Test; -import org.springframework.messaging.Message; import org.springframework.integration.channel.QueueChannel; -import org.springframework.messaging.MessageHandler; import org.springframework.integration.splitter.AbstractMessageSplitter; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHandler; /** * @author Mark Fisher * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.0 */ public class CollectionAndArrayTests { @@ -47,9 +49,10 @@ public class CollectionAndArrayTests { @Test public void listWithRequestReplyHandler() { MessageHandler handler = new AbstractReplyProducingMessageHandler() { + @Override protected Object handleRequestMessage(Message requestMessage) { - return Arrays.asList(new String[] { "foo", "bar" }); + return Arrays.asList("foo", "bar"); } }; QueueChannel channel = new QueueChannel(); @@ -66,9 +69,10 @@ public class CollectionAndArrayTests { @Test public void setWithRequestReplyHandler() { MessageHandler handler = new AbstractReplyProducingMessageHandler() { + @Override protected Object handleRequestMessage(Message requestMessage) { - return new HashSet(Arrays.asList(new String[] { "foo", "bar" })); + return new HashSet<>(Arrays.asList("foo", "bar")); } }; QueueChannel channel = new QueueChannel(); @@ -85,6 +89,7 @@ public class CollectionAndArrayTests { @Test public void arrayWithRequestReplyHandler() { MessageHandler handler = new AbstractReplyProducingMessageHandler() { + @Override protected Object handleRequestMessage(Message requestMessage) { return new String[] { "foo", "bar" }; @@ -104,9 +109,10 @@ public class CollectionAndArrayTests { @Test public void listWithSplittingHandler() { AbstractMessageSplitter handler = new AbstractMessageSplitter() { + @Override protected Object splitMessage(Message message) { - return Arrays.asList(new String[] { "foo", "bar" }); + return Arrays.asList("foo", "bar"); } }; QueueChannel channel = new QueueChannel(); @@ -125,9 +131,10 @@ public class CollectionAndArrayTests { @Test public void setWithSplittingHandler() { AbstractMessageSplitter handler = new AbstractMessageSplitter() { + @Override protected Object splitMessage(Message message) { - return new HashSet(Arrays.asList(new String[] { "foo", "bar" })); + return new HashSet(Arrays.asList("foo", "bar")); } }; QueueChannel channel = new QueueChannel(); @@ -144,6 +151,7 @@ public class CollectionAndArrayTests { @Test public void arrayWithSplittingHandler() { AbstractMessageSplitter handler = new AbstractMessageSplitter() { + @Override protected Object splitMessage(Message message) { return new String[] { "foo", "bar" }; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/CustomConverterMessageProcessingTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/CustomConverterMessageProcessingTests.java index 538b33804c..c39adb5315 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/CustomConverterMessageProcessingTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/CustomConverterMessageProcessingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -25,16 +25,17 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.convert.converter.Converter; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan * @since 2.0 */ @ContextConfiguration @@ -149,7 +150,7 @@ public class CustomConverterMessageProcessingTests { } - public static class TestBean1 { + public static class TestBean1 { private String text; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/MockHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/MockHandlerTests.java index c975268200..06f7299d78 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/MockHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/MockHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -20,21 +20,21 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; - import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Iwein Fuld * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -49,7 +49,7 @@ public class MockHandlerTests { @Test - public void configOk() throws Exception { + public void configOk() { QueueChannel output = new QueueChannel(); Mockito.when(mock.test("foo")).thenReturn("bar"); input.send(MessageBuilder.withPayload("foo").setReplyChannel(output).build()); @@ -59,7 +59,9 @@ public class MockHandlerTests { public interface TestInterface { + String test(String input); + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests-context.xml index e2c0be33c5..ce5b6f1a97 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests-context.xml @@ -6,4 +6,5 @@ + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests.java index febfa6e91d..798f9a4913 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/SpelExpressionRetryStateGeneratorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -22,17 +22,19 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.classify.ClassifierSupport; -import org.springframework.messaging.Message; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; import org.springframework.retry.RetryState; -import org.springframework.retry.support.DefaultRetryState; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell + * @author Artem Bilan + * * @since 2.2 * */ @@ -43,19 +45,20 @@ public class SpelExpressionRetryStateGeneratorTests { @Autowired private RetryStateGenerator configGenerator; - private Message message = MessageBuilder.withPayload("Hello, world!") - .setHeader("foo", "bar") - .setHeader("trueHeader", true) - .setHeader("falseHeader", false) - .build(); + private Message message = + MessageBuilder.withPayload("Hello, world!") + .setHeader("foo", "bar") + .setHeader("trueHeader", true) + .setHeader("falseHeader", false) + .build(); @Test public void testBasic() { SpelExpressionRetryStateGenerator generator = - new SpelExpressionRetryStateGenerator("headers['foo']"); + new SpelExpressionRetryStateGenerator("headers['foo']"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); - assertFalse(((DefaultRetryState) state).isForceRefresh()); + assertFalse(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); } @@ -63,37 +66,37 @@ public class SpelExpressionRetryStateGeneratorTests { public void testBasicConfig() { RetryState state = configGenerator.determineRetryState(message); assertEquals("bar", state.getKey()); - assertFalse(((DefaultRetryState) state).isForceRefresh()); + assertFalse(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); } @Test public void testForceRefreshTrue() { SpelExpressionRetryStateGenerator generator = - new SpelExpressionRetryStateGenerator("headers['foo']", "headers['trueHeader']"); + new SpelExpressionRetryStateGenerator("headers['foo']", "headers['trueHeader']"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); - assertTrue(((DefaultRetryState) state).isForceRefresh()); + assertTrue(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); } @Test public void testForceRefreshFalse() { SpelExpressionRetryStateGenerator generator = - new SpelExpressionRetryStateGenerator("headers['foo']", "headers['falseHeader']"); + new SpelExpressionRetryStateGenerator("headers['foo']", "headers['falseHeader']"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); - assertFalse(((DefaultRetryState) state).isForceRefresh()); + assertFalse(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); } @Test public void testForceRefreshElvis() { SpelExpressionRetryStateGenerator generator = - new SpelExpressionRetryStateGenerator("headers['foo']", "headers['noHeader']?:true"); + new SpelExpressionRetryStateGenerator("headers['foo']", "headers['noHeader']?:true"); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); - assertTrue(((DefaultRetryState) state).isForceRefresh()); + assertTrue(state.isForceRefresh()); assertTrue(state.rollbackFor(new RuntimeException())); } @@ -101,10 +104,11 @@ public class SpelExpressionRetryStateGeneratorTests { public void testClassifier() { SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']"); - generator.setClassifier(new ClassifierSupport(false)); + generator.setClassifier(new ClassifierSupport<>(false)); RetryState state = generator.determineRetryState(message); assertEquals("bar", state.getKey()); - assertFalse(((DefaultRetryState) state).isForceRefresh()); + assertFalse(state.isForceRefresh()); assertFalse(state.rollbackFor(new RuntimeException())); } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerParserTests.java index aa162b013e..c9985793f8 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/json/JsonToObjectTransformerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -25,21 +25,22 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; -import org.springframework.messaging.MessageHandler; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.support.json.Jackson2JsonObjectMapper; import org.springframework.integration.support.json.JsonObjectMapper; import org.springframework.integration.support.json.JsonObjectMapperAdapter; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.MessageHandler; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -65,10 +66,14 @@ public class JsonToObjectTransformerParserTests { @Test public void defaultObjectMapper() { - Object jsonToObjectTransformer = TestUtils.getPropertyValue(this.defaultJacksonMapperTransformer, "transformer"); - assertEquals(Jackson2JsonObjectMapper.class, TestUtils.getPropertyValue(jsonToObjectTransformer, "jsonObjectMapper").getClass()); + Object jsonToObjectTransformer = + TestUtils.getPropertyValue(this.defaultJacksonMapperTransformer, "transformer"); + assertEquals(Jackson2JsonObjectMapper.class, + TestUtils.getPropertyValue(jsonToObjectTransformer, "jsonObjectMapper").getClass()); - String jsonString = "{\"firstName\":\"John\",\"lastName\":\"Doe\",\"age\":42,\"address\":{\"number\":123,\"street\":\"Main Street\"}}"; + String jsonString = + "{\"firstName\":\"John\",\"lastName\":\"Doe\",\"age\":42," + + "\"address\":{\"number\":123,\"street\":\"Main Street\"}}"; QueueChannel replyChannel = new QueueChannel(); Message message = MessageBuilder.withPayload(jsonString).setReplyChannel(replyChannel).build(); this.defaultObjectMapperInput.send(message); @@ -86,7 +91,8 @@ public class JsonToObjectTransformerParserTests { @Test public void testInt2831CustomJsonObjectMapper() { Object jsonToObjectTransformer = TestUtils.getPropertyValue(this.customJsonMapperTransformer, "transformer"); - assertSame(this.jsonObjectMapper, TestUtils.getPropertyValue(jsonToObjectTransformer, "jsonObjectMapper", JsonObjectMapper.class)); + assertSame(this.jsonObjectMapper, + TestUtils.getPropertyValue(jsonToObjectTransformer, "jsonObjectMapper", JsonObjectMapper.class)); String jsonString = "{firstName:'John', lastName:'Doe', age:42, address:{number:123, street:'Main Street'}}"; QueueChannel replyChannel = new QueueChannel(); @@ -104,9 +110,10 @@ public class JsonToObjectTransformerParserTests { static class CustomJsonObjectMapper extends JsonObjectMapperAdapter { @Override - public Object fromJson(Object json, Class valueType) throws Exception { + public Object fromJson(Object json, Class valueType) { return new TestJsonContainer((String) json); } + } static class TestJsonContainer { @@ -120,6 +127,7 @@ public class JsonToObjectTransformerParserTests { public String getJson() { return json; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/MessageMatcher.java b/spring-integration-core/src/test/java/org/springframework/integration/message/MessageMatcher.java index 026a0e519d..6e58c91803 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/message/MessageMatcher.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/message/MessageMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2018 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. @@ -21,6 +21,7 @@ import java.util.Map; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -42,11 +43,13 @@ import org.springframework.messaging.MessageHeaders; * * * @author Dave Syer + * @author Artem Bilan * */ public class MessageMatcher extends BaseMatcher> { private final Object payload; + private final Map headers; public MessageMatcher(Message operand) { @@ -55,7 +58,7 @@ public class MessageMatcher extends BaseMatcher> { } private Map getHeaders(Message operand) { - HashMap headers = new HashMap(operand.getHeaders()); + HashMap headers = new HashMap<>(operand.getHeaders()); headers.remove(MessageHeaders.ID); headers.remove(MessageHeaders.TIMESTAMP); return headers; @@ -64,11 +67,13 @@ public class MessageMatcher extends BaseMatcher> { public boolean matches(Object arg) { Message input = (Message) arg; Map inputHeaders = getHeaders(input); - return input.getPayload().equals(payload) && inputHeaders.equals(headers); + return input.getPayload().equals(this.payload) && inputHeaders.equals(this.headers); } public void describeTo(Description description) { - description.appendText("Headers match except ID and timestamp for payload: ").appendValue(payload).appendText(" and headers: ").appendValue(headers); + description.appendText("Headers match except ID and timestamp for payload: ") + .appendValue(this.payload).appendText(" and headers: ") + .appendValue(this.headers); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java index d6b5463cf5..e28830ec7d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/message/selector/PayloadTypeSelectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -21,33 +21,34 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; +import org.springframework.integration.selector.PayloadTypeSelector; import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.ErrorMessage; import org.springframework.messaging.support.GenericMessage; -import org.springframework.integration.selector.PayloadTypeSelector; /** * @author Mark Fisher + * @author Artem Bilan */ public class PayloadTypeSelectorTests { @Test public void testAcceptedTypeIsSelected() { PayloadTypeSelector selector = new PayloadTypeSelector(String.class); - assertTrue(selector.accept(new GenericMessage("test"))); + assertTrue(selector.accept(new GenericMessage<>("test"))); } @Test public void testNonAcceptedTypeIsNotSelected() { PayloadTypeSelector selector = new PayloadTypeSelector(Integer.class); - assertFalse(selector.accept(new GenericMessage("test"))); + assertFalse(selector.accept(new GenericMessage<>("test"))); } @Test public void testMultipleAcceptedTypes() { PayloadTypeSelector selector = new PayloadTypeSelector(String.class, Integer.class); - assertTrue(selector.accept(new GenericMessage("test1"))); - assertTrue(selector.accept(new GenericMessage(2))); + assertTrue(selector.accept(new GenericMessage<>("test1"))); + assertTrue(selector.accept(new GenericMessage<>(2))); assertFalse(selector.accept(new ErrorMessage(new RuntimeException()))); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java index 4a44e9d151..ec48ffd5d1 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/message/selector/UnexpiredMessageSelectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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. @@ -21,12 +21,13 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.springframework.messaging.Message; import org.springframework.integration.selector.UnexpiredMessageSelector; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; /** * @author Mark Fisher + * @author Artem Bilan */ public class UnexpiredMessageSelectorTests { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java index 79f80295df..3bcbc6216a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -20,38 +20,41 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessagingException; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.channel.TestChannelResolver; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.GenericMessage; -import org.springframework.util.CollectionUtils; /** * @author Mark Fisher + * @author Artem Bilan */ public class MultiChannelRouterTests { @Test public void routeWithChannelMapping() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - public List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] {"channel1", "channel2"}); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + public List getChannelKeys(Message message) { + return Arrays.asList("channel1", "channel2"); + } + }; QueueChannel channel1 = new QueueChannel(); QueueChannel channel2 = new QueueChannel(); TestChannelResolver channelResolver = new TestChannelResolver(); channelResolver.addChannel("channel1", channel1); channelResolver.addChannel("channel2", channel2); router.setChannelResolver(channelResolver); - Message message = new GenericMessage("test"); + Message message = new GenericMessage<>("test"); router.handleMessage(message); Message result1 = channel1.receive(25); assertNotNull(result1); @@ -64,27 +67,28 @@ public class MultiChannelRouterTests { @Test(expected = MessagingException.class) public void channelNameLookupFailure() { AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") + public List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] {"noSuchChannel"}); + return Collections.singletonList("noSuchChannel"); } }; TestChannelResolver channelResolver = new TestChannelResolver(); router.setChannelResolver(channelResolver); - Message message = new GenericMessage("test"); + Message message = new GenericMessage<>("test"); router.handleMessage(message); } @Test(expected = MessagingException.class) public void channelMappingNotAvailable() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - public List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] {"noSuchChannel"}); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + public List getChannelKeys(Message message) { + return Collections.singletonList("noSuchChannel"); + } + }; router.setBeanFactory(mock(BeanFactory.class)); - Message message = new GenericMessage("test"); + Message message = new GenericMessage<>("test"); router.handleMessage(message); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java index 91e1276459..b8dfcc399f 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,10 @@ package org.springframework.integration.router; -import static org.junit.Assert.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import java.io.Serializable; import java.util.Map; @@ -28,15 +28,16 @@ import java.util.concurrent.ConcurrentHashMap; import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandlingException; -import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher * @author Oleg Zhurakousky * @author Gunnar Hillert + * @author Artem Bilan */ public class PayloadTypeRouterTests { @@ -48,15 +49,15 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("stringChannel", stringChannel); beanFactory.registerSingleton("integerChannel", integerChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(String.class.getName(), "stringChannel"); payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); router.setChannelMappings(payloadTypeChannelMap); router.setBeanFactory(beanFactory); - Message message1 = new GenericMessage("test"); - Message message2 = new GenericMessage(123); + Message message1 = new GenericMessage<>("test"); + Message message2 = new GenericMessage<>(123); assertEquals(1, router.getChannelKeys(message1).size()); assertNull(stringChannel.receive(0)); @@ -106,13 +107,13 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("defaultChannel", defaultChannel); beanFactory.registerSingleton("numberChannel", numberChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(Number.class.getName(), "numberChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); router.setChannelMappings(payloadTypeChannelMap); router.setBeanFactory(beanFactory); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(99); + Message message = new GenericMessage<>(99); router.handleMessage(message); Message result = numberChannel.receive(0); assertNotNull(result); @@ -143,7 +144,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("numberChannel", numberChannel); beanFactory.registerSingleton("integerChannel", integerChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(Number.class.getName(), "numberChannel"); payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel"); @@ -152,7 +153,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(99); + Message message = new GenericMessage<>(99); router.handleMessage(message); Message result = integerChannel.receive(0); assertNotNull(result); @@ -172,7 +173,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("defaultChannel", defaultChannel); beanFactory.registerSingleton("comparableChannel", comparableChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -180,7 +181,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(99); + Message message = new GenericMessage<>(99); router.handleMessage(message); Message result = comparableChannel.receive(0); assertNotNull(result); @@ -199,7 +200,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("defaultChannel", defaultChannel); beanFactory.registerSingleton("i2Channel", i2Channel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(I2.class.getName(), "i2Channel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -207,7 +208,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(new C1()); + Message message = new GenericMessage<>(new C1()); router.handleMessage(message); Message result = i2Channel.receive(0); assertNotNull(result); @@ -229,7 +230,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("serializableChannel", serializableChannel); beanFactory.registerSingleton("i3Channel", i3Channel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel"); payloadTypeChannelMap.put(I3.class.getName(), "i3Channel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -238,7 +239,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(new C1()); + Message message = new GenericMessage<>(new C1()); router.handleMessage(message); assertNotNull(serializableChannel.receive(0)); assertNull(i3Channel.receive(0)); @@ -260,7 +261,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("c3Channel", c3Channel); beanFactory.registerSingleton("i4Channel", i4Channel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(C3.class.getName(), "c3Channel"); payloadTypeChannelMap.put(I4.class.getName(), "i4Channel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -269,7 +270,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(new C1()); + Message message = new GenericMessage<>(new C1()); router.handleMessage(message); Message result = c3Channel.receive(0); assertNotNull(result); @@ -291,7 +292,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("c3Channel", c3Channel); beanFactory.registerSingleton("i1AChannel", i1AChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(C3.class.getName(), "c3Channel"); payloadTypeChannelMap.put(I1A.class.getName(), "i1AChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -300,7 +301,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(new C1()); + Message message = new GenericMessage<>(new C1()); router.handleMessage(message); Message result = i1AChannel.receive(0); assertNotNull(result); @@ -320,7 +321,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("numberChannel", numberChannel); beanFactory.registerSingleton("comparableChannel", comparableChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(Number.class.getName(), "numberChannel"); payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -329,7 +330,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(99); + Message message = new GenericMessage<>(99); router.handleMessage(message); Message result = comparableChannel.receive(0); assertNotNull(result); @@ -348,7 +349,7 @@ public class PayloadTypeRouterTests { } @Test(expected = MessageHandlingException.class) - public void ambiguityFailure() throws Exception { + public void ambiguityFailure() { QueueChannel defaultChannel = new QueueChannel(); defaultChannel.setBeanName("defaultChannel"); QueueChannel serializableChannel = new QueueChannel(); @@ -361,7 +362,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("serializableChannel", serializableChannel); beanFactory.registerSingleton("comparableChannel", comparableChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel"); payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -370,7 +371,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage("test"); + Message message = new GenericMessage<>("test"); router.handleMessage(message); } @@ -388,7 +389,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("numberChannel", numberChannel); beanFactory.registerSingleton("serializableChannel", serializableChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(Number.class.getName(), "numberChannel"); payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -397,7 +398,7 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(99); + Message message = new GenericMessage<>(99); router.handleMessage(message); Message result = numberChannel.receive(0); assertNotNull(result); @@ -417,7 +418,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("stringChannel", stringChannel); beanFactory.registerSingleton("integerChannel", integerChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(String.class.getName(), "stringChannel"); payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -425,8 +426,8 @@ public class PayloadTypeRouterTests { router.setBeanFactory(beanFactory); router.setChannelMappings(payloadTypeChannelMap); - Message message1 = new GenericMessage("test"); - Message message2 = new GenericMessage(123); + Message message1 = new GenericMessage<>("test"); + Message message2 = new GenericMessage<>(123); router.handleMessage(message1); router.handleMessage(message2); Message reply1 = stringChannel.receive(0); @@ -446,7 +447,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("stringChannel", stringChannel); beanFactory.registerSingleton("defaultChannel", defaultChannel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(String.class.getName(), "stringChannel"); PayloadTypeRouter router = new PayloadTypeRouter(); @@ -454,8 +455,8 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message1 = new GenericMessage("test"); - Message message2 = new GenericMessage(123); + Message message1 = new GenericMessage<>("test"); + Message message2 = new GenericMessage<>(123); router.handleMessage(message1); router.handleMessage(message2); Message result1 = stringChannel.receive(25); @@ -467,7 +468,7 @@ public class PayloadTypeRouterTests { } @Test - public void classWinsOverMoreDistantAmbiguousInterfaces() throws Exception { + public void classWinsOverMoreDistantAmbiguousInterfaces() { QueueChannel defaultChannel = new QueueChannel(); defaultChannel.setBeanName("defaultChannel"); @@ -485,7 +486,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("i5bChannel", i5bChannel); beanFactory.registerSingleton("c2Channel", c2Channel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(I5A.class.getName(), "i5aChannel"); payloadTypeChannelMap.put(I5B.class.getName(), "i5bChannel"); payloadTypeChannelMap.put(C2.class.getName(), "c2Channel"); @@ -495,13 +496,13 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(new C1()); + Message message = new GenericMessage<>(new C1()); router.handleMessage(message); assertNotNull(c2Channel.receive(100)); } @Test(expected = MessageHandlingException.class) - public void classLosesOverLessDistantAmbiguousInterfaces() throws Exception { + public void classLosesOverLessDistantAmbiguousInterfaces() { QueueChannel defaultChannel = new QueueChannel(); defaultChannel.setBeanName("defaultChannel"); @@ -519,7 +520,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("serializableChannel", serializableChannel); beanFactory.registerSingleton("c3Channel", c3Channel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(I2.class.getName(), "i2Channel"); payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel"); payloadTypeChannelMap.put(C3.class.getName(), "c3Channel"); @@ -529,12 +530,12 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(new C1()); + Message message = new GenericMessage<>(new C1()); router.handleMessage(message); } @Test(expected = MessageHandlingException.class) - public void classLosesOverAmbiguousInterfacesAtSameLevel() throws Exception { + public void classLosesOverAmbiguousInterfacesAtSameLevel() { QueueChannel defaultChannel = new QueueChannel(); defaultChannel.setBeanName("defaultChannel"); @@ -552,7 +553,7 @@ public class PayloadTypeRouterTests { beanFactory.registerSingleton("i1bChannel", i1bChannel); beanFactory.registerSingleton("c2Channel", c2Channel); - Map payloadTypeChannelMap = new ConcurrentHashMap(); + Map payloadTypeChannelMap = new ConcurrentHashMap<>(); payloadTypeChannelMap.put(I1A.class.getName(), "i1aChannel"); payloadTypeChannelMap.put(I1B.class.getName(), "i2bChannel"); payloadTypeChannelMap.put(C2.class.getName(), "c2Channel"); @@ -562,29 +563,49 @@ public class PayloadTypeRouterTests { router.setChannelMappings(payloadTypeChannelMap); router.setDefaultOutputChannel(defaultChannel); - Message message = new GenericMessage(new C1()); + Message message = new GenericMessage<>(new C1()); router.handleMessage(message); } @SuppressWarnings("serial") - public static class C1 extends C2 implements I1A, I1B { } + public static class C1 extends C2 implements I1A, I1B { - public interface I1A extends Serializable { } + } - public interface I1B extends I2 { } + public interface I1A extends Serializable { - public interface I2 extends I3 { } + } - public interface I3 extends I4 { } + public interface I1B extends I2 { - public interface I4 extends I5A, I5B { } + } - public interface I5A { } + public interface I2 extends I3 { - public interface I5B { } + } - public static class C2 extends C3 { } + public interface I3 extends I4 { - public static class C3 implements I4 { } + } + + public interface I4 extends I5A, I5B { + + } + + public interface I5A { + + } + + public interface I5B { + + } + + public static class C2 extends C3 { + + } + + public static class C3 implements I4 { + + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/RouterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/RouterTests.java index 229fa53ece..87aadc063f 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/RouterTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/RouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -29,12 +30,11 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.GenericApplicationContext; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.channel.TestChannelResolver; -import org.springframework.messaging.support.GenericMessage; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessagingException; -import org.springframework.util.CollectionUtils; +import org.springframework.messaging.support.GenericMessage; /** * @author Mark Fisher @@ -46,96 +46,109 @@ public class RouterTests { @Test(expected = MessageDeliveryException.class) public void nullChannelRaisesMessageDeliveryExceptionByDefault() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @Override - protected List getChannelKeys(Message message) { - return null; - } - }; - Message message = new GenericMessage("test"); + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + @Override + protected List getChannelKeys(Message message) { + return null; + } + }; + Message message = new GenericMessage<>("test"); router.handleMessage(message); } @Test(expected = MessageDeliveryException.class) public void nullChannelIdentifierUsingChannelResolverRaisesMessageDeliveryExceptionByDefault() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @Override - protected List getChannelKeys(Message message) { - return null; - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + @Override + protected List getChannelKeys(Message message) { + return null; + } + }; TestChannelResolver channelResolver = new TestChannelResolver(); router.setChannelResolver(channelResolver); - Message message = new GenericMessage("test"); + Message message = new GenericMessage<>("test"); router.handleMessage(message); } @Test(expected = MessageDeliveryException.class) public void nullChannelIdentifierInListRaisesMessageDeliveryExceptionByDefault() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @Override - protected List getChannelKeys(Message message) { - return Collections.singletonList(null); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + @Override + protected List getChannelKeys(Message message) { + return Collections.singletonList(null); + } + }; TestChannelResolver channelResolver = new TestChannelResolver(); router.setChannelResolver(channelResolver); - Message message = new GenericMessage("test"); + Message message = new GenericMessage<>("test"); router.handleMessage(message); } @Test(expected = MessageDeliveryException.class) public void emptyChannelNameArrayRaisesMessageDeliveryExceptionByDefault() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - protected List getChannelKeys(Message message) { - return new ArrayList(); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return new ArrayList<>(); + } + }; TestChannelResolver channelResolver = new TestChannelResolver(); router.setChannelResolver(channelResolver); - Message message = new GenericMessage("test"); + Message message = new GenericMessage<>("test"); router.handleMessage(message); } @Test(expected = MessagingException.class) public void channelMappingIsRequiredWhenResolvingChannelNames() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "notImportant" }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList("notImportant"); + } + }; router.setBeanFactory(mock(BeanFactory.class)); - router.handleMessage(new GenericMessage("this should fail")); + router.handleMessage(new GenericMessage<>("this should fail")); } @Test public void beanFactoryWithRouter() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "testChannel" }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList("testChannel"); + } + }; QueueChannel testChannel = new QueueChannel(); GenericApplicationContext context = new GenericApplicationContext(); context.getBeanFactory().registerSingleton("testChannel", testChannel); router.setBeanFactory(context); context.refresh(); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply = testChannel.receive(0); assertEquals("test", reply.getPayload()); + + context.close(); } @Test public void beanFactoryWithRouterAndMultipleCommaSeparatedChannelNames() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "testChannel1, , testChannel2 " }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList("testChannel1, , testChannel2 "); + } + }; QueueChannel testChannel1 = new QueueChannel(); QueueChannel testChannel2 = new QueueChannel(); @@ -148,24 +161,26 @@ public class RouterTests { router.setBeanFactory(context); context.refresh(); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply1 = testChannel1.receive(0); assertEquals("test", reply1.getPayload()); Message reply2 = testChannel2.receive(0); assertEquals("test", reply2.getPayload()); + + context.close(); } @Test(expected = MessagingException.class) public void channelResolutionIsRequiredByDefault() { + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "testChannelDoesNotExist", "testChannel" }); - } - }; + protected List getChannelKeys(Message message) { + return Arrays.asList("testChannelDoesNotExist", "testChannel"); + } + }; QueueChannel testChannel = new QueueChannel(); GenericApplicationContext context = new GenericApplicationContext(); @@ -173,19 +188,19 @@ public class RouterTests { context.refresh(); router.setBeanFactory(context); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); } @Test public void unresolvableChannelIdentifierInListAreIgnoredWhenResolutionRequiredIsFalse() { + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "testChannelDoesNotExist", "testChannel" }); - } - }; + protected List getChannelKeys(Message message) { + return Arrays.asList("testChannelDoesNotExist", "testChannel"); + } + }; router.setResolutionRequired(false); @@ -195,20 +210,22 @@ public class RouterTests { router.setBeanFactory(context); context.refresh(); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply = testChannel.receive(0); assertEquals("test", reply.getPayload()); + context.close(); } @Test public void beanFactoryWithRouterAndChannelPrefix() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "MyChannel" }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList("MyChannel"); + } + }; router.setPrefix("testing_"); @@ -218,20 +235,23 @@ public class RouterTests { router.setBeanFactory(context); context.refresh(); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply = testChannel.receive(0); assertEquals("test", reply.getPayload()); + + context.close(); } @Test(expected = MessagingException.class) public void beanFactoryWithRouterAndChannelPrefixFailing() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "testing_MyChannel" }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList("testing_MyChannel"); + } + }; router.setPrefix("testing_"); @@ -241,18 +261,20 @@ public class RouterTests { context.refresh(); router.setBeanFactory(context); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); + context.close(); } @Test public void beanFactoryWithRouterAndChannelSuffix() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "MyChannel" }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList("MyChannel"); + } + }; router.setSuffix("_withSuffix"); @@ -262,19 +284,22 @@ public class RouterTests { router.setBeanFactory(context); context.refresh(); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply = testChannel.receive(0); assertEquals("test", reply.getPayload()); + + context.close(); } @Test(expected = MessagingException.class) public void beanFactoryWithRouterAndChannelSuffixFailing() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new String[] { "MyChannel_withSuffix" }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList("MyChannel_withSuffix"); + } + }; router.setSuffix("_withSuffix"); @@ -284,27 +309,29 @@ public class RouterTests { context.refresh(); router.setBeanFactory(context); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); + context.close(); } @Test public void beanFactoryWithRouterAndChannelIdentifiersInListWithinAList() { - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { - List channelNames1 = CollectionUtils.arrayToList(new String[] { "channel1" }); - List channelNames2 = CollectionUtils.arrayToList(new String[] { "channel2" }); + protected List getChannelKeys(Message message) { - List listWithListOfChannelNames = new ArrayList(); + List channelNames1 = Collections.singletonList("channel1"); + List channelNames2 = Collections.singletonList("channel2"); - listWithListOfChannelNames.add(channelNames1); - listWithListOfChannelNames.add(channelNames2); + List listWithListOfChannelNames = new ArrayList<>(); - return listWithListOfChannelNames; - } - }; + listWithListOfChannelNames.add(channelNames1); + listWithListOfChannelNames.add(channelNames2); + + return listWithListOfChannelNames; + } + }; QueueChannel testChannel1 = new QueueChannel(); QueueChannel testChannel2 = new QueueChannel(); @@ -317,13 +344,15 @@ public class RouterTests { router.setBeanFactory(context); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply1 = testChannel1.receive(0); assertEquals("test", reply1.getPayload()); Message reply2 = testChannel2.receive(0); assertEquals("test", reply2.getPayload()); + + context.close(); } @Test @@ -332,21 +361,22 @@ public class RouterTests { final QueueChannel testChannel1 = new QueueChannel(); final QueueChannel testChannel2 = new QueueChannel(); - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { - protected List getChannelKeys(Message message) { + protected List getChannelKeys(Message message) { - MessageChannel[] channelNames1 = new MessageChannel[] { testChannel1 }; - MessageChannel[] channelNames2 = new MessageChannel[] { testChannel2 }; + MessageChannel[] channelNames1 = new MessageChannel[] { testChannel1 }; + MessageChannel[] channelNames2 = new MessageChannel[] { testChannel2 }; - List listWithListOfChannelNames = new ArrayList(); + List listWithListOfChannelNames = new ArrayList<>(); - listWithListOfChannelNames.add(channelNames1); - listWithListOfChannelNames.add(channelNames2); + listWithListOfChannelNames.add(channelNames1); + listWithListOfChannelNames.add(channelNames2); - return listWithListOfChannelNames; - } - }; + return listWithListOfChannelNames; + } + }; GenericApplicationContext context = new GenericApplicationContext(); @@ -355,13 +385,15 @@ public class RouterTests { context.refresh(); router.setBeanFactory(context); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply1 = testChannel1.receive(0); assertEquals("test", reply1.getPayload()); Message reply2 = testChannel2.receive(0); assertEquals("test", reply2.getPayload()); + + context.close(); } @Test @@ -370,12 +402,13 @@ public class RouterTests { final QueueChannel testChannel1 = new QueueChannel(); final QueueChannel testChannel2 = new QueueChannel(); - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new Integer[] { 100, 200 }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Arrays.asList(100, 200); + } + }; GenericApplicationContext context = new GenericApplicationContext(); @@ -385,13 +418,15 @@ public class RouterTests { router.setBeanFactory(context); context.refresh(); - router.handleMessage(new GenericMessage("test")); + router.handleMessage(new GenericMessage<>("test")); Message reply1 = testChannel1.receive(0); assertEquals("test", reply1.getPayload()); Message reply2 = testChannel2.receive(0); assertEquals("test", reply2.getPayload()); + + context.close(); } private class CustomObjectWithChannelName { @@ -410,12 +445,13 @@ public class RouterTests { final QueueChannel testChannel1 = new QueueChannel(); - AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() { - @SuppressWarnings("unchecked") - protected List getChannelKeys(Message message) { - return CollectionUtils.arrayToList(new CustomObjectWithChannelName[] { new CustomObjectWithChannelName() }); - } - }; + AbstractMappingMessageRouter router = + new AbstractMappingMessageRouter() { + + protected List getChannelKeys(Message message) { + return Collections.singletonList(new CustomObjectWithChannelName()); + } + }; GenericApplicationContext context = new GenericApplicationContext(); @@ -423,8 +459,7 @@ public class RouterTests { context.refresh(); router.setBeanFactory(context); - router.handleMessage(new GenericMessage("test")); - + router.handleMessage(new GenericMessage<>("test")); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/DynamicExpressionRouterIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/DynamicExpressionRouterIntegrationTests.java index 0e9c48e287..6effeda9dd 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/DynamicExpressionRouterIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/DynamicExpressionRouterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -21,16 +21,18 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -80,6 +82,7 @@ public class DynamicExpressionRouterIntegrationTests { public int getNumber() { return this.number; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests.java index 73287379fb..5de2c4b69d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -23,15 +23,16 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterParserTests.java index 7674b428aa..e4629dc820 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/HeaderValueRouterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,21 +16,22 @@ package org.springframework.integration.router.config; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -60,10 +61,11 @@ public class HeaderValueRouterParserTests { PollableChannel channel1 = (PollableChannel) context.getBean("channel1"); PollableChannel channel2 = (PollableChannel) context.getBean("channel2"); message1 = channel1.receive(); - assertTrue(message1.getHeaders().get("testHeader").equals("channel1")); + assertEquals("channel1", message1.getHeaders().get("testHeader")); message2 = channel2.receive(); - assertTrue(message2.getHeaders().get("testHeader").equals("channel2")); + assertEquals("channel2", message2.getHeaders().get("testHeader")); } + @Test public void testHeaderValuesWithMapResolver() { context.start(); @@ -78,18 +80,22 @@ public class HeaderValueRouterParserTests { PollableChannel channel1 = (PollableChannel) context.getBean("channel1"); PollableChannel channel2 = (PollableChannel) context.getBean("channel2"); message1 = channel1.receive(); - assertTrue(message1.getHeaders().get("testHeader").equals("1")); + assertEquals("1", message1.getHeaders().get("testHeader")); message2 = channel2.receive(); - assertTrue(message2.getHeaders().get("testHeader").equals("2")); + assertEquals("2", message2.getHeaders().get("testHeader")); } public interface TestServiceA { + void foo(Message message); + } public interface TestServiceB { + void foo(Message message); + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests.java index 40702e6e4c..7dc0621e9c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -19,7 +19,6 @@ package org.springframework.integration.router.config; 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 org.junit.Test; import org.junit.runner.RunWith; @@ -28,18 +27,20 @@ import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.integration.router.RecipientListRouter; +import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.integration.router.RecipientListRouter; -import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky * @author Mark Fisher + * @author Artem Bilan + * * @since 1.0.3 */ @RunWith(SpringJUnit4ClassRunner.class) @@ -62,12 +63,12 @@ public class RecipientListRouterParserTests { @Test public void checkMessageRouting() { context.start(); - Message message = new GenericMessage(1); + Message message = new GenericMessage<>(1); channel.send(message); PollableChannel chanel1 = (PollableChannel) context.getBean("channel1"); PollableChannel chanel2 = (PollableChannel) context.getBean("channel2"); - assertTrue(chanel1.receive(0).getPayload().equals(1)); - assertTrue(chanel2.receive(0).getPayload().equals(1)); + assertEquals(1, chanel1.receive(0).getPayload()); + assertEquals(1, chanel2.receive(0).getPayload()); } @Test @@ -77,7 +78,7 @@ public class RecipientListRouterParserTests { assertEquals(RecipientListRouter.class, handler.getClass()); RecipientListRouter router = (RecipientListRouter) handler; DirectFieldAccessor accessor = new DirectFieldAccessor(router); - assertEquals(new Long(-1), new DirectFieldAccessor( + assertEquals(-1L, new DirectFieldAccessor( accessor.getPropertyValue("messagingTemplate")).getPropertyValue("sendTimeout")); assertEquals(Boolean.FALSE, accessor.getPropertyValue("applySequence")); assertEquals(Boolean.FALSE, accessor.getPropertyValue("ignoreSendFailures")); @@ -90,7 +91,7 @@ public class RecipientListRouterParserTests { assertEquals(RecipientListRouter.class, handler.getClass()); RecipientListRouter router = (RecipientListRouter) handler; DirectFieldAccessor accessor = new DirectFieldAccessor(router); - assertEquals(new Long(1234), new DirectFieldAccessor( + assertEquals(1234L, new DirectFieldAccessor( accessor.getPropertyValue("messagingTemplate")).getPropertyValue("sendTimeout")); assertEquals(Boolean.TRUE, accessor.getPropertyValue("applySequence")); assertEquals(Boolean.TRUE, accessor.getPropertyValue("ignoreSendFailures")); @@ -99,24 +100,24 @@ public class RecipientListRouterParserTests { @Test public void simpleDynamicRouter() { context.start(); - Message message = new GenericMessage(1); + Message message = new GenericMessage<>(1); simpleDynamicInput.send(message); PollableChannel chanel1 = (PollableChannel) context.getBean("channel1"); PollableChannel chanel2 = (PollableChannel) context.getBean("channel2"); - assertTrue(chanel1.receive(0).getPayload().equals(1)); + assertEquals(1, chanel1.receive(0).getPayload()); assertNull(chanel2.receive(0)); } @Test public void noSelectorMatchRouter() { context.start(); - Message message = new GenericMessage(1); + Message message = new GenericMessage<>(1); noSelectorMatchInput.send(message); PollableChannel chanel1 = (PollableChannel) context.getBean("channel1"); PollableChannel chanel2 = (PollableChannel) context.getBean("channel2"); Message output = chanel1.receive(0); assertNotNull(output); - assertTrue(output.getPayload().equals(1)); + assertEquals(1, output.getPayload()); assertNull(chanel2.receive(0)); } @@ -125,6 +126,7 @@ public class RecipientListRouterParserTests { public boolean accept(int number) { return number == 1; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/RfbFixRouter.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/RfbFixRouter.java index ef3d0d387b..4e33a0b359 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/RfbFixRouter.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/RfbFixRouter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2018 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. @@ -18,12 +18,13 @@ package org.springframework.integration.router.config; import java.util.Collection; +import org.springframework.integration.router.AbstractMessageRouter; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.integration.router.AbstractMessageRouter; /** * @author Oleg Zhurakousky + * @author Artem Bilan */ public class RfbFixRouter extends AbstractMessageRouter { @@ -31,4 +32,5 @@ public class RfbFixRouter extends AbstractMessageRouter { protected Collection determineTargetChannels(Message message) { return null; } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/SpelRouterIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/SpelRouterIntegrationTests.java index 1f6d6b2d9c..03ff4fd978 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/SpelRouterIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/SpelRouterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -23,16 +23,17 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artme Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -112,6 +113,7 @@ public class SpelRouterIntegrationTests { public MessageChannel getChannel(int value) { return (value == 0) ? clear : remainders; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/TestSplitterImpl.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/TestSplitterImpl.java index 575a0e2409..a26afccc39 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/TestSplitterImpl.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/TestSplitterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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,15 @@ package org.springframework.integration.router.config; -import org.springframework.messaging.Message; import org.springframework.integration.splitter.AbstractMessageSplitter; +import org.springframework.messaging.Message; /** * @author Mark Fisher + * @author Artem Bilan */ public class TestSplitterImpl extends AbstractMessageSplitter { - @Override protected Object splitMessage(Message message) { return message.getPayload().toString().split("\\."); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/splitter/DynamicExpressionSplitterIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/splitter/DynamicExpressionSplitterIntegrationTests.java index 916a2dab41..c19cb196dc 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/splitter/DynamicExpressionSplitterIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/splitter/DynamicExpressionSplitterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -26,15 +26,16 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -55,13 +56,13 @@ public class DynamicExpressionSplitterIntegrationTests { Message two = output.receive(0); Message three = output.receive(0); Message four = output.receive(0); - assertEquals(new Integer(1), one.getPayload()); + assertEquals(1, one.getPayload()); assertEquals("foo", one.getHeaders().get("foo")); - assertEquals(new Integer(2), two.getPayload()); + assertEquals(2, two.getPayload()); assertEquals("foo", two.getHeaders().get("foo")); - assertEquals(new Integer(3), three.getPayload()); + assertEquals(3, three.getPayload()); assertEquals("foo", three.getHeaders().get("foo")); - assertEquals(new Integer(4), four.getPayload()); + assertEquals(4, four.getPayload()); assertEquals("foo", four.getHeaders().get("foo")); assertNull(output.receive(0)); } @@ -69,7 +70,7 @@ public class DynamicExpressionSplitterIntegrationTests { static class TestBean { - private final List numbers = new ArrayList(); + private final List numbers = new ArrayList<>(); TestBean() { for (int i = 1; i <= 10; i++) { @@ -84,6 +85,7 @@ public class DynamicExpressionSplitterIntegrationTests { public String[] split(String s) { return s.split(","); } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/ClaimCheckTransformerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/ClaimCheckTransformerTests.java index bb1ff0fd3f..069b6ae6d5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/ClaimCheckTransformerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/ClaimCheckTransformerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -22,13 +22,15 @@ import java.util.UUID; import org.junit.Test; -import org.springframework.messaging.Message; import org.springframework.integration.store.MessageStore; import org.springframework.integration.store.SimpleMessageStore; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; /** * @author Mark Fisher + * @author Artem Bilan + * * @since 2.0 */ public class ClaimCheckTransformerTests { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionHeaderEnricherIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionHeaderEnricherIntegrationTests.java index ac3ce765d6..c1d685a79c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionHeaderEnricherIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionHeaderEnricherIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -20,16 +20,18 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionTransformerIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionTransformerIntegrationTests.java index 1fa5bbd173..0ab10c0f83 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionTransformerIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/DynamicExpressionTransformerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -20,16 +20,18 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -56,6 +58,7 @@ public class DynamicExpressionTransformerIntegrationTests { public String getFoo() { return "test"; } + } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/SpelHeaderEnricherIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/SpelHeaderEnricherIntegrationTests.java index aee485331e..3b4df128da 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/SpelHeaderEnricherIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/SpelHeaderEnricherIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -24,16 +24,17 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author David Turanski + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -103,6 +104,7 @@ public class SpelHeaderEnricherIntegrationTests { public int getValue() { return 5; } + } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java index 09c7fd982e..8d3eb19bf2 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -29,7 +29,7 @@ import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.InputStreamResource; @@ -37,15 +37,16 @@ import org.springframework.core.io.InputStreamResource; /** * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.2 */ public class ChainElementsTests { @Test public void chainOutboundGateway() throws Exception { - - try { - this.bootStrap("file-oubound-gateway"); + try { + bootStrap("file-outbound-gateway"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { @@ -57,30 +58,30 @@ public class ChainElementsTests { assertTrue("Error message did not start with '" + expectedMessage + "' but instead returned: '" + actualMessage + "'", actualMessage.startsWith(expectedMessage)); } - } @Test public void chainOutboundGatewayWithInputChannel() throws Exception { - - try { - this.bootStrap("file-oubound-gateway-input-channel"); + try { + bootStrap("file-outbound-gateway-input-channel"); fail("Expected a XmlBeanDefinitionStoreException to be thrown."); } catch (XmlBeanDefinitionStoreException e) { assertEquals("cvc-complex-type.3.2.2: Attribute 'input-channel' is not" + " allowed to appear in element 'int-file:outbound-gateway'.", e.getCause().getMessage()); } - } - private ApplicationContext bootStrap(String configProperty) throws Exception { + private ConfigurableApplicationContext bootStrap(String configProperty) throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); - pfb.setLocation(new ClassPathResource("org/springframework/integration/file/config/chain-elements-config.properties")); + pfb.setLocation(new ClassPathResource( + "org/springframework/integration/file/config/chain-elements-config.properties")); pfb.afterPropertiesSet(); Properties prop = pfb.getObject(); StringBuffer buffer = new StringBuffer(); - buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter")); + buffer.append(prop.getProperty("xmlheaders")) + .append(prop.getProperty(configProperty)) + .append(prop.getProperty("xmlfooter")); ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/chain-elements-config.properties b/spring-integration-file/src/test/java/org/springframework/integration/file/config/chain-elements-config.properties index cedd28d53a..99f9455ebe 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/chain-elements-config.properties +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/chain-elements-config.properties @@ -9,9 +9,9 @@ xmlheaders=\ http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"> xmlfooter= -file-oubound-gateway=\ +file-outbound-gateway=\ \ -file-oubound-gateway-input-channel=\ +file-outbound-gateway-input-channel=\ \ diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/fork/CacheServerProcess.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/fork/CacheServerProcess.java index cb2415cd3e..3ad41967bd 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/fork/CacheServerProcess.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/fork/CacheServerProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors. + * Copyright 2013-2018 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. @@ -23,7 +23,6 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests.java index 4d3378ed2c..e213361a58 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyControlBusIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -23,13 +23,14 @@ import java.io.IOException; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; +import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.integration.support.MessageBuilder; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scripting.ScriptSource; import org.springframework.scripting.support.ResourceScriptSource; @@ -67,7 +68,7 @@ public class GroovyControlBusIntegrationTests { assertNull(this.output.receive(500)); this.scheduler.afterPropertiesSet(); - Resource scriptResource = new ClassPathResource("GroovyControlBusDelayerManagementTest.groovy", this.getClass()); + Resource scriptResource = new ClassPathResource("GroovyControlBusDelayerManagementTest.groovy", getClass()); ScriptSource scriptSource = new ResourceScriptSource(scriptResource); Message message = MessageBuilder.withPayload(scriptSource.getScriptAsString()).build(); this.controlBus.send(message); diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptPayloadMessageProcessorTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptPayloadMessageProcessorTests.java index 789207af1d..c74c3887de 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptPayloadMessageProcessorTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptPayloadMessageProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -22,22 +22,25 @@ import static org.junit.Assert.fail; import java.util.Collections; import java.util.concurrent.atomic.AtomicInteger; -import groovy.lang.Binding; -import groovy.lang.MissingPropertyException; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.springframework.messaging.Message; + import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.scripting.DefaultScriptVariableGenerator; import org.springframework.integration.scripting.ScriptVariableGenerator; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; import org.springframework.test.annotation.Repeat; +import groovy.lang.Binding; +import groovy.lang.MissingPropertyException; + /** * @author Dave Syer * @author Artem Bilan * @author Gunnar Hillert + * * @since 2.0 */ public class GroovyScriptPayloadMessageProcessorTests { @@ -51,7 +54,7 @@ public class GroovyScriptPayloadMessageProcessorTests { @Test @Repeat(20) - public void testSimpleExecution() throws Exception { + public void testSimpleExecution() { int count = countHolder.getAndIncrement(); Message message = MessageBuilder.withPayload("headers.foo" + count).setHeader("foo" + count, "bar").build(); processor = new GroovyCommandMessageProcessor(); @@ -60,7 +63,7 @@ public class GroovyScriptPayloadMessageProcessorTests { } @Test - public void testDoubleExecutionWithNewScript() throws Exception { + public void testDoubleExecutionWithNewScript() { processor = new GroovyCommandMessageProcessor(); Message message = MessageBuilder.withPayload("headers.foo").setHeader("foo", "bar").build(); Object result = processor.processMessage(message); @@ -71,19 +74,20 @@ public class GroovyScriptPayloadMessageProcessorTests { } @Test - public void testSimpleExecutionWithContext() throws Exception { + public void testSimpleExecutionWithContext() { Message message = MessageBuilder.withPayload("\"spam is $spam foo is $headers.foo\"") .setHeader("foo", "bar").build(); ScriptVariableGenerator scriptVariableGenerator = - new DefaultScriptVariableGenerator(Collections.singletonMap("spam", (Object) "bucket")); + new DefaultScriptVariableGenerator(Collections.singletonMap("spam", "bucket")); MessageProcessor processor = new GroovyCommandMessageProcessor(scriptVariableGenerator); Object result = processor.processMessage(message); assertEquals("spam is bucket foo is bar", result.toString()); } @Test //INT-2567 - public void testBindingOverwrite() throws Exception { + public void testBindingOverwrite() { Binding binding = new Binding() { + @Override public Object getVariable(String name) { throw new RuntimeException("intentional"); @@ -101,22 +105,23 @@ public class GroovyScriptPayloadMessageProcessorTests { } @Test //INT-2567 - public void testBindingOverwriteWithContext() throws Exception { + public void testBindingOverwriteWithContext() { final String defaultValue = "default"; Binding binding = new Binding() { + @Override public Object getVariable(String name) { try { return super.getVariable(name); } catch (MissingPropertyException e) { - // ignore + // ignore } return defaultValue; } }; ScriptVariableGenerator scriptVariableGenerator = - new DefaultScriptVariableGenerator(Collections.singletonMap("spam", (Object) "bucket")); + new DefaultScriptVariableGenerator(Collections.singletonMap("spam", "bucket")); Message message = MessageBuilder.withPayload("\"spam is $spam, foo is $foo\"").build(); processor = new GroovyCommandMessageProcessor(binding, scriptVariableGenerator); Object result = processor.processMessage(message); diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/RepeatProcessor.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/RepeatProcessor.java index 7d9a55c8a9..cf5131d6ca 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/RepeatProcessor.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/RepeatProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit; import org.junit.rules.MethodRule; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; + import org.springframework.core.annotation.AnnotationUtils; import org.springframework.test.annotation.Repeat; @@ -37,6 +38,8 @@ import org.springframework.test.annotation.Repeat; * re-initializing the test case). * * @author Dave Syer + * @author Artem Bilan + * * @since 2.0 * */ diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java index f22f1b2809..0bf355133a 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import groovy.lang.GroovyObject; import java.util.HashMap; import java.util.Map; @@ -35,26 +34,29 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationNotAllowedException; import org.springframework.beans.factory.BeanIsAbstractException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageHandlingException; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice; import org.springframework.integration.support.MessageBuilder; import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.MessageHandlingException; +import org.springframework.messaging.PollableChannel; import org.springframework.scripting.groovy.GroovyObjectCustomizer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; +import groovy.lang.GroovyObject; + /** * @author Dave Syer * @author Artem Bilan * @author Gary Russell * @author Gunnar Hillert + * * @since 2.0 */ @ContextConfiguration @@ -81,7 +83,11 @@ public class GroovyControlBusTests { @Test public void testOperationOfControlBus() { // long is > 3 this.groovyCustomizer.executed = false; - Message message = MessageBuilder.withPayload("def result = service.convert('aardvark'); def foo = headers.foo; result+foo").setHeader("foo", "bar").build(); + Message message = + MessageBuilder.withPayload( + "def result = service.convert('aardvark'); def foo = headers.foo; result+foo") + .setHeader("foo", "bar") + .build(); this.input.send(message); assertEquals("catbar", output.receive(0).getPayload()); assertNull(output.receive(0)); @@ -91,7 +97,9 @@ public class GroovyControlBusTests { @Test //INT-2567 public void testOperationWithCustomScope() { - Message message = MessageBuilder.withPayload("def result = threadScopedService.convert('testString')").build(); + Message message = + MessageBuilder.withPayload("def result = threadScopedService.convert('testString')") + .build(); this.input.send(message); assertEquals("cat", output.receive(0).getPayload()); } @@ -99,13 +107,16 @@ public class GroovyControlBusTests { @Test //INT-2567 public void testFailOperationWithCustomScope() { try { - Message message = MessageBuilder.withPayload("def result = requestScopedService.convert('testString')").build(); + Message message = + MessageBuilder.withPayload("def result = requestScopedService.convert('testString')") + .build(); this.input.send(message); fail("Expected BeanCreationException"); } catch (Exception e) { Throwable cause = e.getCause(); - assertTrue("Expected BeanCreationException, got " + cause.getClass() + ":" + cause.getMessage(), cause instanceof BeanCreationException); + assertTrue("Expected BeanCreationException, got " + cause.getClass() + ":" + cause + .getMessage(), cause instanceof BeanCreationException); assertTrue(cause.getMessage().contains("requestScopedService")); } } @@ -113,7 +124,9 @@ public class GroovyControlBusTests { @Test //INT-2567 public void testOperationWithRequestCustomScope() { RequestContextHolder.setRequestAttributes(new MockRequestAttributes()); - Message message = MessageBuilder.withPayload("def result = requestScopedService.convert('testString')").build(); + Message message = + MessageBuilder.withPayload("def result = requestScopedService.convert('testString')") + .build(); this.input.send(message); assertEquals("cat", output.receive(0).getPayload()); @@ -123,13 +136,16 @@ public class GroovyControlBusTests { @Test //INT-2567 public void testFailOperationOnNonManagedComponent() { try { - Message message = MessageBuilder.withPayload("def result = nonManagedService.convert('testString')").build(); + Message message = + MessageBuilder.withPayload("def result = nonManagedService.convert('testString')") + .build(); this.input.send(message); fail("Expected BeanCreationNotAllowedException"); } catch (MessageHandlingException e) { Throwable cause = e.getCause(); - assertTrue("Expected BeanCreationNotAllowedException, got " + cause.getClass() + ":" + cause.getMessage(), cause instanceof BeanCreationNotAllowedException); + assertTrue("Expected BeanCreationNotAllowedException, got " + cause.getClass() + ":" + cause.getMessage(), + cause instanceof BeanCreationNotAllowedException); assertTrue(cause.getMessage().contains("nonManagedService")); } } @@ -143,7 +159,8 @@ public class GroovyControlBusTests { } catch (MessageHandlingException e) { Throwable cause = e.getCause(); - assertTrue("Expected BeanIsAbstractException, got " + cause.getClass() + ":" + cause.getMessage(), cause instanceof BeanIsAbstractException); + assertTrue("Expected BeanIsAbstractException, got " + cause.getClass() + ":" + cause.getMessage(), + cause instanceof BeanIsAbstractException); assertTrue(cause.getMessage().contains("abstractService")); } } @@ -162,6 +179,7 @@ public class GroovyControlBusTests { public String convert(String input) { return "cat"; } + } @@ -170,9 +188,11 @@ public class GroovyControlBusTests { public String convert(String input) { return "cat"; } + } public static class MyGroovyCustomizer implements GroovyObjectCustomizer { + private volatile boolean executed; public void customize(GroovyObject goo) { @@ -183,7 +203,7 @@ public class GroovyControlBusTests { private static class MockRequestAttributes implements RequestAttributes { - private final Map fakeRequest = new HashMap(); + private final Map fakeRequest = new HashMap<>(); public Object getAttribute(String name, int scope) { return fakeRequest.get(name); @@ -227,4 +247,5 @@ public class GroovyControlBusTests { } } + } diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java index 0e3dd5333c..fd99d768a0 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,9 @@ package org.springframework.integration.groovy.config; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import org.hamcrest.Matchers; import java.util.Map; @@ -26,13 +26,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.transformer.support.HeaderValueMessageProcessor; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -41,6 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oleg Zhurakousky * @author Artem Bilan * @author Gunnar Hillert + * * @since 2.0 */ @ContextConfiguration @@ -63,23 +64,26 @@ public class GroovyHeaderEnricherTests { private EventDrivenConsumer headerEnricherWithInlineGroovyScript; @Test - public void referencedScript() throws Exception { - inputA.send(new GenericMessage("Hello")); + public void referencedScript() { + inputA.send(new GenericMessage<>("Hello")); assertEquals("groovy", outputA.receive(1000).getHeaders().get("TEST_HEADER")); } @SuppressWarnings("unchecked") @Test - public void inlineScript() throws Exception { + public void inlineScript() { Map> headers = - TestUtils.getPropertyValue(headerEnricherWithInlineGroovyScript, "handler.transformer.headersToAdd", Map.class); + TestUtils.getPropertyValue(headerEnricherWithInlineGroovyScript, + "handler.transformer.headersToAdd", Map.class); assertEquals(1, headers.size()); HeaderValueMessageProcessor headerValueMessageProcessor = headers.get("TEST_HEADER"); - assertThat(headerValueMessageProcessor.getClass().getName(), Matchers.containsString("MessageProcessingHeaderValueMessageProcessor")); + assertThat(headerValueMessageProcessor.getClass().getName(), + containsString("MessageProcessingHeaderValueMessageProcessor")); Object targetProcessor = TestUtils.getPropertyValue(headerValueMessageProcessor, "targetProcessor"); assertEquals(GroovyScriptExecutingMessageProcessor.class, targetProcessor.getClass()); inputB.send(new GenericMessage("Hello")); assertEquals("groovy", outputB.receive(1000).getHeaders().get("TEST_HEADER")); } + } diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java index f39f170643..f1ad30bb01 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -21,22 +21,23 @@ import static org.junit.Assert.assertNull; import java.beans.PropertyEditorSupport; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.AbstractResource; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.MessageChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -47,7 +48,7 @@ public class GroovyRefreshTests { private MessageChannel referencedScriptInput; @Test - public void referencedScript() throws Exception { + public void referencedScript() { QueueChannel replyChannel = new QueueChannel(); replyChannel.setBeanName("returnAddress"); this.referencedScriptInput.send(MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build()); @@ -58,17 +59,21 @@ public class GroovyRefreshTests { } public static class ResourceEditor extends PropertyEditorSupport { + @Override public void setAsText(String text) throws IllegalArgumentException { super.setValue(new CycleResource()); } + } private static class CycleResource extends AbstractResource { private int count = -1; - private String[] scripts = {"\"groovy-${binding.variables['payload']}-0\"", - "\"groovy-${binding.variables['payload']}-1\""}; + + private String[] scripts = + { "\"groovy-${binding.variables['payload']}-0\"", + "\"groovy-${binding.variables['payload']}-1\"" }; public String getDescription() { return "CycleResource"; @@ -80,16 +85,17 @@ public class GroovyRefreshTests { } @Override - public long lastModified() throws IOException { + public long lastModified() { return -1; } - public InputStream getInputStream() throws IOException { - if (++count > scripts.length - 1) { - count = 0; + public InputStream getInputStream() { + if (++this.count > this.scripts.length - 1) { + this.count = 0; } - return new ByteArrayInputStream(scripts[count].getBytes()); + return new ByteArrayInputStream(this.scripts[count].getBytes()); } } + } diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java index 4a16de5e16..3cf5721b6d 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 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. @@ -27,19 +27,20 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor; import org.springframework.integration.handler.MessageProcessor; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.router.MethodInvokingRouter; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.GenericMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -64,11 +65,11 @@ public class GroovyRouterTests { @Test public void referencedScript() { // long is > 3 - Message message1 = new GenericMessage("aardvark"); - Message message2 = new GenericMessage("bear"); - Message message3 = new GenericMessage("cat"); - Message message4 = new GenericMessage("dog"); - Message message5 = new GenericMessage("elephant"); + Message message1 = new GenericMessage<>("aardvark"); + Message message2 = new GenericMessage<>("bear"); + Message message3 = new GenericMessage<>("cat"); + Message message4 = new GenericMessage<>("dog"); + Message message5 = new GenericMessage<>("elephant"); this.referencedScriptInput.send(message1); this.referencedScriptInput.send(message2); this.referencedScriptInput.send(message3); @@ -85,11 +86,11 @@ public class GroovyRouterTests { @Test public void inlineScript() { // long is > 5 - Message message1 = new GenericMessage("aardvark"); - Message message2 = new GenericMessage("bear"); - Message message3 = new GenericMessage("cat"); - Message message4 = new GenericMessage("dog"); - Message message5 = new GenericMessage("elephant"); + Message message1 = new GenericMessage<>("aardvark"); + Message message2 = new GenericMessage<>("bear"); + Message message3 = new GenericMessage<>("cat"); + Message message4 = new GenericMessage<>("dog"); + Message message5 = new GenericMessage<>("elephant"); this.inlineScriptInput.send(message1); this.inlineScriptInput.send(message2); this.inlineScriptInput.send(message3); diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java index c90ca54fa0..268942c308 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,63 +17,79 @@ package org.springframework.integration.groovy.config; import static org.junit.Assert.assertEquals; - -import java.io.IOException; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.junit.Test; + import org.springframework.core.io.ByteArrayResource; import org.springframework.integration.scripting.RefreshableResourceScriptSource; /** * @author Dave Syer + * @author Artem Bilan */ public class RefreshableResourceScriptSourceTests { @Test public void testGetScriptAsString() throws Exception { - RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()), 1000); + RefreshableResourceScriptSource source = + new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()), 1000); assertEquals("foo", source.getScriptAsString()); } @Test - public void testIsModified() throws Exception { - RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()), 1000); - assertEquals(false, source.isModified()); + public void testIsModified() { + RefreshableResourceScriptSource source = + new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()), 1000); + assertFalse(source.isModified()); } @Test public void testIsModifiedZeroDelay() throws Exception { - RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()) { - @Override - public long lastModified() throws IOException { - return System.currentTimeMillis(); - } - }, 0); + RefreshableResourceScriptSource source = + new RefreshableResourceScriptSource( + new ByteArrayResource("foo".getBytes()) { + + @Override + public long lastModified() { + return System.currentTimeMillis(); + } + + }, 0); Thread.sleep(100L); - assertEquals(true, source.isModified()); + assertTrue(source.isModified()); assertEquals("foo", source.getScriptAsString()); } @Test public void testIsModifiedInfiniteDelay() throws Exception { - RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()) { - @Override - public long lastModified() throws IOException { - return System.currentTimeMillis(); - } - }, -1); - assertEquals(false, source.isModified()); + RefreshableResourceScriptSource source = + new RefreshableResourceScriptSource( + new ByteArrayResource("foo".getBytes()) { + + @Override + public long lastModified() { + return System.currentTimeMillis(); + } + + }, -1); + assertFalse(source.isModified()); assertEquals("foo", source.getScriptAsString()); } @Test - public void testSuggestedClassName() throws Exception { - RefreshableResourceScriptSource source = new RefreshableResourceScriptSource(new ByteArrayResource("foo".getBytes()) { - @Override - public String getFilename() throws IllegalStateException { - return "Foo"; - } - }, 1000); + public void testSuggestedClassName() { + RefreshableResourceScriptSource source = + new RefreshableResourceScriptSource( + new ByteArrayResource("foo".getBytes()) { + + @Override + public String getFilename() throws IllegalStateException { + return "Foo"; + } + + }, 1000); assertEquals("Foo", source.suggestedClassName()); } diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java index ebd10da6f0..d010515118 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -23,10 +23,11 @@ import java.io.ByteArrayInputStream; import java.util.Properties; import org.junit.Test; + import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.InputStreamResource; @@ -34,15 +35,16 @@ import org.springframework.core.io.InputStreamResource; /** * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.2 */ public class ChainElementsTests { @Test public void chainOutboundGateway() throws Exception { - - try { - this.bootStrap("http-oubound-gateway"); + try { + bootStrap("http-outbound-gateway"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { @@ -53,16 +55,18 @@ public class ChainElementsTests { assertTrue("Error message did not start with '" + expectedMessage + "' but instead returned: '" + actualMessage + "'", actualMessage.startsWith(expectedMessage)); } - } - private ApplicationContext bootStrap(String configProperty) throws Exception { + private ConfigurableApplicationContext bootStrap(String configProperty) throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); - pfb.setLocation(new ClassPathResource("org/springframework/integration/http/config/chain-elements-config.properties")); + pfb.setLocation(new ClassPathResource( + "org/springframework/integration/http/config/chain-elements-config.properties")); pfb.afterPropertiesSet(); Properties prop = pfb.getObject(); StringBuffer buffer = new StringBuffer(); - buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter")); + buffer.append(prop.getProperty("xmlheaders")) + .append(prop.getProperty(configProperty)) + .append(prop.getProperty("xmlfooter")); ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac); diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java index fedfb6d55c..cf8538aea9 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletResponse; import org.hamcrest.Matcher; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -167,7 +168,7 @@ public class HttpInboundGatewayParserTests { } @Test - public void testController() throws Exception { + public void testController() { DirectFieldAccessor accessor = new DirectFieldAccessor(inboundController); String errorCode = (String) accessor.getPropertyValue("errorCode"); assertEquals("oops", errorCode); @@ -176,7 +177,7 @@ public class HttpInboundGatewayParserTests { } @Test - public void testControllerViewExp() throws Exception { + public void testControllerViewExp() { DirectFieldAccessor accessor = new DirectFieldAccessor(inboundControllerViewExp); String errorCode = (String) accessor.getPropertyValue("errorCode"); assertEquals("oops", errorCode); @@ -186,16 +187,16 @@ public class HttpInboundGatewayParserTests { } @Test - public void requestWithHeaders() throws Exception { + public void requestWithHeaders() { DefaultHttpHeaderMapper headerMapper = - (DefaultHttpHeaderMapper) TestUtils.getPropertyValue(withMappedHeaders, "headerMapper"); + TestUtils.getPropertyValue(this.withMappedHeaders, "headerMapper", DefaultHttpHeaderMapper.class); HttpHeaders headers = new HttpHeaders(); headers.set("foo", "foo"); headers.set("bar", "bar"); headers.set("baz", "baz"); Map map = headerMapper.toHeaders(headers); - assertTrue(map.size() == 2); + assertEquals(2, map.size()); assertEquals("foo", map.get("foo")); assertEquals("bar", map.get("bar")); @@ -204,15 +205,16 @@ public class HttpInboundGatewayParserTests { MessageHeaders mh = new MessageHeaders(mapOfHeaders); headers = new HttpHeaders(); headerMapper.fromHeaders(mh, headers); - assertTrue(headers.size() == 1); + assertEquals(1, headers.size()); List abc = headers.get("abc"); assertEquals("abc", abc.get(0)); } @Test - public void requestWithHeadersWithConversionService() throws Exception { + public void requestWithHeadersWithConversionService() { DefaultHttpHeaderMapper headerMapper = - (DefaultHttpHeaderMapper) TestUtils.getPropertyValue(withMappedHeadersAndConverter, "headerMapper"); + TestUtils.getPropertyValue(this.withMappedHeadersAndConverter, + "headerMapper", DefaultHttpHeaderMapper.class); headerMapper.setUserDefinedHeaderPrefix("X-"); @@ -221,11 +223,11 @@ public class HttpInboundGatewayParserTests { headers.set("bar", "bar"); headers.set("baz", "baz"); Map map = headerMapper.toHeaders(headers); - assertTrue(map.size() == 2); + assertEquals(2, map.size()); assertEquals("foo", map.get("foo")); assertEquals("bar", map.get("bar")); - Map mapOfHeaders = new HashMap(); + Map mapOfHeaders = new HashMap<>(); mapOfHeaders.put("abc", "abc"); Person person = new Person(); person.setName("Oleg"); @@ -233,7 +235,7 @@ public class HttpInboundGatewayParserTests { MessageHeaders mh = new MessageHeaders(mapOfHeaders); headers = new HttpHeaders(); headerMapper.fromHeaders(mh, headers); - assertTrue(headers.size() == 2); + assertEquals(2, headers.size()); List abc = headers.get("X-abc"); assertEquals("abc", abc.get(0)); List personHeaders = headers.get("X-person"); @@ -244,7 +246,7 @@ public class HttpInboundGatewayParserTests { public void testInboundGatewayWithMessageConverterDefaults() { @SuppressWarnings("unchecked") List> messageConverters = - TestUtils.getPropertyValue(gatewayWithOneCustomConverter, "messageConverters", List.class); + TestUtils.getPropertyValue(this.gatewayWithOneCustomConverter, "messageConverters", List.class); assertThat("There should be only 1 message converter, by default register-default-converters is off", messageConverters.size(), is(1)); @@ -255,7 +257,8 @@ public class HttpInboundGatewayParserTests { @Test public void testInboundGatewayWithNoMessageConverterDefaults() { @SuppressWarnings("unchecked") - List> messageConverters = TestUtils.getPropertyValue(gatewayNoDefaultConverters, "messageConverters", List.class); + List> messageConverters = + TestUtils.getPropertyValue(this.gatewayNoDefaultConverters, "messageConverters", List.class); //First converter should be the customized one assertThat(messageConverters.get(0), instanceOf(SerializingHttpMessageConverter.class)); @@ -266,7 +269,9 @@ public class HttpInboundGatewayParserTests { @Test public void testInboundGatewayWithCustomAndDefaultMessageConverters() { @SuppressWarnings("unchecked") - List> messageConverters = TestUtils.getPropertyValue(gatewayWithCustomAndDefaultConverters, "messageConverters", List.class); + List> messageConverters = + TestUtils.getPropertyValue(this.gatewayWithCustomAndDefaultConverters, "messageConverters", + List.class); //First converter should be the customized one assertThat(messageConverters.get(0), instanceOf(SerializingHttpMessageConverter.class)); diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/chain-elements-config.properties b/spring-integration-http/src/test/java/org/springframework/integration/http/config/chain-elements-config.properties index 0f55d86c92..262285dafd 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/chain-elements-config.properties +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/chain-elements-config.properties @@ -9,7 +9,7 @@ xmlheaders=\ http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"> xmlfooter= -http-oubound-gateway=\ +http-outbound-gateway=\ \ diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcMessageStoreParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcMessageStoreParserTests.java index faae0871e0..261c3f73b5 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcMessageStoreParserTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcMessageStoreParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2018 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. @@ -25,19 +25,26 @@ import java.io.OutputStream; import org.junit.After; import org.junit.Test; + import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.serializer.DefaultDeserializer; import org.springframework.core.serializer.DefaultSerializer; import org.springframework.core.serializer.Deserializer; import org.springframework.core.serializer.Serializer; -import org.springframework.messaging.Message; import org.springframework.integration.jdbc.store.JdbcMessageStore; import org.springframework.integration.store.MessageStore; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; import org.springframework.jdbc.support.lob.LobHandler; +import org.springframework.messaging.Message; import org.springframework.test.util.ReflectionTestUtils; +/** + * @author Mark Fisher + * @author Dave Syer + * @author Gunnar Hillert + * @author Artem Bilan + */ public class JdbcMessageStoreParserTests { private ClassPathXmlApplicationContext context; @@ -103,6 +110,7 @@ public class JdbcMessageStoreParserTests { message = MessageBuilder.fromMessage(message).setHeader("serializer", "CUSTOM").build(); targetSerializer.serialize(message, outputStream); } + } } diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStoreTests.java index 45d097fc0f..70be7afb3f 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/metadata/JdbcMetadataStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2018 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. @@ -24,6 +24,7 @@ import javax.sql.DataSource; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -32,6 +33,8 @@ import org.springframework.transaction.annotation.Transactional; /** * @author Bojan Vukasovic + * @author Artem Bilan + * * @since 5.0 */ @ContextConfiguration @@ -47,7 +50,7 @@ public class JdbcMetadataStoreTests { private JdbcMetadataStore metadataStore; @Before - public void init() throws Exception { + public void init() { metadataStore = new JdbcMetadataStore(dataSource); metadataStore.afterPropertiesSet(); } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java index 37b243cdfe..8d049cdec7 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2016 the original author or authors. + * Copyright 2009-2018 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. @@ -26,11 +26,17 @@ import org.apache.commons.logging.LogFactory; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.junit.Test; + import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.GenericMessage; +/** + * @author Dave Syer + * @author Gary Russell + * @author Artem Bilan + */ public class HandlerMonitoringIntegrationTests { private static Log logger = LogFactory.getLog(HandlerMonitoringIntegrationTests.class); @@ -50,24 +56,23 @@ public class HandlerMonitoringIntegrationTests { } @Test - public void testSendAndHandleWithEndpointName() throws Exception { + public void testSendAndHandleWithEndpointName() { // The handler monitor is registered under the endpoint id (since it is explicit) doTest("explicit-handler.xml", "input", "explicit"); } @Test - public void testSendAndHandleWithAnonymousHandler() throws Exception { + public void testSendAndHandleWithAnonymousHandler() { doTest("anonymous-handler.xml", "anonymous", "anonymous"); } @Test - public void testSendAndHandleWithProxiedHandler() throws Exception { + public void testSendAndHandleWithProxiedHandler() { doTest("proxy-handler.xml", "anonymous", "anonymous"); } @Test - public void testErrorLogger() throws Exception { - + public void testErrorLogger() { ClassPathXmlApplicationContext context = createContext("anonymous-handler.xml", "anonymous"); try { assertTrue(Arrays.asList(messageHandlersMonitor.getHandlerNames()).contains("errorLogger")); @@ -78,14 +83,11 @@ public class HandlerMonitoringIntegrationTests { } - private void doTest(String config, String channelName, String monitor) throws Exception { - + private void doTest(String config, String channelName, String monitor) { ClassPathXmlApplicationContext context = createContext(config, channelName); - try { - int before = service.getCounter(); - channel.send(new GenericMessage("bar")); + channel.send(new GenericMessage<>("bar")); assertEquals(before + 1, service.getCounter()); int count = messageHandlersMonitor.getHandlerDuration(monitor).getCount(); @@ -95,40 +97,47 @@ public class HandlerMonitoringIntegrationTests { finally { context.close(); } - } private ClassPathXmlApplicationContext createContext(String config, String channelName) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config, getClass()); - context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); + context.getAutowireCapableBeanFactory() + .autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); channel = context.getBean(channelName, MessageChannel.class); return context; } public interface Service { + void execute(String input) throws Exception; + int getCounter(); + } public static class SimpleService implements Service { + private int counter; public void execute(String input) throws Exception { Thread.sleep(10L); // make the duration non-zero - counter++; + this.counter++; } public int getCounter() { return counter; } + } @Aspect public static class HandlerInterceptor { + @Before("execution(* *..*Tests*(String)) && args(input)") public void around(String input) { logger.debug("Handling: " + input); } + } } diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.java index 603bdb0b9a..235daa5103 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaOutboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,11 @@ package org.springframework.integration.jpa.config.xml; +import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -42,11 +44,11 @@ import org.springframework.integration.jpa.core.JpaOperations; import org.springframework.integration.jpa.outbound.JpaOutboundGateway; import org.springframework.integration.jpa.support.OutboundGatewayType; import org.springframework.integration.jpa.support.PersistMode; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessagingException; +import org.springframework.messaging.support.GenericMessage; /** @@ -54,6 +56,7 @@ import org.springframework.messaging.MessagingException; * @author Amol Nayak * @author Gary Russell * @author Artem Bilan + * * @since 2.2 * */ @@ -64,21 +67,26 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice private EventDrivenConsumer consumer; @Test - public void testRetrievingJpaOutboundGatewayParser() throws Exception { + public void testRetrievingJpaOutboundGatewayParser() { setUp("JpaOutboundGatewayParserTests.xml", getClass(), "retrievingJpaOutboundGateway"); - final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); + final AbstractMessageChannel inputChannel = + TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("in", inputChannel.getComponentName()); - final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); - final OutboundGatewayType gatewayType = TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class); + final JpaOutboundGateway jpaOutboundGateway = + TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); + final OutboundGatewayType gatewayType = + TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class); assertEquals(OutboundGatewayType.RETRIEVING, gatewayType); long sendTimeout = TestUtils.getPropertyValue(jpaOutboundGateway, "messagingTemplate.sendTimeout", Long.class); assertEquals(100, sendTimeout); assertFalse(TestUtils.getPropertyValue(jpaOutboundGateway, "requiresReply", Boolean.class)); - final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class); + final JpaExecutor jpaExecutor = + TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor); final Class entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class); assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName()); - final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); + final JpaOperations jpaOperations = + TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); assertNotNull(jpaOperations); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "expectSingleResult", Boolean.class)); final LiteralExpression maxResultsExpression = @@ -91,50 +99,59 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice } @Test - public void testRetrievingJpaOutboundGatewayParserWithFirstResult() throws Exception { + public void testRetrievingJpaOutboundGatewayParserWithFirstResult() { setUp("JpaOutboundGatewayParserTests.xml", getClass(), "retrievingJpaOutboundGatewayWithFirstResult"); - final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); + final JpaOutboundGateway jpaOutboundGateway = + TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); Expression firstResultExpression = - TestUtils.getPropertyValue(jpaOutboundGateway, "jpaExecutor.firstResultExpression", Expression.class); + TestUtils.getPropertyValue(jpaOutboundGateway, "jpaExecutor.firstResultExpression", Expression.class); assertNotNull(firstResultExpression); assertEquals(LiteralExpression.class, firstResultExpression.getClass()); assertEquals("1", TestUtils.getPropertyValue(firstResultExpression, "literalValue", String.class)); } @Test - public void testRetrievingJpaOutboundGatewayParserWithFirstResultExpression() throws Exception { - setUp("JpaOutboundGatewayParserTests.xml", getClass(), "retrievingJpaOutboundGatewayWithFirstResultExpression"); - final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); + public void testRetrievingJpaOutboundGatewayParserWithFirstResultExpression() { + setUp("JpaOutboundGatewayParserTests.xml", getClass(), + "retrievingJpaOutboundGatewayWithFirstResultExpression"); + final JpaOutboundGateway jpaOutboundGateway = + TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); Expression firstResultExpression = - TestUtils.getPropertyValue(jpaOutboundGateway, "jpaExecutor.firstResultExpression", Expression.class); + TestUtils.getPropertyValue(jpaOutboundGateway, "jpaExecutor.firstResultExpression", Expression.class); assertNotNull(firstResultExpression); assertEquals(SpelExpression.class, firstResultExpression.getClass()); - assertEquals("header['firstResult']", TestUtils.getPropertyValue(firstResultExpression, "expression", String.class)); + assertEquals("header['firstResult']", + TestUtils.getPropertyValue(firstResultExpression, "expression", String.class)); } @Test - public void testRetrievingJpaOutboundGatewayParserWithMaxResultExpression() throws Exception { + public void testRetrievingJpaOutboundGatewayParserWithMaxResultExpression() { setUp("JpaOutboundGatewayParserTests.xml", getClass(), "retrievingJpaOutboundGatewayWithMaxResultExpression"); - final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); + final JpaOutboundGateway jpaOutboundGateway = + TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); Expression maxNumberOfResultExpression = - TestUtils.getPropertyValue(jpaOutboundGateway, "jpaExecutor.maxResultsExpression", Expression.class); + TestUtils.getPropertyValue(jpaOutboundGateway, "jpaExecutor.maxResultsExpression", Expression.class); assertNotNull(maxNumberOfResultExpression); assertEquals(SpelExpression.class, maxNumberOfResultExpression.getClass()); - assertEquals("header['maxResults']", TestUtils.getPropertyValue(maxNumberOfResultExpression, "expression", String.class)); + assertEquals("header['maxResults']", + TestUtils.getPropertyValue(maxNumberOfResultExpression, "expression", String.class)); } @Test - public void testUpdatingJpaOutboundGatewayParser() throws Exception { + public void testUpdatingJpaOutboundGatewayParser() { setUp("JpaOutboundGatewayParserTests.xml", getClass(), "updatingJpaOutboundGateway"); - final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); + final AbstractMessageChannel inputChannel = + TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("in", inputChannel.getComponentName()); - final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); + final JpaOutboundGateway jpaOutboundGateway = + TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); - final OutboundGatewayType gatewayType = TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class); + final OutboundGatewayType gatewayType = + TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class); assertEquals(OutboundGatewayType.UPDATING, gatewayType); @@ -144,7 +161,8 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice assertFalse(TestUtils.getPropertyValue(jpaOutboundGateway, "requiresReply", Boolean.class)); - final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class); + final JpaExecutor jpaExecutor = + TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor); @@ -152,11 +170,13 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName()); - final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); + final JpaOperations jpaOperations = + TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); assertNotNull(jpaOperations); - final Boolean usePayloadAsParameterSource = TestUtils.getPropertyValue(jpaExecutor, "usePayloadAsParameterSource", Boolean.class); + final Boolean usePayloadAsParameterSource = + TestUtils.getPropertyValue(jpaExecutor, "usePayloadAsParameterSource", Boolean.class); assertTrue(usePayloadAsParameterSource); @@ -173,33 +193,33 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice } @Test - public void advised() throws Throwable { + public void advised() { setUp("JpaOutboundGatewayParserTests.xml", getClass(), "advised"); EventDrivenConsumer jpaOutboundGatewayEndpoint = context.getBean("advised", EventDrivenConsumer.class); - MessageHandler jpaOutboundGateway = TestUtils.getPropertyValue(jpaOutboundGatewayEndpoint, "handler", MessageHandler.class); + MessageHandler jpaOutboundGateway = + TestUtils.getPropertyValue(jpaOutboundGatewayEndpoint, "handler", MessageHandler.class); FooAdvice advice = context.getBean("jpaFooAdvice", FooAdvice.class); assertTrue(AopUtils.isAopProxy(jpaOutboundGateway)); try { - jpaOutboundGateway.handleMessage(new GenericMessage("foo")); + jpaOutboundGateway.handleMessage(new GenericMessage<>("foo")); fail("expected ReplyRequiredException"); } catch (MessagingException e) { assertTrue(e instanceof ReplyRequiredException); } - Mockito.verify(advice).doInvoke(Mockito.any(ExecutionCallback.class), Mockito.any(Object.class), Mockito.any(Message.class)); + Mockito.verify(advice) + .doInvoke(Mockito.any(ExecutionCallback.class), Mockito.any(Object.class), Mockito.any(Message.class)); } @Test - public void testJpaExecutorBeanIdNaming() throws Exception { - + public void testJpaExecutorBeanIdNaming() { this.context = new ClassPathXmlApplicationContext("JpaOutboundGatewayParserTests.xml", getClass()); assertNotNull(context.getBean("retrievingJpaOutboundGateway.jpaExecutor", JpaExecutor.class)); assertNotNull(context.getBean("updatingJpaOutboundGateway.jpaExecutor", JpaExecutor.class)); - } @Test @@ -208,7 +228,9 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice this.context = new ClassPathXmlApplicationContext("JpaInvalidOutboundGatewayParserTests.xml", getClass()); } catch (BeanDefinitionStoreException e) { - assertTrue(e.getMessage().startsWith("Configuration problem: Only one of 'first-result' or 'first-result-expression' is allowed")); + assertThat(e.getMessage(), + startsWith("Configuration problem: Only one of 'first-result' " + + "or 'first-result-expression' is allowed")); return; } fail("BeanDefinitionStoreException expected."); @@ -223,12 +245,12 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice } public void setUp(String name, Class cls, String gatewayId) { - context = new ClassPathXmlApplicationContext(name, cls); - consumer = this.context.getBean(gatewayId, EventDrivenConsumer.class); + context = new ClassPathXmlApplicationContext(name, cls); + consumer = this.context.getBean(gatewayId, EventDrivenConsumer.class); } @Override - protected Object doInvoke(ExecutionCallback callback, Object target, Message message) throws Exception { + protected Object doInvoke(ExecutionCallback callback, Object target, Message message) { // Workaround for access to protected AbstractRequestHandlerAdvice.ExecutionCallback return null; } @@ -236,9 +258,10 @@ public class JpaOutboundGatewayParserTests extends AbstractRequestHandlerAdvice public static class FooAdvice extends AbstractRequestHandlerAdvice { @Override - protected Object doInvoke(ExecutionCallback callback, Object target, Message message) throws Exception { + protected Object doInvoke(ExecutionCallback callback, Object target, Message message) { return null; } } + } diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/EclipseLinkJpaOperationsTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/EclipseLinkJpaOperationsTests.java index 927b22ab48..0bc028130f 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/EclipseLinkJpaOperationsTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/EclipseLinkJpaOperationsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,13 @@ package org.springframework.integration.jpa.core; +import static org.junit.Assert.fail; + import java.text.ParseException; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -33,11 +35,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * *
  * {@code
- * -javaagent:/home//.m2/repository/org/springframework/spring-instrument/3.1.1.RELEASE/spring-instrument-3.1.1.RELEASE.jar
+ * -javaagent:/home//.m2/repository/org/springframework/spring-instrument/3.1.1.RELEASE/spring-instrument-3.1.1
+ * .RELEASE.jar
  * }
  * 
* * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.2 * */ @@ -48,7 +53,6 @@ public class EclipseLinkJpaOperationsTests extends AbstractJpaOperationsTests { @Test @Override public void testExecuteUpdateWithNativeQuery() { - try { super.testExecuteUpdateWithNativeQuery(); } @@ -56,13 +60,12 @@ public class EclipseLinkJpaOperationsTests extends AbstractJpaOperationsTests { return; } - Assert.fail("Was expecting an Exception as OpenJPA does not support Native SQL Queries with Named Parameters."); + fail("Was expecting an Exception as OpenJPA does not support Native SQL Queries with Named Parameters."); } @Test @Override public void testExecuteUpdateWithNativeNamedQuery() { - try { super.testExecuteUpdateWithNativeNamedQuery(); } @@ -70,7 +73,7 @@ public class EclipseLinkJpaOperationsTests extends AbstractJpaOperationsTests { return; } - Assert.fail("Was expecting an Exception as OpenJPA does not support Native SQL Queries with Named Parameters."); + fail("Was expecting an Exception as OpenJPA does not support Native SQL Queries with Named Parameters."); } @Test diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests-context.xml b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests-context.xml index 1d53667fab..6d0e090d22 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests-context.xml +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests-context.xml @@ -1,9 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java index 1e4471c340..81b70a2fd2 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/core/JpaExecutorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,21 @@ package org.springframework.integration.jpa.core; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import java.util.Collections; import java.util.List; import java.util.Map; + import javax.persistence.EntityManager; +import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.expression.common.LiteralExpression; @@ -36,15 +44,12 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - /** * @author Gunnar Hillert * @author Amol Nayak * @author Gary Russell * @author Artem Bilan + * * @since 2.2 */ @ContextConfiguration @@ -61,80 +66,74 @@ public class JpaExecutorTests { * In this test, the {@link JpaExecutor}'s poll method will be called without * specifying a 'query', 'namedQuery' or 'entityClass' property. This should * result in an {@link IllegalArgumentException}. - * - * @throws Exception */ @Test - public void testExecutePollWithNoEntityClassSpecified() throws Exception { - - final JpaExecutor jpaExecutor = new JpaExecutor(mock(EntityManager.class)); + public void testExecutePollWithNoEntityClassSpecified() { + JpaExecutor jpaExecutor = new JpaExecutor(mock(EntityManager.class)); jpaExecutor.afterPropertiesSet(); try { jpaExecutor.poll(); } catch (IllegalStateException e) { - Assert.assertEquals("Exception Message does not match.", + assertEquals("Exception Message does not match.", "For the polling operation, one of " + "the following properties must be specified: " + "query, namedQuery or entityClass.", e.getMessage()); return; } - Assert.fail("Was expecting an IllegalStateException to be thrown."); - + fail("Was expecting an IllegalStateException to be thrown."); } @Test public void testInstantiateJpaExecutorWithNullJpaOperations() { - JpaOperations jpaOperations = null; try { new JpaExecutor(jpaOperations); } catch (IllegalArgumentException e) { - Assert.assertEquals("jpaOperations must not be null.", e.getMessage()); + assertEquals("jpaOperations must not be null.", e.getMessage()); } - } @Test public void testSetMultipleQueryTypes() { JpaExecutor executor = new JpaExecutor(mock(EntityManager.class)); executor.setJpaQuery("select s from Student s"); - Assert.assertNotNull(TestUtils.getPropertyValue(executor, "jpaQuery", String.class)); + assertNotNull(TestUtils.getPropertyValue(executor, "jpaQuery", String.class)); try { executor.setNamedQuery("NamedQuery"); } catch (IllegalArgumentException e) { - Assert.assertEquals("You can define only one of the " + assertEquals("You can define only one of the " + "properties 'jpaQuery', 'nativeQuery', 'namedQuery'", e.getMessage()); } - Assert.assertNull(TestUtils.getPropertyValue(executor, "namedQuery")); + assertNull(TestUtils.getPropertyValue(executor, "namedQuery")); try { executor.setNativeQuery("select * from Student"); } catch (IllegalArgumentException e) { - Assert.assertEquals("You can define only one of the " + assertEquals("You can define only one of the " + "properties 'jpaQuery', 'nativeQuery', 'namedQuery'", e.getMessage()); } - Assert.assertNull(TestUtils.getPropertyValue(executor, "nativeQuery")); + assertNull(TestUtils.getPropertyValue(executor, "nativeQuery")); executor = new JpaExecutor(mock(EntityManager.class)); executor.setNamedQuery("NamedQuery"); - Assert.assertNotNull(TestUtils.getPropertyValue(executor, "namedQuery", String.class)); + assertNotNull(TestUtils.getPropertyValue(executor, "namedQuery", String.class)); try { executor.setJpaQuery("select s from Student s"); } catch (IllegalArgumentException e) { - Assert.assertEquals("You can define only one of the " + assertEquals("You can define only one of the " + "properties 'jpaQuery', 'nativeQuery', 'namedQuery'", e.getMessage()); } - Assert.assertNull(TestUtils.getPropertyValue(executor, "jpaQuery")); + assertNull(TestUtils.getPropertyValue(executor, "jpaQuery")); } @@ -146,7 +145,7 @@ public class JpaExecutorTests { MessageBuilder.withPayload(Collections.singletonMap("firstName", "First One")).build(); JpaExecutor executor = getJpaExecutorForMessageAsParamSource(query); StudentDomain student = (StudentDomain) executor.poll(message); - Assert.assertNotNull(student); + assertNotNull(student); } @Test @@ -157,7 +156,7 @@ public class JpaExecutorTests { MessageBuilder.withPayload("First One").build(); JpaExecutor executor = getJpaExecutorForPayloadAsParamSource(query); StudentDomain student = (StudentDomain) executor.poll(message); - Assert.assertNotNull(student); + assertNotNull(student); } @Test @@ -168,7 +167,7 @@ public class JpaExecutorTests { MessageBuilder.withPayload(Collections.singletonMap("firstName", "First One")).build(); JpaExecutor executor = getJpaExecutorForMessageAsParamSource(query); Integer rowsAffected = (Integer) executor.executeOutboundJpaOperation(message); - Assert.assertTrue(1 == rowsAffected); + assertEquals(1, (int) rowsAffected); } @Test @@ -179,7 +178,7 @@ public class JpaExecutorTests { MessageBuilder.withPayload("First One").build(); JpaExecutor executor = getJpaExecutorForPayloadAsParamSource(query); Integer rowsAffected = (Integer) executor.executeOutboundJpaOperation(message); - Assert.assertTrue(1 == rowsAffected); + assertEquals(1, (int) rowsAffected); } private JpaExecutor getJpaExecutorForMessageAsParamSource(String query) { @@ -211,7 +210,7 @@ public class JpaExecutorTests { } @Test - public void testResultStartingFromThirdRecordForJPAQuery() throws Exception { + public void testResultStartingFromThirdRecordForJPAQuery() { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setJpaQuery("select s from Student s"); jpaExecutor.setFirstResultExpression(new LiteralExpression("2")); @@ -219,12 +218,12 @@ public class JpaExecutorTests { jpaExecutor.afterPropertiesSet(); List results = (List) jpaExecutor.poll(MessageBuilder.withPayload("").build()); - Assert.assertNotNull(results); - Assert.assertEquals(1, results.size()); + assertNotNull(results); + assertEquals(1, results.size()); } @Test - public void testResultStartingFromThirdRecordForNativeQuery() throws Exception { + public void testResultStartingFromThirdRecordForNativeQuery() { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setNativeQuery("select * from Student s"); jpaExecutor.setFirstResultExpression(new LiteralExpression("2")); @@ -232,12 +231,12 @@ public class JpaExecutorTests { jpaExecutor.afterPropertiesSet(); List results = (List) jpaExecutor.poll(MessageBuilder.withPayload("").build()); - Assert.assertNotNull(results); - Assert.assertEquals(1, results.size()); + assertNotNull(results); + assertEquals(1, results.size()); } @Test - public void testResultStartingFromThirdRecordForNamedQuery() throws Exception { + public void testResultStartingFromThirdRecordForNamedQuery() { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setNamedQuery("selectAllStudents"); jpaExecutor.setFirstResultExpression(new LiteralExpression("2")); @@ -245,12 +244,12 @@ public class JpaExecutorTests { jpaExecutor.afterPropertiesSet(); List results = (List) jpaExecutor.poll(MessageBuilder.withPayload("").build()); - Assert.assertNotNull(results); - Assert.assertEquals(1, results.size()); + assertNotNull(results); + assertEquals(1, results.size()); } @Test - public void testResultStartingFromThirdRecordUsingEntity() throws Exception { + public void testResultStartingFromThirdRecordUsingEntity() { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setEntityClass(StudentDomain.class); jpaExecutor.setFirstResultExpression(new LiteralExpression("2")); @@ -258,8 +257,8 @@ public class JpaExecutorTests { jpaExecutor.afterPropertiesSet(); List results = (List) jpaExecutor.poll(MessageBuilder.withPayload("").build()); - Assert.assertNotNull(results); - Assert.assertEquals(1, results.size()); + assertNotNull(results); + assertEquals(1, results.size()); } @Test @@ -269,10 +268,10 @@ public class JpaExecutorTests { jpaExecutor.setMaxResultsExpression(null); } catch (Exception e) { - Assert.assertEquals("maxResultsExpression cannot be null", e.getMessage()); + assertEquals("maxResultsExpression cannot be null", e.getMessage()); return; } - Assert.fail("Expected the test case to throw an exception"); + fail("Expected the test case to throw an exception"); } } diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterTests.java index 5cea995228..51e87d2dfe 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -19,12 +19,12 @@ package org.springframework.integration.jpa.inbound; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Collection; import java.util.List; + import javax.persistence.EntityManager; import org.junit.Test; @@ -39,9 +39,9 @@ import org.springframework.integration.jpa.core.JpaExecutor; import org.springframework.integration.jpa.core.JpaOperations; import org.springframework.integration.jpa.test.Consumer; import org.springframework.integration.jpa.test.JpaTestUtils; -import org.springframework.integration.test.util.OnlyOnceTrigger; import org.springframework.integration.jpa.test.entity.StudentDomain; import org.springframework.integration.scheduling.PollerMetadata; +import org.springframework.integration.test.util.OnlyOnceTrigger; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.test.annotation.DirtiesContext; @@ -56,6 +56,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Gunnar Hillert * @author Gary Russell * @author Artem Bilan + * * @since 2.2 * */ @@ -63,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @Rollback @Transactional("transactionManager") +@DirtiesContext public class JpaPollingChannelAdapterTests { @Autowired @@ -88,8 +90,6 @@ public class JpaPollingChannelAdapterTests { /** * In this test, a Jpa Polling Channel Adapter will use a plain entity class * to retrieve a list of records from the database. - * - * @throws Exception */ @Test @DirtiesContext @@ -99,17 +99,18 @@ public class JpaPollingChannelAdapterTests { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setEntityClass(StudentDomain.class); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); final Consumer consumer = new Consumer(); @@ -124,15 +125,12 @@ public class JpaPollingChannelAdapterTests { Collection primeNumbers = message.getPayload(); - assertTrue(primeNumbers.size() == 3); - + assertEquals(3, primeNumbers.size()); } /** * In this test, a Jpa Polling Channel Adapter will use JpQL query * to retrieve a list of records from the database. - * - * @throws Exception */ @Test public void testWithJpaQuery() throws Exception { @@ -142,17 +140,18 @@ public class JpaPollingChannelAdapterTests { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setJpaQuery("from Student"); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); final Consumer consumer = new Consumer(); @@ -167,15 +166,12 @@ public class JpaPollingChannelAdapterTests { Collection primeNumbers = message.getPayload(); - assertTrue(primeNumbers.size() == 3); - + assertEquals(3, primeNumbers.size()); } /** * In this test, a Jpa Polling Channel Adapter will use JpQL query * to retrieve a list of records from the database with a maxRows value of 1. - * - * @throws Exception */ @Test public void testWithJpaQueryAndMaxResults() throws Exception { @@ -186,17 +182,18 @@ public class JpaPollingChannelAdapterTests { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setJpaQuery("from Student"); jpaExecutor.setMaxResultsExpression(new LiteralExpression("1")); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); final Consumer consumer = new Consumer(); @@ -211,15 +208,12 @@ public class JpaPollingChannelAdapterTests { Collection primeNumbers = message.getPayload(); - assertTrue(primeNumbers.size() == 1); - + assertEquals(1, primeNumbers.size()); } /** * In this test, a Jpa Polling Channel Adapter will use JpQL query * to retrieve a list of records from the database. - * - * @throws Exception */ @Test public void testWithJpaQueryOneResultOnly() throws Exception { @@ -229,16 +223,17 @@ public class JpaPollingChannelAdapterTests { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setJpaQuery("from Student s where s.firstName = 'First Two'"); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); final Consumer consumer = new Consumer(); @@ -253,7 +248,7 @@ public class JpaPollingChannelAdapterTests { Collection students = message.getPayload(); - assertTrue(students.size() == 1); + assertEquals(1, students.size()); StudentDomain student = (StudentDomain) students.iterator().next(); @@ -264,8 +259,6 @@ public class JpaPollingChannelAdapterTests { * In this test, a Jpa Polling Channel Adapter will use JpQL query * to retrieve a list of records from the database. Additionally, the records * will be deleted after the polling. - * - * @throws Exception */ @Test @DirtiesContext @@ -278,17 +271,18 @@ public class JpaPollingChannelAdapterTests { jpaExecutor.setDeleteAfterPoll(true); jpaExecutor.setDeleteInBatch(true); jpaExecutor.setFlush(true); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); final Consumer consumer = new Consumer(); @@ -303,8 +297,7 @@ public class JpaPollingChannelAdapterTests { Collection students = message.getPayload(); - assertTrue(students.size() == 3); - + assertEquals(3, students.size()); Long studentCount = waitForDeletes(students); @@ -337,35 +330,31 @@ public class JpaPollingChannelAdapterTests { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setJpaQuery("from Student s where s.lastName = 'Something Else'"); jpaExecutor.setDeleteAfterPoll(true); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); - Thread.sleep(1000); - final Consumer consumer = new Consumer(); - final List>> received = new ArrayList>>(); - received.add(consumer.poll(10000)); + final List>> received = new ArrayList<>(); + received.add(consumer.poll(100)); final Message> message = received.get(0); adapter.stop(); assertNull(message); - } /** * In this test, a Jpa Polling Channel Adapter will use JpQL query - * to retrieve a list of records from the database. Additionaly, the records + * to retrieve a list of records from the database. Additionally, the records * will be deleted after the polling. - * - * @throws Exception */ @Test @DirtiesContext @@ -377,19 +366,18 @@ public class JpaPollingChannelAdapterTests { jpaExecutor.setJpaQuery("from Student s"); jpaExecutor.setDeleteAfterPoll(true); jpaExecutor.setDeleteInBatch(false); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); - Thread.sleep(1000); - final Consumer consumer = new Consumer(); - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); received.add(consumer.poll(10000)); final Message> message = received.get(0); @@ -401,7 +389,7 @@ public class JpaPollingChannelAdapterTests { final Collection students = message.getPayload(); - assertTrue(students.size() == 3); + assertEquals(3, students.size()); Long studentCount = waitForDeletes(students); @@ -412,8 +400,6 @@ public class JpaPollingChannelAdapterTests { /** * In this test, a Jpa Polling Channel Adapter will use a Native SQL query * to retrieve a list of records from the database. - * - * @throws Exception */ @Test public void testWithNativeSqlQuery() throws Exception { @@ -423,17 +409,18 @@ public class JpaPollingChannelAdapterTests { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setNativeQuery("select * from Student where lastName = 'Last One'"); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); final Consumer consumer = new Consumer(); @@ -448,15 +435,12 @@ public class JpaPollingChannelAdapterTests { Collection students = message.getPayload(); - assertTrue(students.size() == 1); - + assertEquals(1, students.size()); } /** * In this test, a Jpa Polling Channel Adapter will use Named query * to retrieve a list of records from the database. - * - * @throws Exception */ @Test public void testWithNamedQuery() throws Exception { @@ -466,17 +450,18 @@ public class JpaPollingChannelAdapterTests { final JpaExecutor jpaExecutor = new JpaExecutor(entityManager); jpaExecutor.setNamedQuery("selectStudent"); + jpaExecutor.setBeanFactory(this.context); jpaExecutor.afterPropertiesSet(); final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter( - jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader()); + jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, getClass().getClassLoader()); adapter.start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final List>> received = new ArrayList>>(); + final List>> received = new ArrayList<>(); final Consumer consumer = new Consumer(); @@ -491,8 +476,7 @@ public class JpaPollingChannelAdapterTests { Collection students = message.getPayload(); - assertTrue(students.size() == 1); - + assertEquals(1, students.size()); } } diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java index 02068b52c9..f5114ba7dd 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,64 +16,52 @@ package org.springframework.integration.jpa.inbound; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; + import org.springframework.integration.jpa.core.JpaExecutor; /** * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.2 * */ public class JpaPollingChannelAdapterUnitTests { - /** - * - */ @Test public void testReceiveNull() { - JpaExecutor jpaExecutor = mock(JpaExecutor.class); when(jpaExecutor.poll()).thenReturn(null); - final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); + JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); assertNull(jpaPollingChannelAdapter.receive()); - } - /** - * - */ @Test public void testReceiveNotNull() { + JpaExecutor jpaExecutor = mock(JpaExecutor.class); - JpaExecutor jpaExecutor = mock(JpaExecutor.class); - - when(jpaExecutor.poll()).thenReturn("Spring"); - - final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); - assertNotNull("Expecting a Message to be returned.", jpaPollingChannelAdapter.receive()); - assertEquals("Spring", jpaPollingChannelAdapter.receive().getPayload()); + when(jpaExecutor.poll()).thenReturn("Spring"); + JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); + assertNotNull("Expecting a Message to be returned.", jpaPollingChannelAdapter.receive()); + assertEquals("Spring", jpaPollingChannelAdapter.receive().getPayload()); } - /** - * - */ @Test public void testGetComponentType() { + JpaExecutor jpaExecutor = mock(JpaExecutor.class); - JpaExecutor jpaExecutor = mock(JpaExecutor.class); - - final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); - assertEquals("jpa:inbound-channel-adapter", jpaPollingChannelAdapter.getComponentType()); - + JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor); + assertEquals("jpa:inbound-channel-adapter", jpaPollingChannelAdapter.getComponentType()); } } diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests-context.xml b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests-context.xml index 45c6134179..4a12d60548 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests-context.xml +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests-context.xml @@ -1,15 +1,10 @@ @@ -17,7 +12,7 @@ - + diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests.java index b829a8ca9f..f01bfd0784 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/outbound/JpaOutboundChannelAdapterTransactionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,34 +16,38 @@ package org.springframework.integration.jpa.outbound; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.util.List; import javax.sql.DataSource; -import org.junit.Assert; - import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.jpa.test.JpaTestUtils; import org.springframework.integration.jpa.test.entity.StudentDomain; import org.springframework.integration.support.MessageBuilder; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.2 * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@RunWith(SpringRunner.class) +@DirtiesContext public class JpaOutboundChannelAdapterTransactionalTests { @Autowired @@ -54,24 +58,25 @@ public class JpaOutboundChannelAdapterTransactionalTests { DataSource dataSource; @Test - @DirtiesContext - public void saveEntityWithTransaction() throws InterruptedException { - - List results1 = new JdbcTemplate(dataSource).queryForList("Select * from Student"); - Assert.assertNotNull(results1); - Assert.assertTrue(results1.size() == 3); + public void saveEntityWithTransaction() { + List results1 = + new JdbcTemplate(this.dataSource) + .queryForList("Select * from Student"); + assertNotNull(results1); + assertEquals(3, results1.size()); StudentDomain testStudent = JpaTestUtils.getTestStudent(); Message message = MessageBuilder.withPayload(testStudent).build(); - channel.send(message); + this.channel.send(message); - List results2 = new JdbcTemplate(dataSource).queryForList("Select * from Student"); - Assert.assertNotNull(results2); - Assert.assertTrue(results2.size() == 4); - - Assert.assertNull(testStudent.getRollNumber()); + List results2 = + new JdbcTemplate(this.dataSource) + .queryForList("Select * from Student"); + assertNotNull(results2); + assertEquals(4, results2.size()); + assertNull(testStudent.getRollNumber()); } } diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java index 4c75747377..ea335eb966 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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,6 +16,9 @@ package org.springframework.integration.xml.config; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -27,23 +30,25 @@ import org.junit.Test; import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.InputStreamResource; +import org.springframework.integration.xml.transformer.XPathTransformer; /** * @author Gunnar Hillert + * @author Artem Bilan + * * @since 2.2 */ public class ChainElementsTests { @Test public void chainXPathTransformer() throws Exception { - try { - this.bootStrap("xpath-transformer"); + bootStrap("xpath-transformer"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { @@ -59,16 +64,15 @@ public class ChainElementsTests { @Test public void chainXPathTransformerId() throws Exception { - - this.bootStrap("xpath-transformer-id"); - + try (ConfigurableApplicationContext ctx = bootStrap("xpath-transformer-id")) { + assertNotNull(ctx.getBean(XPathTransformer.class)); + } } @Test public void chainXPathRouterOrder() throws Exception { - try { - this.bootStrap("xpath-router-order"); + bootStrap("xpath-router-order"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { @@ -84,9 +88,8 @@ public class ChainElementsTests { @Test public void chainXPathTransformerPoller() throws Exception { - try { - this.bootStrap("xpath-transformer-poller"); + bootStrap("xpath-transformer-poller"); fail("Expected a BeanDefinitionParsingException to be thrown."); } catch (BeanDefinitionParsingException e) { @@ -94,23 +97,28 @@ public class ChainElementsTests { "'int-xml:xpath-transformer' must not define a 'poller' " + "sub-element when used within a chain."; final String actualMessage = e.getMessage(); - assertTrue("Error message did not start with '" + expectedMessage + - "' but instead returned: '" + actualMessage + "'", actualMessage.startsWith(expectedMessage)); + assertThat("Error message did not start with '" + expectedMessage + + "' but instead returned: '" + actualMessage + "'", actualMessage, startsWith(expectedMessage)); } } @Test public void chainXPathTransformerSuccess() throws Exception { - this.bootStrap("xpath-transformer-success"); + try (ConfigurableApplicationContext ctx = bootStrap("xpath-transformer-success")) { + assertNotNull(ctx.getBean(XPathTransformer.class)); + } } - private ApplicationContext bootStrap(String configProperty) throws Exception { + private ConfigurableApplicationContext bootStrap(String configProperty) throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); - pfb.setLocation(new ClassPathResource("org/springframework/integration/xml/config/chain-elements-config.properties")); + pfb.setLocation(new ClassPathResource( + "org/springframework/integration/xml/config/chain-elements-config.properties")); pfb.afterPropertiesSet(); Properties prop = pfb.getObject(); StringBuffer buffer = new StringBuffer(); - buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter")); + buffer.append(prop.getProperty("xmlheaders")) + .append(prop.getProperty(configProperty)) + .append(prop.getProperty("xmlfooter")); ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 449e5d9456..5c2adaeff9 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -9,6 +9,5 @@ -