Unable ImportOrder Checkstyle rule for tests

* Fix wrong import order in tests
* Polishing for not closed application contexts
* Use diamonds
* Use proper assertion operators
* Remove redundant classes
* Improve performance in JPA tests
* Fix typos
This commit is contained in:
Artem Bilan
2018-11-07 15:32:30 -05:00
parent 76c670075b
commit 648aeb8e96
110 changed files with 1540 additions and 1137 deletions

View File

@@ -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));

View File

@@ -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

View File

@@ -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 {

View File

@@ -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));
}

View File

@@ -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<String, Object> headers = stubHeaders(i, 5, 1);
input.send(new GenericMessage<Integer>(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<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) {
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber);
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, sequenceSize);
headers.put(IntegrationMessageHeaderAccessor.CORRELATION_ID, correllationId);

View File

@@ -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<String, Object> headers = stubHeaders(i, 5, 1);
input.send(new GenericMessage<Integer>(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<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) {
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, sequenceNumber);
headers.put(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, sequenceSize);
headers.put(IntegrationMessageHeaderAccessor.CORRELATION_ID, correllationId);

View File

@@ -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<String> 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<String> 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<String> payload = Collections.singletonList("foo");
return MessageBuilder.withPayload(payload).setHeader("bar", 123).build();
}
}
}

View File

@@ -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<String> list = new ArrayList<String>();
List<String> 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);
}
}

View File

@@ -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<String> list = new ArrayList<String>();
private final List<String> 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();

View File

@@ -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<List<List<String>>>(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<String> 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<List<String>>(Arrays.asList("bar", "foo"));
public void testAggregatorWithNestedRouter() {
Message<?> input = new GenericMessage<>(Arrays.asList("bar", "foo"));
List<String> result = sendAndReceiveMessage(router, 2000, input);
assertNotNull("Expected result and got null", result);
assertEquals("[[bar, foo], [bar, foo]]", result.toString());
}
private List<String> sendAndReceiveMessage(DirectChannel channel, int timeout, Message<?> input) {
MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.setReceiveTimeout(timeout);

View File

@@ -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() + "!!!";
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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<String>("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<String>("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<String>("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<String>("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<String>(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<String>(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");
}
}
}

View File

@@ -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<String> {
private final String text;
public TestSource(String text) {
this.text = text;
}
public Message<String> receive() {
return new GenericMessage<String>(this.text);
}
}

View File

@@ -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 {

View File

@@ -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<String>("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<String>("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<String>("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<String>("test1"));
channel.send(new GenericMessage<>("test1"));
}
catch (MessageDeliveryException e) {
exceptionThrown = true;
@@ -104,6 +107,7 @@ public class MessageSelectingInterceptorTests {
this.counter.incrementAndGet();
return this.shouldAccept;
}
}
}

View File

@@ -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<String>("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<String>("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<String>("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<String>("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;
}
}
}

View File

@@ -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<Object> payloads) {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
for (Object payload : payloads) {
buffer.append(payload.toString());
}

View File

@@ -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<String>("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<String>(""));
adapterInput.send(new GenericMessage<>(""));
Message<?> reply = adapterOutput.receive(0);
assertNull(reply);
}
@Test
public void filterWithSelectorImplementationAccepts() {
implementationInput.send(new GenericMessage<String>("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<String>(""));
implementationInput.send(new GenericMessage<>(""));
Message<?> reply = implementationOutput.receive(0);
assertNull(reply);
}
@Test
public void exceptionThrowingFilterAccepts() {
exceptionInput.send(new GenericMessage<String>("test"));
exceptionInput.send(new GenericMessage<>("test"));
Message<?> reply = implementationOutput.receive(0);
assertNotNull(reply);
}
@Test(expected = MessageRejectedException.class)
public void exceptionThrowingFilterRejects() {
exceptionInput.send(new GenericMessage<String>(""));
exceptionInput.send(new GenericMessage<>(""));
}
@Test
public void filterWithDiscardChannel() {
discardInput.send(new GenericMessage<String>(""));
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<String>(""));
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 {
}
}
}

View File

@@ -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<String>("test"));
input.send(new GenericMessage<>("test"));
assertNull(discard.receive(0));
assertNotNull(strings.receive(0));
}
@Test
public void routeWithUnmappedType() {
input.send(new GenericMessage<Integer>(123));
input.send(new GenericMessage<>(123));
assertNull(strings.receive(0));
assertNotNull(discard.receive(0));
}

View File

@@ -39,16 +39,16 @@
<beans:bean id="pojoSelectorBean" class="org.springframework.integration.config.SelectorChainParserTests$StubPojoSelector"/>
<beans:bean id="selector1" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector1" class="org.springframework.integration.config.StubMessageSelector"/>
<beans:bean id="selector2" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector2" parent="selector1"/>
<beans:bean id="selector3" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector3" parent="selector1"/>
<beans:bean id="selector4" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector4" parent="selector1"/>
<beans:bean id="selector5" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector5" parent="selector1"/>
<beans:bean id="selector6" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector6" parent="selector1"/>
</beans:beans>

View File

@@ -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<String>("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<MessageSelector> selectorList4 = this.getSelectors(chain4);
assertEquals(selector6, selectorList4.get(0));
assertTrue(chain1.accept(new GenericMessage<String>("test1")));
assertTrue(chain2.accept(new GenericMessage<String>("test2")));
assertTrue(chain3.accept(new GenericMessage<String>("test3")));
assertTrue(chain4.accept(new GenericMessage<String>("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;
}
}
}

View File

@@ -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<String>("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();
}
}
}

