camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [04/14] camel git commit: Camel catalog - Add api to validate endpoint uri
Date Wed, 23 Dec 2015 08:43:57 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/f635df5d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f635df5d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f635df5d

Branch: refs/heads/master
Commit: f635df5d5cf60f361c8c9fa2135bc73516812f2e
Parents: 56852c6
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Dec 22 10:08:44 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Dec 23 09:05:13 2015 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java      | 13 ++++++++---
 .../camel/catalog/EndpointValidationResult.java | 23 +++++++++++++++++++-
 .../apache/camel/catalog/JSonSchemaHelper.java  | 17 +++++++++++++++
 .../apache/camel/catalog/CamelCatalogTest.java  | 11 +++++++++-
 4 files changed, 59 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f635df5d/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 9ad91bd..d9aebec 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -47,6 +47,7 @@ import static org.apache.camel.catalog.JSonSchemaHelper.getRow;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyBoolean;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyInteger;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyNumber;
+import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyObject;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyRequired;
 import static org.apache.camel.catalog.URISupport.createQueryString;
 import static org.apache.camel.catalog.URISupport.isEmpty;
@@ -675,12 +676,10 @@ public class DefaultCamelCatalog implements CamelCatalog {
             boolean placeholder = value.startsWith("{{") || value.startsWith("${") || value.startsWith("$simple{");
 
             Map<String, String> row = getRow(rows, name);
-            // unknown option
             if (row == null) {
+                // unknown option
                 result.addUnknown(name);
             } else {
-                // invalid value/type
-
                 // is required but the value is empty
                 boolean required = isPropertyRequired(rows, name);
                 if (required && isEmpty(value)) {
@@ -705,6 +704,14 @@ public class DefaultCamelCatalog implements CamelCatalog {
                     }
                 }
 
+                // is reference lookup of bean
+                if (isPropertyObject(rows, name)) {
+                    // must start with # and be at least 2 characters
+                    if (!value.startsWith("#") || value.length() <= 1) {
+                        result.addInvalidReference(name, value);
+                    }
+                }
+
                 // is boolean
                 if (!placeholder && isPropertyBoolean(rows, name)) {
                     // value must be a boolean

http://git-wip-us.apache.org/repos/asf/camel/blob/f635df5d/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 413aaa5..7bb33e1 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
@@ -39,6 +39,7 @@ public class EndpointValidationResult implements Serializable {
     private Set<String> required;
     private Map<String, String> invalidEnum;
     private Map<String, String[]> invalidEnumChoices;
+    private Map<String, String> invalidReference;
     private Map<String, String> invalidBoolean;
     private Map<String, String> invalidInteger;
     private Map<String, String> invalidNumber;
@@ -50,7 +51,7 @@ public class EndpointValidationResult implements Serializable {
     public boolean isSuccess() {
         return syntaxError == null && unknownComponent == null
                 && unknown == null && required == null && invalidEnum
== null && invalidEnumChoices == null
-                && invalidBoolean == null && invalidInteger == null &&
invalidNumber == null;
+                && invalidReference == null && invalidBoolean == null &&
invalidInteger == null && invalidNumber == null;
     }
 
     public void addSyntaxError(String syntaxError) {
@@ -89,6 +90,13 @@ public class EndpointValidationResult implements Serializable {
         invalidEnumChoices.put(name, choices);
     }
 
+    public void addInvalidReference(String name, String value) {
+        if (invalidReference == null) {
+            invalidReference = new LinkedHashMap<String, String>();
+        }
+        invalidReference.put(name, value);
+    }
+
     public void addInvalidBoolean(String name, String value) {
         if (invalidBoolean == null) {
             invalidBoolean = new LinkedHashMap<String, String>();;
@@ -130,6 +138,10 @@ public class EndpointValidationResult implements Serializable {
         return invalidEnum;
     }
 
+    public Map<String, String> getInvalidReference() {
+        return invalidReference;
+    }
+
     public Map<String, String> getInvalidBoolean() {
         return invalidBoolean;
     }
@@ -177,6 +189,15 @@ public class EndpointValidationResult implements Serializable {
                 options.put(entry.getKey(), "Invalid enum value: " + entry.getValue() + ".
Possible values: " + str);
             }
         }
+        if (invalidReference != null) {
+            for (Map.Entry<String, String> entry : invalidReference.entrySet()) {
+                if (!entry.getValue().startsWith("#")) {
+                    options.put(entry.getKey(), "Invalid reference value: " + entry.getValue()
+ " must start with #");
+                } else {
+                    options.put(entry.getKey(), "Invalid reference value: " + entry.getValue()
+ " must not be empty");
+                }
+            }
+        }
         if (invalidBoolean != null) {
             for (Map.Entry<String, String> entry : invalidBoolean.entrySet()) {
                 options.put(entry.getKey(), "Invalid boolean value: " + entry.getValue());

http://git-wip-us.apache.org/repos/asf/camel/blob/f635df5d/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
index e3e4beb..f0755ef 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
@@ -180,6 +180,23 @@ public final class JSonSchemaHelper {
         return false;
     }
 
+    public static boolean isPropertyObject(List<Map<String, String>> rows, String
name) {
+        for (Map<String, String> row : rows) {
+            String type = null;
+            boolean found = false;
+            if (row.containsKey("name")) {
+                found = name.equals(row.get("name"));
+            }
+            if (row.containsKey("type")) {
+                type = row.get("type");
+            }
+            if (found) {
+                return "object".equals(type);
+            }
+        }
+        return false;
+    }
+
     public static String getPropertyDefaultValue(List<Map<String, String>> rows,
String name) {
         for (Map<String, String> row : rows) {
             String defaultValue = null;

http://git-wip-us.apache.org/repos/asf/camel/blob/f635df5d/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 74776b5..08b0979 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
@@ -407,6 +407,15 @@ public class CamelCatalogTest {
         assertFalse(result.isSuccess());
         assertEquals("unknown", result.getInvalidEnum().get("destinationType"));
 
+        // reference okay
+        result = catalog.validateEndpointProperties("jms:queue:myqueue?jmsKeyFormatStrategy=#key");
+        assertTrue(result.isSuccess());
+
+        // reference
+        result = catalog.validateEndpointProperties("jms:queue:myqueue?jmsKeyFormatStrategy=key");
+        assertFalse(result.isSuccess());
+        assertEquals("key", result.getInvalidReference().get("jmsKeyFormatStrategy"));
+
         // okay
         result = catalog.validateEndpointProperties("yammer:MESSAGES?accessToken=aaa&consumerKey=bbb&consumerSecret=ccc&useJson=true&initialDelay=500");
         assertTrue(result.isSuccess());
@@ -436,7 +445,7 @@ public class CamelCatalogTest {
 
     @Test
     public void validatePropertiesSummary() throws Exception {
-        EndpointValidationResult result = catalog.validateEndpointProperties("yammer:MESSAGES?blah=yada&accessToken=aaa&consumerKey=&useJson=no&initialDelay=five");
+        EndpointValidationResult result = catalog.validateEndpointProperties("yammer:MESSAGES?blah=yada&accessToken=aaa&consumerKey=&useJson=no&initialDelay=five&pollStrategy=myStrategy");
         assertFalse(result.isSuccess());
         String reason = result.summaryErrorMessage();
         LOG.info(reason);


Mime
View raw message