camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [06/14] camel git commit: Camel catalog - Add api to validate endpoint uri
Date Wed, 23 Dec 2015 08:43:59 GMT
Camel catalog - Add api to validate endpoint uri


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/95415555
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/95415555
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/95415555

Branch: refs/heads/master
Commit: 95415555ad40cb245599825561a5bf71c7e5c39f
Parents: 91a4946
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Dec 22 10:52:30 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Dec 23 09:05:14 2015 +0100

----------------------------------------------------------------------
 .../camel/catalog/EndpointValidationResult.java | 42 ++++++++++++++++----
 .../apache/camel/catalog/CamelCatalogTest.java  |  9 +++++
 2 files changed, 44 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/95415555/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
index ece32b6..8f463fd 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
@@ -29,6 +29,7 @@ import java.util.Set;
 public class EndpointValidationResult implements Serializable {
 
     private final String uri;
+    private int errors;
 
     // component
     private String syntaxError;
@@ -52,6 +53,10 @@ public class EndpointValidationResult implements Serializable {
         return uri;
     }
 
+    public int getNumberOfErrors() {
+        return errors;
+    }
+
     public boolean isSuccess() {
         boolean ok = syntaxError == null && unknownComponent == null
                 && unknown == null && required == null;
@@ -64,31 +69,42 @@ public class EndpointValidationResult implements Serializable {
 
     public void addSyntaxError(String syntaxError) {
         this.syntaxError = syntaxError;
+        errors++;
     }
 
     public void addUnknownComponent(String name) {
         this.unknownComponent = name;
+        errors++;
     }
 
     public void addUnknown(String name) {
         if (unknown == null) {
             unknown = new LinkedHashSet<String>();
         }
-        unknown.add(name);
+        if (!unknown.contains(name)) {
+            unknown.add(name);
+            errors++;
+        }
     }
 
     public void addRequired(String name) {
         if (required == null) {
             required = new LinkedHashSet<String>();
         }
-        required.add(name);
+        if (!required.contains(name)) {
+            required.add(name);
+            errors++;
+        }
     }
 
     public void addInvalidEnum(String name, String value) {
         if (invalidEnum == null) {
             invalidEnum = new LinkedHashMap<String, String>();
         }
-        invalidEnum.put(name, value);
+        if (!invalidEnum.containsKey(name)) {
+            invalidEnum.put(name, value);
+            errors++;
+        }
     }
 
     public void addInvalidEnumChoices(String name, String[] choices) {
@@ -102,28 +118,40 @@ public class EndpointValidationResult implements Serializable {
         if (invalidReference == null) {
             invalidReference = new LinkedHashMap<String, String>();
         }
-        invalidReference.put(name, value);
+        if (!invalidReference.containsKey(name)) {
+            invalidReference.put(name, value);
+            errors++;
+        }
     }
 
     public void addInvalidBoolean(String name, String value) {
         if (invalidBoolean == null) {
             invalidBoolean = new LinkedHashMap<String, String>();
         }
-        invalidBoolean.put(name, value);
+        if (!invalidBoolean.containsKey(name)) {
+            invalidBoolean.put(name, value);
+            errors++;
+        }
     }
 
     public void addInvalidInteger(String name, String value) {
         if (invalidInteger == null) {
             invalidInteger = new LinkedHashMap<String, String>();
         }
-        invalidInteger.put(name, value);
+        if (!invalidInteger.containsKey(name)) {
+            invalidInteger.put(name, value);
+            errors++;
+        }
     }
 
     public void addInvalidNumber(String name, String value) {
         if (invalidNumber == null) {
             invalidNumber = new LinkedHashMap<String, String>();
         }
-        invalidNumber.put(name, value);
+        if (!invalidNumber.containsKey(name)) {
+            invalidNumber.put(name, value);
+            errors++;
+        }
     }
 
     public String getSyntaxError() {

http://git-wip-us.apache.org/repos/asf/camel/blob/95415555/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index b2fb872..e096244 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -401,20 +401,24 @@ public class CamelCatalogTest {
         result = catalog.validateEndpointProperties("log:mylog?level=WARN&foo=bar");
         assertFalse(result.isSuccess());
         assertTrue(result.getUnknown().contains("foo"));
+        assertEquals(1, result.getNumberOfErrors());
 
         // enum
         result = catalog.validateEndpointProperties("jms:unknown:myqueue");
         assertFalse(result.isSuccess());
         assertEquals("unknown", result.getInvalidEnum().get("destinationType"));
+        assertEquals(1, result.getNumberOfErrors());
 
         // reference okay
         result = catalog.validateEndpointProperties("jms:queue:myqueue?jmsKeyFormatStrategy=#key");
         assertTrue(result.isSuccess());
+        assertEquals(0, result.getNumberOfErrors());
 
         // reference
         result = catalog.validateEndpointProperties("jms:queue:myqueue?jmsKeyFormatStrategy=key");
         assertFalse(result.isSuccess());
         assertEquals("key", result.getInvalidReference().get("jmsKeyFormatStrategy"));
+        assertEquals(1, result.getNumberOfErrors());
 
         // okay
         result = catalog.validateEndpointProperties("yammer:MESSAGES?accessToken=aaa&consumerKey=bbb&consumerSecret=ccc&useJson=true&initialDelay=500");
@@ -423,6 +427,7 @@ public class CamelCatalogTest {
         // required / boolean / integer
         result = catalog.validateEndpointProperties("yammer:MESSAGES?accessToken=aaa&consumerKey=&useJson=no&initialDelay=five");
         assertFalse(result.isSuccess());
+        assertEquals(4, result.getNumberOfErrors());
         assertTrue(result.getRequired().contains("consumerKey"));
         assertTrue(result.getRequired().contains("consumerSecret"));
         assertEquals("no", result.getInvalidBoolean().get("useJson"));
@@ -431,21 +436,25 @@ public class CamelCatalogTest {
         // okay
         result = catalog.validateEndpointProperties("mqtt:myqtt?reconnectBackOffMultiplier=2.5");
         assertTrue(result.isSuccess());
+        assertEquals(0, result.getNumberOfErrors());
 
         // number
         result = catalog.validateEndpointProperties("mqtt:myqtt?reconnectBackOffMultiplier=five");
         assertFalse(result.isSuccess());
         assertEquals("five", result.getInvalidNumber().get("reconnectBackOffMultiplier"));
+        assertEquals(1, result.getNumberOfErrors());
 
         // unknown component
         result = catalog.validateEndpointProperties("foo:bar?me=you");
         assertFalse(result.isSuccess());
         assertTrue(result.getUnknownComponent().equals("foo"));
+        assertEquals(1, result.getNumberOfErrors());
 
         // invalid boolean but default value
         result = catalog.validateEndpointProperties("log:output?showAll=ggg");
         assertFalse(result.isSuccess());
         assertEquals("ggg", result.getInvalidBoolean().get("showAll"));
+        assertEquals(1, result.getNumberOfErrors());
     }
 
     @Test


Mime
View raw message