View File

@@ -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<Advice> adviceChain = new ArrayList<Advice>();
List<Advice> 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<Advice> adviceChain = new ArrayList<Advice>();
List<Advice> 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

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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<String> {
public Message<String> receive() {
return new GenericMessage<String>("test");
return new GenericMessage<>("test");
}
}

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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<String> receive() {
return new GenericMessage<String>(new Date().toString());
return new GenericMessage<>(new Date().toString());
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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";
}
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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
*/

View File

@@ -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<Expression, Expression> propertyExpressions = (Map<Expression, Expression>) accessor.getPropertyValue("propertyExpressions");
Map<Expression, Expression> propertyExpressions =
(Map<Expression, Expression>) accessor.getPropertyValue("propertyExpressions");
for (Map.Entry<Expression, Expression> 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;
}
}
}

View File

@@ -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<Expression, Expression> propertyExpressions = (Map<Expression, Expression>) accessor.getPropertyValue("propertyExpressions");
Map<Expression, Expression> propertyExpressions =
(Map<Expression, Expression>) accessor.getPropertyValue("propertyExpressions");
for (Map.Entry<Expression, Expression> 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;
}
}
}

View File

@@ -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)

View File

@@ -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));
}
}

View File

@@ -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<String, Object> enrich() {
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", 123);
headers.put("bar", "ABC");
return headers;
}
}
}

View File

@@ -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<String>("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;
}
}
}

View File

@@ -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<String, Expression> headerExpressions = TestUtils.getPropertyValue(adapter, "source.headerExpressions", Map.class);
Map<String, Expression> 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());
}
}

View File

@@ -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<MessageSelector> selectors = (List<MessageSelector>) 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;
}
}
}

View File

@@ -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<MessageHandler> handlerList1 = (List<MessageHandler>) new DirectFieldAccessor(bean1.chain).getPropertyValue("handlers");
List<MessageHandler> handlerList2 = (List<MessageHandler>) new DirectFieldAccessor(bean2.chain).getPropertyValue("handlers");
List<MessageHandler> handlerList1 =
(List<MessageHandler>) new DirectFieldAccessor(bean1.chain).getPropertyValue("handlers");
List<MessageHandler> handlerList2 =
(List<MessageHandler>) 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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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<String>("<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());

View File

@@ -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
}
}
}

View File

@@ -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<String>("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));
}
}

View File

