org.springframework.cloud.stream.binder.test.OutputDestination Java Examples

The following examples show how to use org.springframework.cloud.stream.binder.test.OutputDestination. 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 vote down vote up
@Test
public void partitionOnOutputPayloadTestReactive() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration
			.getCompleteConfiguration(PojoFunctionConfiguration.class))
					.web(WebApplicationType.NONE).run("--spring.cloud.function.definition=funcReactive",
							"--spring.cloud.stream.bindings.funcReactive-out-0.producer.partitionKeyExpression=payload.id",
							"--spring.cloud.stream.bindings.funcReactive-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, "funcReactive-in-0");

		assertThat(outputDestination.receive(100, "funcReactive-out-0").getHeaders().get("scst_partition")).isEqualTo(3);

		assertThat(outputDestination.receive(100)).isNull();
	}
}
 
Example #2
Source File: RoutingFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: GreenfieldFunctionEnableBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore
public void testPojoReturn() throws IOException {
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(
					FooTransform.class)).web(WebApplicationType.NONE).run(
							"--spring.cloud.function.definition=fooFunction",
							"--spring.jmx" + ".enabled=false",
							"--logging.level.org.springframework.integration=TRACE")) {
		MessageChannel input = context.getBean("input", MessageChannel.class);
		OutputDestination target = context.getBean(OutputDestination.class);

		ObjectMapper mapper = context.getBean(ObjectMapper.class);

		input.send(MessageBuilder.withPayload("bar").build());
		byte[] payload = target.receive(2000).getPayload();

		Foo result = mapper.readValue(payload, Foo.class);

		assertThat(result.getBar()).isEqualTo("bar");
	}
}
 
Example #4
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testGh1973() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(SupplierAndProcessorConfiguration.class))
					.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false",
							"--spring.cloud.function.definition=echo;supplier",
							"--spring.cloud.stream.bindings.supplier-out-0.destination=output",
							"--spring.cloud.stream.bindings.echo-out-0.destination=output")) {

		InputDestination inputDestination = context.getBean(InputDestination.class);
		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		inputDestination.send(MessageBuilder.withPayload("hello").build());
		assertThat(outputDestination.receive(1000, "output")).isNotNull();
		assertThat(outputDestination.receive(1000, "output")).isNull();
		assertThat(outputDestination.receive(1000, "output")).isNull();

	}
}
 
Example #5
Source File: RoutingFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: RoutingFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: RoutingFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testExplicitRoutingFunctionBindingWithCompositionAndRoutingEnabledImplicitlyAndMoreComposition() {
	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")) {

		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 #8
Source File: MultipleInputOutputFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: MultipleInputOutputFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleInputMultiOutput() {
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(
					ReactiveFunctionConfiguration.class))
							.web(WebApplicationType.NONE)
							.run("--spring.jmx.enabled=false",
								"--spring.cloud.function.definition=singleInputMultipleOutputs")) {
		context.getBean(InputDestination.class);

		InputDestination inputDestination = context.getBean(InputDestination.class);
		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		for (int i = 0; i < 10; i++) {
			inputDestination.send(MessageBuilder.withPayload(String.valueOf(i).getBytes()).build(), "singleInputMultipleOutputs-in-0");
		}

		int counter = 0;
		for (int i = 0; i < 5; i++) {
			Message<byte[]> even = outputDestination.receive(0, "singleInputMultipleOutputs-out-0");
			assertThat(even.getPayload()).isEqualTo(("EVEN: " + String.valueOf(counter++)).getBytes());
			Message<byte[]> odd = outputDestination.receive(0, "singleInputMultipleOutputs-out-1");
			assertThat(odd.getPayload()).isEqualTo(("ODD: " + String.valueOf(counter++)).getBytes());
		}
	}
}
 
Example #10
Source File: MultipleInputOutputFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleFunctions() {
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(
					ReactiveFunctionConfiguration.class))
							.web(WebApplicationType.NONE)
							.run("--spring.jmx.enabled=false",
								"--spring.cloud.function.definition=uppercase;reverse")) {
		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, "uppercase-in-0");
		inputDestination.send(inputMessage, "reverse-in-0");

		Message<byte[]> outputMessage = outputDestination.receive(0, "uppercase-out-0");
		assertThat(outputMessage.getPayload()).isEqualTo("HELLO".getBytes());

		outputMessage = outputDestination.receive(0, "reverse-out-0");
		assertThat(outputMessage.getPayload()).isEqualTo("olleH".getBytes());
	}
}
 
