INTEXT-221: Document S3 Gateway & CheckStyle

JIRA: https://jira.spring.io/browse/INTEXT-221

Also apply Checkstyle for the project
Move testing to the `AssertJ`
Adjust `.travis.yml` for Gradle 2.13
Add `CODE_OF_CONDUCT.adoc`
This commit is contained in:
Artem Bilan
2016-05-18 18:44:38 -04:00
parent f946a1d5e9
commit 5d4bcb37db
39 changed files with 1000 additions and 696 deletions

View File

@@ -16,11 +16,7 @@
package org.springframework.integration.aws.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Method;
import java.util.Collection;
@@ -70,35 +66,37 @@ public class S3InboundChannelAdapterParserTests {
@Test
public void testFtpInboundChannelAdapterComplete() throws Exception {
assertFalse(TestUtils.getPropertyValue(this.s3Inbound, "autoStartup", Boolean.class));
assertThat(TestUtils.getPropertyValue(this.s3Inbound, "autoStartup", Boolean.class)).isFalse();
PriorityBlockingQueue<?> blockingQueue = TestUtils.getPropertyValue(this.s3Inbound,
"source.fileSource.toBeReceived", PriorityBlockingQueue.class);
Comparator<?> comparator = blockingQueue.comparator();
assertSame(this.comparator, comparator);
assertEquals("s3Inbound", this.s3Inbound.getComponentName());
assertEquals("aws:s3-inbound-channel-adapter", this.s3Inbound.getComponentType());
assertSame(this.s3Channel, TestUtils.getPropertyValue(this.s3Inbound, "outputChannel"));
assertThat(comparator).isSameAs(this.comparator);
assertThat(this.s3Inbound.getComponentName()).isEqualTo("s3Inbound");
assertThat(this.s3Inbound.getComponentType()).isEqualTo("aws:s3-inbound-channel-adapter");
assertThat(TestUtils.getPropertyValue(this.s3Inbound, "outputChannel")).isSameAs(this.s3Channel);
S3InboundFileSynchronizingMessageSource inbound = TestUtils.getPropertyValue(this.s3Inbound, "source",
S3InboundFileSynchronizingMessageSource.class);
S3InboundFileSynchronizer fisync = TestUtils.getPropertyValue(inbound, "synchronizer",
S3InboundFileSynchronizer.class);
assertEquals("'foo/bar'",
TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class)
.getExpressionString());
assertNotNull(TestUtils.getPropertyValue(fisync, "localFilenameGeneratorExpression"));
assertTrue(TestUtils.getPropertyValue(fisync, "preserveTimestamp", Boolean.class));
assertEquals(".foo", TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class));
assertThat(TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class)
.getExpressionString())
.isEqualTo("'foo/bar'");
assertThat(TestUtils.getPropertyValue(fisync, "localFilenameGeneratorExpression")).isNotNull();
assertThat(TestUtils.getPropertyValue(fisync, "preserveTimestamp", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class)).isEqualTo(".foo");
String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator");
assertNotNull(remoteFileSeparator);
assertEquals("", remoteFileSeparator);
assertThat(remoteFileSeparator).isNotNull();
assertThat(remoteFileSeparator).isEmpty();
S3SimplePatternFileListFilter filter = TestUtils.getPropertyValue(fisync, "filter",
S3SimplePatternFileListFilter.class);
assertNotNull(filter);
assertSame(this.s3SessionFactory, TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory"));
assertTrue(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class)
.contains(this.acceptAllFilter));
assertThat(filter).isNotNull();
assertThat(TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory"))
.isSameAs(this.s3SessionFactory);
assertThat(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class)
.contains(this.acceptAllFilter))
.isTrue();
final AtomicReference<Method> genMethod = new AtomicReference<Method>();
ReflectionUtils.doWithMethods(AbstractInboundFileSynchronizer.class, new ReflectionUtils.MethodCallback() {
@@ -111,7 +109,7 @@ public class S3InboundChannelAdapterParserTests {
}
});
assertEquals("FOO.afoo", genMethod.get().invoke(fisync, "foo"));
assertThat(genMethod.get().invoke(fisync, "foo")).isEqualTo("FOO.afoo");
}
}

View File

