camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject [1/6] camel git commit: Polished ComponentVerifier interface
Date Thu, 30 Mar 2017 16:05:49 GMT
Repository: camel
Updated Branches:
  refs/heads/master e1d82abd6 -> b1e5a108f


http://git-wip-us.apache.org/repos/asf/camel/blob/c810328e/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterComponentVerifier.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterComponentVerifier.java
b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterComponentVerifier.java
index 27808b8..bd2d761 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterComponentVerifier.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterComponentVerifier.java
@@ -69,19 +69,19 @@ final class TwitterComponentVerifier extends DefaultComponentVerifier
{
         } catch (TwitterException e) {
             // verifyCredentials throws TwitterException when Twitter service or
             // network is unavailable or if supplied credential is wrong
-            ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(ComponentVerifier.CODE_AUTHENTICATION,
e.getErrorMessage())
-                .attribute("twitter.error.code", e.getErrorCode())
-                .attribute("twitter.status.code", e.getStatusCode())
-                .attribute("twitter.exception.code", e.getExceptionCode())
-                .attribute("twitter.exception.message", e.getMessage())
-                .attribute("twitter.exception.caused-by-network-issue", e.isCausedByNetworkIssue())
-                .attribute(ComponentVerifier.EXCEPTION_CLASS, e.getClass().getName())
-                .attribute(ComponentVerifier.EXCEPTION_INSTANCE, e);
+            ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION,
e.getErrorMessage())
+                .detail("twitter_error_code", e.getErrorCode())
+                .detail("twitter_status_code", e.getStatusCode())
+                .detail("twitter_exception_code", e.getExceptionCode())
+                .detail("twitter_exception_message", e.getMessage())
+                .detail("twitter_exception_caused-by-network-issue", e.isCausedByNetworkIssue())
+                .detail(ComponentVerifier.VerificationError.ExceptionAttribute.EXCEPTION_CLASS,
e.getClass().getName())
+                .detail(ComponentVerifier.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE,
e);
 
             // For a complete list of error codes see:
             //   https://dev.twitter.com/overview/api/response-codes
             if (e.getErrorCode() == 89) {
-                errorBuilder.parameter("accessToken");
+                errorBuilder.parameterKey("accessToken");
             }
 
             builder.error(errorBuilder.build());

http://git-wip-us.apache.org/repos/asf/camel/blob/c810328e/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/CamelComponentVerifierTest.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/CamelComponentVerifierTest.java
b/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/CamelComponentVerifierTest.java
index 4b88158..48df2bc 100644
--- a/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/CamelComponentVerifierTest.java
+++ b/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/CamelComponentVerifierTest.java
@@ -16,15 +16,15 @@
  */
 package org.apache.camel.component.twitter;
 
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import org.apache.camel.ComponentVerifier;
+import org.apache.camel.ComponentVerifier.VerificationError;
 import org.junit.Assert;
 import org.junit.Test;
 
