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 d18480ea7a355b54a246ab423685ab1b866de864
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Apr 6 15:19:22 2020 +0200

    CAMEL-14850 - Camel-AWS2-*: Improve the verifiers to check if a particular 
service works on a specified region, CloudWatch
---
 .../aws2/cw/Cw2ComponentVerifierExtension.java          |  5 ++++-
 .../aws2/cw/CwComponentVerifierExtensionTest.java       | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java
 
b/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java
index 128f61e..add9a99 100644
--- 
a/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java
+++ 
b/components/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2ComponentVerifierExtension.java
@@ -63,9 +63,12 @@ public class Cw2ComponentVerifierExtension extends 
DefaultComponentVerifierExten
     @Override
     protected Result verifyConnectivity(Map<String, Object> parameters) {
         ResultBuilder builder = 
ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
-
         try {
             Cw2Configuration configuration = setProperties(new 
Cw2Configuration(), parameters);
+            if 
(!CloudWatchClient.serviceMetadata().regions().contains(configuration.getRegion()))
 {
+                ResultErrorBuilder errorBuilder = 
ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.ILLEGAL_PARAMETER,
 "The service is not supported in this region");
+                return builder.error(errorBuilder.build()).build();
+            }
             AwsBasicCredentials cred = 
AwsBasicCredentials.create(configuration.getAccessKey(), 
configuration.getSecretKey());
             CloudWatchClientBuilder clientBuilder = CloudWatchClient.builder();
             CloudWatchClient client = 
clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred)).region(Region.of(configuration.getRegion())).build();
diff --git 
a/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java
 
b/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java
index 69cebe4..9fa3ccd 100644
--- 
a/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java
+++ 
b/components/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentVerifierExtensionTest.java
@@ -68,5 +68,22 @@ public class CwComponentVerifierExtensionTest extends 
CamelTestSupport {
 
         assertEquals(ComponentVerifierExtension.Result.Status.ERROR, 
result.getStatus());
     }
+    
+    @Test
+    public void testConnectivityAndRegion() throws Exception {
+        Component component = context().getComponent("aws2-cw");
+        ComponentVerifierExtension verifier = 
component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
+
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("secretKey", "l");
+        parameters.put("accessKey", "k");
+        parameters.put("region", "test");
+        parameters.put("namespace", "test");
+
+        ComponentVerifierExtension.Result result = 
verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
+
+        System.err.println(result.getErrors().toString());
+        assertEquals(ComponentVerifierExtension.Result.Status.ERROR, 
result.getStatus());
+    }
 
 }

Reply via email to