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 6531B18983 for ; Wed, 23 Dec 2015 08:43:54 +0000 (UTC) Received: (qmail 75299 invoked by uid 500); 23 Dec 2015 08:43:54 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 75245 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 75235 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 24611E00E5; 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:43:54 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [01/14] camel git commit: Camel catalog - Renamed Repository: camel Updated Branches: refs/heads/camel-2.16.x 10d50677e -> c450a4745 refs/heads/master 6257769b5 -> 95415555a Camel catalog - Renamed Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/56852c66 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/56852c66 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/56852c66 Branch: refs/heads/master Commit: 56852c66fa9cad8efed91b9f6adea518455c2507 Parents: 6257769 Author: Claus Ibsen Authored: Tue Dec 22 09:57:44 2015 +0100 Committer: Claus Ibsen Committed: Wed Dec 23 09:05:12 2015 +0100 ---------------------------------------------------------------------- .../org/apache/camel/catalog/CamelCatalog.java | 2 +- .../camel/catalog/DefaultCamelCatalog.java | 4 +- .../camel/catalog/EndpointValidationResult.java | 217 +++++++++++++++++++ .../apache/camel/catalog/ValidationResult.java | 217 ------------------- .../apache/camel/catalog/CamelCatalogTest.java | 20 +- 5 files changed, 230 insertions(+), 230 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/56852c66/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java ---------------------------------------------------------------------- diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java index f3ce3a1..eeafe6c 100644 --- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java +++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java @@ -175,7 +175,7 @@ public interface CamelCatalog { * @param uri the endpoint uri * @return validation result */ - ValidationResult validateProperties(String uri); + EndpointValidationResult validateEndpointProperties(String uri); /** * Returns the component name from the given endpoint uri http://git-wip-us.apache.org/repos/asf/camel/blob/56852c66/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 efb5db4..9ad91bd 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 @@ -646,8 +646,8 @@ public class DefaultCamelCatalog implements CamelCatalog { } @Override - public ValidationResult validateProperties(String uri) { - ValidationResult result = new ValidationResult(uri); + public EndpointValidationResult validateEndpointProperties(String uri) { + EndpointValidationResult result = new EndpointValidationResult(uri); Map properties; List> rows; http://git-wip-us.apache.org/repos/asf/camel/blob/56852c66/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 new file mode 100644 index 0000000..413aaa5 --- /dev/null +++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java @@ -0,0 +1,217 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.catalog; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * Details result of validating endpoint uri. + */ +public class EndpointValidationResult implements Serializable { + + private final String uri; + + // component + private String syntaxError; + private String unknownComponent; + + // options + private Set unknown; + private Set required; + private Map invalidEnum; + private Map invalidEnumChoices; + private Map invalidBoolean; + private Map invalidInteger; + private Map invalidNumber; + + public EndpointValidationResult(String uri) { + this.uri = uri; + } + + public boolean isSuccess() { + return syntaxError == null && unknownComponent == null + && unknown == null && required == null && invalidEnum == null && invalidEnumChoices == null + && invalidBoolean == null && invalidInteger == null && invalidNumber == null; + } + + public void addSyntaxError(String syntaxError) { + this.syntaxError = syntaxError; + } + + public void addUnknownComponent(String name) { + this.unknownComponent = name; + } + + public void addUnknown(String name) { + if (unknown == null) { + unknown = new LinkedHashSet(); + } + unknown.add(name); + } + + public void addRequired(String name) { + if (required == null) { + required = new LinkedHashSet(); + } + required.add(name); + } + + public void addInvalidEnum(String name, String value) { + if (invalidEnum == null) { + invalidEnum = new LinkedHashMap(); + } + invalidEnum.put(name, value); + } + + public void addInvalidEnumChoices(String name, String[] choices) { + if (invalidEnumChoices == null) { + invalidEnumChoices = new LinkedHashMap(); + } + invalidEnumChoices.put(name, choices); + } + + public void addInvalidBoolean(String name, String value) { + if (invalidBoolean == null) { + invalidBoolean = new LinkedHashMap();; + } + invalidBoolean.put(name, value); + } + + public void addInvalidInteger(String name, String value) { + if (invalidInteger == null) { + invalidInteger = new LinkedHashMap();; + } + invalidInteger.put(name, value); + } + + public void addInvalidNumber(String name, String value) { + if (invalidNumber == null) { + invalidNumber = new LinkedHashMap();; + } + invalidNumber.put(name, value); + } + + public String getSyntaxError() { + return syntaxError; + } + + public Set getUnknown() { + return unknown; + } + + public String getUnknownComponent() { + return unknownComponent; + } + + public Set getRequired() { + return required; + } + + public Map getInvalidEnum() { + return invalidEnum; + } + + public Map getInvalidBoolean() { + return invalidBoolean; + } + + public Map getInvalidInteger() { + return invalidInteger; + } + + public Map getInvalidNumber() { + return invalidNumber; + } + + /** + * A human readable summary of the validation errors. + * + * @return the summary, or null if no validation errors + */ + public String summaryErrorMessage() { + if (isSuccess()) { + return null; + } + + if (syntaxError != null) { + return "Syntax error " + syntaxError; + } else if (unknownComponent != null) { + return "Unknown component " + unknownComponent; + } + + // for each invalid option build a reason message + Map options = new LinkedHashMap(); + if (unknown != null) { + for (String name : unknown) { + options.put(name, "Unknown field"); + } + } + if (required != null) { + for (String name : required) { + options.put(name, "Missing required field"); + } + } + if (invalidEnum != null) { + for (Map.Entry entry : invalidEnum.entrySet()) { + String[] choices = invalidEnumChoices.get(entry.getKey()); + String str = Arrays.asList(choices).toString(); + options.put(entry.getKey(), "Invalid enum value: " + entry.getValue() + ". Possible values: " + str); + } + } + if (invalidBoolean != null) { + for (Map.Entry entry : invalidBoolean.entrySet()) { + options.put(entry.getKey(), "Invalid boolean value: " + entry.getValue()); + } + } + if (invalidInteger != null) { + for (Map.Entry entry : invalidInteger.entrySet()) { + options.put(entry.getKey(), "Invalid integer value: " + entry.getValue()); + } + } + if (invalidNumber != null) { + for (Map.Entry entry : invalidNumber.entrySet()) { + options.put(entry.getKey(), "Invalid number value: " + entry.getValue()); + } + } + + // build a table with the error summary nicely formatted + // lets use 24 as min length + int maxLen = 24; + for (String key : options.keySet()) { + maxLen = Math.max(maxLen, key.length()); + } + String format = "%" + maxLen + "s %s"; + + // build the human error summary + StringBuilder sb = new StringBuilder(); + sb.append("Endpoint validator error\n"); + sb.append("---------------------------------------------------------------------------------------------------------------------------------------\n"); + sb.append("\n\t").append(uri).append("\n"); + for (Map.Entry option : options.entrySet()) { + String out = String.format(format, option.getKey(), option.getValue()); + sb.append("\n\t").append(out); + } + sb.append("\n\n"); + + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/56852c66/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java ---------------------------------------------------------------------- diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java deleted file mode 100644 index 40aacb3..0000000 --- a/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java +++ /dev/null @@ -1,217 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.catalog; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -/** - * Details result of validating endpoint uri. - */ -public class ValidationResult implements Serializable { - - private final String uri; - - // component - private String syntaxError; - private String unknownComponent; - - // options - private Set unknown; - private Set required; - private Map invalidEnum; - private Map invalidEnumChoices; - private Map invalidBoolean; - private Map invalidInteger; - private Map invalidNumber; - - public ValidationResult(String uri) { - this.uri = uri; - } - - public boolean isSuccess() { - return syntaxError == null && unknownComponent == null - && unknown == null && required == null && invalidEnum == null && invalidEnumChoices == null - && invalidBoolean == null && invalidInteger == null && invalidNumber == null; - } - - public void addSyntaxError(String syntaxError) { - this.syntaxError = syntaxError; - } - - public void addUnknownComponent(String name) { - this.unknownComponent = name; - } - - public void addUnknown(String name) { - if (unknown == null) { - unknown = new LinkedHashSet(); - } - unknown.add(name); - } - - public void addRequired(String name) { - if (required == null) { - required = new LinkedHashSet(); - } - required.add(name); - } - - public void addInvalidEnum(String name, String value) { - if (invalidEnum == null) { - invalidEnum = new LinkedHashMap(); - } - invalidEnum.put(name, value); - } - - public void addInvalidEnumChoices(String name, String[] choices) { - if (invalidEnumChoices == null) { - invalidEnumChoices = new LinkedHashMap(); - } - invalidEnumChoices.put(name, choices); - } - - public void addInvalidBoolean(String name, String value) { - if (invalidBoolean == null) { - invalidBoolean = new LinkedHashMap();; - } - invalidBoolean.put(name, value); - } - - public void addInvalidInteger(String name, String value) { - if (invalidInteger == null) { - invalidInteger = new LinkedHashMap();; - } - invalidInteger.put(name, value); - } - - public void addInvalidNumber(String name, String value) { - if (invalidNumber == null) { - invalidNumber = new LinkedHashMap();; - } - invalidNumber.put(name, value); - } - - public String getSyntaxError() { - return syntaxError; - } - - public Set getUnknown() { - return unknown; - } - - public String getUnknownComponent() { - return unknownComponent; - } - - public Set getRequired() { - return required; - } - - public Map getInvalidEnum() { - return invalidEnum; - } - - public Map getInvalidBoolean() { - return invalidBoolean; - } - - public Map getInvalidInteger() { - return invalidInteger; - } - - public Map getInvalidNumber() { - return invalidNumber; - } - - /** - * A human readable summary of the validation errors. - * - * @return the summary, or null if no validation errors - */ - public String summaryErrorMessage() { - if (isSuccess()) { - return null; - } - - if (syntaxError != null) { - return "Syntax error " + syntaxError; - } else if (unknownComponent != null) { - return "Unknown component " + unknownComponent; - } - - // for each invalid option build a reason message - Map options = new LinkedHashMap(); - if (unknown != null) { - for (String name : unknown) { - options.put(name, "Unknown field"); - } - } - if (required != null) { - for (String name : required) { - options.put(name, "Missing required field"); - } - } - if (invalidEnum != null) { - for (Map.Entry entry : invalidEnum.entrySet()) { - String[] choices = invalidEnumChoices.get(entry.getKey()); - String str = Arrays.asList(choices).toString(); - options.put(entry.getKey(), "Invalid enum value: " + entry.getValue() + ". Possible values: " + str); - } - } - if (invalidBoolean != null) { - for (Map.Entry entry : invalidBoolean.entrySet()) { - options.put(entry.getKey(), "Invalid boolean value: " + entry.getValue()); - } - } - if (invalidInteger != null) { - for (Map.Entry entry : invalidInteger.entrySet()) { - options.put(entry.getKey(), "Invalid integer value: " + entry.getValue()); - } - } - if (invalidNumber != null) { - for (Map.Entry entry : invalidNumber.entrySet()) { - options.put(entry.getKey(), "Invalid number value: " + entry.getValue()); - } - } - - // build a table with the error summary nicely formatted - // lets use 24 as min length - int maxLen = 24; - for (String key : options.keySet()) { - maxLen = Math.max(maxLen, key.length()); - } - String format = "%" + maxLen + "s %s"; - - // build the human error summary - StringBuilder sb = new StringBuilder(); - sb.append("Endpoint validator error\n"); - sb.append("---------------------------------------------------------------------------------------------------------------------------------------\n"); - sb.append("\n\t").append(uri).append("\n"); - for (Map.Entry option : options.entrySet()) { - String out = String.format(format, option.getKey(), option.getValue()); - sb.append("\n\t").append(out); - } - sb.append("\n\n"); - - return sb.toString(); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/56852c66/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 b33ad5c..74776b5 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 @@ -394,25 +394,25 @@ public class CamelCatalogTest { @Test public void validateProperties() throws Exception { // valid - ValidationResult result = catalog.validateProperties("log:mylog"); + EndpointValidationResult result = catalog.validateEndpointProperties("log:mylog"); assertTrue(result.isSuccess()); // unknown - result = catalog.validateProperties("log:mylog?level=WARN&foo=bar"); + result = catalog.validateEndpointProperties("log:mylog?level=WARN&foo=bar"); assertFalse(result.isSuccess()); assertTrue(result.getUnknown().contains("foo")); // enum - result = catalog.validateProperties("jms:unknown:myqueue"); + result = catalog.validateEndpointProperties("jms:unknown:myqueue"); assertFalse(result.isSuccess()); assertEquals("unknown", result.getInvalidEnum().get("destinationType")); // okay - result = catalog.validateProperties("yammer:MESSAGES?accessToken=aaa&consumerKey=bbb&consumerSecret=ccc&useJson=true&initialDelay=500"); + result = catalog.validateEndpointProperties("yammer:MESSAGES?accessToken=aaa&consumerKey=bbb&consumerSecret=ccc&useJson=true&initialDelay=500"); assertTrue(result.isSuccess()); // required / boolean / integer - result = catalog.validateProperties("yammer:MESSAGES?accessToken=aaa&consumerKey=&useJson=no&initialDelay=five"); + result = catalog.validateEndpointProperties("yammer:MESSAGES?accessToken=aaa&consumerKey=&useJson=no&initialDelay=five"); assertFalse(result.isSuccess()); assertTrue(result.getRequired().contains("consumerKey")); assertTrue(result.getRequired().contains("consumerSecret")); @@ -420,28 +420,28 @@ public class CamelCatalogTest { assertEquals("five", result.getInvalidInteger().get("initialDelay")); // okay - result = catalog.validateProperties("mqtt:myqtt?reconnectBackOffMultiplier=2.5"); + result = catalog.validateEndpointProperties("mqtt:myqtt?reconnectBackOffMultiplier=2.5"); assertTrue(result.isSuccess()); // number - result = catalog.validateProperties("mqtt:myqtt?reconnectBackOffMultiplier=five"); + result = catalog.validateEndpointProperties("mqtt:myqtt?reconnectBackOffMultiplier=five"); assertFalse(result.isSuccess()); assertEquals("five", result.getInvalidNumber().get("reconnectBackOffMultiplier")); // unknown component - result = catalog.validateProperties("foo:bar?me=you"); + result = catalog.validateEndpointProperties("foo:bar?me=you"); assertFalse(result.isSuccess()); assertTrue(result.getUnknownComponent().equals("foo")); } @Test public void validatePropertiesSummary() throws Exception { - ValidationResult result = catalog.validateProperties("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"); assertFalse(result.isSuccess()); String reason = result.summaryErrorMessage(); LOG.info(reason); - result = catalog.validateProperties("jms:unknown:myqueue"); + result = catalog.validateEndpointProperties("jms:unknown:myqueue"); assertFalse(result.isSuccess()); reason = result.summaryErrorMessage(); LOG.info(reason);