+import static org.apache.camel.ComponentVerifier.VerificationError.asAttribute;
+
 public class CamelComponentVerifierTest extends CamelTwitterTestSupport {
     @Override
     public boolean isUseRouteBuilder() {
@@ -54,9 +54,9 @@ public class CamelComponentVerifierTest extends CamelTwitterTestSupport
{
 
         Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
         Assert.assertEquals(1, result.getErrors().size());
-        Assert.assertEquals(ComponentVerifier.CODE_AUTHENTICATION, result.getErrors().get(0).getCode());
-        Assert.assertEquals(401, result.getErrors().get(0).getAttributes().get("twitter.status.code"));
-        Assert.assertEquals(32, result.getErrors().get(0).getAttributes().get("twitter.error.code"));
+        Assert.assertEquals(VerificationError.StandardCode.AUTHENTICATION, result.getErrors().get(0).getCode());
+        Assert.assertEquals(401, result.getErrors().get(0).getDetails().get(asAttribute("twitter_status_code")));
+        Assert.assertEquals(32, result.getErrors().get(0).getDetails().get(asAttribute("twitter_error_code")));
     }
 
     @Test
@@ -71,11 +71,11 @@ public class CamelComponentVerifierTest extends CamelTwitterTestSupport
{
 
         Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
         Assert.assertEquals(1, result.getErrors().size());
-        Assert.assertEquals(ComponentVerifier.CODE_AUTHENTICATION, result.getErrors().get(0).getCode());
-        Assert.assertEquals(401, result.getErrors().get(0).getAttributes().get("twitter.status.code"));
-        Assert.assertEquals(89, result.getErrors().get(0).getAttributes().get("twitter.error.code"));
-        Assert.assertEquals(1, result.getErrors().get(0).getParameters().size());
-        Assert.assertEquals("accessToken", result.getErrors().get(0).getParameters().iterator().next());
+        Assert.assertEquals(VerificationError.StandardCode.AUTHENTICATION, result.getErrors().get(0).getCode());
+        Assert.assertEquals(401, result.getErrors().get(0).getDetails().get(asAttribute("twitter_status_code")));
+        Assert.assertEquals(89, result.getErrors().get(0).getDetails().get(asAttribute("twitter_error_code")));
+        Assert.assertEquals(1, result.getErrors().get(0).getParameterKeys().size());
+        Assert.assertEquals("accessToken", result.getErrors().get(0).getParameterKeys().iterator().next());
     }
 
     @Test
@@ -97,8 +97,8 @@ public class CamelComponentVerifierTest extends CamelTwitterTestSupport
{
             expected.add("accessToken");
             expected.add("accessTokenSecret");
 
-            for (ComponentVerifier.Error error : result.getErrors()) {
-                expected.removeAll(error.getParameters());
+            for(VerificationError error : result.getErrors()) {
+                expected.removeAll(error.getParameterKeys());
             }
 
             Assert.assertTrue("Missing expected params: " + expected.toString(), expected.isEmpty());
@@ -110,9 +110,9 @@ public class CamelComponentVerifierTest extends CamelTwitterTestSupport
{
 
             Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
             Assert.assertEquals(1, result.getErrors().size());
-            Assert.assertEquals(ComponentVerifier.CODE_EXCEPTION, result.getErrors().get(0).getCode());
-            Assert.assertNotNull(result.getErrors().get(0).getAttributes().get(ComponentVerifier.EXCEPTION_INSTANCE));
-            Assert.assertTrue(result.getErrors().get(0).getAttributes().get(ComponentVerifier.EXCEPTION_INSTANCE)
instanceof IllegalArgumentException);
+            Assert.assertEquals(VerificationError.StandardCode.EXCEPTION, result.getErrors().get(0).getCode());
+            Assert.assertNotNull(result.getErrors().get(0).getDetails().get(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE));
+            Assert.assertTrue(result.getErrors().get(0).getDetails().get(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE)
instanceof IllegalArgumentException);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/c810328e/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
----------------------------------------------------------------------
diff --git a/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
index 71c71f6..447eda2 100644
--- a/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
+++ b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
@@ -61,7 +61,7 @@ public abstract class DefaultConnectorComponent extends DefaultComponent
impleme
         // clean-up parameters so that validation won't fail later on
         // in DefaultConnectorComponent.validateParameters()
         parameters.clear();
-        
+
         String scheme = model.getBaseScheme();
 
         // now create the endpoint instance which either happens with a new
@@ -147,9 +147,9 @@ public abstract class DefaultConnectorComponent extends DefaultComponent
impleme
             return (scope, map) -> {
                 return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.UNSUPPORTED,
scope)
                     .error(
-                        ResultErrorBuilder.withCode("unsupported")
-                            .attribute("camel.connector.name", getConnectorName())
-                            .attribute("camel.component.name", getComponentName())
+                        ResultErrorBuilder.withCode(ComponentVerifier.VerificationError.StandardCode.UNSUPPORTED)
+                            .detail("camel_connector_name", getConnectorName())
+                            .detail("camel_component_name", getComponentName())
                             .build())
                     .build();
             };


Mime
View raw message