diff --git a/pom.xml b/pom.xml index 779b3b893..8a789cce4 100644 --- a/pom.xml +++ b/pom.xml @@ -17,13 +17,20 @@ 1.8 Aluminium-SR1 - Brooklyn.SR2 + Chelsea.BUILD-SNAPSHOT 1.0.0.RC1 1.5.2.RELEASE + + org.springframework.cloud + spring-cloud-stream-dependencies + ${spring-cloud-stream.version} + pom + import + io.projectreactor reactor-bom diff --git a/spring-cloud-function-stream/pom.xml b/spring-cloud-function-stream/pom.xml index fa8e43c0e..3b0bc7a98 100644 --- a/spring-cloud-function-stream/pom.xml +++ b/spring-cloud-function-stream/pom.xml @@ -14,10 +14,6 @@ .. - - 1.1.1.BUILD-SNAPSHOT - - io.projectreactor @@ -31,11 +27,22 @@ org.springframework.cloud spring-cloud-stream-reactive + + org.springframework.cloud + spring-cloud-stream-test-support + test + org.springframework.cloud spring-cloud-function-core ${project.version} + + org.springframework.cloud + spring-cloud-function-context + test + ${project.version} + org.springframework.cloud spring-cloud-stream-binder-rabbit diff --git a/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/consumer/StreamingConsumerTests.java b/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/consumer/StreamingConsumerTests.java new file mode 100644 index 000000000..c0efa9d2d --- /dev/null +++ b/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/consumer/StreamingConsumerTests.java @@ -0,0 +1,75 @@ +/* + * Copyright 2017 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.function.stream.consumer; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +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.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.cloud.stream.messaging.Sink; +import org.springframework.cloud.stream.test.binder.MessageCollector; +import org.springframework.context.annotation.Bean; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = StreamingConsumerTests.StreamingSinkTest.class, properties = { + "spring.cloud.stream.bindings.input.destination=data-in", + "spring.cloud.function.stream.endpoint=sinkConsumer" }) +public class StreamingConsumerTests { + + @Autowired + Sink sink; + + @Autowired + List sinkCollector; + + @Test + public void test() throws Exception { + sink.input().send(MessageBuilder.withPayload("foo").build()); + assertThat(sinkCollector).containsExactly("foo"); + } + + @SpringBootApplication + public static class StreamingSinkTest { + + @Bean + public List sinkCollector() { + return new ArrayList<>(); + } + + @Bean + public Consumer sinkConsumer(final List sinkCollector) { + return s -> sinkCollector.add(s); + } + } +} diff --git a/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/function/StreamingFunctionTests.java b/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/function/StreamingFunctionTests.java new file mode 100644 index 000000000..552f9e7ce --- /dev/null +++ b/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/function/StreamingFunctionTests.java @@ -0,0 +1,68 @@ +/* + * Copyright 2017 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.function.stream.function; + +import java.util.concurrent.TimeUnit; +import java.util.function.Function; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.cloud.stream.test.binder.MessageCollector; +import org.springframework.context.annotation.Bean; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = StreamingFunctionTests.StreamingFunctionApplication.class, properties = { + "spring.cloud.stream.bindings.input.destination=data-in", + "spring.cloud.stream.bindings.output.destination=data-out", + "spring.cloud.function.stream.endpoint=uppercase" }) +public class StreamingFunctionTests { + + @Autowired + Processor processor; + + @Autowired + MessageCollector messageCollector; + + @Test + public void test() throws Exception { + processor.input().send(MessageBuilder.withPayload("foo").build()); + Message result = messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS); + assertThat(result.getPayload()).isEqualTo("FOO"); + } + + @SpringBootApplication + public static class StreamingFunctionApplication { + + @Bean + public Function uppercase() { + return s -> s.toUpperCase(); + } + } +} diff --git a/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/supplier/StreamSupplierTests.java b/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/supplier/StreamSupplierTests.java new file mode 100644 index 000000000..af4a14bb1 --- /dev/null +++ b/spring-cloud-function-stream/src/test/java/org/springframework/cloud/function/stream/supplier/StreamSupplierTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2017 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.function.stream.supplier; + +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.stream.messaging.Source; +import org.springframework.cloud.stream.test.binder.MessageCollector; +import org.springframework.context.annotation.Bean; +import org.springframework.messaging.Message; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Marius Bogoevici + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = StreamSupplierTests.StreamingFunctionApplication.class, properties = { + "spring.cloud.stream.bindings.output.destination=data-out", + "spring.cloud.function.stream.endpoint=simpleSupplier" }) +public class StreamSupplierTests { + + @Autowired + Source source; + + @Autowired + MessageCollector messageCollector; + + @Test + public void test() throws Exception { + Message result = messageCollector.forChannel(source.output()).poll(1000, TimeUnit.MILLISECONDS); + assertThat(result.getPayload()).isEqualTo("foo"); + } + + @SpringBootApplication + public static class StreamingFunctionApplication { + + @Bean + public Supplier simpleSupplier() { + return () -> "foo"; + } + } +}