Java Code Examples for org.springframework.cloud.stream.binder.test.OutputDestination#receive()
The following examples show how to use
org.springframework.cloud.stream.binder.test.OutputDestination#receive() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testBindingWithReactiveFunction() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(ReactiveFunctionConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessageOne = MessageBuilder.withPayload("Hello".getBytes()).build(); Message<byte[]> inputMessageTwo = MessageBuilder.withPayload("Hello Again".getBytes()).build(); inputDestination.send(inputMessageOne); inputDestination.send(inputMessageTwo); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("Hello".getBytes()); outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("Hello Again".getBytes()); } }
Example 2
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testRoutingViaExplicitEnablingAndRoutingExpressionHeader() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( RoutingFunctionConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.routing.enabled=true")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context .getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder .withPayload("Hello".getBytes()) .setHeader("spring.cloud.function.routing-expression", "'echo'") .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) .build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("Hello".getBytes()); } }
Example 3
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testRoutingViaExplicitEnablingAndRoutingExpressionProperty() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( RoutingFunctionConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.routing-expression=headers.contentType.toString().equals('text/plain') ? 'echo' : null", "--spring.cloud.stream.function.routing.enabled=true")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context .getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder .withPayload("Hello".getBytes()) .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) .build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("Hello".getBytes()); } }
Example 4
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void byteArrayToPojoInboundContentTypeHeader() { ApplicationContext context = new SpringApplicationBuilder( StringToPojoStreamListener.class).web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "{\"name\":\"oleg\"}"; source.send(new GenericMessage<>(jsonPayload.getBytes(), new MessageHeaders(Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)))); Message<byte[]> outputMessage = target.receive(); assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE)) .isEqualTo(MimeTypeUtils.APPLICATION_JSON); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo(jsonPayload); }
Example 5
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void typelessToPojoWithTextHeaderContentTypeBinding() { ApplicationContext context = new SpringApplicationBuilder( TypelessToPojoStreamListener.class).web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "{\"name\":\"oleg\"}"; source.send(MessageBuilder.withPayload(jsonPayload.getBytes()) .setHeader(MessageHeaders.CONTENT_TYPE, MimeType.valueOf("text/plain")) .build()); Message<byte[]> outputMessage = target.receive(); assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE)) .isEqualTo(MimeTypeUtils.APPLICATION_JSON); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo(jsonPayload); }
Example 6
Source File: MultipleInputOutputFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testMultiInputSingleOutput() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( ReactiveFunctionConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=multiInputSingleOutput")) { context.getBean(InputDestination.class); InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> stringInputMessage = MessageBuilder.withPayload("one".getBytes()).build(); Message<byte[]> integerInputMessage = MessageBuilder.withPayload("1".getBytes()).build(); inputDestination.send(stringInputMessage, "multiInputSingleOutput-in-0"); inputDestination.send(integerInputMessage, "multiInputSingleOutput-in-1"); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("one".getBytes()); outputMessage = outputDestination.receive(0, "multiInputSingleOutput-out-0"); assertThat(outputMessage.getPayload()).isEqualTo("1".getBytes()); } }
Example 7
Source File: MultipleInputOutputFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testMultipleFunctionsWithComposition() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( ReactiveFunctionConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=uppercase|reverse;reverse|uppercase")) { context.getBean(InputDestination.class); InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessage, "uppercasereverse-in-0"); inputDestination.send(inputMessage, "reverseuppercase-in-0"); Message<byte[]> outputMessage = outputDestination.receive(0, "uppercasereverse-out-0"); System.out.println(new String(outputMessage.getPayload())); assertThat(outputMessage.getPayload()).isEqualTo("OLLEH".getBytes()); outputMessage = outputDestination.receive(0, "reverseuppercase-out-0"); assertThat(outputMessage.getPayload()).isEqualTo("OLLEH".getBytes()); } }
Example 8
Source File: StreamOutputDestinationMessageReceiver.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
@Override public Message<?> receive(String destination, long timeout, TimeUnit timeUnit) { try { OutputDestination outputDestination = this.context .getBean(OutputDestination.class); return outputDestination.receive(timeUnit.toMillis(timeout), destination); } catch (Exception e) { log.error("Exception occurred while trying to read a message from " + " a channel with name [" + destination + "]", e); throw new IllegalStateException(e); } }
Example 9
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testSimpleFunctionWithoutDefinitionProperty() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(SingleFunctionConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("Hello".getBytes()); } }
Example 10
Source File: MultipleInputOutputFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testMultiInputSingleOutputWithCustomContentType() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( ContentTypeConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=multiInputSingleOutput", "--spring.cloud.stream.bindings.multiInputSingleOutput-in-0.content-type=string/person", "--spring.cloud.stream.bindings.multiInputSingleOutput-in-1.content-type=string/employee")) { context.getBean(InputDestination.class); InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> stringInputMessage = MessageBuilder.withPayload("ricky".getBytes()).build(); Message<byte[]> integerInputMessage = MessageBuilder.withPayload("bobby".getBytes()).build(); inputDestination.send(stringInputMessage, "multiInputSingleOutput-in-0"); inputDestination.send(integerInputMessage, "multiInputSingleOutput-in-1"); Message<byte[]> outputMessage = outputDestination.receive(1000, "multiInputSingleOutput-out-0"); assertThat(outputMessage.getPayload()).isEqualTo("RICKY".getBytes()); outputMessage = outputDestination.receive(1000, "multiInputSingleOutput-out-0"); assertThat(outputMessage.getPayload()).isEqualTo("BOBBY".getBytes()); } }
Example 11
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void typelessToPojoInboundContentTypeBinding() { ApplicationContext context = new SpringApplicationBuilder( TypelessToPojoStreamListener.class).web(WebApplicationType.NONE).run( "--spring.cloud.stream.bindings.input.contentType=text/plain", "--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "{\"name\":\"oleg\"}"; source.send(new GenericMessage<>(jsonPayload.getBytes())); Message<byte[]> outputMessage = target.receive(); assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE)) .isEqualTo(MimeTypeUtils.APPLICATION_JSON); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo(jsonPayload); }
Example 12
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testPojoFunction() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( RoutingFunctionConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.definition=" + RoutingFunction.FUNCTION_NAME)) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context .getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder .withPayload("{\"name\":\"bob\"}".getBytes()) .setHeader("spring.cloud.function.definition", "pojoecho") .build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("{\"name\":\"bob\"}".getBytes()); } }
Example 13
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testExplicitRoutingFunctionBindingWithCompositionAndRoutingEnabledImplicitly() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( RoutingFunctionConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.definition=enrich|" + RoutingFunction.FUNCTION_NAME)) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context .getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder .withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("HELLO".getBytes()); } }
Example 14
Source File: StreamBridgeTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testBridgeFunctionsWitthPartitionInformation() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(EmptyConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.cloud.stream.source=foo;bar", "--spring.cloud.stream.bindings.foo-out-0.producer.partitionKeyExpression=payload", "--spring.cloud.stream.bindings.foo-out-0.producer.partitionCount=2", "--spring.jmx.enabled=false")) { StreamBridge bridge = context.getBean(StreamBridge.class); bridge.send("foo-out-0", "a"); bridge.send("bar-out-0", "b"); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> message = outputDestination.receive(100, "foo-out-0"); assertThat(new String(message.getPayload())).isEqualTo("a"); assertThat(message.getHeaders().get("scst_partition")).isEqualTo(1); assertThat(new String(outputDestination.receive(100, "bar-out-0").getPayload())).isEqualTo("b"); } }
Example 15
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Test public void testWithTypelessMessageInputParameterAndServiceActivator() { ApplicationContext context = new SpringApplicationBuilder( TypelessMessageConfigurationSA.class).web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "[\"foo\",\"bar\"]"; source.send(MessageBuilder.withPayload(jsonPayload.getBytes()).build()); Message<byte[]> outputMessage = target.receive(); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo(jsonPayload); }
Example 16
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Test public void testWithMapInputParameter() { ApplicationContext context = new SpringApplicationBuilder( MapInputConfiguration.class).web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "{\"name\":\"oleg\"}"; source.send(new GenericMessage<>(jsonPayload.getBytes())); Message<byte[]> outputMessage = target.receive(); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo(jsonPayload); }
Example 17
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Test public void pojoMessageToStringMessage() { ApplicationContext context = new SpringApplicationBuilder( PojoMessageToStringMessageStreamListener.class) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "{\"name\":\"oleg\"}"; source.send(new GenericMessage<>(jsonPayload.getBytes())); Message<byte[]> outputMessage = target.receive(); assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE)) .isEqualTo(MimeTypeUtils.TEXT_PLAIN); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo("oleg"); }
Example 18
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Test public void stringToMapMessageStreamListener() { ApplicationContext context = new SpringApplicationBuilder( StringToMapMessageStreamListener.class).web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "{\"name\":\"oleg\"}"; source.send(new GenericMessage<>(jsonPayload.getBytes())); Message<byte[]> outputMessage = target.receive(); assertThat(new String(outputMessage.getPayload())).isEqualTo("oleg"); }
Example 19
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Test public void testWithTypelessInputParameterAndServiceActivator() { ApplicationContext context = new SpringApplicationBuilder( TypelessPayloadConfigurationSA.class).web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "[\"foo\",\"bar\"]"; source.send(MessageBuilder.withPayload(jsonPayload.getBytes()).build()); Message<byte[]> outputMessage = target.receive(); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo(jsonPayload); }
Example 20
Source File: ContentTypeTckTests.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Test public void byteArrayMessageToStringJsonMessageStreamListener() { ApplicationContext context = new SpringApplicationBuilder( ByteArrayMessageToStringJsonMessageStreamListener.class) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); OutputDestination target = context.getBean(OutputDestination.class); String jsonPayload = "{\"name\":\"oleg\"}"; source.send(new GenericMessage<>(jsonPayload.getBytes())); Message<byte[]> outputMessage = target.receive(); assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE)) .isEqualTo(MimeTypeUtils.APPLICATION_JSON); assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)) .isEqualTo("{\"name\":\"bob\"}"); }