This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7f8e3a98a975b3c48f851b2f785082cec8a40551 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Aug 21 16:53:53 2019 +0200 Camel-AWS-SQS: Fixed CS --- .../aws/sqs/MessageDeduplicationIdStrategy.java | 2 +- .../camel/component/aws/sqs/SqsComponent.java | 24 +++-- .../camel/component/aws/sqs/SqsConfiguration.java | 3 +- .../camel/component/aws/sqs/SqsConstants.java | 3 +- .../camel/component/aws/sqs/SqsConsumer.java | 4 +- .../camel/component/aws/sqs/SqsEndpoint.java | 95 +++++++++-------- .../component/aws/sqs/SqsHeaderFilterStrategy.java | 4 +- .../camel/component/aws/sqs/SqsOperations.java | 4 +- .../camel/component/aws/sqs/SqsProducer.java | 6 +- .../component/aws/sqs/AmazonSQSClientMock.java | 23 +++-- .../component/aws/sqs/SqsBatchConsumerTest.java | 19 ++-- .../aws/sqs/SqsComponentClientRegistryTest.java | 6 +- .../aws/sqs/SqsComponentConfigurationTest.java | 113 +++++++++++---------- .../component/aws/sqs/SqsComponentSpringTest.java | 30 +++--- .../camel/component/aws/sqs/SqsComponentTest.java | 41 ++++---- .../aws/sqs/SqsConcurrentConsumerTest.java | 22 ++-- .../component/aws/sqs/SqsConfigurationTest.java | 1 - .../aws/sqs/SqsConsumerIdleMessageTest.java | 8 +- .../sqs/SqsDoesNotExtendMessageVisibilityTest.java | 3 +- .../aws/sqs/SqsEndpointExplicitQueueUrlTest.java | 5 +- .../camel/component/aws/sqs/SqsEndpointTest.java | 73 +++++-------- .../aws/sqs/SqsEndpointUseExistingQueueTest.java | 17 ++-- .../aws/sqs/SqsExtendMessageVisibilityTest.java | 9 +- .../aws/sqs/SqsFilterMessagesWithNoDeleteTest.java | 36 +++---- .../component/aws/sqs/SqsProducerBatchTest.java | 7 +- .../component/aws/sqs/SqsProducerDeleteTest.java | 7 +- .../aws/sqs/SqsProducerListQueuesTest.java | 7 +- .../integration/SqsComponentIntegrationTest.java | 50 ++++----- .../SqsConsumerMessageIntegrationTest.java | 11 +- .../SqsProducerBatchSendFifoIntegrationTest.java | 5 +- .../SqsProducerDeleteMessageIntegrationTest.java | 5 +- 31 files changed, 310 insertions(+), 333 deletions(-) diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/MessageDeduplicationIdStrategy.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/MessageDeduplicationIdStrategy.java index 099b414..9f9310d 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/MessageDeduplicationIdStrategy.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/MessageDeduplicationIdStrategy.java @@ -19,7 +19,7 @@ package org.apache.camel.component.aws.sqs; import org.apache.camel.Exchange; public interface MessageDeduplicationIdStrategy { - + String getMessageDeduplicationId(Exchange exchange); } diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java index 68660e3..e6ec965 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java @@ -31,23 +31,23 @@ import org.apache.camel.util.ObjectHelper; @Component("aws-sqs") public class SqsComponent extends DefaultComponent { - + @Metadata private String accessKey; @Metadata private String secretKey; @Metadata private String region; - @Metadata(label = "advanced") + @Metadata(label = "advanced") private SqsConfiguration configuration; - + public SqsComponent() { this(null); } public SqsComponent(CamelContext context) { super(context); - + this.configuration = new SqsConfiguration(); registerExtension(new SqsComponentVerifierExtension()); } @@ -86,8 +86,9 @@ public class SqsComponent extends DefaultComponent { if (configuration.getAmazonSQSClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("AmazonSQSClient or accessKey and secretKey must be specified."); } - - // Verify that visibilityTimeout is set if extendMessageVisibility is set to true. + + // Verify that visibilityTimeout is set if extendMessageVisibility is + // set to true. if (configuration.isExtendMessageVisibility() && (configuration.getVisibilityTimeout() == null)) { throw new IllegalArgumentException("Extending message visibility (extendMessageVisibility) requires visibilityTimeout to be set on the Endpoint."); } @@ -96,7 +97,7 @@ public class SqsComponent extends DefaultComponent { sqsEndpoint.setConsumerProperties(parameters); return sqsEndpoint; } - + public SqsConfiguration getConfiguration() { return configuration; } @@ -107,7 +108,7 @@ public class SqsComponent extends DefaultComponent { public void setConfiguration(SqsConfiguration configuration) { this.configuration = configuration; } - + public String getAccessKey() { return configuration.getAccessKey(); } @@ -129,18 +130,19 @@ public class SqsComponent extends DefaultComponent { public void setSecretKey(String secretKey) { configuration.setSecretKey(secretKey); } - + public String getRegion() { return configuration.getRegion(); } /** - * Specify the queue region which could be used with queueOwnerAWSAccountId to build the service URL. + * Specify the queue region which could be used with queueOwnerAWSAccountId + * to build the service URL. */ public void setRegion(String region) { configuration.setRegion(region); } - + private void checkAndSetRegistryClient(SqsConfiguration configuration) { Set<AmazonSQS> clients = getCamelContext().getRegistry().findByType(AmazonSQS.class); if (clients.size() == 1) { diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java index e449e16..b8d0f6c 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConfiguration.java @@ -367,7 +367,8 @@ public class SqsConfiguration implements Cloneable { /** * Specify the queue region which could be used with queueOwnerAWSAccountId - * to build the service URL. When using this parameter, the configuration will expect the capitalized name of the region (for example AP_EAST_1) + * to build the service URL. When using this parameter, the configuration + * will expect the capitalized name of the region (for example AP_EAST_1) * You'll need to use the name Regions.EU_WEST_1.name() */ public void setRegion(String region) { diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConstants.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConstants.java index 4294fd7..d02d30c 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConstants.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConstants.java @@ -18,7 +18,6 @@ package org.apache.camel.component.aws.sqs; /** * Constants used in Camel AWS SQS module - * */ public interface SqsConstants { @@ -31,4 +30,4 @@ public interface SqsConstants { String MESSAGE_GROUP_ID_PROPERTY = "CamelAwsMessageGroupId"; String SQS_QUEUE_PREFIX = "CamelAwsSqsPrefix"; String SQS_OPERATION = "CamelAwsSqsOperation"; -} \ No newline at end of file +} diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java index 5c764d8..4458af5 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsConsumer.java @@ -161,8 +161,8 @@ public class SqsConsumer extends ScheduledBatchPollingConsumer { int period = visibilityTimeout.intValue(); int repeatSeconds = Double.valueOf(visibilityTimeout.doubleValue() * 1.5).intValue(); if (log.isDebugEnabled()) { - log.debug("Scheduled TimeoutExtender task to start after {} delay, and run with {}/{} period/repeat (seconds), to extend exchangeId: {}", - delay, period, repeatSeconds, exchange.getExchangeId()); + log.debug("Scheduled TimeoutExtender task to start after {} delay, and run with {}/{} period/repeat (seconds), to extend exchangeId: {}", delay, period, + repeatSeconds, exchange.getExchangeId()); } final ScheduledFuture<?> scheduledFuture = this.scheduledExecutor.scheduleAtFixedRate(new TimeoutExtender(exchange, repeatSeconds), delay, period, TimeUnit.SECONDS); diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java index ff8ac4e..8fb6d86 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java @@ -54,10 +54,10 @@ import org.apache.camel.util.FileUtil; import org.apache.camel.util.ObjectHelper; /** - * The aws-sqs component is used for sending and receiving messages to Amazon's SQS service. + * The aws-sqs component is used for sending and receiving messages to Amazon's + * SQS service. */ -@UriEndpoint(firstVersion = "2.6.0", scheme = "aws-sqs", title = "AWS Simple Queue Service", syntax = "aws-sqs:queueNameOrArn", - label = "cloud,messaging") +@UriEndpoint(firstVersion = "2.6.0", scheme = "aws-sqs", title = "AWS Simple Queue Service", syntax = "aws-sqs:queueNameOrArn", label = "cloud,messaging") public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterStrategyAware { private AmazonSQS client; @@ -106,53 +106,54 @@ public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterSt sqsConsumer.setScheduler(scheduler); return sqsConsumer; } - + @Override protected void doInit() throws Exception { super.doInit(); - client = getConfiguration().getAmazonSQSClient() != null - ? getConfiguration().getAmazonSQSClient() : getClient(); + client = getConfiguration().getAmazonSQSClient() != null ? getConfiguration().getAmazonSQSClient() : getClient(); - // check the setting the headerFilterStrategy - if (headerFilterStrategy == null) { - headerFilterStrategy = new SqsHeaderFilterStrategy(); - } + // check the setting the headerFilterStrategy + if (headerFilterStrategy == null) { + headerFilterStrategy = new SqsHeaderFilterStrategy(); + } - if (configuration.getQueueUrl() != null) { - queueUrl = configuration.getQueueUrl(); + if (configuration.getQueueUrl() != null) { + queueUrl = configuration.getQueueUrl(); + } else { + // If both region and Account ID is provided the queue URL can be + // built manually. + // This allows accessing queues where you don't have permission to + // list queues or query queues + if (configuration.getRegion() != null && configuration.getQueueOwnerAWSAccountId() != null) { + String host = configuration.getAmazonAWSHost(); + host = FileUtil.stripTrailingSeparator(host); + queueUrl = "https://sqs." + Regions.valueOf(configuration.getRegion()).getName() + "." + host + "/" + configuration.getQueueOwnerAWSAccountId() + "/" + + configuration.getQueueName(); + } else if (configuration.getQueueOwnerAWSAccountId() != null) { + GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(); + getQueueUrlRequest.setQueueName(configuration.getQueueName()); + getQueueUrlRequest.setQueueOwnerAWSAccountId(configuration.getQueueOwnerAWSAccountId()); + GetQueueUrlResult getQueueUrlResult = client.getQueueUrl(getQueueUrlRequest); + queueUrl = getQueueUrlResult.getQueueUrl(); } else { - // If both region and Account ID is provided the queue URL can be built manually. - // This allows accessing queues where you don't have permission to list queues or query queues - if (configuration.getRegion() != null && configuration.getQueueOwnerAWSAccountId() != null) { - String host = configuration.getAmazonAWSHost(); - host = FileUtil.stripTrailingSeparator(host); - queueUrl = "https://sqs." + Regions.valueOf(configuration.getRegion()).getName() + "." + host + "/" - + configuration.getQueueOwnerAWSAccountId() + "/" + configuration.getQueueName(); - } else if (configuration.getQueueOwnerAWSAccountId() != null) { - GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(); - getQueueUrlRequest.setQueueName(configuration.getQueueName()); - getQueueUrlRequest.setQueueOwnerAWSAccountId(configuration.getQueueOwnerAWSAccountId()); - GetQueueUrlResult getQueueUrlResult = client.getQueueUrl(getQueueUrlRequest); - queueUrl = getQueueUrlResult.getQueueUrl(); - } else { - // check whether the queue already exists - ListQueuesResult listQueuesResult = client.listQueues(); - for (String url : listQueuesResult.getQueueUrls()) { - if (url.endsWith("/" + configuration.getQueueName())) { - queueUrl = url; - log.trace("Queue available at '{}'.", queueUrl); - break; - } + // check whether the queue already exists + ListQueuesResult listQueuesResult = client.listQueues(); + for (String url : listQueuesResult.getQueueUrls()) { + if (url.endsWith("/" + configuration.getQueueName())) { + queueUrl = url; + log.trace("Queue available at '{}'.", queueUrl); + break; } } } + } - if (queueUrl == null && configuration.isAutoCreateQueue()) { - createQueue(client); - } else { - log.debug("Using Amazon SQS queue url: {}", queueUrl); - updateQueueAttributes(client); - } + if (queueUrl == null && configuration.isAutoCreateQueue()) { + createQueue(client); + } else { + log.debug("Using Amazon SQS queue url: {}", queueUrl); + updateQueueAttributes(client); + } } protected void createQueue(AmazonSQS client) { @@ -266,10 +267,11 @@ public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterSt message.setHeader(SqsConstants.ATTRIBUTES, msg.getAttributes()); message.setHeader(SqsConstants.MESSAGE_ATTRIBUTES, msg.getMessageAttributes()); - //Need to apply the SqsHeaderFilterStrategy this time + // Need to apply the SqsHeaderFilterStrategy this time HeaderFilterStrategy headerFilterStrategy = getHeaderFilterStrategy(); - //add all sqs message attributes as camel message headers so that knowledge of - //the Sqs class MessageAttributeValue will not leak to the client + // add all sqs message attributes as camel message headers so that + // knowledge of + // the Sqs class MessageAttributeValue will not leak to the client for (Entry<String, MessageAttributeValue> entry : msg.getMessageAttributes().entrySet()) { String header = entry.getKey(); Object value = translateValue(entry.getValue()); @@ -300,7 +302,9 @@ public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterSt } /** - * Provide the possibility to override this method for an mock implementation + * Provide the possibility to override this method for an mock + * implementation + * * @return AmazonSQSClient */ AmazonSQS createClient() { @@ -347,7 +351,8 @@ public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterSt /** * Gets the maximum number of messages as a limit to poll at each polling. * <p/> - * Is default unlimited, but use 0 or negative number to disable it as unlimited. + * Is default unlimited, but use 0 or negative number to disable it as + * unlimited. */ public void setMaxMessagesPerPoll(int maxMessagesPerPoll) { this.maxMessagesPerPoll = maxMessagesPerPoll; diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsHeaderFilterStrategy.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsHeaderFilterStrategy.java index 118f25b..8892ec1 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsHeaderFilterStrategy.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsHeaderFilterStrategy.java @@ -20,11 +20,11 @@ import org.apache.camel.support.DefaultHeaderFilterStrategy; public class SqsHeaderFilterStrategy extends DefaultHeaderFilterStrategy { public SqsHeaderFilterStrategy() { - initialize(); + initialize(); } protected void initialize() { // filter headers begin with "Camel" or "org.apache.camel" - setOutFilterPattern("(breadcrumbId|Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*"); + setOutFilterPattern("(breadcrumbId|Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*"); } } diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsOperations.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsOperations.java index 2ef17c7..0a65a87 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsOperations.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsOperations.java @@ -18,7 +18,5 @@ package org.apache.camel.component.aws.sqs; public enum SqsOperations { - sendBatchMessage, - deleteMessage, - listQueues + sendBatchMessage, deleteMessage, listQueues } diff --git a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java index edd929f..b260177 100644 --- a/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java +++ b/components/camel-aws-sqs/src/main/java/org/apache/camel/component/aws/sqs/SqsProducer.java @@ -105,7 +105,7 @@ public class SqsProducer extends DefaultProducer { if (exchange.getIn().getBody() instanceof Iterable) { Iterable c = exchange.getIn().getBody(Iterable.class); for (Object o : c) { - String object = (String) o; + String object = (String)o; SendMessageBatchRequestEntry entry = new SendMessageBatchRequestEntry(); entry.setId(UUID.randomUUID().toString()); entry.setMessageAttributes(translateAttributes(exchange.getIn().getHeaders(), exchange)); @@ -125,7 +125,7 @@ public class SqsProducer extends DefaultProducer { message.setBody(result); } } - + private void deleteMessage(AmazonSQS amazonSQS, Exchange exchange) { String receiptHandle = exchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE, String.class); DeleteMessageRequest request = new DeleteMessageRequest(); @@ -138,7 +138,7 @@ public class SqsProducer extends DefaultProducer { Message message = getMessageForResponse(exchange); message.setBody(result); } - + private void listQueues(AmazonSQS amazonSQS, Exchange exchange) { ListQueuesRequest request = new ListQueuesRequest(); if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(SqsConstants.SQS_QUEUE_PREFIX))) { diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/AmazonSQSClientMock.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/AmazonSQSClientMock.java index a6c333b..356ed5a 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/AmazonSQSClientMock.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/AmazonSQSClientMock.java @@ -71,7 +71,7 @@ public class AmazonSQSClientMock extends AbstractAmazonSQS { ListQueuesResult result = new ListQueuesResult(); return result; } - + @Override public ListQueuesResult listQueues(ListQueuesRequest request) { ListQueuesResult result = new ListQueuesResult(); @@ -98,12 +98,12 @@ public class AmazonSQSClientMock extends AbstractAmazonSQS { message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee"); message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458"); message.setReceiptHandle("0NNAq8PwvXsyZkR6yu4nQ07FGxNmOBWi5zC9+4QMqJZ0DJ3gVOmjI2Gh/oFnb0IeJqy5Zc8kH4JX7GVpfjcEDjaAPSeOkXQZRcaBqt" - + "4lOtyfj0kcclVV/zS7aenhfhX5Ixfgz/rHhsJwtCPPvTAdgQFGYrqaHly+etJiawiNPVc="); - + + "4lOtyfj0kcclVV/zS7aenhfhX5Ixfgz/rHhsJwtCPPvTAdgQFGYrqaHly+etJiawiNPVc="); + synchronized (messages) { messages.add(message); } - + SendMessageResult result = new SendMessageResult(); result.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458"); result.setMD5OfMessageBody("6a1559560f67c5e7a7d5d838bf0272ee"); @@ -115,7 +115,7 @@ public class AmazonSQSClientMock extends AbstractAmazonSQS { Integer maxNumberOfMessages = receiveMessageRequest.getMaxNumberOfMessages() != null ? receiveMessageRequest.getMaxNumberOfMessages() : Integer.MAX_VALUE; ReceiveMessageResult result = new ReceiveMessageResult(); Collection<Message> resultMessages = new ArrayList<>(); - + synchronized (messages) { int fetchSize = 0; for (Iterator<Message> iterator = messages.iterator(); iterator.hasNext() && fetchSize < maxNumberOfMessages; fetchSize++) { @@ -125,14 +125,14 @@ public class AmazonSQSClientMock extends AbstractAmazonSQS { scheduleCancelInflight(receiveMessageRequest.getQueueUrl(), rc); } } - + result.setMessages(resultMessages); return result; } /* - * Cancel (put back onto queue) in flight messages if the visibility time has expired - * and has not been manually deleted (ack'd) + * Cancel (put back onto queue) in flight messages if the visibility time + * has expired and has not been manually deleted (ack'd) */ private void scheduleCancelInflight(final String queueUrl, final Message message) { if (scheduler != null) { @@ -193,11 +193,12 @@ public class AmazonSQSClientMock extends AbstractAmazonSQS { } @Override - public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) throws AmazonServiceException, AmazonClientException { + public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest changeMessageVisibilityRequest) + throws AmazonServiceException, AmazonClientException { this.changeMessageVisibilityRequests.add(changeMessageVisibilityRequest); return new ChangeMessageVisibilityResult(); } - + @Override public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest request) { SendMessageBatchResult result = new SendMessageBatchResult(); @@ -219,4 +220,4 @@ public class AmazonSQSClientMock extends AbstractAmazonSQS { result.setFailed(entriesFail); return result; } -} \ No newline at end of file +} diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsBatchConsumerTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsBatchConsumerTest.java index 7d8c45e..1516727 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsBatchConsumerTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsBatchConsumerTest.java @@ -27,15 +27,15 @@ import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SqsBatchConsumerTest extends CamelTestSupport { - + @EndpointInject("mock:result") private MockEndpoint mock; - + @Test public void receiveBatch() throws Exception { mock.expectedMessageCount(5); assertMockEndpointsSatisfied(); - + mock.message(0).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(0); mock.message(1).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(1); mock.message(2).exchangeProperty(Exchange.BATCH_INDEX).isEqualTo(2); @@ -49,10 +49,10 @@ public class SqsBatchConsumerTest extends CamelTestSupport { mock.message(4).exchangeProperty(Exchange.BATCH_COMPLETE).isEqualTo(true); mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 5); } - + @BindToRegistry("amazonSQSClient") public AmazonSQSClientMock addClient() throws Exception { - + AmazonSQSClientMock clientMock = new AmazonSQSClientMock(); // add 6 messages, one more we will poll for (int counter = 0; counter < 6; counter++) { @@ -61,10 +61,10 @@ public class SqsBatchConsumerTest extends CamelTestSupport { message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee"); message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458"); message.setReceiptHandle("0NNAq8PwvXsyZkR6yu4nQ07FGxNmOBWi5"); - + clientMock.messages.add(message); } - + return clientMock; } @@ -73,9 +73,8 @@ public class SqsBatchConsumerTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&delay=5000&maxMessagesPerPoll=5") - .to("mock:result"); + from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&delay=5000&maxMessagesPerPoll=5").to("mock:result"); } }; } -} \ No newline at end of file +} diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentClientRegistryTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentClientRegistryTest.java index 40159c3..5dda4bb 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentClientRegistryTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentClientRegistryTest.java @@ -27,15 +27,15 @@ public class SqsComponentClientRegistryTest extends CamelTestSupport { AmazonSQSClientMock awsSQSClient = new AmazonSQSClientMock(); context.getRegistry().bind("awsSQSClient", awsSQSClient); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue"); + SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue"); assertNotNull(endpoint.getConfiguration().getAmazonSQSClient()); } - + @Test(expected = IllegalArgumentException.class) public void createEndpointWithMinimalSQSClientMisconfiguration() throws Exception { SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue"); + SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue"); } } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java index b80ff53..96a35aa 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java @@ -21,15 +21,15 @@ import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SqsComponentConfigurationTest extends CamelTestSupport { - + @Test public void createEndpointWithMinimalConfiguration() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy"); - + SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy"); + assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); @@ -44,10 +44,11 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { assertNull(endpoint.getConfiguration().getRedrivePolicy()); assertNull(endpoint.getConfiguration().getRegion()); } + @Test public void createEndpointWithOnlyAccessKeyAndSecretKey() throws Exception { SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy"); + SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy"); assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); @@ -63,11 +64,11 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { assertNull(endpoint.getConfiguration().getRedrivePolicy()); assertNull(endpoint.getConfiguration().getRegion()); } - + @Test public void createEndpointWithOnlyAccessKeyAndSecretKeyAndRegion() throws Exception { SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy®ion=US_WEST_1"); + SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy®ion=US_WEST_1"); assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); @@ -83,14 +84,15 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { assertNull(endpoint.getConfiguration().getPolicy()); assertNull(endpoint.getConfiguration().getRedrivePolicy()); } - + @Test public void createEndpointWithMinimalArnConfiguration() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://arn:aws:sqs:us-east-1:account:MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy"); + SqsEndpoint endpoint = (SqsEndpoint)component + .createEndpoint("aws-sqs://arn:aws:sqs:us-east-1:account:MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy"); assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion()); assertEquals("account", endpoint.getConfiguration().getQueueOwnerAWSAccountId()); @@ -101,10 +103,10 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointAttributeNames() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&attributeNames=foo,bar"); + SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&attributeNames=foo,bar"); assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); @@ -116,12 +118,12 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { @Test public void createEndpointWithMinimalConfigurationAndProvidedClient() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); - + SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"); - + SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"); + assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertNull(endpoint.getConfiguration().getAccessKey()); assertNull(endpoint.getConfiguration().getSecretKey()); @@ -136,23 +138,22 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { assertNull(endpoint.getConfiguration().getRedrivePolicy()); assertNull(endpoint.getConfiguration().getRegion()); } - + @Test public void createEndpointWithMaximalConfiguration() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx" - + "&secretKey=yyy&attributeNames=color,size" - + "&messageAttributeNames=msgColor,msgSize&DefaultVisibilityTimeout=1000&visibilityTimeout=2000&maximumMessageSize=65536&messageRetentionPeriod=1209600&policy=" - + "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyQueue%2FSQSDefaultPolicy%22%2C%22Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22" - + "Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyQueue%22%7D%5D%7D" - + "&delaySeconds=123&receiveMessageWaitTimeSeconds=10&waitTimeSeconds=20" - + "&queueOwnerAWSAccountId=111222333®ion=us-east-1" - + "&redrivePolicy={\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:195004372649:MyDeadLetterQueue\"}"); - + SqsEndpoint endpoint = (SqsEndpoint)component + .createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx" + "&secretKey=yyy&attributeNames=color,size" + + "&messageAttributeNames=msgColor,msgSize&DefaultVisibilityTimeout=1000&visibilityTimeout=2000&maximumMessageSize=65536&messageRetentionPeriod=1209600&policy=" + + "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyQueue%2FSQSDefaultPolicy%22%2C%22Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22" + + "Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyQueue%22%7D%5D%7D" + + "&delaySeconds=123&receiveMessageWaitTimeSeconds=10&waitTimeSeconds=20" + "&queueOwnerAWSAccountId=111222333®ion=us-east-1" + + "&redrivePolicy={\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:195004372649:MyDeadLetterQueue\"}"); + assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyy", endpoint.getConfiguration().getSecretKey()); @@ -164,93 +165,95 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { assertEquals(new Integer(65536), endpoint.getConfiguration().getMaximumMessageSize()); assertEquals(new Integer(1209600), endpoint.getConfiguration().getMessageRetentionPeriod()); assertEquals("{\"Version\":\"2008-10-17\",\"Id\":\"/195004372649/MyQueue/SQSDefaultPolicy\",\"Statement\":[{\"Sid\":\"Queue1ReceiveMessage\",\"Effect\":\"Allow\",\"Principal\":" - + "{\"AWS\":\"*\"},\"Action\":\"SQS:ReceiveMessage\",\"Resource\":\"/195004372649/MyQueue\"}]}", - endpoint.getConfiguration().getPolicy()); - assertEquals("{\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:195004372649:MyDeadLetterQueue\"}", endpoint.getConfiguration().getRedrivePolicy()); + + "{\"AWS\":\"*\"},\"Action\":\"SQS:ReceiveMessage\",\"Resource\":\"/195004372649/MyQueue\"}]}", endpoint.getConfiguration().getPolicy()); + assertEquals("{\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:195004372649:MyDeadLetterQueue\"}", + endpoint.getConfiguration().getRedrivePolicy()); assertEquals(new Integer(123), endpoint.getConfiguration().getDelaySeconds()); assertEquals(Integer.valueOf(10), endpoint.getConfiguration().getReceiveMessageWaitTimeSeconds()); assertEquals(Integer.valueOf(20), endpoint.getConfiguration().getWaitTimeSeconds()); assertEquals("111222333", endpoint.getConfiguration().getQueueOwnerAWSAccountId()); assertEquals("us-east-1", endpoint.getConfiguration().getRegion()); } - + @Test public void createEndpointWithPollConsumerConfiguration() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient" - + "&accessKey=xxx&secretKey=yyy&initialDelay=300&delay=400&maxMessagesPerPoll=50"); - SqsConsumer consumer = (SqsConsumer) endpoint.createConsumer(null); - + SqsEndpoint endpoint = (SqsEndpoint)component + .createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient" + "&accessKey=xxx&secretKey=yyy&initialDelay=300&delay=400&maxMessagesPerPoll=50"); + SqsConsumer consumer = (SqsConsumer)endpoint.createConsumer(null); + assertEquals(300, consumer.getInitialDelay()); assertEquals(400, consumer.getDelay()); assertEquals(50, consumer.getMaxMessagesPerPoll()); } - + @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutAccessKeyConfiguration() throws Exception { SqsComponent component = new SqsComponent(context); component.createEndpoint("aws-sqs://MyQueue?secretKey=yyy"); } - + @Test(expected = IllegalArgumentException.class) public void createEndpointWithoutSecretKeyConfiguration() throws Exception { SqsComponent component = new SqsComponent(context); component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx"); } - - // Setting extendMessageVisibility on an SQS consumer should make visibilityTimeout compulsory + + // Setting extendMessageVisibility on an SQS consumer should make + // visibilityTimeout compulsory @Test(expected = IllegalArgumentException.class) public void createEndpointWithExtendMessageVisibilityAndNoVisibilityTimeoutThrowsException() throws Exception { SqsComponent component = new SqsComponent(context); component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&extendMessageVisibility=true"); } - + @Test public void createEndpointWithExtendMessageVisibilityTrueAndVisibilityTimeoutSet() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); assertNotNull(component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=true")); } - + @Test public void createEndpointWithExtendMessageVisibilityFalseAndVisibilityTimeoutSet() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); - assertNotNull(component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=false")); + assertNotNull(component + .createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=false")); } - + @Test public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); - + SqsComponent component = new SqsComponent(context); component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"); } - + @Test public void createEndpointWithComponentElements() throws Exception { AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + context.getRegistry().bind("amazonSQSClient", mock); SqsComponent component = new SqsComponent(context); component.setAccessKey("XXX"); component.setSecretKey("YYY"); SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"); - + assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("XXX", endpoint.getConfiguration().getAccessKey()); assertEquals("YYY", endpoint.getConfiguration().getSecretKey()); } - + @Test public void createEndpointWithComponentAndEndpointElements() throws Exception { SqsComponent component = new SqsComponent(context); @@ -258,13 +261,13 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString()); SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1"); - + assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion()); } - + @Test public void createEndpointWithoutAutoCreation() throws Exception { SqsComponent component = new SqsComponent(context); @@ -272,7 +275,7 @@ public class SqsComponentConfigurationTest extends CamelTestSupport { component.setSecretKey("YYY"); component.setRegion(Regions.US_WEST_1.toString()); SqsEndpoint endpoint = (SqsEndpoint)component.createEndpoint("aws-sqs://MyQueue?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1&autoCreateQueue=false"); - + assertEquals("MyQueue", endpoint.getConfiguration().getQueueName()); assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey()); assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentSpringTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentSpringTest.java index e9e6ca7..f0c41a7 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentSpringTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentSpringTest.java @@ -33,25 +33,25 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SqsComponentSpringTest extends CamelSpringTestSupport { - + @EndpointInject("direct:start") private ProducerTemplate template; - + @EndpointInject("mock:result") private MockEndpoint result; - + @Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); - + Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); - + assertMockEndpointsSatisfied(); - + Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); @@ -59,23 +59,23 @@ public class SqsComponentSpringTest extends CamelSpringTestSupport { assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); - + assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); } - + @Test public void sendInOut() throws Exception { result.expectedMessageCount(1); - + Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); - + assertMockEndpointsSatisfied(); - + Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); @@ -83,11 +83,11 @@ public class SqsComponentSpringTest extends CamelSpringTestSupport { assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); - + assertNotNull(exchange.getOut().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getOut().getHeader(SqsConstants.MD5_OF_BODY)); } - + @Test public void sendBatchMessage() throws Exception { result.expectedMessageCount(1); @@ -109,7 +109,7 @@ public class SqsComponentSpringTest extends CamelSpringTestSupport { assertEquals(2, res.getFailed().size()); assertEquals(2, res.getSuccessful().size()); } - + @Test public void deleteMessage() throws Exception { result.expectedMessageCount(1); @@ -130,4 +130,4 @@ public class SqsComponentSpringTest extends CamelSpringTestSupport { protected ClassPathXmlApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext("org/apache/camel/component/aws/sqs/SqsComponentSpringTest-context.xml"); } -} \ No newline at end of file +} diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentTest.java index 4ed382b..0d5f120 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentTest.java @@ -28,28 +28,28 @@ import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SqsComponentTest extends CamelTestSupport { - + @EndpointInject("direct:start") private ProducerTemplate template; - + @EndpointInject("mock:result") private MockEndpoint result; - + @BindToRegistry("amazonSQSClient") private AmazonSQSClientMock client = new AmazonSQSClientMock(); - + @Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); - + Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); - + assertMockEndpointsSatisfied(); - + Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); @@ -57,24 +57,24 @@ public class SqsComponentTest extends CamelTestSupport { assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); - + assertEquals("This is my message text.", exchange.getIn().getBody()); assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); } - + @Test public void sendInOut() throws Exception { result.expectedMessageCount(1); - + Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); - + assertMockEndpointsSatisfied(); - + Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); @@ -82,7 +82,7 @@ public class SqsComponentTest extends CamelTestSupport { assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); - + assertEquals("This is my message text.", exchange.getOut().getBody()); assertNotNull(exchange.getOut().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getOut().getHeader(SqsConstants.MD5_OF_BODY)); @@ -91,16 +91,15 @@ public class SqsComponentTest extends CamelTestSupport { @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { - final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&messageRetentionPeriod=%s&maximumMessageSize=%s&policy=%s", - "1209600", "65536", ""); + final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&messageRetentionPeriod=%s&maximumMessageSize=%s&policy=%s", "1209600", "65536", + ""); + @Override public void configure() throws Exception { - from("direct:start") - .to(sqsURI); - - from(sqsURI) - .to("mock:result"); + from("direct:start").to(sqsURI); + + from(sqsURI).to("mock:result"); } }; } -} \ No newline at end of file +} diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConcurrentConsumerTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConcurrentConsumerTest.java index d9d5cd7..e374461 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConcurrentConsumerTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConcurrentConsumerTest.java @@ -38,7 +38,8 @@ public class SqsConcurrentConsumerTest extends CamelTestSupport { @Test public void consumeMessagesFromQueue() throws Exception { - // simple test to make sure that concurrent consumers were used in the test + // simple test to make sure that concurrent consumers were used in the + // test NotifyBuilder notifier = new NotifyBuilder(context).whenCompleted(NUM_MESSAGES).create(); assertTrue("We didn't process " + NUM_MESSAGES + " messages as we expected!", notifier.matches(5, TimeUnit.SECONDS)); @@ -46,10 +47,10 @@ public class SqsConcurrentConsumerTest extends CamelTestSupport { if (isPlatform("windows")) { // threading is different on windows } else { - // usually we use all threads evenly but sometimes threads are reused so just test that 50%+ was used + // usually we use all threads evenly but sometimes threads are + // reused so just test that 50%+ was used if (threadNumbers.size() < (NUM_CONCURRENT / 2)) { - fail(String.format("We were expecting to have about half of %d numbers of concurrent consumers, but only found %d", - NUM_CONCURRENT, threadNumbers.size())); + fail(String.format("We were expecting to have about half of %d numbers of concurrent consumers, but only found %d", NUM_CONCURRENT, threadNumbers.size())); } } } @@ -77,13 +78,12 @@ public class SqsConcurrentConsumerTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("aws-sqs://demo?concurrentConsumers=" + NUM_CONCURRENT + "&maxMessagesPerPoll=10&amazonSQSClient=#client") - .process(new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - threadNumbers.add(Thread.currentThread().getId()); - } - }).log("processed a new message!"); + from("aws-sqs://demo?concurrentConsumers=" + NUM_CONCURRENT + "&maxMessagesPerPoll=10&amazonSQSClient=#client").process(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + threadNumbers.add(Thread.currentThread().getId()); + } + }).log("processed a new message!"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConfigurationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConfigurationTest.java index a8c291f..c7e9c1b 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConfigurationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConfigurationTest.java @@ -34,7 +34,6 @@ public class SqsConfigurationTest { } } - @Test public void itReturnsAnInformativeErrorForBadMessageDeduplicationIdStrategy() throws Exception { SqsConfiguration sqsConfiguration = new SqsConfiguration(); diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConsumerIdleMessageTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConsumerIdleMessageTest.java index 978edc4..c82048f 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConsumerIdleMessageTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsConsumerIdleMessageTest.java @@ -30,7 +30,7 @@ public class SqsConsumerIdleMessageTest extends CamelTestSupport { @BindToRegistry("amazonSQSClient") private AmazonSQSClientMock client = new AmazonSQSClientMock(); - + @Test public void testConsumeIdleMessages() throws Exception { Thread.sleep(110); @@ -40,15 +40,13 @@ public class SqsConsumerIdleMessageTest extends CamelTestSupport { assertTrue(mock.getExchanges().get(0).getIn().getBody() == null); assertTrue(mock.getExchanges().get(1).getIn().getBody() == null); } - + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { - from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&delay=50&maxMessagesPerPoll=5" - + "&sendEmptyMessageWhenIdle=true") - .to("mock:result"); + from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&delay=50&maxMessagesPerPoll=5" + "&sendEmptyMessageWhenIdle=true").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsDoesNotExtendMessageVisibilityTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsDoesNotExtendMessageVisibilityTest.java index 5c58aae..5a08ffc 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsDoesNotExtendMessageVisibilityTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsDoesNotExtendMessageVisibilityTest.java @@ -65,8 +65,7 @@ public class SqsDoesNotExtendMessageVisibilityTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient") - .to("mock:result"); + from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java index d3db13c..59599c3 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointExplicitQueueUrlTest.java @@ -23,7 +23,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; - public class SqsEndpointExplicitQueueUrlTest extends Assert { private static final String QUEUE_URL = "http://localhost:9324/queue/default"; @@ -33,11 +32,11 @@ public class SqsEndpointExplicitQueueUrlTest extends Assert { @Before public void setUp() { amazonSQSClient = Mockito.mock(AmazonSQSClient.class); - + SqsConfiguration config = new SqsConfiguration(); config.setQueueUrl(QUEUE_URL); config.setAmazonSQSClient(amazonSQSClient); - + endpoint = new SqsEndpoint("aws-sqs://test-queue", new SqsComponent(new DefaultCamelContext()), config); } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java index c35d53d..4e953f0 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointTest.java @@ -63,11 +63,9 @@ public class SqsEndpointTest { @Test public void doStartWithDifferentQueueOwner() throws Exception { - GetQueueUrlRequest expectedGetQueueUrlRequest = new GetQueueUrlRequest("test-queue") - .withQueueOwnerAWSAccountId("111222333"); + GetQueueUrlRequest expectedGetQueueUrlRequest = new GetQueueUrlRequest("test-queue").withQueueOwnerAWSAccountId("111222333"); Mockito.when(amazonSQSClient.getQueueUrl(expectedGetQueueUrlRequest)) - .thenReturn(new GetQueueUrlResult() - .withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); + .thenReturn(new GetQueueUrlResult().withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); endpoint.getConfiguration().setQueueOwnerAWSAccountId("111222333"); endpoint.doInit(); @@ -81,12 +79,10 @@ public class SqsEndpointTest { config.setQueueName("test-queue.fifo"); config.setMessageDeduplicationIdStrategy("useContentBasedDeduplication"); - CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue.fifo") - .addAttributesEntry(QueueAttributeName.FifoQueue.name(), "true") - .addAttributesEntry(QueueAttributeName.ContentBasedDeduplication.name(), "true"); + CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue.fifo").addAttributesEntry(QueueAttributeName.FifoQueue.name(), "true") + .addAttributesEntry(QueueAttributeName.ContentBasedDeduplication.name(), "true"); Mockito.when(amazonSQSClient.createQueue(ArgumentMatchers.any(CreateQueueRequest.class))) - .thenReturn(new CreateQueueResult() - .withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue.fifo")); + .thenReturn(new CreateQueueResult().withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue.fifo")); endpoint.createQueue(amazonSQSClient); @@ -99,12 +95,10 @@ public class SqsEndpointTest { config.setQueueName("test-queue.fifo"); config.setMessageDeduplicationIdStrategy("useExchangeId"); - CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue.fifo") - .addAttributesEntry(QueueAttributeName.FifoQueue.name(), "true") - .addAttributesEntry(QueueAttributeName.ContentBasedDeduplication.name(), "false"); + CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue.fifo").addAttributesEntry(QueueAttributeName.FifoQueue.name(), "true") + .addAttributesEntry(QueueAttributeName.ContentBasedDeduplication.name(), "false"); Mockito.when(amazonSQSClient.createQueue(ArgumentMatchers.any(CreateQueueRequest.class))) - .thenReturn(new CreateQueueResult() - .withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue.fifo")); + .thenReturn(new CreateQueueResult().withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue.fifo")); endpoint.createQueue(amazonSQSClient); @@ -121,23 +115,19 @@ public class SqsEndpointTest { config.setReceiveMessageWaitTimeSeconds(5); config.setRedrivePolicy("{ \"deadLetterTargetArn\" : String, \"maxReceiveCount\" : Integer }"); - CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue") - .addAttributesEntry(QueueAttributeName.VisibilityTimeout.name(), "1000") - .addAttributesEntry(QueueAttributeName.MaximumMessageSize.name(), "128") - .addAttributesEntry(QueueAttributeName.MessageRetentionPeriod.name(), "1000") - .addAttributesEntry(QueueAttributeName.Policy.name(), "{\"Version\": \"2012-10-17\"}") - .addAttributesEntry(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), "5") - .addAttributesEntry(QueueAttributeName.RedrivePolicy.name(), "{ \"deadLetterTargetArn\" : String, \"maxReceiveCount\" : Integer }"); + CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue").addAttributesEntry(QueueAttributeName.VisibilityTimeout.name(), "1000") + .addAttributesEntry(QueueAttributeName.MaximumMessageSize.name(), "128").addAttributesEntry(QueueAttributeName.MessageRetentionPeriod.name(), "1000") + .addAttributesEntry(QueueAttributeName.Policy.name(), "{\"Version\": \"2012-10-17\"}").addAttributesEntry(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), "5") + .addAttributesEntry(QueueAttributeName.RedrivePolicy.name(), "{ \"deadLetterTargetArn\" : String, \"maxReceiveCount\" : Integer }"); Mockito.when(amazonSQSClient.createQueue(ArgumentMatchers.any(CreateQueueRequest.class))) - .thenReturn(new CreateQueueResult() - .withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); + .thenReturn(new CreateQueueResult().withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); endpoint.createQueue(amazonSQSClient); Mockito.verify(amazonSQSClient).createQueue(expectedCreateQueueRequest); assertEquals("https://sqs.us-east-1.amazonaws.com/111222333/test-queue", endpoint.getQueueUrl()); } - + @Test public void createQueueWithSSEShouldCreateStandardQueueWithSSESet() { config.setDefaultVisibilityTimeout(1000); @@ -150,25 +140,20 @@ public class SqsEndpointTest { config.setKmsDataKeyReusePeriodSeconds(300); config.setServerSideEncryptionEnabled(true); - CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue") - .addAttributesEntry(QueueAttributeName.VisibilityTimeout.name(), "1000") - .addAttributesEntry(QueueAttributeName.MaximumMessageSize.name(), "128") - .addAttributesEntry(QueueAttributeName.MessageRetentionPeriod.name(), "1000") - .addAttributesEntry(QueueAttributeName.Policy.name(), "{\"Version\": \"2012-10-17\"}") - .addAttributesEntry(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), "5") - .addAttributesEntry(QueueAttributeName.KmsMasterKeyId.name(), "keyMaster1") - .addAttributesEntry(QueueAttributeName.KmsDataKeyReusePeriodSeconds.name(), "300") - .addAttributesEntry(QueueAttributeName.RedrivePolicy.name(), "{ \"deadLetterTargetArn\" : String, \"maxReceiveCount\" : Integer }"); + CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue").addAttributesEntry(QueueAttributeName.VisibilityTimeout.name(), "1000") + .addAttributesEntry(QueueAttributeName.MaximumMessageSize.name(), "128").addAttributesEntry(QueueAttributeName.MessageRetentionPeriod.name(), "1000") + .addAttributesEntry(QueueAttributeName.Policy.name(), "{\"Version\": \"2012-10-17\"}").addAttributesEntry(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), "5") + .addAttributesEntry(QueueAttributeName.KmsMasterKeyId.name(), "keyMaster1").addAttributesEntry(QueueAttributeName.KmsDataKeyReusePeriodSeconds.name(), "300") + .addAttributesEntry(QueueAttributeName.RedrivePolicy.name(), "{ \"deadLetterTargetArn\" : String, \"maxReceiveCount\" : Integer }"); Mockito.when(amazonSQSClient.createQueue(ArgumentMatchers.any(CreateQueueRequest.class))) - .thenReturn(new CreateQueueResult() - .withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); + .thenReturn(new CreateQueueResult().withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); endpoint.createQueue(amazonSQSClient); Mockito.verify(amazonSQSClient).createQueue(expectedCreateQueueRequest); assertEquals("https://sqs.us-east-1.amazonaws.com/111222333/test-queue", endpoint.getQueueUrl()); } - + @Test public void createQueueWithoutSSEShouldNotCreateStandardQueueWithSSESet() { config.setDefaultVisibilityTimeout(1000); @@ -180,20 +165,16 @@ public class SqsEndpointTest { config.setKmsMasterKeyId("keyMaster1"); config.setKmsDataKeyReusePeriodSeconds(300); - CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue") - .addAttributesEntry(QueueAttributeName.VisibilityTimeout.name(), "1000") - .addAttributesEntry(QueueAttributeName.MaximumMessageSize.name(), "128") - .addAttributesEntry(QueueAttributeName.MessageRetentionPeriod.name(), "1000") - .addAttributesEntry(QueueAttributeName.Policy.name(), "{\"Version\": \"2012-10-17\"}") - .addAttributesEntry(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), "5") - .addAttributesEntry(QueueAttributeName.RedrivePolicy.name(), "{ \"deadLetterTargetArn\" : String, \"maxReceiveCount\" : Integer }"); + CreateQueueRequest expectedCreateQueueRequest = new CreateQueueRequest("test-queue").addAttributesEntry(QueueAttributeName.VisibilityTimeout.name(), "1000") + .addAttributesEntry(QueueAttributeName.MaximumMessageSize.name(), "128").addAttributesEntry(QueueAttributeName.MessageRetentionPeriod.name(), "1000") + .addAttributesEntry(QueueAttributeName.Policy.name(), "{\"Version\": \"2012-10-17\"}").addAttributesEntry(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), "5") + .addAttributesEntry(QueueAttributeName.RedrivePolicy.name(), "{ \"deadLetterTargetArn\" : String, \"maxReceiveCount\" : Integer }"); Mockito.when(amazonSQSClient.createQueue(ArgumentMatchers.any(CreateQueueRequest.class))) - .thenReturn(new CreateQueueResult() - .withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); + .thenReturn(new CreateQueueResult().withQueueUrl("https://sqs.us-east-1.amazonaws.com/111222333/test-queue")); endpoint.createQueue(amazonSQSClient); Mockito.verify(amazonSQSClient).createQueue(expectedCreateQueueRequest); assertEquals("https://sqs.us-east-1.amazonaws.com/111222333/test-queue", endpoint.getQueueUrl()); } -} \ No newline at end of file +} diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointUseExistingQueueTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointUseExistingQueueTest.java index 3acf398..e6a2b69 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointUseExistingQueueTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsEndpointUseExistingQueueTest.java @@ -42,7 +42,7 @@ public class SqsEndpointUseExistingQueueTest extends CamelTestSupport { @EndpointInject("mock:result") private MockEndpoint mock; - + @BindToRegistry("amazonSQSClient") private AmazonSQSClientMock client = new SqsEndpointUseExistingQueueTest.AmazonSQSClientMock(); @@ -58,14 +58,13 @@ public class SqsEndpointUseExistingQueueTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient") - .to("mock:result"); + from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient").to("mock:result"); } }; } - + static class AmazonSQSClientMock extends AmazonSQSClient { - + AmazonSQSClientMock() { super(new BasicAWSCredentials("myAccessKey", "mySecretKey")); } @@ -78,24 +77,24 @@ public class SqsEndpointUseExistingQueueTest extends CamelTestSupport { result.getQueueUrls().add("http://queue.amazonaws.com/0815/Bar"); return result; } - + @Override public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) throws AmazonServiceException, AmazonClientException { throw new AmazonServiceException("forced exception for test if this method is called"); } - + @Override public SetQueueAttributesResult setQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest) throws AmazonServiceException, AmazonClientException { return new SetQueueAttributesResult(); } - + @Override public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) throws AmazonServiceException, AmazonClientException { ReceiveMessageResult result = new ReceiveMessageResult(); List<Message> resultMessages = result.getMessages(); Message message = new Message(); resultMessages.add(message); - + return result; } } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsExtendMessageVisibilityTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsExtendMessageVisibilityTest.java index 94fae22..1ba3be4 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsExtendMessageVisibilityTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsExtendMessageVisibilityTest.java @@ -35,7 +35,7 @@ public class SqsExtendMessageVisibilityTest extends CamelTestSupport { @EndpointInject("mock:result") private MockEndpoint mock; - + @BindToRegistry("amazonSQSClient") private AmazonSQSClientMock client = new AmazonSQSClientMock(); @@ -63,7 +63,9 @@ public class SqsExtendMessageVisibilityTest extends CamelTestSupport { for (ChangeMessageVisibilityRequest req : this.client.changeMessageVisibilityRequests) { assertEquals("https://queue.amazonaws.com/541925086079/MyQueue", req.getQueueUrl()); assertEquals(RECEIPT_HANDLE, req.getReceiptHandle()); - Integer expectedTimeout = new Integer(6); // Should be 1.5 x TIMEOUT as takes into account the delay period + Integer expectedTimeout = new Integer(6); // Should be 1.5 x TIMEOUT + // as takes into account + // the delay period assertEquals(expectedTimeout, req.getVisibilityTimeout()); } } @@ -73,8 +75,7 @@ public class SqsExtendMessageVisibilityTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&extendMessageVisibility=true&visibilityTimeout=" + TIMEOUT) - .to("mock:result"); + from("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient&extendMessageVisibility=true&visibilityTimeout=" + TIMEOUT).to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsFilterMessagesWithNoDeleteTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsFilterMessagesWithNoDeleteTest.java index 5bc634f..3e7243f 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsFilterMessagesWithNoDeleteTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsFilterMessagesWithNoDeleteTest.java @@ -46,9 +46,9 @@ public class SqsFilterMessagesWithNoDeleteTest extends TestSupport { @Test public void testDoesNotGetThroughFilter() throws Exception { final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient" - // note we will NOT delete if this message gets filtered out - + "&deleteIfFiltered=false" - + "&defaultVisibilityTimeout=1"); + // note we will NOT delete if this + // message gets filtered out + + "&deleteIfFiltered=false" + "&defaultVisibilityTimeout=1"); AmazonSQSClientMock clientMock = new AmazonSQSClientMock(); populateMessages(clientMock); @@ -59,9 +59,9 @@ public class SqsFilterMessagesWithNoDeleteTest extends TestSupport { @Override public void configure() throws Exception { from(sqsURI) - // try to filter using a non-existent header... should not go through - .filter(simple("${header.login} == true")) - .to("mock:result"); + // try to filter using a non-existent header... should not + // go through + .filter(simple("${header.login} == true")).to("mock:result"); } }); @@ -76,7 +76,8 @@ public class SqsFilterMessagesWithNoDeleteTest extends TestSupport { // we shouldn't get assertIsSatisfied(2000, TimeUnit.MILLISECONDS); - // however, the message should not be deleted, that is, it should be left on the queue + // however, the message should not be deleted, that is, it should be + // left on the queue String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class); assertEquals(response, "Message: hello, world!"); @@ -88,10 +89,12 @@ public class SqsFilterMessagesWithNoDeleteTest extends TestSupport { @Test public void testGetThroughFilter() throws Exception { final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient" - // note we will NOT delete if this message gets filtered out, but if it goes - // through filter, it should be deleted! - + "&deleteIfFiltered=false" - + "&defaultVisibilityTimeout=1"); + // note we will NOT delete if this + // message gets filtered out, but if + // it goes + // through filter, it should be + // deleted! + + "&deleteIfFiltered=false" + "&defaultVisibilityTimeout=1"); AmazonSQSClientMock clientMock = new AmazonSQSClientMock(); populateMessages(clientMock); @@ -101,12 +104,10 @@ public class SqsFilterMessagesWithNoDeleteTest extends TestSupport { ctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { - from(sqsURI) - .setHeader("login", constant(true)) + from(sqsURI).setHeader("login", constant(true)) - // this filter should allow the message to pass.. - .filter(simple("${header.login} == true")) - .to("mock:result"); + // this filter should allow the message to pass.. + .filter(simple("${header.login} == true")).to("mock:result"); } }); @@ -120,7 +121,8 @@ public class SqsFilterMessagesWithNoDeleteTest extends TestSupport { // the message should get through filter and mock should assert this assertIsSatisfied(2000, TimeUnit.MILLISECONDS); - // however, the message should not be deleted, that is, it should be left on the queue + // however, the message should not be deleted, that is, it should be + // left on the queue String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class); assertNull(response); diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerBatchTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerBatchTest.java index 39c0daf..8c36956 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerBatchTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerBatchTest.java @@ -35,13 +35,13 @@ public class SqsProducerBatchTest extends CamelTestSupport { @BindToRegistry("client") AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + @EndpointInject("direct:start") private ProducerTemplate template; @EndpointInject("mock:result") private MockEndpoint result; - + @Test public void sendBatchMessage() throws Exception { result.expectedMessageCount(1); @@ -69,8 +69,7 @@ public class SqsProducerBatchTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:start") - .to("aws-sqs://camel-1?amazonSQSClient=#client&operation=sendBatchMessage").to("mock:result"); + from("direct:start").to("aws-sqs://camel-1?amazonSQSClient=#client&operation=sendBatchMessage").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerDeleteTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerDeleteTest.java index fc4c7cf..000ea68 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerDeleteTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerDeleteTest.java @@ -32,13 +32,13 @@ public class SqsProducerDeleteTest extends CamelTestSupport { @BindToRegistry("client") AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + @EndpointInject("direct:start") private ProducerTemplate template; @EndpointInject("mock:result") private MockEndpoint result; - + @Test public void deleteMessage() throws Exception { result.expectedMessageCount(1); @@ -60,8 +60,7 @@ public class SqsProducerDeleteTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:start") - .to("aws-sqs://camel-1?amazonSQSClient=#client&operation=deleteMessage").to("mock:result"); + from("direct:start").to("aws-sqs://camel-1?amazonSQSClient=#client&operation=deleteMessage").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerListQueuesTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerListQueuesTest.java index f122cde..b1badd1 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerListQueuesTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/SqsProducerListQueuesTest.java @@ -32,13 +32,13 @@ public class SqsProducerListQueuesTest extends CamelTestSupport { @BindToRegistry("client") AmazonSQSClientMock mock = new AmazonSQSClientMock(); - + @EndpointInject("direct:start") private ProducerTemplate template; @EndpointInject("mock:result") private MockEndpoint result; - + @Test public void listQueues() throws Exception { result.expectedMessageCount(1); @@ -61,8 +61,7 @@ public class SqsProducerListQueuesTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:start") - .to("aws-sqs://camel-1?amazonSQSClient=#client&operation=listQueues").to("mock:result"); + from("direct:start").to("aws-sqs://camel-1?amazonSQSClient=#client&operation=listQueues").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java index 57c840a..9b24678 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java @@ -30,28 +30,28 @@ import org.junit.Test; @Ignore("Must be manually tested. Provide your own accessKey and secretKey!") public class SqsComponentIntegrationTest extends CamelTestSupport { - + private String accessKey = "xxx"; private String secretKey = "yyy"; - + @EndpointInject("direct:start") private ProducerTemplate template; - + @EndpointInject("mock:result") private MockEndpoint result; - + @Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); - + Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); - + assertMockEndpointsSatisfied(); - + Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); @@ -59,23 +59,23 @@ public class SqsComponentIntegrationTest extends CamelTestSupport { assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); - + assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); } - + @Test public void sendInOut() throws Exception { result.expectedMessageCount(1); - + Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); - + assertMockEndpointsSatisfied(); - + Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); @@ -83,27 +83,27 @@ public class SqsComponentIntegrationTest extends CamelTestSupport { assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); - + assertNotNull(exchange.getOut().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getOut().getHeader(SqsConstants.MD5_OF_BODY)); } - + @Override protected RouteBuilder createRouteBuilder() throws Exception { - final String sqsEndpointUri = String.format("aws-sqs://MyNewCamelQueue?accessKey=%s&secretKey=%s&messageRetentionPeriod=%s&maximumMessageSize=%s&visibilityTimeout=%s&policy=%s", - accessKey, secretKey, "1209600", "65536", "60", "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyNewCamelQueue%2FSQSDefaultPolicy%22%2C%22" - + "Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22" - + "Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyNewCamelQueue%22%7D%5D%7D"); - + final String sqsEndpointUri = String + .format("aws-sqs://MyNewCamelQueue?accessKey=%s&secretKey=%s&messageRetentionPeriod=%s&maximumMessageSize=%s&visibilityTimeout=%s&policy=%s", accessKey, secretKey, + "1209600", "65536", "60", + "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyNewCamelQueue%2FSQSDefaultPolicy%22%2C%22" + + "Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22" + + "Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyNewCamelQueue%22%7D%5D%7D"); + return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:start") - .to(sqsEndpointUri); - - from(sqsEndpointUri) - .to("mock:result"); + from("direct:start").to(sqsEndpointUri); + + from(sqsEndpointUri).to("mock:result"); } }; } -} \ No newline at end of file +} diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java index f680b49..93195f9 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java @@ -39,19 +39,19 @@ public class SqsConsumerMessageIntegrationTest extends CamelTestSupport { @Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); - + Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("ignore"); } }); - + exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("test1"); } }); - + assertMockEndpointsSatisfied(); } @@ -65,10 +65,7 @@ public class SqsConsumerMessageIntegrationTest extends CamelTestSupport { from("direct:start").startupOrder(2).to(sqsEndpointUri); from("aws-sqs://camel-1?accessKey=RAW(xxxx)&secretKey=RAW(xxxx)®ion=EU_WEST_1&deleteAfterRead=false&deleteIfFiltered=true").startupOrder(1) - .filter(simple("${body} != 'ignore'")) - .log("${body}") - .log("${header.CamelAwsSqsReceiptHandle}") - .to("mock:result"); + .filter(simple("${body} != 'ignore'")).log("${body}").log("${header.CamelAwsSqsReceiptHandle}").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java index 0c92df0..86a1fa0 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java @@ -61,9 +61,8 @@ public class SqsProducerBatchSendFifoIntegrationTest extends CamelTestSupport { @Override protected RouteBuilder createRouteBuilder() throws Exception { - final String sqsEndpointUri = - String.format("aws-sqs://camel-1.fifo?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&messageGroupIdStrategy=useExchangeId" - + "&messageDeduplicationIdStrategy=useContentBasedDeduplication"); + final String sqsEndpointUri = String.format("aws-sqs://camel-1.fifo?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&messageGroupIdStrategy=useExchangeId" + + "&messageDeduplicationIdStrategy=useContentBasedDeduplication"); return new RouteBuilder() { @Override diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java index 91f810c..39a8589 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java @@ -59,9 +59,8 @@ public class SqsProducerDeleteMessageIntegrationTest extends CamelTestSupport { from("direct:start").startupOrder(2).to(sqsEndpointUri); from("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&deleteAfterRead=false").startupOrder(1).log("${body}") - .to("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&operation=deleteMessage").log("${body}") - .log("${header.CamelAwsSqsReceiptHandle}") - .to("mock:result"); + .to("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&operation=deleteMessage").log("${body}").log("${header.CamelAwsSqsReceiptHandle}") + .to("mock:result"); } }; }