INT-665: test splitter and aggregator
This commit is contained in:
@@ -33,7 +33,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -239,7 +238,6 @@ public class MethodInvokingMessageGroupProcessorTests {
|
||||
assertThat((Integer) messageCaptor.getValue().getPayload(), is(7));
|
||||
}
|
||||
|
||||
@Ignore("INT-938: it probably should work if there is a converter registered, but maybe a SpEL bug?")
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldFindSimpleAggregatorMethodWithIterator() throws Exception {
|
||||
@@ -248,8 +246,8 @@ public class MethodInvokingMessageGroupProcessorTests {
|
||||
class SimpleAggregator {
|
||||
public Integer and(Iterator<Integer> flags) {
|
||||
int result = 0;
|
||||
for (int flag = flags.next(); flags.hasNext();) {
|
||||
result = result | flag;
|
||||
while (flags.hasNext()) {
|
||||
result = result | flags.next();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.GenericMessage;
|
||||
import org.springframework.integration.core.MessageBuilder;
|
||||
import org.springframework.integration.core.StringMessage;
|
||||
|
||||
@@ -40,7 +40,6 @@ public class MethodInvokingSplitterTests {
|
||||
|
||||
private SplitterTestBean testBean = new SplitterTestBean();
|
||||
|
||||
|
||||
@Test
|
||||
public void splitStringToStringArray() throws Exception {
|
||||
StringMessage message = new StringMessage("foo.bar");
|
||||
@@ -297,6 +296,29 @@ public class MethodInvokingSplitterTests {
|
||||
assertEquals("bar", reply2.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitListPayload() throws Exception {
|
||||
class ListSplitter {
|
||||
@SuppressWarnings("unused")
|
||||
public List<String> split(List<String> list) {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
;
|
||||
GenericMessage<List<?>> message = new GenericMessage<List<?>>(Arrays.asList("foo", "bar"));
|
||||
MethodInvokingSplitter splitter = new MethodInvokingSplitter(new ListSplitter(), "split");
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
splitter.setOutputChannel(replyChannel);
|
||||
splitter.handleMessage(message);
|
||||
List<Message<?>> replies = replyChannel.clear();
|
||||
Message<?> reply1 = replies.get(0);
|
||||
assertNotNull(reply1);
|
||||
assertEquals("foo", reply1.getPayload());
|
||||
Message<?> reply2 = replies.get(1);
|
||||
assertNotNull(reply2);
|
||||
assertEquals("bar", reply2.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headerForObjectReturnValues() throws Exception {
|
||||
StringMessage message = new StringMessage("foo.bar");
|
||||
@@ -339,8 +361,7 @@ public class MethodInvokingSplitterTests {
|
||||
|
||||
@Test
|
||||
public void splitMessageHeader() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("ignored")
|
||||
.setHeader("testHeader", "foo.bar").build();
|
||||
Message<String> message = MessageBuilder.withPayload("ignored").setHeader("testHeader", "foo.bar").build();
|
||||
MethodInvokingSplitter splitter = this.getSplitter("splitHeader");
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
splitter.setOutputChannel(replyChannel);
|
||||
@@ -356,9 +377,9 @@ public class MethodInvokingSplitterTests {
|
||||
|
||||
@Test
|
||||
public void splitPayloadAndHeader() throws Exception {
|
||||
Message<String> message = MessageBuilder.withPayload("a.b")
|
||||
.setHeader("testHeader", "c.d").build();
|
||||
Method splittingMethod = this.testBean.getClass().getMethod("splitPayloadAndHeader", String.class, String.class);
|
||||
Message<String> message = MessageBuilder.withPayload("a.b").setHeader("testHeader", "c.d").build();
|
||||
Method splittingMethod = this.testBean.getClass()
|
||||
.getMethod("splitPayloadAndHeader", String.class, String.class);
|
||||
MethodInvokingSplitter splitter = new MethodInvokingSplitter(testBean, splittingMethod);
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
splitter.setOutputChannel(replyChannel);
|
||||
@@ -422,14 +443,12 @@ public class MethodInvokingSplitterTests {
|
||||
new MethodInvokingSplitter(new MultiplePublicMethodTestBean());
|
||||
}
|
||||
|
||||
|
||||
private MethodInvokingSplitter getSplitter(String methodName) throws Exception {
|
||||
Class<?> paramType = methodName.startsWith("message") ? Message.class : String.class;
|
||||
Method splittingMethod = this.testBean.getClass().getMethod(methodName, paramType);
|
||||
return new MethodInvokingSplitter(testBean, splittingMethod);
|
||||
}
|
||||
|
||||
|
||||
public static class SplitterTestBean {
|
||||
|
||||
public String[] stringToStringArray(String input) {
|
||||
@@ -491,17 +510,16 @@ public class MethodInvokingSplitterTests {
|
||||
public List<String> splitPayloadAndHeader(String payload, @Header("testHeader") String header) {
|
||||
String regex = "\\.";
|
||||
List<String> results = new ArrayList<String>();
|
||||
for (String s: payload.split(regex)) {
|
||||
for (String s : payload.split(regex)) {
|
||||
results.add(s);
|
||||
}
|
||||
for (String s: header.split(regex)) {
|
||||
for (String s : header.split(regex)) {
|
||||
results.add(s);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SingleAnnotationTestBean {
|
||||
|
||||
@Splitter
|
||||
@@ -514,7 +532,6 @@ public class MethodInvokingSplitterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class AmbiguousTypeMatchTestBean {
|
||||
|
||||
@Splitter
|
||||
@@ -528,7 +545,6 @@ public class MethodInvokingSplitterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SinglePublicMethodTestBean {
|
||||
|
||||
public String[] publicMethod(String input) {
|
||||
@@ -540,7 +556,6 @@ public class MethodInvokingSplitterTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class MultiplePublicMethodTestBean {
|
||||
|
||||
public String[] method1(String input) {
|
||||
|
||||
Reference in New Issue
Block a user