Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ED0C218986 for ; Wed, 23 Dec 2015 08:43:54 +0000 (UTC) Received: (qmail 75914 invoked by uid 500); 23 Dec 2015 08:43:54 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 75710 invoked by uid 500); 23 Dec 2015 08:43:54 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 75482 invoked by uid 99); 23 Dec 2015 08:43:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Dec 2015 08:43:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6CB3BE07D9; Wed, 23 Dec 2015 08:43:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Wed, 23 Dec 2015 08:44:02 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [09/14] camel git commit: Camel catalog - Add api to validate endpoint uri 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/cbf31791 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cbf31791 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cbf31791 Branch: refs/heads/camel-2.16.x Commit: cbf317918742ce68bd5e744d0299c01a4f3c99f8 Parents: 9aeccdb Author: Claus Ibsen Authored: Tue Dec 22 10:08:44 2015 +0100 Committer: Claus Ibsen Committed: Wed Dec 23 09:42:56 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/cbf31791/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 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/cbf31791/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 required; private Map invalidEnum; private Map invalidEnumChoices; + private Map invalidReference; private Map invalidBoolean; private Map invalidInteger; private Map 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(); + } + invalidReference.put(name, value); + } + public void addInvalidBoolean(String name, String value) { if (invalidBoolean == null) { invalidBoolean = new LinkedHashMap();; @@ -130,6 +138,10 @@ public class EndpointValidationResult implements Serializable { return invalidEnum; } + public Map getInvalidReference() { + return invalidReference; + } + public Map 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 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 entry : invalidBoolean.entrySet()) { options.put(entry.getKey(), "Invalid boolean value: " + entry.getValue()); http://git-wip-us.apache.org/repos/asf/camel/blob/cbf31791/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> rows, String name) { + for (Map 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> rows, String name) { for (Map row : rows) { String defaultValue = null; http://git-wip-us.apache.org/repos/asf/camel/blob/cbf31791/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);