@@ -16,10 +16,7 @@
package org.springframework.integration.aws.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -86,59 +83,69 @@ public class S3MessageHandlerParserTests {
@Test
public void testS3OutboundChannelAdapterParser() {
assertSame(this.amazonS3,
TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "transferManager.s3"));
assertEquals("foo", TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"bucketExpression.literalValue"));
assertEquals("'bar'", TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"destinationBucketExpression.expression"));
assertEquals("'baz'", TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"destinationKeyExpression.expression"));
assertEquals("payload.name", TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"keyExpression.expression"));
assertEquals("'qux'", TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"objectAclExpression.expression"));
assertEquals(S3MessageHandler.Command.COPY.name(),
TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "commandExpression.literalValue"));
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "transferManager.s3"))
.isSameAs(this.amazonS3);
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"bucketExpression.literalValue"))
.isEqualTo("foo");
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"destinationBucketExpression.expression"))
.isEqualTo("'bar'");
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"destinationKeyExpression.expression"))
.isEqualTo("'baz'");
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"keyExpression.expression"))
.isEqualTo("payload.name");
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler,
"objectAclExpression.expression"))
.isEqualTo("'qux'");
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "commandExpression.literalValue"))
.isEqualTo(S3MessageHandler.Command.COPY.name());
assertFalse(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "produceReply", Boolean.class));
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "produceReply", Boolean.class))
.isFalse();
assertSame(this.progressListener,
TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "s3ProgressListener"));
assertSame(this.uploadMetadataProvider,
TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "uploadMetadataProvider"));
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "s3ProgressListener"))
.isSameAs(this.progressListener);
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapterHandler, "uploadMetadataProvider"))
.isSameAs(this.uploadMetadataProvider);
assertEquals(100, this.s3OutboundChannelAdapter.getPhase());
assertFalse(this.s3OutboundChannelAdapter.isAutoStartup());
assertFalse(this.s3OutboundChannelAdapter.isRunning());
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.s3OutboundChannelAdapter, "inputChannel"));
assertSame(this.s3OutboundChannelAdapterHandler,
TestUtils.getPropertyValue(this.s3OutboundChannelAdapter, "handler"));
assertThat(this.s3OutboundChannelAdapter.getPhase()).isEqualTo(100);
assertThat(this.s3OutboundChannelAdapter.isAutoStartup()).isFalse();
assertThat(this.s3OutboundChannelAdapter.isRunning()).isFalse();
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapter, "inputChannel"))
.isSameAs(this.errorChannel);
assertThat(TestUtils.getPropertyValue(this.s3OutboundChannelAdapter, "handler"))
.isSameAs(this.s3OutboundChannelAdapterHandler);
}
@Test
public void testS3OutboundGatewayParser() {
assertSame(this.transferManager,
TestUtils.getPropertyValue(this.s3OutboundGatewayHandler, "transferManager"));
assertEquals("'FOO'", TestUtils.getPropertyValue(this.s3OutboundGatewayHandler,
"bucketExpression.expression"));
assertThat(TestUtils.getPropertyValue(this.s3OutboundGatewayHandler, "transferManager"))
.isSameAs(this.transferManager);
assertThat(TestUtils.getPropertyValue(this.s3OutboundGatewayHandler,
"bucketExpression.expression"))
.isEqualTo("'FOO'");
Expression commandExpression =
TestUtils.getPropertyValue(this.s3OutboundGatewayHandler, "commandExpression", Expression.class);
assertEquals("'" + S3MessageHandler.Command.DOWNLOAD.name() + "'",
TestUtils.getPropertyValue(commandExpression, "expression"));
assertThat(TestUtils.getPropertyValue(commandExpression, "expression"))
.isEqualTo("'" + S3MessageHandler.Command.DOWNLOAD.name() + "'");
StandardEvaluationContext evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory);
S3MessageHandler.Command command =
commandExpression.getValue(evaluationContext, S3MessageHandler.Command.class);
assertEquals(S3MessageHandler.Command.DOWNLOAD, command);
assertThat(command).isEqualTo(S3MessageHandler.Command.DOWNLOAD);
assertTrue(TestUtils.getPropertyValue(this.s3OutboundGatewayHandler, "produceReply", Boolean.class));
assertSame(this.nullChannel, TestUtils.getPropertyValue(this.s3OutboundGatewayHandler, "outputChannel"));
assertThat(TestUtils.getPropertyValue(this.s3OutboundGatewayHandler, "produceReply", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(this.s3OutboundGatewayHandler, "outputChannel"))
.isSameAs(this.nullChannel);
assertTrue(this.s3OutboundGateway.isRunning());
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.s3OutboundGateway, "inputChannel"));
assertSame(this.s3OutboundGatewayHandler, TestUtils.getPropertyValue(this.s3OutboundGateway, "handler"));
assertThat(this.s3OutboundGateway.isRunning()).isTrue();
assertThat(TestUtils.getPropertyValue(this.s3OutboundGateway, "inputChannel")).isSameAs(this.errorChannel);
assertThat(TestUtils.getPropertyValue(this.s3OutboundGateway, "handler"))
.isSameAs(this.s3OutboundGatewayHandler);
}
}

View File

@@ -1,35 +1,28 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.config.xml;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer;
import org.springframework.integration.aws.inbound.SnsInboundChannelAdapter;
import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.test.util.TestUtils;
@@ -62,19 +55,25 @@ public class SnsInboundChannelAdapterParserTests {
@Test
public void testSnsInboundChannelAdapterParser() {
assertSame(this.amazonSns, TestUtils.getPropertyValue(this.snsInboundChannelAdapter,
"notificationStatusResolver.amazonSns"));
assertTrue(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "handleNotificationStatus", Boolean.class));
assertArrayEquals(new String[] {"/foo"},
TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "requestMapping.pathPatterns", String[].class));
assertEquals("payload.Message",
TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "payloadExpression.expression"));
assertFalse(this.snsInboundChannelAdapter.isRunning());
assertEquals(100, this.snsInboundChannelAdapter.getPhase());
assertFalse(this.snsInboundChannelAdapter.isAutoStartup());
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "requestChannel"));
assertSame(this.nullChannel, TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "errorChannel"));
assertEquals(2000L, TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "messagingTemplate.sendTimeout"));
assertThat(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "notificationStatusResolver.amazonSns"))
.isSameAs(this.amazonSns);
assertThat(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "handleNotificationStatus",
Boolean.class))
.isTrue();
assertThat(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "requestMapping.pathPatterns",
String[].class))
.isEqualTo(new String[] { "/foo" });
assertThat(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "payloadExpression.expression"))
.isEqualTo("payload.Message");
assertThat(this.snsInboundChannelAdapter.isRunning()).isFalse();
assertThat(this.snsInboundChannelAdapter.getPhase()).isEqualTo(100);
assertThat(this.snsInboundChannelAdapter.isAutoStartup()).isFalse();
assertThat(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "requestChannel"))
.isSameAs(this.errorChannel);
assertThat(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "errorChannel"))
.isSameAs(this.nullChannel);
assertThat(TestUtils.getPropertyValue(this.snsInboundChannelAdapter, "messagingTemplate.sendTimeout"))
.isEqualTo(2000L);
}
}

View File

