org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration Java Examples
The following examples show how to use
org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration.
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 testWithExplicitBindingInstructions() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(SplittableTypesConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.cloud.function.definition=funcArrayOfMessages", "--spring.cloud.stream.function.bindings.funcArrayOfMessages-in-0=input", "--spring.cloud.stream.function.bindings.funcArrayOfMessages-out-0=output", "--spring.cloud.stream.bindings.input.destination=myInput", "--spring.cloud.stream.bindings.output.destination=myOutput", "--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("aa,bb,cc,dd".getBytes()).build(); inputDestination.send(inputMessage, "myInput"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("aa"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("bb"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("cc"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("dd"); assertThat(outputDestination.receive(100)).isNull(); } }
Example #2
Source File: ErrorBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testConfigurationWithDefaultErrorHandler() { ApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( ErrorBindingTests.ErrorConfigurationDefault.class)) .web(WebApplicationType.NONE) .run("--spring.cloud.stream.bindings.input.consumer.max-attempts=1", "--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); source.send(new GenericMessage<byte[]>("Hello".getBytes())); source.send(new GenericMessage<byte[]>("Hello".getBytes())); source.send(new GenericMessage<byte[]>("Hello".getBytes())); ErrorConfigurationDefault errorConfiguration = context .getBean(ErrorConfigurationDefault.class); assertThat(errorConfiguration.counter == 3); }
Example #3
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testReactiveFunctionWithOutputAsMonoVoid() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(FunctionalConsumerConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) { assertThat(context.containsBean("funcConsumer-out-0")).isFalse(); InputDestination inputDestination = context.getBean(InputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessage); assertThat(System.getProperty("consumer")).isEqualTo("Hello"); System.clearProperty("consumer"); } }
Example #4
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void contentTypeAsByteArrayTest() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(PojoFunctionConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.cloud.function.definition=echoPerson", "--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("{\"name\":\"Jim Lahey\",\"id\":420}".getBytes()) .setHeader(MessageHeaders.CONTENT_TYPE, "application/json".getBytes(StandardCharsets.UTF_8)) .build(); inputDestination.send(inputMessage, "echoPerson-in-0"); assertThat(outputDestination.receive(100, "echoPerson-out-0").getPayload()).isEqualTo("{\"name\":\"Jim Lahey\",\"id\":420}".getBytes()); } }
Example #5
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 #6
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 #7
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testRoutingViaExplicitDefinitionAndDefinitionHeader() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( RoutingFunctionConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=" + RoutingFunction.FUNCTION_NAME)) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context .getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder .withPayload("Hello".getBytes()) .setHeader("spring.cloud.function.definition", "echo|uppercase") .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) .build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("HELLO".getBytes()); } }
Example #8
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testDefaultRoutingFunctionBindingFlux() { 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); Message<byte[]> inputMessage = MessageBuilder .withPayload("Hello".getBytes()) .setHeader("spring.cloud.function.definition", "echoFlux") .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) .build(); inputDestination.send(inputMessage); TestChannelBinder binder = context.getBean(TestChannelBinder.class); Throwable ex = ((Exception) binder.getLastError().getPayload()).getCause(); assertThat(ex).isInstanceOf(IllegalStateException.class); assertThat(ex.getMessage()).isEqualTo("Routing to functions that return Publisher is not supported in the context of Spring Cloud Stream."); } }
Example #9
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 #10
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 #11
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 #12
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testExplicitRoutingFunctionBindingWithCompositionAndRoutingEnabledExplicitlyAndMoreComposition() { 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 + "|reverse", "--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()).build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("OLLEH".getBytes()); } }
Example #13
Source File: RoutingFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testRoutingViaExplicitEnablingAndDefinitionHeader() { 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(FunctionProperties.PREFIX + ".definition", "echo") .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) .build(); inputDestination.send(inputMessage); Message<byte[]> outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("Hello".getBytes()); } }
Example #14
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void partitionOnOutputPayloadTest() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(PojoFunctionConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.cloud.function.definition=func", "--spring.cloud.stream.bindings.func-out-0.producer.partitionKeyExpression=payload.id", "--spring.cloud.stream.bindings.func-out-0.producer.partitionCount=5", "--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("Jim Lahey".getBytes()).build(); inputDestination.send(inputMessage, "func-in-0"); assertThat(outputDestination.receive(100, "func-out-0").getHeaders().get("scst_partition")).isEqualTo(3); assertThat(outputDestination.receive(100)).isNull(); } }
Example #15
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testWithExplicitBindingInstructionsOnlyDestination() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(SplittableTypesConfiguration.class)) .web(WebApplicationType.NONE).run( "--spring.cloud.function.definition=funcArrayOfMessages", "--spring.cloud.stream.bindings.funcArrayOfMessages-in-0.destination=myInput", "--spring.cloud.stream.bindings.funcArrayOfMessages-out-0.destination=myOutput", "--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("aa,bb,cc,dd".getBytes()).build(); inputDestination.send(inputMessage, "myInput"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("aa"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("bb"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("cc"); assertThat(new String(outputDestination.receive(100, "myOutput").getPayload())).isEqualTo("dd"); assertThat(outputDestination.receive(100)).isNull(); } }
Example #16
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void partitionOnOutputPayloadWithSupplierTest() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(PojoFunctionConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.cloud.function.definition=personSupplier", "--spring.cloud.stream.bindings.personSupplier-out-0.producer.partitionKeyExpression=payload.id", "--spring.cloud.stream.bindings.personSupplier-out-0.producer.partitionCount=5", "--spring.jmx.enabled=false")) { OutputDestination outputDestination = context.getBean(OutputDestination.class); assertThat(outputDestination.receive(1000, "personSupplier-out-0").getHeaders().get("scst_partition")).isEqualTo(1); assertThat(outputDestination.receive(100)).isNull(); } }
Example #17
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testOutputAsArrayOfMessages() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(SplittableTypesConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.cloud.function.definition=funcArrayOfMessages", "--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("aa,bb,cc,dd".getBytes()).build(); inputDestination.send(inputMessage); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("aa"); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("bb"); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("cc"); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("dd"); assertThat(outputDestination.receive(100)).isNull(); } }
Example #18
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testOutputAsCollectionOfMessages() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(SplittableTypesConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.cloud.function.definition=funcCollectionOfMessages", "--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("aa,bb,cc,dd".getBytes()).build(); inputDestination.send(inputMessage); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("aa"); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("bb"); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("cc"); assertThat(new String(outputDestination.receive(100).getPayload())).isEqualTo("dd"); assertThat(outputDestination.receive(100)).isNull(); } }
Example #19
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testNoFunctionEnabledConfiguration() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(NoFunctionEnabledConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) { try { context.getBean(FunctionConfiguration.class); fail(); } catch (Exception e) { // ignore } } }
Example #20
Source File: MultipleInputOutputFunctionTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testMultiInputSingleOutputWithCustomContentType2() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( ContentTypeConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=multiInputSingleOutput2", "--spring.cloud.stream.bindings.multiInputSingleOutput2-in-0.content-type=string/person", "--spring.cloud.stream.bindings.multiInputSingleOutput2-in-1.content-type=string/employee", "--spring.cloud.stream.bindings.multiInputSingleOutput2-out-0.content-type=string/person")) { 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, "multiInputSingleOutput2-in-0"); inputDestination.send(integerInputMessage, "multiInputSingleOutput2-in-1"); Message<byte[]> outputMessage = outputDestination.receive(1000, "multiInputSingleOutput2-out-0"); assertThat(outputMessage.getPayload()).isEqualTo("rickybobby".getBytes()); } }
Example #21
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testSupplierWithCustomPoller() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(SupplierWithExplicitPollerConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.stream.poller.fixed-delay=2000")) { OutputDestination outputDestination = context.getBean(OutputDestination.class); PollerMetadata pollerMetadata = context.getBean(PollerMetadata.class); assertThat(((PeriodicTrigger) pollerMetadata.getTrigger()).getPeriod()).isEqualTo(2000); Message<byte[]> outputMessage = outputDestination.receive(6000); assertThat(outputMessage.getPayload()).isEqualTo("hello".getBytes()); } }
Example #22
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testWithIntegrationFlowAsFunction() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration .getCompleteConfiguration(FunctionSampleSpringIntegrationConfiguration.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 #23
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testWithContextTypeApplicationProperty() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(SingleFunctionConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.input.content-type=text/plain", "--debug")) { 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 #24
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testDeclaredTypeVsActualInstance() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(SCF_GH_409Configuration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) { InputDestination inputDestination = context.getBean(InputDestination.class); Message<byte[]> inputMessageOne = MessageBuilder.withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessageOne); fail(); } catch (Exception ex) { // good } }
Example #25
Source File: ErrorBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testConfigurationWithCustomErrorHandler() { ApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration( ErrorBindingTests.ErrorConfigurationWithCustomErrorHandler.class)) .web(WebApplicationType.NONE) .run("--spring.cloud.stream.bindings.input.consumer.max-attempts=1", "--spring.jmx.enabled=false"); InputDestination source = context.getBean(InputDestination.class); source.send(new GenericMessage<byte[]>("Hello".getBytes())); source.send(new GenericMessage<byte[]>("Hello".getBytes())); source.send(new GenericMessage<byte[]>("Hello".getBytes())); ErrorConfigurationWithCustomErrorHandler errorConfiguration = context .getBean(ErrorConfigurationWithCustomErrorHandler.class); assertThat(errorConfiguration.counter == 6); }
Example #26
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void fooFunctionComposedWithConsumerNonReactive() { System.clearProperty("spring.cloud.function.definition"); try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(FunctionConsumerCopositionConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=echo|consumer")) { assertThat(context.containsBean("echoconsumer-out-0")).isFalse(); InputDestination inputDestination = context.getBean(InputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessage); assertThat(System.getProperty("FunctionConsumerCopositionConfiguration")).isEqualTo("Hello"); System.clearProperty("FunctionConsumerCopositionConfiguration"); } }
Example #27
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 #28
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testSimpleFunctionWithNativeProperty() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(NoEnableBindingConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=func")) { 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 #29
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @Test public void testFunctionWithUseNativeEncoding() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(NoEnableBindingConfiguration.class)) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=func", "--spring.cloud.stream.bindings.func-out-0.producer.useNativeEncoding=true")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessage); Message outputMessage = outputDestination.receive(); assertThat(outputMessage.getPayload()).isEqualTo("Hello"); } }
Example #30
Source File: ImplicitFunctionBindingTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testReactiveFunctionWithState() { try (ConfigurableApplicationContext context = new SpringApplicationBuilder( TestChannelBinderConfiguration.getCompleteConfiguration(NoEnableBindingConfiguration.class)) .web(WebApplicationType.NONE) .run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=aggregate")) { InputDestination inputDestination = context.getBean(InputDestination.class); OutputDestination outputDestination = context.getBean(OutputDestination.class); Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build(); inputDestination.send(inputMessage); inputDestination.send(inputMessage); inputDestination.send(inputMessage); assertThat(new String(outputDestination.receive(2000).getPayload())).isEqualTo("HelloHelloHello"); assertThat(new String(outputDestination.receive(2000).getPayload())).isEqualTo(""); inputDestination.send(inputMessage); inputDestination.send(inputMessage); inputDestination.send(inputMessage); inputDestination.send(inputMessage); assertThat(new String(outputDestination.receive(2000).getPayload())).isEqualTo("HelloHelloHelloHello"); } }