You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/07/28 08:09:46 UTC
[camel] 01/03: Camel-AWS SQS: Use BindToRegistry annotation
wherever possible
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 c1b5363031ce4c0e01b732bc010c0a2df420e6ad
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Sun Jul 28 10:06:52 2019 +0200
Camel-AWS SQS: Use BindToRegistry annotation wherever possible
---
.../camel/component/aws/sqs/SqsBatchConsumerTest.java | 10 ++++------
.../camel/component/aws/sqs/SqsComponentTest.java | 12 ++++--------
.../component/aws/sqs/SqsConcurrentConsumerTest.java | 10 +++++-----
.../component/aws/sqs/SqsConsumerIdleMessageTest.java | 14 ++++----------
.../sqs/SqsDoesNotExtendMessageVisibilityTest.java | 17 ++++++-----------
.../aws/sqs/SqsEndpointUseExistingQueueTest.java | 14 ++++----------
.../aws/sqs/SqsExtendMessageVisibilityTest.java | 19 +++++++------------
7 files changed, 34 insertions(+), 62 deletions(-)
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 a029d3d..07438bf 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
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws.sqs;
import com.amazonaws.services.sqs.model.Message;
+import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
@@ -50,9 +51,8 @@ public class SqsBatchConsumerTest extends CamelTestSupport {
mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 5);
}
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
+ @BindToRegistry("amazonSQSClient")
+ public AmazonSQSClientMock addClient() throws Exception {
AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
// add 6 messages, one more we will poll
@@ -66,9 +66,7 @@ public class SqsBatchConsumerTest extends CamelTestSupport {
clientMock.messages.add(message);
}
- registry.bind("amazonSQSClient", clientMock);
-
- return registry;
+ return clientMock;
}
@Override
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 92f8faa..dccd35e 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
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.aws.sqs;
+import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
@@ -35,6 +36,9 @@ public class SqsComponentTest extends CamelTestSupport {
@EndpointInject("mock:result")
private MockEndpoint result;
+ @BindToRegistry("amazonSQSClient")
+ private AmazonSQSClientMock client = new AmazonSQSClientMock();
+
@Test
public void sendInOnly() throws Exception {
result.expectedMessageCount(1);
@@ -84,14 +88,6 @@ public class SqsComponentTest extends CamelTestSupport {
assertNotNull(exchange.getOut().getHeader(SqsConstants.MESSAGE_ID));
assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getOut().getHeader(SqsConstants.MD5_OF_BODY));
}
-
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
- registry.bind("amazonSQSClient", new AmazonSQSClientMock());
-
- return registry;
- }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
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 d3d9a40..6b8ec3d 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
@@ -21,6 +21,8 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.amazonaws.services.sqs.model.Message;
+
+import org.apache.camel.BindToRegistry;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.NotifyBuilder;
@@ -53,13 +55,11 @@ public class SqsConcurrentConsumerTest extends CamelTestSupport {
}
}
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry reg = super.createRegistry();
+ @BindToRegistry("client")
+ public AmazonSQSClientMock addClient() throws Exception {
AmazonSQSClientMock client = new AmazonSQSClientMock();
createDummyMessages(client, NUM_MESSAGES);
- reg.bind("client", client);
- return reg;
+ return client;
}
private void createDummyMessages(AmazonSQSClientMock client, int numMessages) {
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 2f5af5e..9e2eb4c 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
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.aws.sqs;
+import org.apache.camel.BindToRegistry;
/**
* Test to verify that the polling consumer delivers an empty Exchange when the
* sendEmptyMessageWhenIdle property is set and a polling event yields no results.
@@ -27,6 +28,9 @@ import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class SqsConsumerIdleMessageTest extends CamelTestSupport {
+
+ @BindToRegistry("amazonSQSClient")
+ private AmazonSQSClientMock client = new AmazonSQSClientMock();
@Test
public void testConsumeIdleMessages() throws Exception {
@@ -39,16 +43,6 @@ public class SqsConsumerIdleMessageTest extends CamelTestSupport {
}
@Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
-
- AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
- registry.bind("amazonSQSClient", clientMock);
-
- return registry;
- }
-
- @Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
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 25bed1c..56de601 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
@@ -17,6 +17,8 @@
package org.apache.camel.component.aws.sqs;
import com.amazonaws.services.sqs.model.Message;
+
+import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
@@ -34,7 +36,8 @@ public class SqsDoesNotExtendMessageVisibilityTest extends CamelTestSupport {
@EndpointInject("mock:result")
private MockEndpoint mock;
- private AmazonSQSClientMock clientMock;
+ @BindToRegistry("amazonSQSClient")
+ private AmazonSQSClientMock client = new AmazonSQSClientMock();
@Test
public void defaultsToDisabled() throws Exception {
@@ -52,18 +55,10 @@ public class SqsDoesNotExtendMessageVisibilityTest extends CamelTestSupport {
message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
message.setReceiptHandle(RECEIPT_HANDLE);
- this.clientMock.messages.add(message);
+ this.client.messages.add(message);
assertMockEndpointsSatisfied(); // Wait for message to arrive.
- assertTrue("Expected no changeMessageVisibility requests.", this.clientMock.changeMessageVisibilityRequests.size() == 0);
- }
-
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
- this.clientMock = new AmazonSQSClientMock();
- registry.bind("amazonSQSClient", this.clientMock);
- return registry;
+ assertTrue("Expected no changeMessageVisibility requests.", this.client.changeMessageVisibilityRequests.size() == 0);
}
@Override
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 0140d9e..6a4a5df 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
@@ -31,6 +31,7 @@ import com.amazonaws.services.sqs.model.ReceiveMessageResult;
import com.amazonaws.services.sqs.model.SetQueueAttributesRequest;
import com.amazonaws.services.sqs.model.SetQueueAttributesResult;
+import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
@@ -42,6 +43,9 @@ public class SqsEndpointUseExistingQueueTest extends CamelTestSupport {
@EndpointInject("mock:result")
private MockEndpoint mock;
+
+ @BindToRegistry("amazonSQSClient")
+ private AmazonSQSClientMock client = new SqsEndpointUseExistingQueueTest.AmazonSQSClientMock();
@Test
public void defaultsToDisabled() throws Exception {
@@ -51,16 +55,6 @@ public class SqsEndpointUseExistingQueueTest extends CamelTestSupport {
}
@Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
-
- AmazonSQSClientMock clientMock = new SqsEndpointUseExistingQueueTest.AmazonSQSClientMock();
- registry.bind("amazonSQSClient", clientMock);
-
- return registry;
- }
-
- @Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
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 0ca94eb..13eb29d 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
@@ -18,6 +18,8 @@ package org.apache.camel.component.aws.sqs;
import com.amazonaws.services.sqs.model.ChangeMessageVisibilityRequest;
import com.amazonaws.services.sqs.model.Message;
+
+import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
@@ -35,7 +37,8 @@ public class SqsExtendMessageVisibilityTest extends CamelTestSupport {
@EndpointInject("mock:result")
private MockEndpoint mock;
- private AmazonSQSClientMock clientMock;
+ @BindToRegistry("amazonSQSClient")
+ private AmazonSQSClientMock client = new AmazonSQSClientMock();
@Test
public void longReceiveExtendsMessageVisibility() throws Exception {
@@ -53,12 +56,12 @@ public class SqsExtendMessageVisibilityTest extends CamelTestSupport {
message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
message.setReceiptHandle(RECEIPT_HANDLE);
- this.clientMock.messages.add(message);
+ this.client.messages.add(message);
assertMockEndpointsSatisfied(); // Wait for message to arrive.
- assertTrue("Expected at least one changeMessageVisibility request.", this.clientMock.changeMessageVisibilityRequests.size() >= 1);
- for (ChangeMessageVisibilityRequest req : this.clientMock.changeMessageVisibilityRequests) {
+ assertTrue("Expected at least one changeMessageVisibility request.", this.client.changeMessageVisibilityRequests.size() >= 1);
+ 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
@@ -67,14 +70,6 @@ public class SqsExtendMessageVisibilityTest extends CamelTestSupport {
}
@Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry registry = super.createRegistry();
- this.clientMock = new AmazonSQSClientMock();
- registry.bind("amazonSQSClient", this.clientMock);
- return registry;
- }
-
- @Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override