Java Code Examples for org.springframework.integration.test.util.TestUtils#getPropertyValue()

The following examples show how to use org.springframework.integration.test.util.TestUtils#getPropertyValue() . 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: SqsPermissionsParserTests.java    From spring-integration-aws with MIT License 6 votes vote down vote up
@Test
public void outboundPermissions() {
	EventDrivenConsumer consumer = context.getBean("sqs-outbound",
			EventDrivenConsumer.class);
	assertThat(consumer, is(notNullValue()));

	final SqsExecutor executor = TestUtils.getPropertyValue(consumer,
			"handler.sqsExecutor", SqsExecutor.class);
	assertThat(executor, is(notNullValue()));

	@SuppressWarnings("unchecked")
	Set<Permission> permissions = (Set<Permission>) TestUtils
			.getPropertyValue(executor, "permissions");
	assertThat("permissions is not null", permissions, is(notNullValue()));
	assertThat("all permissions loaded", permissions.size(), is(equalTo(1)));
}
 
Example 2
Source File: SpelExpressionConverterConfigurationTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void converterCorrectlyInstalled() {
	Expression expression = this.pojo.getExpression();
	assertThat(expression.getValue("{\"a\": {\"b\": 5}}").toString()).isEqualTo("5");

	List<PropertyAccessor> propertyAccessors = TestUtils.getPropertyValue(
			this.evaluationContext, "propertyAccessors", List.class);

	assertThat(propertyAccessors)
			.hasAtLeastOneElementOfType(JsonPropertyAccessor.class);

	propertyAccessors = TestUtils.getPropertyValue(this.config.evaluationContext,
			"propertyAccessors", List.class);

	assertThat(propertyAccessors)
			.hasAtLeastOneElementOfType(JsonPropertyAccessor.class);
}
 
Example 3
Source File: AmazonS3SourceMockTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
@Override
public void test() throws Exception {
	for (int i = 1; i <= 2; i++) {
		Message<?> received = this.messageCollector.forChannel(this.channels.output())
				.poll(10, TimeUnit.SECONDS);
		assertNotNull(received);
		assertThat(received, hasPayload(new File(this.config.getLocalDir(), i + ".test")));
	}

	assertEquals(2, this.config.getLocalDir().list().length);

	AWSCredentialsProvider awsCredentialsProvider =
			TestUtils.getPropertyValue(this.amazonS3, "awsCredentialsProvider", AWSCredentialsProvider.class);

	AWSCredentials credentials = awsCredentialsProvider.getCredentials();
	assertEquals(AWS_ACCESS_KEY, credentials.getAWSAccessKeyId());
	assertEquals(AWS_SECRET_KEY, credentials.getAWSSecretKey());

	assertEquals(Region.US_GovCloud, this.amazonS3.getRegion());
	assertEquals(new URI("https://s3-us-gov-west-1.amazonaws.com"),
			TestUtils.getPropertyValue(this.amazonS3, "endpoint"));
}
 
Example 4
Source File: SnsPermissionsParserTests.java    From spring-integration-aws with MIT License 6 votes vote down vote up
@Test
public void channelPermissions() {
	SubscribableChannel channel = context.getBean("sns-channel",
			SubscribableChannel.class);
	assertThat(channel, is(notNullValue()));

	final SnsExecutor executor = TestUtils.getPropertyValue(channel,
			"snsExecutor", SnsExecutor.class);
	assertThat("snsExecutor is not null", executor, is(notNullValue()));

	@SuppressWarnings("unchecked")
	Set<Permission> permissions = (Set<Permission>) TestUtils
			.getPropertyValue(executor, "permissions");
	assertThat("permissions is not null", permissions, is(notNullValue()));
	assertThat("all permissions loaded", permissions.size(), is(equalTo(1)));
}
 