@@ -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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("test1"));
dispatcher.dispatch(new GenericMessage<>("test1"));
}
catch (Exception e) {
// ignore
}
assertEquals(1, counter.get());
dispatcher.removeHandler(target);
dispatcher.dispatch(new GenericMessage<String>("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<String>("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<String>("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<String>("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");
}
}
}
}

View File

@@ -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<Integer> received = new ArrayList<Integer>();
List<Integer> 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<Integer> numbers = new LinkedBlockingQueue<Integer>();
private final BlockingQueue<Integer> numbers = new LinkedBlockingQueue<>();
public void receive(Integer number) {
this.numbers.add(number);

View File

@@ -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<String> sayHello(Message<?> message) {
return new GenericMessage<String>("hello " + message.getPayload());
return new GenericMessage<>("hello " + message.getPayload());
}
}

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}
}

View File

@@ -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<String>(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<String>(Arrays.asList(new String[] { "foo", "bar" }));
return new HashSet<String>(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" };

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -6,4 +6,5 @@
<bean id="generator" class="org.springframework.integration.handler.advice.SpelExpressionRetryStateGenerator">
<constructor-arg value="headers['foo']"/>
</bean>
</beans>

View File

@@ -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<String> message = MessageBuilder.withPayload("Hello, world!")
.setHeader("foo", "bar")
.setHeader("trueHeader", true)
.setHeader("falseHeader", false)
.build();
private Message<String> 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<Throwable, Boolean>(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()));
}
}

View File

@@ -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<String> 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;
}
}
}

View File

@@ -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;
* </pre>
*
* @author Dave Syer
* @author Artem Bilan
*
*/
public class MessageMatcher extends BaseMatcher<Message<?>> {
private final Object payload;
private final Map<String, Object> headers;
public MessageMatcher(Message<?> operand) {
@@ -55,7 +58,7 @@ public class MessageMatcher extends BaseMatcher<Message<?>> {
}
private Map<String, Object> getHeaders(Message<?> operand) {
HashMap<String, Object> headers = new HashMap<String, Object>(operand.getHeaders());
HashMap<String, Object> headers = new HashMap<>(operand.getHeaders());
headers.remove(MessageHeaders.ID);
headers.remove(MessageHeaders.TIMESTAMP);
return headers;
@@ -64,11 +67,13 @@ public class MessageMatcher extends BaseMatcher<Message<?>> {
public boolean matches(Object arg) {
Message<?> input = (Message<?>) arg;
Map<String, Object> 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);
}
}

View File

@@ -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<String>("test")));
assertTrue(selector.accept(new GenericMessage<>("test")));
}
@Test
public void testNonAcceptedTypeIsNotSelected() {
PayloadTypeSelector selector = new PayloadTypeSelector(Integer.class);
assertFalse(selector.accept(new GenericMessage<String>("test")));
assertFalse(selector.accept(new GenericMessage<>("test")));
}
@Test
public void testMultipleAcceptedTypes() {
PayloadTypeSelector selector = new PayloadTypeSelector(String.class, Integer.class);
assertTrue(selector.accept(new GenericMessage<String>("test1")));
assertTrue(selector.accept(new GenericMessage<Integer>(2)));
assertTrue(selector.accept(new GenericMessage<>("test1")));
assertTrue(selector.accept(new GenericMessage<>(2)));
assertFalse(selector.accept(new ErrorMessage(new RuntimeException())));
}

View File

@@ -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 {

View File

@@ -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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] {"channel1", "channel2"});
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
public List<Object> 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<String> message = new GenericMessage<String>("test");
Message<String> 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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] {"noSuchChannel"});
return Collections.singletonList("noSuchChannel");
}
};
TestChannelResolver channelResolver = new TestChannelResolver();
router.setChannelResolver(channelResolver);
Message<String> message = new GenericMessage<String>("test");
Message<String> message = new GenericMessage<>("test");
router.handleMessage(message);
}
@Test(expected = MessagingException.class)
public void channelMappingNotAvailable() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@SuppressWarnings("unchecked")
public List<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] {"noSuchChannel"});
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
public List<Object> getChannelKeys(Message<?> message) {
return Collections.singletonList("noSuchChannel");
}
};
router.setBeanFactory(mock(BeanFactory.class));
Message<String> message = new GenericMessage<String>("test");
Message<String> message = new GenericMessage<>("test");
router.handleMessage(message);
}