@@ -1,29 +1,22 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.config.xml;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
@@ -85,42 +78,43 @@ public class SnsOutboundChannelAdapterParserTests {
@Test
public void testSnsOutboundChannelAdapterDefaultParser() throws Exception {
Object handler = TestUtils.getPropertyValue(this.defaultAdapter, "handler");
assertFalse(AopUtils.isAopProxy(handler));
assertThat(AopUtils.isAopProxy(handler)).isFalse();
assertSame(this.defaultAdapterHandler, handler);
assertThat(handler).isSameAs(this.defaultAdapterHandler);
assertThat(TestUtils.getPropertyValue(handler, "adviceChain", List.class).get(0),
instanceOf(RequestHandlerRetryAdvice.class));
assertThat(TestUtils.getPropertyValue(handler, "adviceChain", List.class).get(0))
.isInstanceOf(RequestHandlerRetryAdvice.class);
assertSame(this.defaultAdapterChannel, TestUtils.getPropertyValue(this.defaultAdapter, "inputChannel"));
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "inputChannel"))
.isSameAs(this.defaultAdapterChannel);
assertSame(this.amazonSns, TestUtils.getPropertyValue(this.defaultAdapterHandler, "amazonSns"));
assertNotNull(TestUtils.getPropertyValue(this.defaultAdapterHandler, "evaluationContext"));
assertNull(TestUtils.getPropertyValue(this.defaultAdapterHandler, "topicArnExpression"));
assertNull(TestUtils.getPropertyValue(this.defaultAdapterHandler, "subjectExpression"));
assertNull(TestUtils.getPropertyValue(this.defaultAdapterHandler, "bodyExpression"));
assertThat(TestUtils.getPropertyValue(this.defaultAdapterHandler, "amazonSns")).isSameAs(this.amazonSns);
assertThat(TestUtils.getPropertyValue(this.defaultAdapterHandler, "evaluationContext")).isNotNull();
assertThat(TestUtils.getPropertyValue(this.defaultAdapterHandler, "topicArnExpression")).isNull();
assertThat(TestUtils.getPropertyValue(this.defaultAdapterHandler, "subjectExpression")).isNull();
assertThat(TestUtils.getPropertyValue(this.defaultAdapterHandler, "bodyExpression")).isNull();
}
@Test
public void testSnsOutboundChannelAdapterParser() {
assertSame(this.notificationChannel, TestUtils.getPropertyValue(this.snsGateway, "inputChannel"));
assertSame(this.snsGatewayHandler, TestUtils.getPropertyValue(this.snsGateway, "handler"));
assertFalse(TestUtils.getPropertyValue(this.snsGateway, "autoStartup", Boolean.class));
assertEquals(new Integer(201), TestUtils.getPropertyValue(this.snsGateway, "phase", Integer.class));
assertTrue(TestUtils.getPropertyValue(this.snsGatewayHandler, "produceReply", Boolean.class));
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.snsGatewayHandler, "outputChannel"));
assertThat(TestUtils.getPropertyValue(this.snsGateway, "inputChannel")).isSameAs(this.notificationChannel);
assertThat(TestUtils.getPropertyValue(this.snsGateway, "handler")).isSameAs(this.snsGatewayHandler);
assertThat(TestUtils.getPropertyValue(this.snsGateway, "autoStartup", Boolean.class)).isFalse();
assertThat(TestUtils.getPropertyValue(this.snsGateway, "phase", Integer.class)).isEqualTo(201);
assertThat(TestUtils.getPropertyValue(this.snsGatewayHandler, "produceReply", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(this.snsGatewayHandler, "outputChannel")).isSameAs(this.errorChannel);
assertSame(this.amazonSns, TestUtils.getPropertyValue(this.snsGatewayHandler, "amazonSns"));
assertNotNull(TestUtils.getPropertyValue(this.snsGatewayHandler, "evaluationContext"));
assertEquals("foo",
TestUtils.getPropertyValue(this.snsGatewayHandler, "topicArnExpression", Expression.class)
.getExpressionString());
assertEquals("bar",
TestUtils.getPropertyValue(this.snsGatewayHandler, "subjectExpression", Expression.class)
.getExpressionString());
assertEquals("payload.toUpperCase()",
TestUtils.getPropertyValue(this.snsGatewayHandler, "bodyExpression", Expression.class)
.getExpressionString());
assertThat(TestUtils.getPropertyValue(this.snsGatewayHandler, "amazonSns")).isSameAs(this.amazonSns);
assertThat(TestUtils.getPropertyValue(this.snsGatewayHandler, "evaluationContext")).isNotNull();
assertThat(TestUtils.getPropertyValue(this.snsGatewayHandler, "topicArnExpression", Expression.class)
.getExpressionString())
.isEqualTo("foo");
assertThat(TestUtils.getPropertyValue(this.snsGatewayHandler, "subjectExpression", Expression.class)
.getExpressionString())
.isEqualTo("bar");
assertThat(TestUtils.getPropertyValue(this.snsGatewayHandler, "bodyExpression", Expression.class)
.getExpressionString())
.isEqualTo("payload.toUpperCase()");
}
}

View File

@@ -1,30 +1,26 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doThrow;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -78,8 +74,8 @@ public class SqsMessageDrivenChannelAdapterParserTests {
@Bean
public DestinationResolver<?> destinationResolver() {
DestinationResolver<?> destinationResolver = Mockito.mock(DestinationResolver.class);
doThrow(DestinationResolutionException.class)
.when(destinationResolver)
willThrow(DestinationResolutionException.class)
.given(destinationResolver)
.resolveDestination(anyString());
return destinationResolver;
}
@@ -89,30 +85,35 @@ public class SqsMessageDrivenChannelAdapterParserTests {
SimpleMessageListenerContainer listenerContainer =
TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter, "listenerContainer",
SimpleMessageListenerContainer.class);
assertSame(this.amazonSqs, TestUtils.getPropertyValue(listenerContainer, "amazonSqs"));
assertSame(this.resourceIdResolver, TestUtils.getPropertyValue(listenerContainer, "resourceIdResolver"));
assertSame(this.taskExecutor, TestUtils.getPropertyValue(listenerContainer, "taskExecutor"));
assertSame(this.destinationResolver, TestUtils.getPropertyValue(listenerContainer, "destinationResolver"));
assertFalse(listenerContainer.isRunning());
assertEquals(5, TestUtils.getPropertyValue(listenerContainer, "maxNumberOfMessages"));
assertEquals(200, TestUtils.getPropertyValue(listenerContainer, "visibilityTimeout"));
assertEquals(40, TestUtils.getPropertyValue(listenerContainer, "waitTimeOut"));
assertThat(TestUtils.getPropertyValue(listenerContainer, "amazonSqs")).isSameAs(this.amazonSqs);
assertThat(TestUtils.getPropertyValue(listenerContainer, "resourceIdResolver"))
.isSameAs(this.resourceIdResolver);
assertThat(TestUtils.getPropertyValue(listenerContainer, "taskExecutor")).isSameAs(this.taskExecutor);
assertThat(TestUtils.getPropertyValue(listenerContainer, "destinationResolver"))
.isSameAs(this.destinationResolver);
assertThat(listenerContainer.isRunning()).isFalse();
assertThat(TestUtils.getPropertyValue(listenerContainer, "maxNumberOfMessages")).isEqualTo(5);
assertThat(TestUtils.getPropertyValue(listenerContainer, "visibilityTimeout")).isEqualTo(200);
assertThat(TestUtils.getPropertyValue(listenerContainer, "waitTimeOut")).isEqualTo(40);
@SuppressWarnings("rawtypes")
Map queues = TestUtils.getPropertyValue(listenerContainer, "registeredQueues", Map.class);
assertTrue(queues.keySet().contains("foo"));
assertTrue(queues.keySet().contains("bar"));
assertThat(queues.keySet().contains("foo")).isTrue();
assertThat(queues.keySet().contains("bar")).isTrue();
assertEquals(100, this.sqsMessageDrivenChannelAdapter.getPhase());
assertFalse(this.sqsMessageDrivenChannelAdapter.isAutoStartup());
assertFalse(this.sqsMessageDrivenChannelAdapter.isRunning());
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter, "outputChannel"));
assertSame(this.nullChannel, TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter, "errorChannel"));
assertEquals(2000L, TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter,
"messagingTemplate.sendTimeout"));
assertEquals(SqsMessageDeletionPolicy.NEVER,
TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter, "messageDeletionPolicy",
SqsMessageDeletionPolicy.class));
assertThat(this.sqsMessageDrivenChannelAdapter.getPhase()).isEqualTo(100);
assertThat(this.sqsMessageDrivenChannelAdapter.isAutoStartup()).isFalse();
assertThat(this.sqsMessageDrivenChannelAdapter.isRunning()).isFalse();
assertThat(TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter, "outputChannel"))
.isSameAs(this.errorChannel);
assertThat(TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter, "errorChannel"))
.isSameAs(this.nullChannel);
assertThat(TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter,
"messagingTemplate.sendTimeout"))
.isEqualTo(2000L);
assertThat(TestUtils.getPropertyValue(this.sqsMessageDrivenChannelAdapter, "messageDeletionPolicy",
SqsMessageDeletionPolicy.class))
.isEqualTo(SqsMessageDeletionPolicy.NEVER);
}
}