Example 5
Source File: JmsSourceTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
	AbstractMessageListenerContainer container = TestUtils.getPropertyValue(this.endpoint, "listenerContainer",
			AbstractMessageListenerContainer.class);
	assertThat(container, instanceOf(DefaultMessageListenerContainer.class));
	assertEquals(Session.AUTO_ACKNOWLEDGE, TestUtils.getPropertyValue(container, "sessionAcknowledgeMode"));
	assertTrue(TestUtils.getPropertyValue(container, "sessionTransacted", Boolean.class));
	assertEquals("jmssource.test.queue", TestUtils.getPropertyValue(container, "destination"));
	assertEquals("JMSCorrelationId=foo", TestUtils.getPropertyValue(container, "messageSelector"));
	assertFalse(TestUtils.getPropertyValue(container, "subscriptionDurable", Boolean.class));
	assertFalse(TestUtils.getPropertyValue(container, "subscriptionShared", Boolean.class));
	assertEquals(3, TestUtils.getPropertyValue(container, "concurrentConsumers"));
	assertEquals(4, TestUtils.getPropertyValue(container, "maxConcurrentConsumers"));
	assertFalse(TestUtils.getPropertyValue(container, "pubSubDomain", Boolean.class));

	template.convertAndSend("jmssource.test.queue", "Hello, world!");
	Message<?> received = messageCollector.forChannel(channels.output()).poll(10, TimeUnit.SECONDS);
	assertNotNull(received);
	assertEquals("Hello, world!", received.getPayload());
}
 
Example 6
Source File: JmsSourceTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
	AbstractMessageListenerContainer container = TestUtils.getPropertyValue(this.endpoint, "listenerContainer",
			AbstractMessageListenerContainer.class);
	assertThat(container, instanceOf(DefaultMessageListenerContainer.class));
	assertEquals(Session.AUTO_ACKNOWLEDGE, TestUtils.getPropertyValue(container, "sessionAcknowledgeMode"));
	assertTrue(TestUtils.getPropertyValue(container, "sessionTransacted", Boolean.class));
	assertEquals("client", TestUtils.getPropertyValue(container, "clientId"));
	assertEquals("topic", TestUtils.getPropertyValue(container, "destination"));
	assertTrue(TestUtils.getPropertyValue(container, "subscriptionDurable", Boolean.class));
	assertEquals("subName", TestUtils.getPropertyValue(container, "subscriptionName"));
	assertFalse(TestUtils.getPropertyValue(container, "subscriptionShared", Boolean.class));
	assertEquals(3, TestUtils.getPropertyValue(container, "concurrentConsumers"));
	assertEquals(4, TestUtils.getPropertyValue(container, "maxConcurrentConsumers"));
	assertTrue(TestUtils.getPropertyValue(container, "pubSubDomain", Boolean.class));
}
 