Example #11
Source File: MultipleInputOutputFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #12
Source File: MultipleInputOutputFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: RoutingFunctionTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testExplicitRoutingFunctionBindingWithCompositionAndRoutingEnabledExplicitly() {
	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,
									"--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("HELLO".getBytes());
	}
}
 
Example #14
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void partitionOnOutputPayloadWithReactiveSupplierTest() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration
			.getCompleteConfiguration(PojoFunctionConfiguration.class))
					.web(WebApplicationType.NONE).run("--spring.cloud.function.definition=reactivePersonSupplier",
							"--spring.cloud.stream.bindings.reactivePersonSupplier-out-0.producer.partitionKeyExpression=payload.id",
							"--spring.cloud.stream.bindings.reactivePersonSupplier-out-0.producer.partitionCount=5",
							"--spring.jmx.enabled=false")) {

		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		assertThat(outputDestination.receive(1000, "reactivePersonSupplier-out-0").getHeaders().get("scst_partition")).isEqualTo(1);

		assertThat(outputDestination.receive(100)).isNull();
	}
}
 
Example #15
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #16
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #17
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #18
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #19
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #20
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void typelessToPojoOutboundContentTypeBinding() {
	ApplicationContext context = new SpringApplicationBuilder(
			TypelessToMessageStreamListener.class).web(WebApplicationType.NONE).run(
					"--spring.cloud.stream.bindings.output.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(MessageBuilder.withPayload(jsonPayload.getBytes())
			.setHeader("contentType", new MimeType("text", "plain")).build());

	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(jsonPayload);
}
 
Example #21
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #22
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testCollectionAndMapConversionDuringComposition() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration
			.getCompleteConfiguration(CompositionWithCollectionConfiguration.class))
					.web(WebApplicationType.NONE).run("--spring.cloud.function.definition=funcA|funcB",
							"--spring.jmx.enabled=false")) {

		InputDestination inputDestination = context.getBean(InputDestination.class);
		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		Message<byte[]> inputMessage = MessageBuilder.withPayload("[{\"key1\":1, \"key2\":2},{\"key3\":3}]".getBytes()).build();

		inputDestination.send(inputMessage);
		String result = new String(outputDestination.receive().getPayload());

		assertThat(result).isEqualTo("[{\"key1\":\"1\",\"key2\":\"2\"},{\"key3\":\"3\"}]");
	}
}
 
Example #23
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupplierWithCustomPollerAndMappedOutput() {
	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",
							"--spring.cloud.function.bindings.supplier-out-0=output")) {

		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 #24
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #25
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void typelessMessageToPojoInboundContentTypeBinding() {
	ApplicationContext context = new SpringApplicationBuilder(
			TypelessMessageToPojoStreamListener.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 #26
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 #27
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void customMessageConverter_defaultContentTypeBinding() {
	ApplicationContext context = new SpringApplicationBuilder(
			StringToStringStreamListener.class, CustomConverters.class)
					.web(WebApplicationType.NONE)
					.run("--spring.cloud.stream.default.contentType=foo/bar",
							"--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).isNotNull();
	assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8))
			.isEqualTo("FooBarMessageConverter");
	assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE))
			.isEqualTo(MimeType.valueOf("foo/bar"));
}
 
Example #28
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void outboundMessageWithTextContentTypeOnly() {
	ApplicationContext context = new SpringApplicationBuilder(
			TypelessToMessageTextOnlyContentTypeStreamListener.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("contentType", new MimeType("text")).build());

	Message<byte[]> outputMessage = target.receive();
	assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString())
			.isEqualTo("text/plain");
	assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8))
			.isEqualTo(jsonPayload);
}
 
Example #30
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void pojoToStringOutboundContentTypeBinding() {
	ApplicationContext context = new SpringApplicationBuilder(
			PojoToStringStreamListener.class).web(WebApplicationType.NONE).run(
					"--spring.cloud.stream.bindings.output.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.TEXT_PLAIN);
	assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8))
			.isEqualTo("oleg");
}