View File

@@ -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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<String> message1 = new GenericMessage<String>("test");
Message<Integer> message2 = new GenericMessage<Integer>(123);
Message<String> message1 = new GenericMessage<>("test");
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<>();
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setChannelMappings(payloadTypeChannelMap);
router.setBeanFactory(beanFactory);
router.setDefaultOutputChannel(defaultChannel);
Message<Integer> message = new GenericMessage<Integer>(99);
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<Integer> message = new GenericMessage<Integer>(99);
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<Integer> message = new GenericMessage<Integer>(99);
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<C1> message = new GenericMessage<C1>(new C1());
Message<C1> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<C1> message = new GenericMessage<C1>(new C1());
Message<C1> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<C1> message = new GenericMessage<C1>(new C1());
Message<C1> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<C1> message = new GenericMessage<C1>(new C1());
Message<C1> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<Integer> message = new GenericMessage<Integer>(99);
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<String> message = new GenericMessage<String>("test");
Message<String> message = new GenericMessage<>("test");
router.handleMessage(message);
}
@@ -388,7 +389,7 @@ public class PayloadTypeRouterTests {
beanFactory.registerSingleton("numberChannel", numberChannel);
beanFactory.registerSingleton("serializableChannel", serializableChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<Integer> message = new GenericMessage<Integer>(99);
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<String> message1 = new GenericMessage<String>("test");
Message<Integer> message2 = new GenericMessage<Integer>(123);
Message<String> message1 = new GenericMessage<>("test");
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<String> message1 = new GenericMessage<String>("test");
Message<Integer> message2 = new GenericMessage<Integer>(123);
Message<String> message1 = new GenericMessage<>("test");
Message<Integer> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<C1> message = new GenericMessage<C1>(new C1());
Message<C1> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<C1> message = new GenericMessage<C1>(new C1());
Message<C1> 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<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
Map<String, String> 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<C1> message = new GenericMessage<C1>(new C1());
Message<C1> 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 {
}
}

View File

@@ -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<Object> getChannelKeys(Message<?> message) {
return null;
}
};
Message<String> message = new GenericMessage<String>("test");
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
@Override
protected List<Object> getChannelKeys(Message<?> message) {
return null;
}
};
Message<String> message = new GenericMessage<>("test");
router.handleMessage(message);
}
@Test(expected = MessageDeliveryException.class)
public void nullChannelIdentifierUsingChannelResolverRaisesMessageDeliveryExceptionByDefault() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@Override
protected List<Object> getChannelKeys(Message<?> message) {
return null;
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
@Override
protected List<Object> getChannelKeys(Message<?> message) {
return null;
}
};
TestChannelResolver channelResolver = new TestChannelResolver();
router.setChannelResolver(channelResolver);
Message<String> message = new GenericMessage<String>("test");
Message<String> message = new GenericMessage<>("test");
router.handleMessage(message);
}
@Test(expected = MessageDeliveryException.class)
public void nullChannelIdentifierInListRaisesMessageDeliveryExceptionByDefault() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@Override
protected List<Object> getChannelKeys(Message<?> message) {
return Collections.singletonList(null);
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
@Override
protected List<Object> getChannelKeys(Message<?> message) {
return Collections.singletonList(null);
}
};
TestChannelResolver channelResolver = new TestChannelResolver();
router.setChannelResolver(channelResolver);
Message<String> message = new GenericMessage<String>("test");
Message<String> message = new GenericMessage<>("test");
router.handleMessage(message);
}
@Test(expected = MessageDeliveryException.class)
public void emptyChannelNameArrayRaisesMessageDeliveryExceptionByDefault() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
protected List<Object> getChannelKeys(Message<?> message) {
return new ArrayList<Object>();
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> getChannelKeys(Message<?> message) {
return new ArrayList<>();
}
};
TestChannelResolver channelResolver = new TestChannelResolver();
router.setChannelResolver(channelResolver);
Message<String> message = new GenericMessage<String>("test");
Message<String> message = new GenericMessage<>("test");
router.handleMessage(message);
}
@Test(expected = MessagingException.class)
public void channelMappingIsRequiredWhenResolvingChannelNames() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@SuppressWarnings("unchecked")
protected List<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "notImportant" });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> getChannelKeys(Message<?> message) {
return Collections.singletonList("notImportant");
}
};
router.setBeanFactory(mock(BeanFactory.class));
router.handleMessage(new GenericMessage<String>("this should fail"));
router.handleMessage(new GenericMessage<>("this should fail"));
}
@Test
public void beanFactoryWithRouter() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@SuppressWarnings("unchecked")
protected List<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "testChannel" });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "testChannel1, , testChannel2 " });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "testChannelDoesNotExist", "testChannel" });
}
};
protected List<Object> 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<String>("test"));
router.handleMessage(new GenericMessage<>("test"));
}
@Test
public void unresolvableChannelIdentifierInListAreIgnoredWhenResolutionRequiredIsFalse() {
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@SuppressWarnings("unchecked")
protected List<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "testChannelDoesNotExist", "testChannel" });
}
};
protected List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "MyChannel" });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "testing_MyChannel" });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("test"));
router.handleMessage(new GenericMessage<>("test"));
context.close();
}
@Test
public void beanFactoryWithRouterAndChannelSuffix() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@SuppressWarnings("unchecked")
protected List<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "MyChannel" });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new String[] { "MyChannel_withSuffix" });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("test"));
router.handleMessage(new GenericMessage<>("test"));
context.close();
}
@Test
public void beanFactoryWithRouterAndChannelIdentifiersInListWithinAList() {
AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {
@SuppressWarnings("unchecked")
protected List<Object> getChannelKeys(Message<?> message) {
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
List<String> channelNames1 = CollectionUtils.arrayToList(new String[] { "channel1" });
List<String> channelNames2 = CollectionUtils.arrayToList(new String[] { "channel2" });
protected List<Object> getChannelKeys(Message<?> message) {
List<Object> listWithListOfChannelNames = new ArrayList<Object>();
List<String> channelNames1 = Collections.singletonList("channel1");
List<String> channelNames2 = Collections.singletonList("channel2");
listWithListOfChannelNames.add(channelNames1);
listWithListOfChannelNames.add(channelNames2);
List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
protected List<Object> getChannelKeys(Message<?> message) {
MessageChannel[] channelNames1 = new MessageChannel[] { testChannel1 };
MessageChannel[] channelNames2 = new MessageChannel[] { testChannel2 };
MessageChannel[] channelNames1 = new MessageChannel[] { testChannel1 };
MessageChannel[] channelNames2 = new MessageChannel[] { testChannel2 };
List<Object> listWithListOfChannelNames = new ArrayList<Object>();
List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new Integer[] { 100, 200 });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("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<Object> getChannelKeys(Message<?> message) {
return CollectionUtils.arrayToList(new CustomObjectWithChannelName[] { new CustomObjectWithChannelName() });
}
};
AbstractMappingMessageRouter router =
new AbstractMappingMessageRouter() {
protected List<Object> 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<String>("test"));
router.handleMessage(new GenericMessage<>("test"));
}
}

View File

@@ -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;
}
}
}

