diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/utils/MessageChannelBeanDefinitionRegistryUtils.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/utils/MessageChannelBeanDefinitionRegistryUtils.java index 9274a87b5..6941a3d96 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/utils/MessageChannelBeanDefinitionRegistryUtils.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/utils/MessageChannelBeanDefinitionRegistryUtils.java @@ -94,12 +94,12 @@ public abstract class MessageChannelBeanDefinitionRegistryUtils { Input input = AnnotationUtils.findAnnotation(method, Input.class); if (input != null) { String name = getName(input, method); - registerInputChannelBeanDefinition(name, input.value(), registry); + registerInputChannelBeanDefinition(input.value(), name, registry); } Output output = AnnotationUtils.findAnnotation(method, Output.class); if (output != null) { String name = getName(output, method); - registerOutputChannelBeanDefinition(name, output.value(), registry); + registerOutputChannelBeanDefinition(output.value(), name, registry); } } diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceBindingTestsWithBindingTargets.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceBindingTestsWithBindingTargets.java new file mode 100644 index 000000000..2089d5a0b --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceBindingTestsWithBindingTargets.java @@ -0,0 +1,70 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(ArbitraryInterfaceBindingTestsWithBindingTargets.TestFooChannels.class) +public class ArbitraryInterfaceBindingTestsWithBindingTargets { + + @Autowired + @ModuleChannels(ArbitraryInterfaceBindingTestsWithBindingTargets.TestFooChannels.class) + public FooChannels fooChannels; + + @Autowired + private Binder binder; + + @Test + public void testArbitraryInterfaceChannelsBound() { + verify(binder).bindConsumer(eq("someQueue.0"), eq(fooChannels.foo()), Mockito.any()); + verify(binder).bindConsumer(eq("someQueue.1"), eq(fooChannels.bar()), Mockito.any()); + verify(binder).bindProducer(eq("someQueue.2"), eq(fooChannels.baz()), Mockito.any()); + verify(binder).bindProducer(eq("someQueue.3"), eq(fooChannels.qux()), Mockito.any()); + verifyNoMoreInteractions(binder); + } + + @EnableModule(FooChannels.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + @PropertySource("classpath:/org/springframework/cloud/stream/binder/arbitrary-binding-test.properties") + public static class TestFooChannels { + + } + +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceBindingTestsWithDefaults.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceBindingTestsWithDefaults.java new file mode 100644 index 000000000..280150980 --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceBindingTestsWithDefaults.java @@ -0,0 +1,68 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(ArbitraryInterfaceBindingTestsWithDefaults.TestFooChannels.class) +public class ArbitraryInterfaceBindingTestsWithDefaults { + + @Autowired + @ModuleChannels(ArbitraryInterfaceBindingTestsWithDefaults.TestFooChannels.class) + public FooChannels fooChannels; + + @Autowired + private Binder binder; + + @Test + public void testArbitraryInterfaceChannelsBound() { + verify(binder).bindConsumer(eq("foo"), eq(fooChannels.foo()), Mockito.any()); + verify(binder).bindConsumer(eq("bar"), eq(fooChannels.bar()), Mockito.any()); + verify(binder).bindProducer(eq("baz"), eq(fooChannels.baz()), Mockito.any()); + verify(binder).bindProducer(eq("qux"), eq(fooChannels.qux()), Mockito.any()); + verifyNoMoreInteractions(binder); + } + + @EnableModule(FooChannels.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + public static class TestFooChannels { + + } + +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/FooChannels.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/FooChannels.java new file mode 100644 index 000000000..341307961 --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/FooChannels.java @@ -0,0 +1,39 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import org.springframework.cloud.stream.annotation.Input; +import org.springframework.cloud.stream.annotation.Output; +import org.springframework.messaging.MessageChannel; + +/** + * @author Marius Bogoevici + */ +public interface FooChannels { + + @Input + MessageChannel foo(); + + @Input + MessageChannel bar(); + + @Output + MessageChannel baz(); + + @Output + MessageChannel qux(); +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingTestsWithBindingTargets.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingTestsWithBindingTargets.java new file mode 100644 index 000000000..cf39fb729 --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingTestsWithBindingTargets.java @@ -0,0 +1,65 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.annotation.Processor; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(ProcessorBindingTestsWithBindingTargets.TestProcessor.class) +public class ProcessorBindingTestsWithBindingTargets { + + @Autowired + private Binder binder; + + @Autowired @ModuleChannels(TestProcessor.class) + private Processor testProcessor; + + @Test + public void testSourceOutputChannelBound() { + verify(binder).bindConsumer(eq("testtock.0"), eq(testProcessor.input()), Mockito.any()); + verify(binder).bindProducer(eq("testtock.1"), eq(testProcessor.output()), Mockito.any()); + } + + @EnableModule(Processor.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + @PropertySource("classpath:/org/springframework/cloud/stream/binder/processor-binding-test.properties") + public static class TestProcessor { + + } +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingTestsWithDefaults.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingTestsWithDefaults.java new file mode 100644 index 000000000..7db626371 --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingTestsWithDefaults.java @@ -0,0 +1,65 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.util.Properties; + +import org.apache.catalina.core.ApplicationContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.annotation.Processor; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(ProcessorBindingTestsWithDefaults.TestProcessor.class) +public class ProcessorBindingTestsWithDefaults { + + @Autowired + private Binder binder; + + @Autowired @ModuleChannels(TestProcessor.class) + private Processor processor; + + @Test + public void testSourceOutputChannelBound() { + Mockito.verify(binder).bindConsumer(eq("input"), eq(processor.input()), Mockito.any()); + Mockito.verify(binder).bindProducer(eq("output"), eq(processor.output()), Mockito.any()); + verifyNoMoreInteractions(binder); + } + + @EnableModule(Processor.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + public static class TestProcessor { + + } +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingTestsWithBindingTargets.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingTestsWithBindingTargets.java new file mode 100644 index 000000000..764780972 --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingTestsWithBindingTargets.java @@ -0,0 +1,66 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.annotation.Sink; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(SinkBindingTestsWithBindingTargets.TestSink.class) +public class SinkBindingTestsWithBindingTargets { + + @Autowired + private Binder binder; + + @Autowired @ModuleChannels(TestSink.class) + private Sink testSink; + + @Test + public void testSourceOutputChannelBound() { + verify(binder).bindConsumer(eq("testtock"), eq(testSink.input()), Mockito.any()); + verifyNoMoreInteractions(binder); + } + + @EnableModule(Sink.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + @PropertySource("classpath:/org/springframework/cloud/stream/binder/sink-binding-test.properties") + public static class TestSink { + + } +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingTestsWithDefaults.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingTestsWithDefaults.java new file mode 100644 index 000000000..6acf3d93f --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingTestsWithDefaults.java @@ -0,0 +1,65 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.annotation.Processor; +import org.springframework.cloud.stream.annotation.Sink; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(SinkBindingTestsWithDefaults.TestSink.class) +public class SinkBindingTestsWithDefaults { + + @Autowired + private Binder binder; + + @Autowired @ModuleChannels(TestSink.class) + private Sink testSink; + + @Test + public void testSourceOutputChannelBound() { + verify(binder).bindConsumer(eq("input"), eq(testSink.input()), Mockito.any()); + verifyNoMoreInteractions(binder); + } + + @EnableModule(Sink.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + public static class TestSink { + + } +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingTestsWithBindingTargets.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingTestsWithBindingTargets.java new file mode 100644 index 000000000..08df2a56b --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingTestsWithBindingTargets.java @@ -0,0 +1,66 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.annotation.Source; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(SourceBindingTestsWithBindingTargets.TestSource.class) +public class SourceBindingTestsWithBindingTargets { + + @Autowired + private Binder binder; + + @Autowired @ModuleChannels(TestSource.class) + private Source testSource; + + @Test + public void testSourceOutputChannelBound() { + verify(binder).bindProducer(eq("testtock"), eq(testSource.output()), Mockito.any()); + verifyNoMoreInteractions(binder); + } + + @EnableModule(Source.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + @PropertySource("classpath:/org/springframework/cloud/stream/binder/source-binding-test.properties") + public static class TestSource { + + } +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingTestsWithDefaults.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingTestsWithDefaults.java new file mode 100644 index 000000000..728ecdd3e --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingTestsWithDefaults.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 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.cloud.stream.binder; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.annotation.Source; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(SourceBindingTestsWithDefaults.TestSource.class) +public class SourceBindingTestsWithDefaults { + + @Autowired + private Binder binder; + + @Autowired @ModuleChannels(TestSource.class) + private Source testSource; + + @Test + public void testSourceOutputChannelBound() { + verify(binder).bindProducer(eq("output"), eq(testSource.output()), Mockito.any()); + verifyNoMoreInteractions(binder); + } + + @EnableModule(Source.class) + @EnableAutoConfiguration + @Import(MockBinderConfiguration.class) + public static class TestSource { + + } +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/interceptor/BoundChannelsInterceptedTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/interceptor/BoundChannelsInterceptedTest.java new file mode 100644 index 000000000..2f833272e --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/interceptor/BoundChannelsInterceptedTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2015 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.cloud.stream.interceptor; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.stream.annotation.EnableModule; +import org.springframework.cloud.stream.annotation.ModuleChannels; +import org.springframework.cloud.stream.annotation.Sink; +import org.springframework.cloud.stream.utils.MockBinderConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.integration.config.GlobalChannelInterceptor; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.ChannelInterceptor; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Verifies that interceptors used by modules are applied correctly to generated channels. + * + * @author Marius Bogoevici + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(BoundChannelsInterceptedTest.Foo.class) +public class BoundChannelsInterceptedTest { + + public static final Message TEST_MESSAGE = MessageBuilder.withPayload("bar").build(); + + @Autowired + ChannelInterceptor channelInterceptor; + + @Autowired + @ModuleChannels(BoundChannelsInterceptedTest.Foo.class) + public Sink fooSink; + + @Test + public void testBoundChannelsIntercepted() { + fooSink.input().send(TEST_MESSAGE); + verify(channelInterceptor).preSend(TEST_MESSAGE, fooSink.input()); + verifyNoMoreInteractions(channelInterceptor); + } + + + @SpringBootApplication + @EnableModule(Sink.class) + @Import(MockBinderConfiguration.class) + public static class Foo { + + @ServiceActivator(inputChannel = Sink.INPUT) + public void fooSink(Message message) { + } + + @GlobalChannelInterceptor @Bean + public ChannelInterceptor globalChannelInterceptor() { + return mock(ChannelInterceptor.class); + } + + } +} diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/utils/MockBinderConfiguration.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/utils/MockBinderConfiguration.java new file mode 100644 index 000000000..c50d54651 --- /dev/null +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/utils/MockBinderConfiguration.java @@ -0,0 +1,35 @@ +/* + * Copyright 2015 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.cloud.stream.utils; + +import org.mockito.Mockito; + +import org.springframework.cloud.stream.binder.Binder; +import org.springframework.context.annotation.Bean; + +/** + * A simple configuration that creates mock {@link org.springframework.cloud.stream.binder.Binder}s. + * + * @author Marius Bogoevici + */ +public class MockBinderConfiguration { + + @Bean + public Binder binder() { + return Mockito.mock(Binder.class); + } +} diff --git a/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/arbitrary-binding-test.properties b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/arbitrary-binding-test.properties new file mode 100644 index 000000000..3b26bca97 --- /dev/null +++ b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/arbitrary-binding-test.properties @@ -0,0 +1,4 @@ +spring.cloud.stream.bindings.foo=someQueue.0 +spring.cloud.stream.bindings.bar=someQueue.1 +spring.cloud.stream.bindings.baz=someQueue.2 +spring.cloud.stream.bindings.qux=someQueue.3 diff --git a/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/processor-binding-test.properties b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/processor-binding-test.properties new file mode 100644 index 000000000..5551f2a31 --- /dev/null +++ b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/processor-binding-test.properties @@ -0,0 +1,2 @@ +spring.cloud.stream.bindings.input=testtock.0 +spring.cloud.stream.bindings.output=testtock.1 diff --git a/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/sink-binding-test.properties b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/sink-binding-test.properties new file mode 100644 index 000000000..4c11271fe --- /dev/null +++ b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/sink-binding-test.properties @@ -0,0 +1 @@ +spring.cloud.stream.bindings.input=testtock diff --git a/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/source-binding-test.properties b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/source-binding-test.properties new file mode 100644 index 000000000..bb70f4f1c --- /dev/null +++ b/spring-cloud-stream/src/test/resources/org/springframework/cloud/stream/binder/source-binding-test.properties @@ -0,0 +1 @@ +spring.cloud.stream.bindings.output=testtock