Example 7
Source File: RabbitSourceTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	Advice[] adviceChain = TestUtils.getPropertyValue(this.container, "adviceChain", Advice[].class);
	assertEquals(1, adviceChain.length);
	RetryTemplate retryTemplate = TestUtils.getPropertyValue(adviceChain[0], "retryOperations",
			RetryTemplate.class);
	assertEquals(5, TestUtils.getPropertyValue(retryTemplate, "retryPolicy.maxAttempts"));
	assertEquals(123L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.initialInterval"));
	assertEquals(345L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.maxInterval"));
	assertEquals(1.5, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.multiplier"));
	assertEquals("scsapp-testq", this.container.getQueueNames()[0]);
	assertFalse(TestUtils.getPropertyValue(this.container, "defaultRequeueRejected", Boolean.class));
	assertEquals(2, TestUtils.getPropertyValue(this.container, "concurrentConsumers"));
	assertEquals(3, TestUtils.getPropertyValue(this.container, "maxConcurrentConsumers"));
	assertEquals(AcknowledgeMode.NONE, TestUtils.getPropertyValue(this.container, "acknowledgeMode"));
	assertEquals(10, TestUtils.getPropertyValue(this.container, "prefetchCount"));
	assertEquals(5, TestUtils.getPropertyValue(this.container, "txSize"));

	this.rabbitTemplate.convertAndSend("", "scsapp-testq", "foo", new MessagePostProcessor() {

		@Override
		public org.springframework.amqp.core.Message postProcessMessage(
				org.springframework.amqp.core.Message message) throws AmqpException {
			message.getMessageProperties().getHeaders().put("bar", "baz");
			return message;
		}

	});
	Message<?> out = this.messageCollector.forChannel(this.channels.output()).poll(10,  TimeUnit.SECONDS);
	assertNotNull(out);
	assertEquals("foo", out.getPayload());
	assertEquals("baz", out.getHeaders().get("bar"));
	assertNull(out.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
}
 
Example 8
Source File: RabbitSourceTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	Advice[] adviceChain = TestUtils.getPropertyValue(this.container, "adviceChain", Advice[].class);
	assertEquals(0, adviceChain.length);
	assertTrue(TestUtils.getPropertyValue(this.container, "transactional", Boolean.class));
	assertEquals(AcknowledgeMode.AUTO, TestUtils.getPropertyValue(this.container, "acknowledgeMode"));
	assertEquals("scsapp-testq", this.container.getQueueNames()[0]);
	assertEquals("scsapp-testq2", this.container.getQueueNames()[1]);
}
 
Example 9
Source File: SnsClientConfigurationTest.java    From spring-integration-aws with MIT License 5 votes vote down vote up
@Test
public void testClientConfigurationInjectedExplicitly() {

	setUp("SnsClientConfigurationTests.xml", getClass(),
			"snsChannelWithClientConfiguration");

	final ClientConfiguration clientConfiguration = TestUtils
			.getPropertyValue(snsChannelWithClientConfiguration,
					"snsExecutor.awsClientConfiguration",
					ClientConfiguration.class);
	assertThat(clientConfiguration.getProtocol(), is(Protocol.HTTPS));
	assertThat(clientConfiguration.getProxyHost(), is("PROXY_HOST"));
}
 
Example 10
Source File: AmazonS3SinkMockTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
@Override
public void test() throws Exception {
	AmazonS3 amazonS3Client = TestUtils.getPropertyValue(this.s3MessageHandler, "transferManager.s3",
			AmazonS3.class);

	InputStream payload = new StringInputStream("a");
	Message<?> message = MessageBuilder.withPayload(payload)
			.setHeader("key", "myInputStream")
			.build();

	this.channels.input().send(message);

	ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor =
			ArgumentCaptor.forClass(PutObjectRequest.class);
	verify(amazonS3Client, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture());

	PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue();
	assertThat(putObjectRequest.getBucketName(), equalTo(S3_BUCKET));
	assertThat(putObjectRequest.getKey(), equalTo("myInputStream"));
	assertNull(putObjectRequest.getFile());
	assertNotNull(putObjectRequest.getInputStream());

	ObjectMetadata metadata = putObjectRequest.getMetadata();
	assertThat(metadata.getContentMD5(), equalTo(Md5Utils.md5AsBase64(payload)));
	assertThat(metadata.getContentLength(), equalTo(1L));
	assertThat(metadata.getContentType(), equalTo(MediaType.APPLICATION_JSON_VALUE));
	assertThat(metadata.getContentDisposition(), equalTo("test.json"));
}
 
Example 11
Source File: SnsInboundChannelAdapterParserTests.java    From spring-integration-aws with MIT License 4 votes vote down vote up
@Test
public void testSnsInboundChannelAdapterParser() throws Exception {

	setUp("SnsInboundChannelAdapterParserTests.xml", getClass(),
			"snsInboundChannelAdapter");

	final AbstractMessageChannel outputChannel = TestUtils
			.getPropertyValue(this.producer, "outputChannel",
					AbstractMessageChannel.class);

	assertEquals("out", outputChannel.getComponentName());

	final SnsExecutor snsExecutor = TestUtils.getPropertyValue(
			this.producer, "snsExecutor", SnsExecutor.class);

	assertNotNull(snsExecutor);

	final String topicNameProperty = TestUtils.getPropertyValue(
			snsExecutor, "topicName", String.class);

	assertEquals("testTopic", topicNameProperty);

}
 
Example 12
Source File: AmazonS3SinkMockTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Test
@Override
public void test() throws Exception {
	AmazonS3 amazonS3Client = TestUtils.getPropertyValue(this.s3MessageHandler, "transferManager.s3",
			AmazonS3.class);

	File file = this.temporaryFolder.newFile("foo.mp3");
	Message<?> message = MessageBuilder.withPayload(file)
			.build();

	this.channels.input().send(message);

	ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor =
			ArgumentCaptor.forClass(PutObjectRequest.class);
	verify(amazonS3Client, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture());

	PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue();
	assertThat(putObjectRequest.getBucketName(), equalTo(S3_BUCKET));
	assertThat(putObjectRequest.getKey(), equalTo("foo.mp3"));
	assertNotNull(putObjectRequest.getFile());
	assertNull(putObjectRequest.getInputStream());

	ObjectMetadata metadata = putObjectRequest.getMetadata();
	assertThat(metadata.getContentMD5(), equalTo(Md5Utils.md5AsBase64(file)));
	assertThat(metadata.getContentLength(), equalTo(0L));
	assertThat(metadata.getContentType(), equalTo("audio/mpeg"));

	ProgressListener listener = putObjectRequest.getGeneralProgressListener();
	S3ProgressPublisher.publishProgress(listener, ProgressEventType.TRANSFER_COMPLETED_EVENT);

	assertTrue(this.transferCompletedLatch.await(10, TimeUnit.SECONDS));
	assertTrue(this.aclLatch.await(10, TimeUnit.SECONDS));

	ArgumentCaptor<SetObjectAclRequest> setObjectAclRequestArgumentCaptor =
			ArgumentCaptor.forClass(SetObjectAclRequest.class);
	verify(amazonS3Client).setObjectAcl(setObjectAclRequestArgumentCaptor.capture());

	SetObjectAclRequest setObjectAclRequest = setObjectAclRequestArgumentCaptor.getValue();

	assertThat(setObjectAclRequest.getBucketName(), equalTo(S3_BUCKET));
	assertThat(setObjectAclRequest.getKey(), equalTo("foo.mp3"));
	assertNull(setObjectAclRequest.getAcl());
	assertThat(setObjectAclRequest.getCannedAcl(), equalTo(CannedAccessControlList.PublicReadWrite));
}
 
Example 13
Source File: BindingServiceTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
@Ignore
public void testLateBindingConsumer() throws Exception {
	BindingServiceProperties properties = new BindingServiceProperties();
	properties.setBindingRetryInterval(1);
	Map<String, BindingProperties> bindingProperties = new HashMap<>();
	BindingProperties props = new BindingProperties();
	props.setDestination("foo");
	final String inputChannelName = "input";
	bindingProperties.put(inputChannelName, props);
	properties.setBindings(bindingProperties);
	DefaultBinderFactory binderFactory = createMockBinderFactory();
	Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.initialize();
	BindingService service = new BindingService(properties, binderFactory, scheduler);
	MessageChannel inputChannel = new DirectChannel();
	final Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
	final CountDownLatch fail = new CountDownLatch(2);
	doAnswer(i -> {
		fail.countDown();
		if (fail.getCount() == 1) {
			throw new RuntimeException("fail");
		}
		return mockBinding;
	}).when(binder).bindConsumer(eq("foo"), isNull(), same(inputChannel),
			any(ConsumerProperties.class));
	Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
			inputChannelName);
	assertThat(fail.await(10, TimeUnit.SECONDS)).isTrue();
	assertThat(bindings).hasSize(1);
	Binding<MessageChannel> delegate = TestUtils
			.getPropertyValue(bindings.iterator().next(), "delegate", Binding.class);
	int n = 0;
	while (n++ < 300 && delegate == null) {
		Thread.sleep(400);
	}
	assertThat(delegate).isSameAs(mockBinding);
	service.unbindConsumers(inputChannelName);
	verify(binder, times(2)).bindConsumer(eq("foo"), isNull(), same(inputChannel),
			any(ConsumerProperties.class));
	verify(delegate).unbind();
	binderFactory.destroy();
}
 
Example 14
Source File: BindingServiceTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testLateBindingProducer() throws Exception {
	BindingServiceProperties properties = new BindingServiceProperties();
	properties.setBindingRetryInterval(1);
	Map<String, BindingProperties> bindingProperties = new HashMap<>();
	BindingProperties props = new BindingProperties();
	props.setDestination("foo");
	final String outputChannelName = "output";
	bindingProperties.put(outputChannelName, props);
	properties.setBindings(bindingProperties);
	DefaultBinderFactory binderFactory = createMockBinderFactory();
	Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.initialize();
	BindingService service = new BindingService(properties, binderFactory, scheduler);
	MessageChannel outputChannel = new DirectChannel();
	final Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
	final CountDownLatch fail = new CountDownLatch(2);
	doAnswer(i -> {
		fail.countDown();
		if (fail.getCount() == 1) {
			throw new RuntimeException("fail");
		}
		return mockBinding;
	}).when(binder).bindProducer(eq("foo"), same(outputChannel),
			any(ProducerProperties.class));
	Binding<MessageChannel> binding = service.bindProducer(outputChannel,
			outputChannelName);
	assertThat(fail.await(10, TimeUnit.SECONDS)).isTrue();
	assertThat(binding).isNotNull();
	Binding delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class);
	int n = 0;
	while (n++ < 300 && delegate == null) {
		Thread.sleep(100);
		delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class);
	}
	assertThat(delegate).isSameAs(mockBinding);
	service.unbindProducers(outputChannelName);
	verify(binder, times(2)).bindProducer(eq("foo"), same(outputChannel),
			any(ProducerProperties.class));
	verify(delegate).unbind();
	binderFactory.destroy();
	scheduler.destroy();
}
 