View File

@@ -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)

View File

@@ -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);
}
}

View File

@@ -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<Integer>(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<Integer>(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<Integer>(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;
}
}
}

View File

@@ -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<MessageChannel> determineTargetChannels(Message<?> message) {
return null;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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("\\.");

View File

@@ -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<Integer> numbers = new ArrayList<Integer>();
private final List<Integer> 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(",");
}
}
}

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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";
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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();

View File

@@ -9,9 +9,9 @@ xmlheaders=\
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
xmlfooter= </beans>
file-oubound-gateway=<int:chain input-channel="fileOutboundGatewayInsideChain" output-channel="nullChannel">\
file-outbound-gateway=<int:chain input-channel="fileOutboundGatewayInsideChain" output-channel="nullChannel">\
<int-file:outbound-gateway id="myFileOutboundGateway" request-channel="request" directory="${java.io.tmpdir}/anyDir" delete-source-files="true"/>\
</int:chain>
file-oubound-gateway-input-channel=<int:chain input-channel="fileOutboundGatewayInsideChain" output-channel="nullChannel">\
file-outbound-gateway-input-channel=<int:chain input-channel="fileOutboundGatewayInsideChain" output-channel="nullChannel">\
<int-file:outbound-gateway id="myFileOutboundGateway" input-channel="request" directory="${java.io.tmpdir}/anyDir" delete-source-files="true"/>\
</int:chain>