View File

@@ -1,24 +1,22 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -26,9 +24,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.aws.core.env.ResourceIdResolver;
import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
@@ -62,18 +58,21 @@ public class SqsMessageHandlerParserTests {
@Test
public void testSqsMessageHandlerParser() {
assertSame(this.amazonSqs,
TestUtils.getPropertyValue(this.sqsOutboundChannelAdapterHandler, "template.amazonSqs"));
assertSame(this.resourceIdResolver, TestUtils.getPropertyValue(this.sqsOutboundChannelAdapterHandler,
"template.destinationResolver.targetDestinationResolver.resourceIdResolver"));
assertEquals("foo", TestUtils.getPropertyValue(this.sqsOutboundChannelAdapterHandler,
"queueExpression.literalValue"));
assertEquals(100, this.sqsOutboundChannelAdapter.getPhase());
assertFalse(this.sqsOutboundChannelAdapter.isAutoStartup());
assertFalse(this.sqsOutboundChannelAdapter.isRunning());
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.sqsOutboundChannelAdapter, "inputChannel"));
assertSame(this.sqsOutboundChannelAdapterHandler,
TestUtils.getPropertyValue(this.sqsOutboundChannelAdapter, "handler"));
assertThat(TestUtils.getPropertyValue(this.sqsOutboundChannelAdapterHandler, "template.amazonSqs"))
.isSameAs(this.amazonSqs);
assertThat(TestUtils.getPropertyValue(this.sqsOutboundChannelAdapterHandler,
"template.destinationResolver.targetDestinationResolver.resourceIdResolver"))
.isSameAs(this.resourceIdResolver);
assertThat(TestUtils.getPropertyValue(this.sqsOutboundChannelAdapterHandler,
"queueExpression.literalValue"))
.isEqualTo("foo");
assertThat(this.sqsOutboundChannelAdapter.getPhase()).isEqualTo(100);
assertThat(this.sqsOutboundChannelAdapter.isAutoStartup()).isFalse();
assertThat(this.sqsOutboundChannelAdapter.isRunning()).isFalse();
assertThat(TestUtils.getPropertyValue(this.sqsOutboundChannelAdapter, "inputChannel"))
.isSameAs(this.errorChannel);
assertThat(TestUtils.getPropertyValue(this.sqsOutboundChannelAdapter, "handler"))
.isSameAs(this.sqsOutboundChannelAdapterHandler);
}
}

View File

@@ -1,26 +1,27 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.config.xml;
import org.junit.Assert;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.aws.outbound.SqsMessageHandler;
import org.springframework.integration.test.util.TestUtils;
@@ -33,37 +34,39 @@ public class SqsOutboundChannelAdapterParserTests {
@Test(expected = BeanDefinitionStoreException.class)
public void test_sqs_resource_resolver_defined_with_queue_messaging_template() {
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad.xml", this.getClass());
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad.xml", getClass()).close();
}
@Test(expected = BeanDefinitionStoreException.class)
public void test_sqs_defined_with_queue_messaging_template() {
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad2.xml", this.getClass());
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad2.xml", getClass()).close();
}
@Test(expected = BeanDefinitionStoreException.class)
public void test_resource_resolver_defined_with_queue_messaging_template() {
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad3.xml", this.getClass());
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad3.xml", getClass()).close();
}
@Test(expected = BeanDefinitionStoreException.class)
public void test_neither_sqs_nor_queue_messaging_template_defined() {
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad4.xml", this.getClass());
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-bad4.xml", getClass()).close();
}
@Test
public void test_happy_path_with_queue_messaging_template() {
ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-good.xml", this.getClass());
ConfigurableApplicationContext applicationContext =
new ClassPathXmlApplicationContext("SqsOutboundChannelAdapterParserTests-context-good.xml", getClass());
SqsMessageHandler handlerWithTemplate =
applicationContext.getBean("sqsOutboundChannelAdapterWithQueueMessagingTemplate.handler",
SqsMessageHandler.class);
Assert.assertNotNull(TestUtils.getPropertyValue(handlerWithTemplate, "template"));
assertThat(TestUtils.getPropertyValue(handlerWithTemplate, "template")).isNotNull();
SqsMessageHandler handlerWithSqs = applicationContext.getBean("sqsOutboundChannelAdapterWithSqs.handler",
SqsMessageHandler.class);
Assert.assertNotNull(TestUtils.getPropertyValue(handlerWithSqs, "template"));
assertThat(TestUtils.getPropertyValue(handlerWithSqs, "template")).isNotNull();
applicationContext.close();
}
}

View File