Example 15
Source File: AbstractMessageChannelBinderTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testEndpointLifecycle() throws Exception {
	// @checkstyle:off
	AbstractMessageChannelBinder<ConsumerProperties, ProducerProperties, ProvisioningProvider<ConsumerProperties, ProducerProperties>> binder = this.context
			.getBean(AbstractMessageChannelBinder.class);
	// @checkstyle:on

	ConsumerProperties consumerProperties = new ConsumerProperties();
	consumerProperties.setMaxAttempts(1); // to force error infrastructure creation

	Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo", "fooGroup",
			new DirectChannel(), consumerProperties);
	DirectFieldAccessor consumerBindingAccessor = new DirectFieldAccessor(
			consumerBinding);
	MessageProducer messageProducer = (MessageProducer) consumerBindingAccessor
			.getPropertyValue("lifecycle");
	assertThat(((Lifecycle) messageProducer).isRunning()).isTrue();
	assertThat(messageProducer.getOutputChannel()).isNotNull();

	SubscribableChannel errorChannel = (SubscribableChannel) consumerBindingAccessor
			.getPropertyValue("lifecycle.errorChannel");
	assertThat(errorChannel).isNotNull();
	Set<MessageHandler> handlers = TestUtils.getPropertyValue(errorChannel,
			"dispatcher.handlers", Set.class);
	assertThat(handlers.size()).isEqualTo(2);
	Iterator<MessageHandler> iterator = handlers.iterator();
	assertThat(iterator.next()).isInstanceOf(BridgeHandler.class);
	assertThat(iterator.next()).isInstanceOf(LastSubscriberMessageHandler.class);
	assertThat(this.context.containsBean("foo.fooGroup.errors")).isTrue();
	assertThat(this.context.containsBean("foo.fooGroup.errors.recoverer")).isTrue();
	assertThat(this.context.containsBean("foo.fooGroup.errors.handler")).isTrue();
	assertThat(this.context.containsBean("foo.fooGroup.errors.bridge")).isTrue();
	consumerBinding.unbind();
	assertThat(this.context.containsBean("foo.fooGroup.errors")).isFalse();
	assertThat(this.context.containsBean("foo.fooGroup.errors.recoverer")).isFalse();
	assertThat(this.context.containsBean("foo.fooGroup.errors.handler")).isFalse();
	assertThat(this.context.containsBean("foo.fooGroup.errors.bridge")).isFalse();

	assertThat(((Lifecycle) messageProducer).isRunning()).isFalse();

	ProducerProperties producerProps = new ProducerProperties();
	producerProps.setErrorChannelEnabled(true);
	Binding<MessageChannel> producerBinding = binder.bindProducer("bar",
			new DirectChannel(), producerProps);
	assertThat(this.context.containsBean("bar.errors")).isTrue();
	assertThat(this.context.containsBean("bar.errors.bridge")).isTrue();
	producerBinding.unbind();
	assertThat(this.context.containsBean("bar.errors")).isFalse();
	assertThat(this.context.containsBean("bar.errors.bridge")).isFalse();
}
 
