Polishing
This commit is contained in:
@@ -39,7 +39,7 @@ import org.springframework.messaging.handler.annotation.Payload;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_MESSAGE_HANDLER_METHOD_PARAMS;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_DECLARATIVE_METHOD_PARAMETERS;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
@@ -50,7 +50,7 @@ public class StreamListenerAnnotatedMethodArgumentsTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAnnotatedArguments() throws Exception {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestPojoWithAnnotatedArguments1.class,
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestPojoWithAnnotatedArguments.class,
|
||||
"--server.port=0");
|
||||
|
||||
TestPojoWithAnnotatedArguments testPojoWithAnnotatedArguments = context
|
||||
@@ -60,7 +60,7 @@ public class StreamListenerAnnotatedMethodArgumentsTests {
|
||||
sink.input().send(MessageBuilder.withPayload("{\"foo\":\"barbar" + id + "\"}")
|
||||
.setHeader("contentType", "application/json").setHeader("testHeader", "testValue").build());
|
||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments).hasSize(3);
|
||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(0)).isInstanceOf(StreamListenerTestInterfaces.FooPojo.class);
|
||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(0)).isInstanceOf(StreamListenerTestUtils.FooPojo.class);
|
||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(0)).hasFieldOrPropertyWithValue("foo",
|
||||
"barbar" + id);
|
||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(1)).isInstanceOf(Map.class);
|
||||
@@ -75,20 +75,22 @@ public class StreamListenerAnnotatedMethodArgumentsTests {
|
||||
@Test
|
||||
public void testInputAnnotationAtMethodParameter() throws Exception {
|
||||
try {
|
||||
SpringApplication.run(TestPojoWithAnnotatedArguments2.class, "--server.port=0");
|
||||
fail("Exception expected: "+ INVALID_MESSAGE_HANDLER_METHOD_PARAMS);
|
||||
SpringApplication.run(TestPojoWithInvalidInputAnnotatedArgument.class, "--server.port=0");
|
||||
fail("Exception expected: "+ INVALID_DECLARATIVE_METHOD_PARAMETERS);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
assertThat(e.getCause().getMessage()).contains(INVALID_MESSAGE_HANDLER_METHOD_PARAMS);
|
||||
assertThat(e.getCause().getMessage()).contains(INVALID_DECLARATIVE_METHOD_PARAMETERS);
|
||||
}
|
||||
}
|
||||
|
||||
@EnableBinding(Processor.class)
|
||||
@EnableAutoConfiguration
|
||||
public static class TestPojoWithAnnotatedArguments1 extends TestPojoWithAnnotatedArguments {
|
||||
public static class TestPojoWithAnnotatedArguments {
|
||||
|
||||
List<Object> receivedArguments = new ArrayList<>();
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
public void receive(@Payload StreamListenerTestInterfaces.FooPojo fooPojo,
|
||||
public void receive(@Payload StreamListenerTestUtils.FooPojo fooPojo,
|
||||
@Headers Map<String, Object> headers,
|
||||
@Header(MessageHeaders.CONTENT_TYPE) String contentType) {
|
||||
this.receivedArguments.add(fooPojo);
|
||||
@@ -99,10 +101,13 @@ public class StreamListenerAnnotatedMethodArgumentsTests {
|
||||
|
||||
@EnableBinding(Processor.class)
|
||||
@EnableAutoConfiguration
|
||||
public static class TestPojoWithAnnotatedArguments2 extends TestPojoWithAnnotatedArguments {
|
||||
public static class TestPojoWithInvalidInputAnnotatedArgument {
|
||||
|
||||
List<Object> receivedArguments = new ArrayList<>();
|
||||
|
||||
@StreamListener
|
||||
public void receive(@Input(Processor.INPUT) @Payload StreamListenerTestInterfaces.FooPojo fooPojo,
|
||||
public void receive(
|
||||
@Input(Processor.INPUT) @Payload StreamListenerTestUtils.FooPojo fooPojo,
|
||||
@Headers Map<String, Object> headers,
|
||||
@Header(MessageHeaders.CONTENT_TYPE) String contentType) {
|
||||
this.receivedArguments.add(fooPojo);
|
||||
@@ -110,8 +115,4 @@ public class StreamListenerAnnotatedMethodArgumentsTests {
|
||||
this.receivedArguments.add(contentType);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestPojoWithAnnotatedArguments {
|
||||
List<Object> receivedArguments = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ public class StreamListenerContentTypeConversionTests {
|
||||
|
||||
@Test
|
||||
public void testContentTypeConversion() throws Exception {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestSink1.class,
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestSinkWithContentTypeConversion.class,
|
||||
"--server.port=0");
|
||||
@SuppressWarnings("unchecked")
|
||||
TestSink1 testSink = context.getBean(TestSink1.class);
|
||||
TestSinkWithContentTypeConversion testSink = context.getBean(TestSinkWithContentTypeConversion.class);
|
||||
Sink sink = context.getBean(Sink.class);
|
||||
String id = UUID.randomUUID().toString();
|
||||
sink.input().send(
|
||||
@@ -59,13 +59,13 @@ public class StreamListenerContentTypeConversionTests {
|
||||
|
||||
@EnableBinding(Sink.class)
|
||||
@EnableAutoConfiguration
|
||||
public static class TestSink1 {
|
||||
public static class TestSinkWithContentTypeConversion {
|
||||
|
||||
List<StreamListenerTestInterfaces.FooPojo> receivedArguments = new ArrayList<>();
|
||||
List<StreamListenerTestUtils.FooPojo> receivedArguments = new ArrayList<>();
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@StreamListener(Sink.INPUT)
|
||||
public void receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public void receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
this.receivedArguments.add(fooPojo);
|
||||
this.latch.countDown();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class StreamListenerDuplicateMappingTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDuplicateMapping() throws Exception {
|
||||
try {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestDuplicateMapping1.class,
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestDuplicateMapping.class,
|
||||
"--server.port=0");
|
||||
fail("Exception expected on duplicate mapping");
|
||||
}
|
||||
@@ -50,14 +50,14 @@ public class StreamListenerDuplicateMappingTests {
|
||||
|
||||
@EnableBinding(Processor.class)
|
||||
@EnableAutoConfiguration
|
||||
public static class TestDuplicateMapping1 {
|
||||
public static class TestDuplicateMapping {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
public void receive(Message<String> fooMessage) {
|
||||
}
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
public void receive2(Message<String> fooMessage) {
|
||||
public void receiveDuplicateMapping(Message<String> fooMessage) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StreamListenerHandlerBeanTests {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection InputConfigs() {
|
||||
return Arrays.asList(new Class[] { TestHandlerBean1.class, TestHandlerBean2.class });
|
||||
return Arrays.asList(TestHandlerBeanWithSendTo.class, TestHandlerBean2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,11 +89,11 @@ public class StreamListenerHandlerBeanTests {
|
||||
|
||||
@EnableBinding(Processor.class)
|
||||
@EnableAutoConfiguration
|
||||
public static class TestHandlerBean1 {
|
||||
public static class TestHandlerBeanWithSendTo {
|
||||
|
||||
@Bean
|
||||
public HandlerBean1 handlerBean() {
|
||||
return new HandlerBean1();
|
||||
public HandlerBeanWithSendTo handlerBean() {
|
||||
return new HandlerBeanWithSendTo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,30 +102,30 @@ public class StreamListenerHandlerBeanTests {
|
||||
public static class TestHandlerBean2 {
|
||||
|
||||
@Bean
|
||||
public HandlerBean2 handlerBean() {
|
||||
return new HandlerBean2();
|
||||
public HandlerBeanWithOutput handlerBean() {
|
||||
return new HandlerBeanWithOutput();
|
||||
}
|
||||
}
|
||||
|
||||
public static class HandlerBean1 extends HandlerBean {
|
||||
public static class HandlerBeanWithSendTo extends HandlerBean {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@SendTo(Processor.OUTPUT)
|
||||
public StreamListenerTestInterfaces.BarPojo receive(StreamListenerTestInterfaces.FooPojo fooMessage) {
|
||||
public StreamListenerTestUtils.BarPojo receive(StreamListenerTestUtils.FooPojo fooMessage) {
|
||||
this.receivedPojos.add(fooMessage);
|
||||
StreamListenerTestInterfaces.BarPojo barPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
|
||||
barPojo.setBar(fooMessage.getFoo());
|
||||
return barPojo;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HandlerBean2 extends HandlerBean {
|
||||
public static class HandlerBeanWithOutput extends HandlerBean {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@Output(Processor.OUTPUT)
|
||||
public StreamListenerTestInterfaces.BarPojo receive(StreamListenerTestInterfaces.FooPojo fooMessage) {
|
||||
public StreamListenerTestUtils.BarPojo receive(StreamListenerTestUtils.FooPojo fooMessage) {
|
||||
this.receivedPojos.add(fooMessage);
|
||||
StreamListenerTestInterfaces.BarPojo barPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
|
||||
barPojo.setBar(fooMessage.getFoo());
|
||||
return barPojo;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class StreamListenerHandlerBeanTests {
|
||||
|
||||
public static class HandlerBean {
|
||||
|
||||
List<StreamListenerTestInterfaces.FooPojo> receivedPojos = new ArrayList<>();
|
||||
List<StreamListenerTestUtils.FooPojo> receivedPojos = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
@@ -45,14 +46,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.AMBIGUOUS_MESSAGE_HANDLER_METHOD_ARGUMENTS;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INPUT_AT_STREAM_LISTENER;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_DECLARATIVE_METHOD_PARAMETERS;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_INBOUND_NAME;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_MESSAGE_HANDLER_METHOD_PARAMS;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_OUTBOUND_NAME;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_OUTPUT_VALUES;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.NO_INPUT_DESTINATION;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.RETURN_TYPE_MULTIPLE_OUTBOUND_SPECIFIED;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.RETURN_TYPE_NO_OUTBOUND_SPECIFIED;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.TARGET_BEAN_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
@@ -61,9 +61,9 @@ import static org.springframework.cloud.stream.binding.StreamListenerErrorMessag
|
||||
public class StreamListenerHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void testMethodWIthInputOnStreamListener() throws Exception {
|
||||
public void testInvalidInputOnMethod() throws Exception {
|
||||
try {
|
||||
SpringApplication.run(TestMethodWIthInputOnStreamListener.class, "--server.port=0");
|
||||
SpringApplication.run(TestInvalidInputOnMethod.class, "--server.port=0");
|
||||
fail("Exception expected: "+ INPUT_AT_STREAM_LISTENER);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
@@ -72,7 +72,7 @@ public class StreamListenerHandlerMethodTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeWithMultipleOutput() throws Exception {
|
||||
public void testInvalidReturnTypeWithSendToAndOutput() throws Exception {
|
||||
try {
|
||||
SpringApplication.run(TestReturnTypeWithMultipleOutput.class, "--server.port=0");
|
||||
fail("Exception expected: "+ RETURN_TYPE_MULTIPLE_OUTBOUND_SPECIFIED);
|
||||
@@ -83,9 +83,9 @@ public class StreamListenerHandlerMethodTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeWithNoOutput() throws Exception {
|
||||
public void testInvalidReturnTypeWithNoOutput() throws Exception {
|
||||
try {
|
||||
SpringApplication.run(TestReturnTypeWithNoOutput.class, "--server.port=0");
|
||||
SpringApplication.run(TestInvalidReturnTypeWithNoOutput.class, "--server.port=0");
|
||||
fail("Exception expected: " + RETURN_TYPE_NO_OUTBOUND_SPECIFIED);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
@@ -94,9 +94,9 @@ public class StreamListenerHandlerMethodTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodInputAnnotationWithNoValue() throws Exception {
|
||||
public void testInvalidInputAnnotationWithNoValue() throws Exception {
|
||||
try {
|
||||
SpringApplication.run(TestMethodInputAnnotationWithNoValue.class, "--server.port=0");
|
||||
SpringApplication.run(TestInvalidInputAnnotationWithNoValue.class, "--server.port=0");
|
||||
fail("Exception expected: "+ INVALID_INBOUND_NAME);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
@@ -105,9 +105,9 @@ public class StreamListenerHandlerMethodTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodOutputAnnotationWithNoValue() throws Exception {
|
||||
public void testInvalidOutputAnnotationWithNoValue() throws Exception {
|
||||
try {
|
||||
SpringApplication.run(TestMethodOutputAnnotationWithNoValue.class, "--server.port=0");
|
||||
SpringApplication.run(TestInvalidOutputAnnotationWithNoValue.class, "--server.port=0");
|
||||
fail("Exception expected: "+ INVALID_OUTBOUND_NAME);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
@@ -122,7 +122,8 @@ public class StreamListenerHandlerMethodTests {
|
||||
fail("Exception expected on using invalid inbound name");
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
assertThat(e.getCause().getMessage()).contains(TARGET_BEAN_NOT_EXISTS + ": invalid");
|
||||
assertThat(e.getCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
assertThat(e.getCause()).hasMessageContaining("'invalid'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +134,8 @@ public class StreamListenerHandlerMethodTests {
|
||||
fail("Exception expected on using invalid outbound name");
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
assertThat(e.getCause().getMessage()).contains(TARGET_BEAN_NOT_EXISTS + ": invalid");
|
||||
assertThat(e.getCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
assertThat(e.getCause()).hasMessageContaining("'invalid'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,10 +165,10 @@ public class StreamListenerHandlerMethodTests {
|
||||
public void testMethodWithInputAsMethodAndParameter() throws Exception {
|
||||
try {
|
||||
SpringApplication.run(TestMethodWithInputAsMethodAndParameter.class, "--server.port=0");
|
||||
fail("Exception expected: " + INVALID_MESSAGE_HANDLER_METHOD_PARAMS);
|
||||
fail("Exception expected: " + INVALID_DECLARATIVE_METHOD_PARAMETERS);
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
assertThat(e.getCause().getMessage()).contains(INVALID_MESSAGE_HANDLER_METHOD_PARAMS);
|
||||
assertThat(e.getCause().getMessage()).contains(INVALID_DECLARATIVE_METHOD_PARAMETERS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +198,7 @@ public class StreamListenerHandlerMethodTests {
|
||||
public void testMethodWithMultipleInputParameters() throws Exception {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestMethodWithMultipleInputParameters.class, "--server.port=0");
|
||||
Processor processor = context.getBean(Processor.class);
|
||||
StreamListenerTestInterfaces.FooInboundChannel1 inboundChannel2 = context.getBean(StreamListenerTestInterfaces.FooInboundChannel1.class);
|
||||
StreamListenerTestUtils.FooInboundChannel1 inboundChannel2 = context.getBean(StreamListenerTestUtils.FooInboundChannel1.class);
|
||||
String id = UUID.randomUUID().toString();
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
((SubscribableChannel) processor.output()).subscribe(new MessageHandler() {
|
||||
@@ -219,7 +221,7 @@ public class StreamListenerHandlerMethodTests {
|
||||
ConfigurableApplicationContext context = SpringApplication.run(TestMethodWithMultipleOutputParameters.class, "--server.port=0");
|
||||
Processor processor = context.getBean(Processor.class);
|
||||
String id = UUID.randomUUID().toString();
|
||||
StreamListenerTestInterfaces.FooOutboundChannel1 source2 = context.getBean(StreamListenerTestInterfaces.FooOutboundChannel1.class);
|
||||
StreamListenerTestUtils.FooOutboundChannel1 source2 = context.getBean(StreamListenerTestUtils.FooOutboundChannel1.class);
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
((SubscribableChannel) processor.output()).subscribe(new MessageHandler() {
|
||||
@Override
|
||||
@@ -243,13 +245,13 @@ public class StreamListenerHandlerMethodTests {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@EnableBinding({Processor.class, StreamListenerTestInterfaces.FooOutboundChannel1.class})
|
||||
@EnableBinding({Processor.class, StreamListenerTestUtils.FooOutboundChannel1.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestMethodWithMultipleOutputParameters {
|
||||
|
||||
@StreamListener
|
||||
public void receive(@Input(Processor.INPUT) SubscribableChannel input, @Output(Processor.OUTPUT) final MessageChannel output1,
|
||||
@Output(StreamListenerTestInterfaces.FooOutboundChannel1.OUTPUT) final MessageChannel output2) {
|
||||
@Output(StreamListenerTestUtils.FooOutboundChannel1.OUTPUT) final MessageChannel output2) {
|
||||
input.subscribe(new MessageHandler() {
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
@@ -269,17 +271,17 @@ public class StreamListenerHandlerMethodTests {
|
||||
public static class TestMethodWithoutInput {
|
||||
|
||||
@StreamListener
|
||||
public void receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public void receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableBinding({Sink.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestMethodWIthInputOnStreamListener {
|
||||
public static class TestInvalidInputOnMethod {
|
||||
|
||||
@StreamListener
|
||||
@Input(Sink.INPUT)
|
||||
public void receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public void receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +290,7 @@ public class StreamListenerHandlerMethodTests {
|
||||
public static class TestAmbiguousMethodArguments1 {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
public void receive(@Payload StreamListenerTestInterfaces.FooPojo fooPojo, String value) {
|
||||
public void receive(@Payload StreamListenerTestUtils.FooPojo fooPojo, String value) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,24 +299,24 @@ public class StreamListenerHandlerMethodTests {
|
||||
public static class TestAmbiguousMethodArguments2 {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
public void receive(@Payload StreamListenerTestInterfaces.FooPojo fooPojo, @Payload StreamListenerTestInterfaces.BarPojo barPojo) {
|
||||
public void receive(@Payload StreamListenerTestUtils.FooPojo fooPojo, @Payload StreamListenerTestUtils.BarPojo barPojo) {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableBinding({Processor.class, StreamListenerTestInterfaces.FooOutboundChannel1.class})
|
||||
@EnableBinding({Processor.class, StreamListenerTestUtils.FooOutboundChannel1.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestReturnTypeWithMultipleOutput {
|
||||
|
||||
@StreamListener
|
||||
public String receive(@Input(Processor.INPUT) SubscribableChannel input1, @Output(Processor.OUTPUT) MessageChannel output1,
|
||||
@Output(StreamListenerTestInterfaces.FooOutboundChannel1.OUTPUT) MessageChannel output2) {
|
||||
@Output(StreamListenerTestUtils.FooOutboundChannel1.OUTPUT) MessageChannel output2) {
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
|
||||
@EnableBinding({Processor.class, StreamListenerTestInterfaces.FooOutboundChannel1.class})
|
||||
@EnableBinding({Processor.class, StreamListenerTestUtils.FooOutboundChannel1.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestReturnTypeWithNoOutput {
|
||||
public static class TestInvalidReturnTypeWithNoOutput {
|
||||
|
||||
@StreamListener
|
||||
public String receive(@Input(Processor.INPUT) SubscribableChannel input1) {
|
||||
@@ -324,7 +326,7 @@ public class StreamListenerHandlerMethodTests {
|
||||
|
||||
@EnableBinding({Processor.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestMethodInputAnnotationWithNoValue {
|
||||
public static class TestInvalidInputAnnotationWithNoValue {
|
||||
|
||||
@StreamListener
|
||||
public void receive(@Input SubscribableChannel input) {
|
||||
@@ -333,7 +335,7 @@ public class StreamListenerHandlerMethodTests {
|
||||
|
||||
@EnableBinding({Processor.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestMethodOutputAnnotationWithNoValue {
|
||||
public static class TestInvalidOutputAnnotationWithNoValue {
|
||||
|
||||
@StreamListener
|
||||
public void receive(@Input(Processor.OUTPUT) SubscribableChannel input, @Output MessageChannel output) {
|
||||
@@ -363,16 +365,16 @@ public class StreamListenerHandlerMethodTests {
|
||||
public static class TestMethodWithInputAsMethodAndParameter {
|
||||
|
||||
@StreamListener
|
||||
public void receive(@Input(Sink.INPUT) StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public void receive(@Input(Sink.INPUT) StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableBinding({Processor.class, StreamListenerTestInterfaces.FooOutboundChannel1.class})
|
||||
@EnableBinding({Processor.class, StreamListenerTestUtils.FooOutboundChannel1.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestMethodWithOutputAsMethodAndParameter {
|
||||
|
||||
@StreamListener
|
||||
@Output(StreamListenerTestInterfaces.FooOutboundChannel1.OUTPUT)
|
||||
@Output(StreamListenerTestUtils.FooOutboundChannel1.OUTPUT)
|
||||
public void receive(@Input(Processor.INPUT) SubscribableChannel input, @Output(Processor.OUTPUT) final MessageChannel output1) {
|
||||
input.subscribe(new MessageHandler() {
|
||||
@Override
|
||||
@@ -383,12 +385,12 @@ public class StreamListenerHandlerMethodTests {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableBinding({Processor.class, StreamListenerTestInterfaces.FooInboundChannel1.class})
|
||||
@EnableBinding({Processor.class, StreamListenerTestUtils.FooInboundChannel1.class})
|
||||
@EnableAutoConfiguration
|
||||
public static class TestMethodWithMultipleInputParameters {
|
||||
|
||||
@StreamListener
|
||||
public void receive(@Input(Processor.INPUT) SubscribableChannel input1, @Input(StreamListenerTestInterfaces.FooInboundChannel1.INPUT) SubscribableChannel input2,
|
||||
public void receive(@Input(Processor.INPUT) SubscribableChannel input1, @Input(StreamListenerTestUtils.FooInboundChannel1.INPUT) SubscribableChannel input2,
|
||||
final @Output(Processor.OUTPUT) MessageChannel output) {
|
||||
input1.subscribe(new MessageHandler() {
|
||||
@Override
|
||||
|
||||
@@ -72,7 +72,7 @@ public class StreamListenerMessageArgumentTests {
|
||||
.getBean(TestPojoWithMessageArgument.class);
|
||||
assertThat(testPojoWithMessageArgument.receivedMessages).hasSize(1);
|
||||
assertThat(testPojoWithMessageArgument.receivedMessages.get(0).getPayload()).isEqualTo("barbar" + id);
|
||||
Message<StreamListenerTestInterfaces.BarPojo> message = (Message<StreamListenerTestInterfaces.BarPojo>) collector
|
||||
Message<StreamListenerTestUtils.BarPojo> message = (Message<StreamListenerTestUtils.BarPojo>) collector
|
||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().getBar()).isEqualTo("barbar" + id);
|
||||
@@ -85,9 +85,9 @@ public class StreamListenerMessageArgumentTests {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@SendTo(Processor.OUTPUT)
|
||||
public StreamListenerTestInterfaces.BarPojo receive(Message<String> fooMessage) {
|
||||
public StreamListenerTestUtils.BarPojo receive(Message<String> fooMessage) {
|
||||
this.receivedMessages.add(fooMessage);
|
||||
StreamListenerTestInterfaces.BarPojo barPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
|
||||
barPojo.setBar(fooMessage.getPayload());
|
||||
return barPojo;
|
||||
}
|
||||
@@ -99,9 +99,9 @@ public class StreamListenerMessageArgumentTests {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@Output(Processor.OUTPUT)
|
||||
public StreamListenerTestInterfaces.BarPojo receive(Message<String> fooMessage) {
|
||||
public StreamListenerTestUtils.BarPojo receive(Message<String> fooMessage) {
|
||||
this.receivedMessages.add(fooMessage);
|
||||
StreamListenerTestInterfaces.BarPojo barPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
|
||||
barPojo.setBar(fooMessage.getPayload());
|
||||
return barPojo;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class StreamListenerMethodReturnWithConversionTests extends Suite {
|
||||
TestPojoWithMimeType testPojoWithMimeType = context.getBean(TestPojoWithMimeType.class);
|
||||
assertThat(testPojoWithMimeType.receivedPojos).hasSize(1);
|
||||
assertThat(testPojoWithMimeType.receivedPojos.get(0)).hasFieldOrPropertyWithValue("foo", "barbar" + id);
|
||||
Message<StreamListenerTestInterfaces.BarPojo> message = (Message<StreamListenerTestInterfaces.BarPojo>) collector.forChannel(processor.output()).poll(1,
|
||||
Message<StreamListenerTestUtils.BarPojo> message = (Message<StreamListenerTestUtils.BarPojo>) collector.forChannel(processor.output()).poll(1,
|
||||
TimeUnit.SECONDS);
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().getBar()).isEqualTo("barbar" + id);
|
||||
@@ -135,9 +135,9 @@ public class StreamListenerMethodReturnWithConversionTests extends Suite {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@SendTo(Processor.OUTPUT)
|
||||
public StreamListenerTestInterfaces.BarPojo receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public StreamListenerTestUtils.BarPojo receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
this.receivedPojos.add(fooPojo);
|
||||
StreamListenerTestInterfaces.BarPojo barPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
|
||||
barPojo.setBar(fooPojo.getFoo());
|
||||
return barPojo;
|
||||
}
|
||||
@@ -149,16 +149,16 @@ public class StreamListenerMethodReturnWithConversionTests extends Suite {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@Output(Processor.OUTPUT)
|
||||
public StreamListenerTestInterfaces.BarPojo receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public StreamListenerTestUtils.BarPojo receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
this.receivedPojos.add(fooPojo);
|
||||
StreamListenerTestInterfaces.BarPojo barPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
|
||||
barPojo.setBar(fooPojo.getFoo());
|
||||
return barPojo;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestPojoWithMimeType {
|
||||
List<StreamListenerTestInterfaces.FooPojo> receivedPojos = new ArrayList<>();
|
||||
List<StreamListenerTestUtils.FooPojo> receivedPojos = new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class StreamListenerMethodWithReturnMessageTests {
|
||||
.getBean(TestPojoWithMessageReturn.class);
|
||||
assertThat(testPojoWithMessageReturn.receivedPojos).hasSize(1);
|
||||
assertThat(testPojoWithMessageReturn.receivedPojos.get(0)).hasFieldOrPropertyWithValue("foo", "barbar" + id);
|
||||
Message<StreamListenerTestInterfaces.BarPojo> message = (Message<StreamListenerTestInterfaces.BarPojo>) collector
|
||||
Message<StreamListenerTestUtils.BarPojo> message = (Message<StreamListenerTestUtils.BarPojo>) collector
|
||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().getBar()).isEqualTo("barbar" + id);
|
||||
@@ -86,9 +86,9 @@ public class StreamListenerMethodWithReturnMessageTests {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@SendTo(Processor.OUTPUT)
|
||||
public Message<?> receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public Message<?> receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
this.receivedPojos.add(fooPojo);
|
||||
StreamListenerTestInterfaces.BarPojo barPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
|
||||
barPojo.setBar(fooPojo.getFoo());
|
||||
return MessageBuilder.withPayload(barPojo).setHeader("foo", "bar").build();
|
||||
}
|
||||
@@ -100,16 +100,16 @@ public class StreamListenerMethodWithReturnMessageTests {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@Output(Processor.OUTPUT)
|
||||
public Message<?> receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public Message<?> receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
this.receivedPojos.add(fooPojo);
|
||||
StreamListenerTestInterfaces.BarPojo bazPojo = new StreamListenerTestInterfaces.BarPojo();
|
||||
StreamListenerTestUtils.BarPojo bazPojo = new StreamListenerTestUtils.BarPojo();
|
||||
bazPojo.setBar(fooPojo.getFoo());
|
||||
return MessageBuilder.withPayload(bazPojo).setHeader("foo", "bar").build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestPojoWithMessageReturn {
|
||||
List<StreamListenerTestInterfaces.FooPojo> receivedPojos = new ArrayList<>();
|
||||
List<StreamListenerTestUtils.FooPojo> receivedPojos = new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class StreamListenerMethodWithReturnValueTests {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@SendTo(Processor.OUTPUT)
|
||||
public String receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public String receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
this.receivedPojos.add(fooPojo);
|
||||
return fooPojo.getFoo();
|
||||
}
|
||||
@@ -98,14 +98,14 @@ public class StreamListenerMethodWithReturnValueTests {
|
||||
|
||||
@StreamListener(Processor.INPUT)
|
||||
@Output(Processor.OUTPUT)
|
||||
public String receive(StreamListenerTestInterfaces.FooPojo fooPojo) {
|
||||
public String receive(StreamListenerTestUtils.FooPojo fooPojo) {
|
||||
this.receivedPojos.add(fooPojo);
|
||||
return fooPojo.getFoo();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestStringProcessor {
|
||||
List<StreamListenerTestInterfaces.FooPojo> receivedPojos = new ArrayList<>();
|
||||
List<StreamListenerTestUtils.FooPojo> receivedPojos = new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.messaging.SubscribableChannel;
|
||||
/**
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
public class StreamListenerTestInterfaces {
|
||||
public class StreamListenerTestUtils {
|
||||
|
||||
public static class FooPojo {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
@@ -39,7 +40,6 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.INVALID_DECLARATIVE_METHOD_PARAMETERS;
|
||||
import static org.springframework.cloud.stream.binding.StreamListenerErrorMessages.TARGET_BEAN_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
@@ -71,7 +71,8 @@ public class StreamListenerWithAnnotatedInputOutputArgsTests {
|
||||
fail("Exception expected on using invalid bindable target as method parameter");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e.getMessage()).contains(TARGET_BEAN_NOT_EXISTS + ": invalid");
|
||||
assertThat(e.getCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
assertThat(e.getCause()).hasMessageContaining("'invalid'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user