@@ -16,13 +16,7 @@
package org.springframework.integration.aws.inbound;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Matchers.any;
@@ -34,7 +28,6 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
@@ -84,8 +77,6 @@ public class S3InboundChannelAdapterTests {
@ClassRule
public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder();
private static File REMOTE_FOLDER;
private static List<S3Object> S3_OBJECTS;
private static File LOCAL_FOLDER;
@@ -95,17 +86,18 @@ public class S3InboundChannelAdapterTests {
@BeforeClass
public static void setup() throws IOException {
REMOTE_FOLDER = TEMPORARY_FOLDER.newFolder("remote");
File aFile = new File(REMOTE_FOLDER, "a.test");
File remoteFolder = TEMPORARY_FOLDER.newFolder("remote");
File aFile = new File(remoteFolder, "a.test");
FileCopyUtils.copy("Hello".getBytes(), aFile);
File bFile = new File(REMOTE_FOLDER, "b.test");
File bFile = new File(remoteFolder, "b.test");
FileCopyUtils.copy("Bye".getBytes(), bFile);
File otherFile = new File(REMOTE_FOLDER, "otherFile");
File otherFile = new File(remoteFolder, "otherFile");
FileCopyUtils.copy("Other".getBytes(), otherFile);
S3_OBJECTS = new ArrayList<>();
for (File file : REMOTE_FOLDER.listFiles()) {
for (File file : remoteFolder.listFiles()) {
S3Object s3Object = new S3Object();
s3Object.setBucketName(S3_BUCKET);
s3Object.setKey(file.getName());
@@ -113,41 +105,41 @@ public class S3InboundChannelAdapterTests {
S3_OBJECTS.add(s3Object);
}
LOCAL_FOLDER = new File(TEMPORARY_FOLDER.getRoot(), "local");
LOCAL_FOLDER = TEMPORARY_FOLDER.newFolder("local");
}
@Test
public void testS3InboundChannelAdapter() throws IOException {
Message<?> message = this.s3FilesChannel.receive(10000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(File.class));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(File.class);
File localFile = (File) message.getPayload();
assertEquals("A.TEST.a", localFile.getName());
assertThat(localFile.getName()).isEqualTo("A.TEST.a");
// The test remote files are created with the current timestamp + 1 day.
assertThat(localFile.lastModified(), Matchers.greaterThan(System.currentTimeMillis()));
assertThat(localFile.lastModified()).isGreaterThan(System.currentTimeMillis());
message = this.s3FilesChannel.receive(10000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(File.class));
assertThat(message).isNotNull();
assertThat(message.getPayload()).isInstanceOf(File.class);
localFile = (File) message.getPayload();
assertEquals("B.TEST.a", localFile.getName());
assertThat(localFile.getName()).isEqualTo("B.TEST.a");
assertThat(localFile.lastModified(), Matchers.greaterThan(System.currentTimeMillis()));
assertThat(localFile.lastModified()).isGreaterThan(System.currentTimeMillis());
assertNull(this.s3FilesChannel.receive(10));
assertThat(this.s3FilesChannel.receive(10)).isNull();
File file = new File(LOCAL_FOLDER, "A.TEST.a");
assertTrue(file.exists());
assertThat(file.exists()).isTrue();
String content = FileCopyUtils.copyToString(new FileReader(file));
assertEquals("Hello", content);
assertThat(content).isEqualTo("Hello");
file = new File(LOCAL_FOLDER, "B.TEST.a");
assertTrue(file.exists());
assertThat(file.exists()).isTrue();
content = FileCopyUtils.copyToString(new FileReader(file));
assertEquals("Bye", content);
assertThat(content).isEqualTo("Bye");
assertFalse(new File(LOCAL_FOLDER, "otherFile.a").exists());
assertThat(new File(LOCAL_FOLDER, "otherFile.a").exists()).isFalse();
}
@Configuration

View File

@@ -1,25 +1,23 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -28,7 +26,7 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -98,11 +96,11 @@ public class SnsInboundChannelAdapterTests {
.andExpect(status().isNoContent());
Message<?> receive = inputChannel.receive(10000);
assertNotNull(receive);
assertTrue(receive.getHeaders().containsKey(AwsHeaders.SNS_MESSAGE_TYPE));
assertEquals("SubscriptionConfirmation", receive.getHeaders().get(AwsHeaders.SNS_MESSAGE_TYPE));
assertThat(receive).isNotNull();
assertThat(receive.getHeaders().containsKey(AwsHeaders.SNS_MESSAGE_TYPE)).isTrue();
assertThat(receive.getHeaders().get(AwsHeaders.SNS_MESSAGE_TYPE)).isEqualTo("SubscriptionConfirmation");
assertTrue(receive.getHeaders().containsKey(AwsHeaders.NOTIFICATION_STATUS));
assertThat(receive.getHeaders().containsKey(AwsHeaders.NOTIFICATION_STATUS)).isTrue();
NotificationStatus notificationStatus = (NotificationStatus) receive.getHeaders()
.get(AwsHeaders.NOTIFICATION_STATUS);
@@ -123,11 +121,11 @@ public class SnsInboundChannelAdapterTests {
.andExpect(status().isNoContent());
Message<?> receive = inputChannel.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
Map<String, String> payload = (Map<String, String>) receive.getPayload();
assertEquals("foo", payload.get("Subject"));
assertEquals("bar", payload.get("Message"));
assertThat(payload.get("Subject")).isEqualTo("foo");
assertThat(payload.get("Message")).isEqualTo("bar");
}
@Test
@@ -140,11 +138,11 @@ public class SnsInboundChannelAdapterTests {
.andExpect(status().isNoContent());
Message<?> receive = inputChannel.receive(10000);
assertNotNull(receive);
assertTrue(receive.getHeaders().containsKey(AwsHeaders.SNS_MESSAGE_TYPE));
assertEquals("UnsubscribeConfirmation", receive.getHeaders().get(AwsHeaders.SNS_MESSAGE_TYPE));
assertThat(receive).isNotNull();
assertThat(receive.getHeaders().containsKey(AwsHeaders.SNS_MESSAGE_TYPE)).isTrue();
assertThat(receive.getHeaders().get(AwsHeaders.SNS_MESSAGE_TYPE)).isEqualTo("UnsubscribeConfirmation");
assertTrue(receive.getHeaders().containsKey(AwsHeaders.NOTIFICATION_STATUS));
assertThat(receive.getHeaders().containsKey(AwsHeaders.NOTIFICATION_STATUS)).isTrue();
NotificationStatus notificationStatus = (NotificationStatus) receive.getHeaders()
.get(AwsHeaders.NOTIFICATION_STATUS);
@@ -160,7 +158,7 @@ public class SnsInboundChannelAdapterTests {
@Bean
public AmazonSNS amazonSns() {
return Mockito.mock(AmazonSNS.class);
return BDDMockito.mock(AmazonSNS.class);
}
@Bean

View File

@@ -1,29 +1,26 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.inbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -60,13 +57,13 @@ public class SqsMessageDrivenChannelAdapterTests {
@Test
public void testSqsMessageDrivenChannelAdapter() {
org.springframework.messaging.Message<?> receive = this.inputChannel.receive(1000);
assertNotNull(receive);
assertThat((String) receive.getPayload(), Matchers.isOneOf("messageContent", "messageContent2"));
assertEquals("testQueue", receive.getHeaders().get(AwsHeaders.QUEUE));
assertThat(receive).isNotNull();
assertThat((String) receive.getPayload()).isIn("messageContent", "messageContent2");
assertThat(receive.getHeaders().get(AwsHeaders.QUEUE)).isEqualTo("testQueue");
receive = this.inputChannel.receive(1000);
assertNotNull(receive);
assertThat((String) receive.getPayload(), Matchers.isOneOf("messageContent", "messageContent2"));
assertEquals("testQueue", receive.getHeaders().get(AwsHeaders.QUEUE));
assertThat(receive).isNotNull();
assertThat((String) receive.getPayload()).isIn("messageContent", "messageContent2");
assertThat(receive.getHeaders().get(AwsHeaders.QUEUE)).isEqualTo("testQueue");
}
@Configuration
@@ -76,20 +73,22 @@ public class SqsMessageDrivenChannelAdapterTests {
@Bean
public AmazonSQSAsync amazonSqs() {
AmazonSQSAsync sqs = mock(AmazonSQSAsync.class);
when(sqs.getQueueUrl(new GetQueueUrlRequest("testQueue"))).thenReturn(new GetQueueUrlResult().
withQueueUrl("http://testQueue.amazonaws.com"));
given(sqs.getQueueUrl(new GetQueueUrlRequest("testQueue")))
.willReturn(new GetQueueUrlResult().withQueueUrl("http://testQueue.amazonaws.com"));
when(sqs.receiveMessage(new ReceiveMessageRequest("http://testQueue.amazonaws.com")
given(sqs.receiveMessage(new ReceiveMessageRequest("http://testQueue.amazonaws.com")
.withAttributeNames("All")
.withMessageAttributeNames("All")
.withMaxNumberOfMessages(10)))
.thenReturn(new ReceiveMessageResult()
.willReturn(new ReceiveMessageResult()
.withMessages(new Message().withBody("messageContent"),
new Message().withBody("messageContent2")))
.thenReturn(new ReceiveMessageResult());
when(sqs.getQueueAttributes(any(GetQueueAttributesRequest.class)))
.thenReturn(new GetQueueAttributesResult());
.willReturn(new ReceiveMessageResult());
given(sqs.getQueueAttributes(any(GetQueueAttributesRequest.class)))
.willReturn(new GetQueueAttributesResult());
return sqs;
}

View File

@@ -1,24 +1,22 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.outbound;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -63,8 +61,8 @@ public abstract class AbstractSqsMessageHandlerTests {
this.sqsSendChannel.send(message);
}
catch (Exception e) {
assertThat(e, instanceOf(MessageHandlingException.class));
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
assertThat(e).isInstanceOf(MessageHandlingException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
}
this.sqsMessageHandler.setQueue("foo");
@@ -72,12 +70,14 @@ public abstract class AbstractSqsMessageHandlerTests {
ArgumentCaptor<SendMessageRequest> sendMessageRequestArgumentCaptor =
ArgumentCaptor.forClass(SendMessageRequest.class);
verify(this.amazonSqs).sendMessage(sendMessageRequestArgumentCaptor.capture());
assertEquals("http://queue-url.com/foo", sendMessageRequestArgumentCaptor.getValue().getQueueUrl());
assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl())
.isEqualTo("http://queue-url.com/foo");
message = MessageBuilder.withPayload("message").setHeader(AwsHeaders.QUEUE, "bar").build();
this.sqsSendChannel.send(message);
verify(this.amazonSqs, times(2)).sendMessage(sendMessageRequestArgumentCaptor.capture());
assertEquals("http://queue-url.com/bar", sendMessageRequestArgumentCaptor.getValue().getQueueUrl());
assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl())
.isEqualTo("http://queue-url.com/bar");
SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
Expression expression = spelExpressionParser.parseExpression("headers.foo");
@@ -85,7 +85,8 @@ public abstract class AbstractSqsMessageHandlerTests {
message = MessageBuilder.withPayload("message").setHeader("foo", "baz").build();
this.sqsSendChannel.send(message);
verify(this.amazonSqs, times(3)).sendMessage(sendMessageRequestArgumentCaptor.capture());
assertEquals("http://queue-url.com/baz", sendMessageRequestArgumentCaptor.getValue().getQueueUrl());
assertThat(sendMessageRequestArgumentCaptor.getValue().getQueueUrl())
.isEqualTo("http://queue-url.com/baz");
}
}

View File

@@ -1,33 +1,29 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.outbound;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -36,7 +32,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -45,14 +40,11 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.http.client.methods.HttpRequestBase;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -149,21 +141,21 @@ public class S3MessageHandlerTests {
verify(this.amazonS3, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture());
PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue();
assertEquals("myBucket", putObjectRequest.getBucketName());
assertEquals("foo.mp3", putObjectRequest.getKey());
assertNull(putObjectRequest.getFile());
assertNotNull(putObjectRequest.getInputStream());
assertThat(putObjectRequest.getBucketName()).isEqualTo("myBucket");
assertThat(putObjectRequest.getKey()).isEqualTo("foo.mp3");
assertThat(putObjectRequest.getFile()).isNull();
assertThat(putObjectRequest.getInputStream()).isNotNull();
ObjectMetadata metadata = putObjectRequest.getMetadata();
assertEquals(Md5Utils.md5AsBase64(file), metadata.getContentMD5());
assertEquals(0, metadata.getContentLength());
assertEquals("audio/mpeg", metadata.getContentType());
assertThat(metadata.getContentMD5()).isEqualTo(Md5Utils.md5AsBase64(file));
assertThat(metadata.getContentLength()).isEqualTo(0);
assertThat(metadata.getContentType()).isEqualTo("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));
assertThat(this.transferCompletedLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.aclLatch.await(10, TimeUnit.SECONDS)).isTrue();
ArgumentCaptor<SetObjectAclRequest> setObjectAclRequestArgumentCaptor =
ArgumentCaptor.forClass(SetObjectAclRequest.class);
@@ -171,10 +163,10 @@ public class S3MessageHandlerTests {
SetObjectAclRequest setObjectAclRequest = setObjectAclRequestArgumentCaptor.getValue();
assertEquals("myBucket", setObjectAclRequest.getBucketName());
assertEquals("foo.mp3", setObjectAclRequest.getKey());
assertNull(setObjectAclRequest.getAcl());
assertEquals(CannedAccessControlList.PublicReadWrite, setObjectAclRequest.getCannedAcl());
assertThat(setObjectAclRequest.getBucketName()).isEqualTo("myBucket");
assertThat(setObjectAclRequest.getKey()).isEqualTo("foo.mp3");
assertThat(setObjectAclRequest.getAcl()).isNull();
assertThat(setObjectAclRequest.getCannedAcl()).isEqualTo(CannedAccessControlList.PublicReadWrite);
}
@Test
@@ -192,16 +184,16 @@ public class S3MessageHandlerTests {
verify(this.amazonS3, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture());
PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue();
assertEquals("myBucket", putObjectRequest.getBucketName());
assertEquals("myStream", putObjectRequest.getKey());
assertNull(putObjectRequest.getFile());
assertNotNull(putObjectRequest.getInputStream());
assertThat(putObjectRequest.getBucketName()).isEqualTo("myBucket");
assertThat(putObjectRequest.getKey()).isEqualTo("myStream");
assertThat(putObjectRequest.getFile()).isNull();
assertThat(putObjectRequest.getInputStream()).isNotNull();
ObjectMetadata metadata = putObjectRequest.getMetadata();
assertEquals(Md5Utils.md5AsBase64(payload), metadata.getContentMD5());
assertEquals(1, metadata.getContentLength());
assertEquals(MediaType.APPLICATION_JSON_VALUE, metadata.getContentType());
assertEquals("test.json", metadata.getContentDisposition());
assertThat(metadata.getContentMD5()).isEqualTo(Md5Utils.md5AsBase64(payload));
assertThat(metadata.getContentLength()).isEqualTo(1);
assertThat(metadata.getContentType()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
assertThat(metadata.getContentDisposition()).isEqualTo("test.json");
}
@Test
@@ -214,26 +206,19 @@ public class S3MessageHandlerTests {
this.s3SendChannel.send(message);
File[] fileArray = directoryForDownload.listFiles();
assertNotNull(fileArray);
assertEquals(2, fileArray.length);
assertThat(fileArray).isNotNull();
assertThat(fileArray.length).isEqualTo(2);
List<File> files = Arrays.asList(fileArray);
Collections.sort(files, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
Collections.sort(files, (o1, o2) -> o1.getName().compareTo(o2.getName()));
File file1 = files.get(0);
assertEquals("bar", file1.getName());
assertEquals("bb", FileCopyUtils.copyToString(new FileReader(file1)));
assertThat(file1.getName()).isEqualTo("bar");
assertThat(FileCopyUtils.copyToString(new FileReader(file1))).isEqualTo("bb");
File file2 = files.get(1);
assertEquals("foo", file2.getName());
assertEquals("f", FileCopyUtils.copyToString(new FileReader(file2)));
assertThat(file2.getName()).isEqualTo("foo");
assertThat(FileCopyUtils.copyToString(new FileReader(file2))).isEqualTo("f");
}
@Test
@@ -245,15 +230,15 @@ public class S3MessageHandlerTests {
this.s3ProcessChannel.send(new GenericMessage<>(payload));
Message<?> receive = this.s3ReplyChannel.receive(10000);
assertNotNull(receive);
assertThat(receive).isNotNull();
Assert.assertThat(receive.getPayload(), instanceOf(Copy.class));
assertThat(receive.getPayload()).isInstanceOf(Copy.class);
Copy copy = (Copy) receive.getPayload();
assertEquals("Copying object from myBucket/mySource to theirBucket/theirTarget", copy.getDescription());
assertThat(copy.getDescription()).isEqualTo("Copying object from myBucket/mySource to theirBucket/theirTarget");
copy.waitForCompletion();
assertEquals(Transfer.TransferState.Completed, copy.getState());
assertThat(copy.getState()).isEqualTo(Transfer.TransferState.Completed);
}
@Configuration
@@ -264,9 +249,9 @@ public class S3MessageHandlerTests {
public AmazonS3 amazonS3() {
AmazonS3 amazonS3 = mock(AmazonS3.class);
when(amazonS3.putObject(any(PutObjectRequest.class))).thenReturn(new PutObjectResult());
when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))).thenReturn(new ObjectMetadata());
when(amazonS3.copyObject(any(CopyObjectRequest.class))).thenReturn(new CopyObjectResult());
given(amazonS3.putObject(any(PutObjectRequest.class))).willReturn(new PutObjectResult());
given(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))).willReturn(new ObjectMetadata());
given(amazonS3.copyObject(any(CopyObjectRequest.class))).willReturn(new CopyObjectResult());
ObjectListing objectListing = spy(new ObjectListing());
@@ -284,8 +269,8 @@ public class S3MessageHandlerTests {
fileSummary2.setSize(2);
s3ObjectSummaries.add(fileSummary2);
when(objectListing.getObjectSummaries()).thenReturn(s3ObjectSummaries);
when(amazonS3.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
given(objectListing.getObjectSummaries()).willReturn(s3ObjectSummaries);
given(amazonS3.listObjects(any(ListObjectsRequest.class))).willReturn(objectListing);
final S3Object file1 = new S3Object();
file1.setBucketName("myBucket");
@@ -317,34 +302,28 @@ public class S3MessageHandlerTests {
// no-op
}
doAnswer(new Answer<S3Object>() {
@Override
public S3Object answer(InvocationOnMock invocation) throws Throwable {
GetObjectRequest getObjectRequest = (GetObjectRequest) invocation.getArguments()[0];
String key = getObjectRequest.getKey();
if ("foo".equals(key)) {
return file1;
}
else if ("bar".equals(key)) {
return file2;
}
else {
return (S3Object) invocation.callRealMethod();
}
willAnswer(invocation -> {
GetObjectRequest getObjectRequest = (GetObjectRequest) invocation.getArguments()[0];
String key = getObjectRequest.getKey();
if ("foo".equals(key)) {
return file1;
}
}).when(amazonS3).getObject(any(GetObjectRequest.class));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
aclLatch().countDown();
return null;
else if ("bar".equals(key)) {
return file2;
}
else {
return invocation.callRealMethod();
}
})
.given(amazonS3)
.getObject(any(GetObjectRequest.class));
}).when(amazonS3).setObjectAcl(any(SetObjectAclRequest.class));
willAnswer(invocation -> {
aclLatch().countDown();
return null;
})
.given(amazonS3)
.setObjectAcl(any(SetObjectAclRequest.class));
return amazonS3;
}
@@ -388,17 +367,12 @@ public class S3MessageHandlerTests {
PARSER.parseExpression("payload instanceof T(java.io.File) ? payload.name : headers.key");
s3MessageHandler.setKeyExpression(keyExpression);
s3MessageHandler.setObjectAclExpression(new ValueExpression<>(CannedAccessControlList.PublicReadWrite));
s3MessageHandler.setUploadMetadataProvider(new S3MessageHandler.UploadMetadataProvider() {
@Override
public void populateMetadata(ObjectMetadata metadata, Message<?> message) {
if (message.getPayload() instanceof InputStream) {
metadata.setContentLength(1);
metadata.setContentType(MediaType.APPLICATION_JSON_VALUE);
metadata.setContentDisposition("test.json");
}
s3MessageHandler.setUploadMetadataProvider((metadata, message) -> {
if (message.getPayload() instanceof InputStream) {
metadata.setContentLength(1);
metadata.setContentType(MediaType.APPLICATION_JSON_VALUE);
metadata.setContentDisposition("test.json");
}
});
s3MessageHandler.setProgressListener(s3ProgressListener());
return s3MessageHandler;

View File

@@ -1,26 +1,23 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.outbound;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.junit.Test;
@@ -38,12 +35,12 @@ public class SnsMessageBuilderTests {
fail("IllegalArgumentException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), containsString("defaultMessage must not be empty."));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
assertThat(e.getMessage()).contains("defaultMessage must not be empty.");
}
String message = SnsBodyBuilder.withDefault("foo").build();
assertEquals("{\"default\":\"foo\"}", message);
assertThat(message).isEqualTo("{\"default\":\"foo\"}");
try {
SnsBodyBuilder.withDefault("foo")
@@ -52,8 +49,8 @@ public class SnsMessageBuilderTests {
fail("IllegalArgumentException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), containsString("protocols must not be empty."));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
assertThat(e.getMessage()).contains("protocols must not be empty.");
}
try {
SnsBodyBuilder.withDefault("foo")
@@ -62,15 +59,15 @@ public class SnsMessageBuilderTests {
fail("IllegalArgumentException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), containsString("protocols must not contain empty elements."));
assertThat(e).isInstanceOf(IllegalArgumentException.class);
assertThat(e.getMessage()).contains("protocols must not contain empty elements.");
}
message = SnsBodyBuilder.withDefault("foo")
.forProtocols("{\"foo\" : \"bar\"}", "sms")
.build();
assertEquals("{\"default\":\"foo\",\"sms\":\"{\\\"foo\\\" : \\\"bar\\\"}\"}", message);
assertThat(message).isEqualTo("{\"default\":\"foo\",\"sms\":\"{\\\"foo\\\" : \\\"bar\\\"}\"}");
}
}

View File

@@ -1,34 +1,30 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.outbound;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -83,21 +79,22 @@ public class SnsMessageHandlerTests {
this.sendToSnsChannel.send(message);
Message<?> reply = replyChannel.receive(1000);
assertNotNull(reply);
assertThat(reply).isNotNull();
ArgumentCaptor<PublishRequest> captor = ArgumentCaptor.forClass(PublishRequest.class);
verify(this.amazonSNS).publish(captor.capture());
PublishRequest publishRequest = captor.getValue();
assertEquals("json", publishRequest.getMessageStructure());
assertEquals("topic", publishRequest.getTopicArn());
assertEquals("subject", publishRequest.getSubject());
assertEquals("{\"default\":\"foo\",\"sms\":\"{\\\"foo\\\" : \\\"bar\\\"}\"}", publishRequest.getMessage());
assertThat(publishRequest.getMessageStructure()).isEqualTo("json");
assertThat(publishRequest.getTopicArn()).isEqualTo("topic");
assertThat(publishRequest.getSubject()).isEqualTo("subject");
assertThat(publishRequest.getMessage())
.isEqualTo("{\"default\":\"foo\",\"sms\":\"{\\\"foo\\\" : \\\"bar\\\"}\"}");
assertEquals("111", reply.getHeaders().get(AwsHeaders.SNS_PUBLISHED_MESSAGE_ID));
assertEquals("topic", reply.getHeaders().get(AwsHeaders.TOPIC));
assertSame(publishRequest, reply.getPayload());
assertThat(reply.getHeaders().get(AwsHeaders.SNS_PUBLISHED_MESSAGE_ID)).isEqualTo("111");
assertThat(reply.getHeaders().get(AwsHeaders.TOPIC)).isEqualTo("topic");
assertThat(reply.getPayload()).isSameAs(publishRequest);
}
@Configuration
@@ -108,13 +105,9 @@ public class SnsMessageHandlerTests {
public AmazonSNS amazonSNS() {
AmazonSNS mock = mock(AmazonSNS.class);
doAnswer(new Answer<PublishResult>() {
@Override
public PublishResult answer(InvocationOnMock invocation) throws Throwable {
return new PublishResult().withMessageId("111");
}
}).when(mock).publish(any(PublishRequest.class));
willAnswer(invocation -> new PublishResult().withMessageId("111"))
.given(mock)
.publish(any(PublishRequest.class));
return mock;
}

View File

@@ -1,28 +1,26 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.outbound;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -55,17 +53,14 @@ public class SqsMessageHandlerTests extends AbstractSqsMessageHandlerTests {
public AmazonSQS amazonSqs() {
AmazonSQS amazonSqs = mock(AmazonSQS.class);
doAnswer(new Answer<GetQueueUrlResult>() {
@Override
public GetQueueUrlResult answer(InvocationOnMock invocation) throws Throwable {
GetQueueUrlRequest getQueueUrlRequest = (GetQueueUrlRequest) invocation.getArguments()[0];
GetQueueUrlResult queueUrl = new GetQueueUrlResult();
queueUrl.setQueueUrl("http://queue-url.com/" + getQueueUrlRequest.getQueueName());
return queueUrl;
}
}).when(amazonSqs).getQueueUrl(any(GetQueueUrlRequest.class));
willAnswer(invocation -> {
GetQueueUrlRequest getQueueUrlRequest = (GetQueueUrlRequest) invocation.getArguments()[0];
GetQueueUrlResult queueUrl = new GetQueueUrlResult();
queueUrl.setQueueUrl("http://queue-url.com/" + getQueueUrlRequest.getQueueName());
return queueUrl;
})
.given(amazonSqs)
.getQueueUrl(any(GetQueueUrlRequest.class));
return amazonSqs;
}

View File

@@ -1,28 +1,26 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.aws.outbound;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
import org.springframework.context.annotation.Bean;
@@ -55,17 +53,14 @@ public class SqsMessageHandlerWithQueueMessagingTemplateTests extends AbstractSq
public AmazonSQS amazonSqs() {
AmazonSQS amazonSqs = mock(AmazonSQS.class);
doAnswer(new Answer<GetQueueUrlResult>() {
@Override
public GetQueueUrlResult answer(InvocationOnMock invocation) throws Throwable {
GetQueueUrlRequest getQueueUrlRequest = (GetQueueUrlRequest) invocation.getArguments()[0];
GetQueueUrlResult queueUrl = new GetQueueUrlResult();
queueUrl.setQueueUrl("http://queue-url.com/" + getQueueUrlRequest.getQueueName());
return queueUrl;
}
}).when(amazonSqs).getQueueUrl(any(GetQueueUrlRequest.class));
willAnswer(invocation -> {
GetQueueUrlRequest getQueueUrlRequest = (GetQueueUrlRequest) invocation.getArguments()[0];
GetQueueUrlResult queueUrl = new GetQueueUrlResult();
queueUrl.setQueueUrl("http://queue-url.com/" + getQueueUrlRequest.getQueueName());
return queueUrl;
})
.given(amazonSqs)
.getQueueUrl(any(GetQueueUrlRequest.class));
return amazonSqs;
}