Example 16
Source File: SqsMessageMarshallerTests.java    From spring-integration-aws with MIT License 4 votes vote down vote up
private void checkMessageMarshallerRef(SqsExecutor sqsExecutor) {
	final MessageMarshaller messageMarshaller = TestUtils.getPropertyValue(
			sqsExecutor, "messageMarshaller", MessageMarshaller.class);
	assertNotNull(messageMarshaller);
	assertThat(messageMarshaller, instanceOf(TestMessageMarshaller.class));
}
 
Example 17
Source File: SqsMessageHandlerParserTests.java    From spring-integration-aws with MIT License 4 votes vote down vote up
@Test
public void testSqsMessageHandlerParser() throws Exception {
	setUp("SqsMessageHandlerParserTests.xml", getClass());

	final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(
			this.consumer, "inputChannel", AbstractMessageChannel.class);

	assertEquals("target", inputChannel.getComponentName());

	final SqsExecutor sqsExecutor = TestUtils.getPropertyValue(
			this.consumer, "handler.sqsExecutor", SqsExecutor.class);

	assertNotNull(sqsExecutor);

	final String queueNameProperty = TestUtils.getPropertyValue(
			sqsExecutor, "queueName", String.class);

	assertEquals("testQueue", queueNameProperty);

}
 
