camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: Camel catalog - Add api to validate endpoint uri
Date Thu, 24 Dec 2015 09:18:38 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/5fb9c98b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5fb9c98b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5fb9c98b

Branch: refs/heads/camel-2.16.x
Commit: 5fb9c98bfece7b276bfb7523fd40f3440eeb75b6
Parents: 46e3e4a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Dec 24 10:17:53 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Dec 24 10:18:28 2015 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java       |  6 ++++++
 .../camel/catalog/EndpointValidationResult.java  | 19 ++++++++++++++++++-
 .../apache/camel/catalog/CamelCatalogTest.java   |  1 +
 3 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5fb9c98b/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 92088a1..10dfd96 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
@@ -693,6 +693,12 @@ public class DefaultCamelCatalog implements CamelCatalog {
                     }
                 }
             } else {
+                // default value
+                String defaultValue = getPropertyDefaultValue(rows, name);
+                if (defaultValue != null) {
+                    result.addDefaultValue(name, defaultValue);
+                }
+
                 // is required but the value is empty
                 boolean required = isPropertyRequired(rows, name);
                 if (required && isEmpty(value)) {

http://git-wip-us.apache.org/repos/asf/camel/blob/5fb9c98b/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 4c03e2f..dba4032 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
@@ -45,6 +45,7 @@ public class EndpointValidationResult implements Serializable {
     private Map<String, String> invalidBoolean;
     private Map<String, String> invalidInteger;
     private Map<String, String> invalidNumber;
+    private Map<String, String> defaultValues;
 
     public EndpointValidationResult(String uri) {
         this.uri = uri;
@@ -162,6 +163,13 @@ public class EndpointValidationResult implements Serializable {
         }
     }
 
+    public void addDefaultValue(String name, String value)  {
+        if (defaultValues == null) {
+            defaultValues = new LinkedHashMap<String, String>();
+        }
+        defaultValues.put(name, value);
+    }
+
     public String getSyntaxError() {
         return syntaxError;
     }
@@ -206,6 +214,10 @@ public class EndpointValidationResult implements Serializable {
         return invalidNumber;
     }
 
+    public Map<String, String> getDefaultValues() {
+        return defaultValues;
+    }
+
     /**
      * A human readable summary of the validation errors.
      *
@@ -243,8 +255,13 @@ public class EndpointValidationResult implements Serializable {
         if (invalidEnum != null) {
             for (Map.Entry<String, String> entry : invalidEnum.entrySet()) {
                 String[] choices = invalidEnumChoices.get(entry.getKey());
+                String defaultValue = defaultValues != null ? defaultValues.get(entry.getKey())
: null;
                 String str = Arrays.asList(choices).toString();
-                options.put(entry.getKey(), "Invalid enum value: " + entry.getValue() + ".
Possible values: " + str);
+                String msg = "Invalid enum value: " + entry.getValue() + ". Possible values:
" + str;
+                if (defaultValue != null) {
+                    msg += ". Default value: " + defaultValue;
+                }
+                options.put(entry.getKey(), msg);
             }
         }
         if (invalidReference != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/5fb9c98b/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 e096244..e3c6d0b 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,7 @@ public class CamelCatalogTest {
         result = catalog.validateEndpointProperties("jms:unknown:myqueue");
         assertFalse(result.isSuccess());
         assertEquals("unknown", result.getInvalidEnum().get("destinationType"));
+        assertEquals("queue", result.getDefaultValues().get("destinationType"));
         assertEquals(1, result.getNumberOfErrors());
 
         // reference okay


Mime
View raw message