View File

@@ -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;

View File

@@ -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);

View File

@@ -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<Object> 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);

View File

@@ -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
*
*/

View File

@@ -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<String, Object> fakeRequest = new HashMap<String, Object>();
private final Map<String, Object> fakeRequest = new HashMap<>();
public Object getAttribute(String name, int scope) {
return fakeRequest.get(name);
@@ -227,4 +247,5 @@ public class GroovyControlBusTests {
}
}
}

View File

@@ -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<String>("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<String, HeaderValueMessageProcessor<?>> 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<String>("Hello"));
assertEquals("groovy", outputB.receive(1000).getHeaders().get("TEST_HEADER"));
}
}

View File

@@ -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());
}
}
}

View File

@@ -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<String>("aardvark");
Message<?> message2 = new GenericMessage<String>("bear");
Message<?> message3 = new GenericMessage<String>("cat");
Message<?> message4 = new GenericMessage<String>("dog");
Message<?> message5 = new GenericMessage<String>("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<String>("aardvark");
Message<?> message2 = new GenericMessage<String>("bear");
Message<?> message3 = new GenericMessage<String>("cat");
Message<?> message4 = new GenericMessage<String>("dog");
Message<?> message5 = new GenericMessage<String>("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);

View File

@@ -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());
}

View File

@@ -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);

View File

@@ -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<String, Object> 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<String> 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<String, Object> map = headerMapper.toHeaders(headers);
assertTrue(map.size() == 2);
assertEquals(2, map.size());
assertEquals("foo", map.get("foo"));
assertEquals("bar", map.get("bar"));
Map<String, Object> mapOfHeaders = new HashMap<String, Object>();
Map<String, Object> 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<String> abc = headers.get("X-abc");
assertEquals("abc", abc.get(0));
List<String> personHeaders = headers.get("X-person");
@@ -244,7 +246,7 @@ public class HttpInboundGatewayParserTests {
public void testInboundGatewayWithMessageConverterDefaults() {
@SuppressWarnings("unchecked")
List<HttpMessageConverter<?>> 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<HttpMessageConverter<?>> messageConverters = TestUtils.getPropertyValue(gatewayNoDefaultConverters, "messageConverters", List.class);
List<HttpMessageConverter<?>> 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<HttpMessageConverter<?>> messageConverters = TestUtils.getPropertyValue(gatewayWithCustomAndDefaultConverters, "messageConverters", List.class);
List<HttpMessageConverter<?>> messageConverters =
TestUtils.getPropertyValue(this.gatewayWithCustomAndDefaultConverters, "messageConverters",
List.class);
//First converter should be the customized one
assertThat(messageConverters.get(0), instanceOf(SerializingHttpMessageConverter.class));

View File

@@ -9,7 +9,7 @@ xmlheaders=\
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
xmlfooter= </beans>
http-oubound-gateway=<int:chain id="httpChain" input-channel="httpOutboundGatewayInsideChain" output-channel="nullChannel">\
http-outbound-gateway=<int:chain id="httpChain" input-channel="httpOutboundGatewayInsideChain" output-channel="nullChannel">\
<int-http:outbound-gateway request-channel="requestChannel" url="http://google.com/" http-method="POST"/>\
</int:chain>

View File

@@ -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);
}
}
}

View File

@@ -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();
}

View File

@@ -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<String>("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);
}
}
}

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