org.springframework.integration.test.util.TestUtils Java Examples

The following examples show how to use org.springframework.integration.test.util.TestUtils. 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: SqsChannelParserTests.java    From spring-integration-aws with MIT License 6 votes vote down vote up
@Test
public void testSqsInboundChannelAdapterParser() throws Exception {

	setUp("SqsChannelParserTests.xml", getClass(), "sqsChannel");

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

	assertNotNull(sqsExecutor);

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

	assertEquals("testQueue", queueNameProperty);

	Object sqsExecutorProxy = context.getBean("sqsExecutorProxy");
	assertNotNull(sqsExecutorProxy);
	assertEquals(SqsExecutorProxy.class, sqsExecutorProxy.getClass());
	SqsExecutor proxiedExecutor = TestUtils.getPropertyValue(
			sqsExecutorProxy, "sqsExecutor", SqsExecutor.class);
	assertNotNull(proxiedExecutor);
	SqsExecutor innerBean = context.getBean(SqsExecutor.class);
	assertSame(innerBean, proxiedExecutor);
}
 
Example #2
Source File: ThroughputSinkTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void testSink() throws Exception {
	assertNotNull(this.sink.input());
	this.sink.input().send(new GenericMessage<>("foo"));
	Log logger = spy(TestUtils.getPropertyValue(this.configuration, "logger", Log.class));
	new DirectFieldAccessor(this.configuration).setPropertyValue("logger", logger);
	final CountDownLatch latch = new CountDownLatch(1);
	doAnswer(new Answer<Void>() {

		@Override
		public Void answer(InvocationOnMock invocation) throws Throwable {
			invocation.callRealMethod();
			latch.countDown();
			return null;
		}

	}).when(logger).info(anyString());
	assertTrue(latch.await(10, TimeUnit.SECONDS));
}
 
Example #3
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 #4
Source File: SplitterProcessorIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
	assertThat(this.splitter, instanceOf(FileSplitter.class));
	assertSame(this.splitter, TestUtils.getPropertyValue(this.consumer, "handler"));
	File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "splitter.proc.test");
	FileOutputStream fos = new FileOutputStream(file);
	fos.write("hello\nworld\n".getBytes());
	fos.close();
	this.channels.input().send(new GenericMessage<>(file));
	Message<?> m = this.collector.forChannel(this.channels.output()).poll(10, TimeUnit.SECONDS);
	assertNotNull(m);
	assertThat(m.getPayload(), instanceOf(FileMarker.class));
	assertThat((FileMarker) m.getPayload(), hasMark(Mark.START));
	assertThat(m, allOf(hasSequenceNumber(1), hasSequenceSize(0)));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("hello")));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("world")));
	assertThat(this.collector.forChannel(this.channels.output()),
			receivesPayloadThat(allOf(
					instanceOf(FileMarker.class),
		 			hasMark(Mark.END))));
	file.delete();
}
 
Example #5
Source File: SplitterProcessorIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
	assertThat(this.splitter, instanceOf(FileSplitter.class));
	assertSame(this.splitter, TestUtils.getPropertyValue(this.consumer, "handler"));
	File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "splitter.proc.test");
	FileOutputStream fos = new FileOutputStream(file);
	fos.write("hello\nworld\n".getBytes());
	fos.close();
	this.channels.input().send(new GenericMessage<>(file));
	Message<?> m = this.collector.forChannel(this.channels.output()).poll(10, TimeUnit.SECONDS);
	assertNotNull(m);
	assertNull((m.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)));
	assertThat(m, hasPayload("hello"));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("world")));
	file.delete();
}
 