Example 18
Source File: SnsMessageMarshallerTests.java    From spring-integration-aws with MIT License 4 votes vote down vote up
private void checkMessageMarshallerRef(SnsExecutor snsExecutor) {
	final MessageMarshaller messageMarshaller = TestUtils.getPropertyValue(
			snsExecutor, "messageMarshaller", MessageMarshaller.class);
	assertNotNull(messageMarshaller);
	assertThat(messageMarshaller, instanceOf(TestMessageMarshaller.class));
}
 
Example 19
Source File: KafkaStreamsBinderWordCountIntegrationTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 4 votes vote down vote up
@Test
public void testSendToTombstone()
		throws Exception {
	SpringApplication app = new SpringApplication(
			WordCountProcessorApplication.class);
	app.setWebApplicationType(WebApplicationType.NONE);

	try (ConfigurableApplicationContext context = app.run("--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.input.destination=words-1",
			"--spring.cloud.stream.bindings.output.destination=counts-1",
			"--spring.cloud.stream.kafka.streams.bindings.input.consumer.application-id=testKstreamWordCountWithInputBindingLevelApplicationId",
			"--spring.cloud.stream.kafka.streams.binder.configuration.commit.interval.ms=1000",
			"--spring.cloud.stream.kafka.streams.binder.configuration.default.key.serde"
					+ "=org.apache.kafka.common.serialization.Serdes$StringSerde",
			"--spring.cloud.stream.kafka.streams.binder.configuration.default.value.serde"
					+ "=org.apache.kafka.common.serialization.Serdes$StringSerde",
			"--spring.cloud.stream.kafka.streams.bindings.output.producer.valueSerde=org.springframework.kafka.support.serializer.JsonSerde",
			"--spring.cloud.stream.kafka.streams.timeWindow.length=5000",
			"--spring.cloud.stream.kafka.streams.timeWindow.advanceBy=0",
			"--spring.cloud.stream.bindings.input.consumer.concurrency=2",
			"--spring.cloud.stream.kafka.streams.binder.brokers="
					+ embeddedKafka.getBrokersAsString())) {
		receiveAndValidate("words-1", "counts-1");
		// Assertions on StreamBuilderFactoryBean
		StreamsBuilderFactoryBean streamsBuilderFactoryBean = context
				.getBean("&stream-builder-WordCountProcessorApplication-process", StreamsBuilderFactoryBean.class);
		KafkaStreams kafkaStreams = streamsBuilderFactoryBean.getKafkaStreams();
		assertThat(kafkaStreams).isNotNull();
		// Ensure that concurrency settings are mapped to number of stream task
		// threads in Kafka Streams.
		final Properties streamsConfiguration = streamsBuilderFactoryBean.getStreamsConfiguration();
		final Integer concurrency = (Integer) streamsConfiguration
				.get(StreamsConfig.NUM_STREAM_THREADS_CONFIG);
		assertThat(concurrency).isEqualTo(2);

		sendTombStoneRecordsAndVerifyGracefulHandling();

		CleanupConfig cleanup = TestUtils.getPropertyValue(streamsBuilderFactoryBean,
				"cleanupConfig", CleanupConfig.class);
		assertThat(cleanup.cleanupOnStart()).isTrue();
		assertThat(cleanup.cleanupOnStop()).isFalse();
	}
}
 
Example 20
Source File: SqsOutboundGatewayParserTests.java    From spring-integration-aws with MIT License 3 votes vote down vote up
@Test
public void testRetrievingSqsOutboundGatewayParser() throws Exception {
	setUp("SqsOutboundGatewayParserTests.xml", getClass(),
			"sqsOutboundGateway");

	final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(
			this.consumer, "inputChannel", AbstractMessageChannel.class);

	assertEquals("in", inputChannel.getComponentName());

	final SqsOutboundGateway sqsOutboundGateway = TestUtils
			.getPropertyValue(this.consumer, "handler",
					SqsOutboundGateway.class);

	long sendTimeout = TestUtils.getPropertyValue(sqsOutboundGateway,
			"messagingTemplate.sendTimeout", Long.class);

	assertEquals(100, sendTimeout);

	final SqsExecutor sqsExecutor = TestUtils.getPropertyValue(
			this.consumer, "handler.sqsExecutor", SqsExecutor.class);

	assertNotNull(sqsExecutor);

	final String queueNameProperty = TestUtils.getPropertyValue(
			sqsExecutor, "queueName", String.class);

	assertEquals("testQueue", queueNameProperty);

}