Example #6
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 #7
Source File: SqsPermissionsParserTests.java    From spring-integration-aws with MIT License 6 votes vote down vote up
@Test
public void outboundGatewayPermissions() {
	EventDrivenConsumer consumer = context.getBean("sqs-gateway",
			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 #8
Source File: LogSinkApplicationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
	assertNotNull(this.sink.input());
	assertEquals(LoggingHandler.Level.WARN, this.logSinkHandler.getLevel());
	Log logger = TestUtils.getPropertyValue(this.logSinkHandler, "messageLogger",
			Log.class);
	assertEquals("foo", TestUtils.getPropertyValue(logger, "name"));
	logger = spy(logger);
	new DirectFieldAccessor(this.logSinkHandler).setPropertyValue("messageLogger",
			logger);
	GenericMessage<String> message = new GenericMessage<>("foo");
	this.sink.input().send(message);
	ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
	verify(logger).warn(captor.capture());
	assertEquals("FOO", captor.getValue());
	this.logSinkHandler.setExpression("#this");
	this.sink.input().send(message);
	verify(logger, times(2)).warn(captor.capture());
	assertSame(message, captor.getValue());
}
 
Example #9
Source File: SqsPermissionsParserTests.java    From spring-integration-aws with MIT License 6 votes vote down vote up
@Test
public void channelPermissions() {
	SubscribableChannel channel = context.getBean("sqs-channel",
			SubscribableChannel.class);
	assertThat(channel, is(notNullValue()));

	final SqsExecutor executor = TestUtils.getPropertyValue(channel,
			"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 #10
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 #11
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 #12
Source File: SnsPermissionsParserTests.java    From spring-integration-aws with MIT License 6 votes vote down vote up
@Test
public void outboundPermissions() {
	EventDrivenConsumer consumer = context.getBean("sns-outbound",
			EventDrivenConsumer.class);
	assertThat(consumer, is(notNullValue()));

	final SnsExecutor executor = TestUtils.getPropertyValue(consumer,
			"handler.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 #13
Source File: SnsPermissionsParserTests.java    From spring-integration-aws with MIT License 6 votes vote down vote up
@Test
public void outboundGatewayPermissions() {
	EventDrivenConsumer consumer = context.getBean("sns-gateway",
			EventDrivenConsumer.class);
	assertThat(consumer, is(notNullValue()));

	final SnsExecutor executor = TestUtils.getPropertyValue(consumer,
			"handler.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 #14
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 #15
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 #16
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 #17
Source File: JmsSourceTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	AbstractMessageListenerContainer container = TestUtils.getPropertyValue(this.endpoint, "listenerContainer",
			AbstractMessageListenerContainer.class);
	assertThat(container, instanceOf(SimpleMessageListenerContainer.class));
	assertEquals(Session.DUPS_OK_ACKNOWLEDGE, TestUtils.getPropertyValue(container, "sessionAcknowledgeMode"));
	assertFalse(TestUtils.getPropertyValue(container, "sessionTransacted", Boolean.class));
	assertEquals("client", TestUtils.getPropertyValue(container, "clientId"));
	assertEquals("topic", 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"));
	assertTrue(TestUtils.getPropertyValue(container, "pubSubDomain", Boolean.class));
}
 
Example #18
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 #19
Source File: KafkastreamsBinderPojoInputStringOutputIntegrationTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
public void testKstreamBinderWithPojoInputAndStringOuput() throws Exception {
	SpringApplication app = new SpringApplication(ProductCountApplication.class);
	app.setWebApplicationType(WebApplicationType.NONE);
	ConfigurableApplicationContext context = app.run("--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.input.destination=foos",
			"--spring.cloud.stream.bindings.output.destination=counts-id",
			"--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.input.consumer.applicationId=ProductCountApplication-xyz",
			"--spring.cloud.stream.kafka.streams.binder.brokers="
					+ embeddedKafka.getBrokersAsString());
	try {
		receiveAndValidateFoo();
		// Assertions on StreamBuilderFactoryBean
		StreamsBuilderFactoryBean streamsBuilderFactoryBean = context
				.getBean("&stream-builder-ProductCountApplication-process", StreamsBuilderFactoryBean.class);
		CleanupConfig cleanup = TestUtils.getPropertyValue(streamsBuilderFactoryBean,
				"cleanupConfig", CleanupConfig.class);
		assertThat(cleanup.cleanupOnStart()).isFalse();
		assertThat(cleanup.cleanupOnStop()).isTrue();
	}
	finally {
		context.close();
	}
}
 
Example #20
Source File: SqsClientConfigurationTest.java    From spring-integration-aws with MIT License 5 votes vote down vote up
@Test
public void testClientConfigurationInjectedExplicitly() {

	setUp("SqsClientConfigurationTests.xml", getClass(),
			"sqsChannelWithClientConfiguration");

	final ClientConfiguration clientConfiguration = TestUtils
			.getPropertyValue(sqsChannelWithClientConfiguration,
					"sqsExecutor.awsClientConfiguration",
					ClientConfiguration.class);
	assertThat(clientConfiguration.getProtocol(), is(Protocol.HTTPS));
	assertThat(clientConfiguration.getProxyHost(), is("PROXY_HOST"));
}
 
Example #21
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 #22
Source File: SnsChannelParserTests.java    From spring-integration-aws with MIT License 5 votes vote down vote up
@Test
public void testSnsChannelParser() {
	setUp("SnsChannelParserTests.xml", getClass(), "snsChannel");

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

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

	assertEquals(true, TestUtils.getPropertyValue(channel, "autoStartup",
			Boolean.class));

	assertTrue(TestUtils.getPropertyValue(channel, "phase", Integer.class) == 0);

	@SuppressWarnings("unchecked")
	final List<Subscription> subscriptions = TestUtils.getPropertyValue(
			snsExecutor, "subscriptionList", List.class);
	assertThat(subscriptions, is(not(empty())));
	Subscription defS = subscriptions.get(0);
	assertThat(defS.getEndpoint(), containsString("www.example.com"));

	Object snsExecutorProxy = context.getBean("snsExecutorProxy");
	assertNotNull(snsExecutorProxy);
	assertEquals(SnsExecutorProxy.class, snsExecutorProxy.getClass());
	SnsExecutor proxiedExecutor = TestUtils.getPropertyValue(
			snsExecutorProxy, "snsExecutor", SnsExecutor.class);
	assertNotNull(proxiedExecutor);
	SnsExecutor innerBean = context.getBean(SnsExecutor.class);
	assertSame(innerBean, proxiedExecutor);
}
 
Example #23
Source File: SyslogSourceTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	assertThat(this.connectionFactory, Matchers.instanceOf(TcpNioServerConnectionFactory.class));
	assertTrue(TestUtils.getPropertyValue(this.connectionFactory, "lookupHost", Boolean.class));
	assertEquals(123, TestUtils.getPropertyValue(this.connectionFactory, "soTimeout"));
	assertEquals(5, TestUtils.getPropertyValue(this.connectionFactory, "deserializer.maxMessageSize"));
}
 
Example #24
Source File: FtpSourceIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void sourceFilesAsRef() throws InterruptedException {
	assertEquals("*", TestUtils.getPropertyValue(TestUtils.getPropertyValue(sourcePollingChannelAdapter,
								"source.synchronizer.filter.fileFilters", Set.class).iterator().next(), "path"));
	for (int i = 1; i <= 2; i++) {
		@SuppressWarnings("unchecked")
		Message<File> received = (Message<File>) messageCollector.forChannel(ftpSource.output()).poll(10,
				TimeUnit.SECONDS);
		assertNotNull(received);
		assertThat(received.getPayload(), equalTo(new File(config.getLocalDir() + "/ftpSource" + i + ".txt")));
	}
	assertThat(this.sessionFactory, instanceOf(CachingSessionFactory.class));
}
 
Example #25
Source File: SftpSourceIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void sourceFilesAsRef() throws InterruptedException {
	assertEquals(".*", TestUtils.getPropertyValue(TestUtils.getPropertyValue(sourcePollingChannelAdapter,
			"source.synchronizer.filter.fileFilters", Set.class).iterator().next(), "pattern").toString());
	for (int i = 1; i <= 2; i++) {
		@SuppressWarnings("unchecked")
		Message<File> received = (Message<File>) messageCollector.forChannel(sftpSource.output()).poll(10,
				TimeUnit.SECONDS);
		assertNotNull(received);
		assertThat(received.getPayload(), equalTo(new File(config.getLocalDir() + "/sftpSource" + i + ".txt")));
	}
}
 
Example #26
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 #27
Source File: MailSourceConfigurationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleTest() throws Exception {

	Message<?> received = this.messageCollector.forChannel(source.output()).poll(10, TimeUnit.SECONDS);
	assertNotNull(received);
	assertThat(received.getPayload(), Matchers.instanceOf(String.class));
	assertTrue(!received.getPayload().equals("Test Mail"));

	MailToStringTransformer mailToStringTransformer = this.beanFactory.getBean(MailToStringTransformer.class);
	assertEquals("cp1251", TestUtils.getPropertyValue(mailToStringTransformer, "charset"));
}
 
Example #28
Source File: SplitterProcessorIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
	assertThat(this.splitter, instanceOf(DefaultMessageSplitter.class));
	assertSame(this.splitter, TestUtils.getPropertyValue(this.consumer, "handler"));
	this.channels.input().send(new GenericMessage<>(Arrays.asList("hello", "world")));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("hello")));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("world")));
}
 
Example #29
Source File: SplitterProcessorIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
	assertThat(this.splitter, instanceOf(DefaultMessageSplitter.class));
	assertSame(this.splitter, TestUtils.getPropertyValue(this.consumer, "handler"));
	this.channels.input().send(new GenericMessage<>("hello,world"));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("hello")));
	assertThat(this.collector.forChannel(this.channels.output()), receivesPayloadThat(is("world")));
}
 
Example #30
Source File: TcpSinkTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	assertThat(this.connectionFactory, Matchers.instanceOf(TcpNioClientConnectionFactory.class));
	assertEquals("foo", this.connectionFactory.getHost());
	assertTrue(TestUtils.getPropertyValue(this.connectionFactory, "lookupHost", Boolean.class));
	assertTrue(TestUtils.getPropertyValue(this.connectionFactory, "usingDirectBuffers", Boolean.class));
	assertEquals(123, TestUtils.getPropertyValue(this.connectionFactory, "soTimeout"));
	assertTrue(this.connectionFactory.isSingleUse());
	assertEquals("bar", TestUtils.getPropertyValue(this.connectionFactory, "mapper.charset"));
}