You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/12/23 09:44:01 UTC
[08/14] camel git commit: Camel catalog - Renamed
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/9aeccdb0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9aeccdb0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9aeccdb0
Branch: refs/heads/camel-2.16.x
Commit: 9aeccdb09ef11a749f00e8252dd368245f422279
Parents: 10d5067
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 22 09:57:44 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 23 09:42:49 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/9aeccdb0/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/9aeccdb0/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<String, String> properties;
List<Map<String, String>> rows;
http://git-wip-us.apache.org/repos/asf/camel/blob/9aeccdb0/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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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<String> unknown;
+ private Set<String> required;
+ private Map<String, String> invalidEnum;
+ private Map<String, String[]> invalidEnumChoices;
+ private Map<String, String> invalidBoolean;
+ private Map<String, String> invalidInteger;
+ private Map<String, String> 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<String>();
+ }
+ unknown.add(name);
+ }
+
+ public void addRequired(String name) {
+ if (required == null) {
+ required = new LinkedHashSet<String>();
+ }
+ required.add(name);
+ }
+
+ public void addInvalidEnum(String name, String value) {
+ if (invalidEnum == null) {
+ invalidEnum = new LinkedHashMap<String, String>();
+ }
+ invalidEnum.put(name, value);
+ }
+
+ public void addInvalidEnumChoices(String name, String[] choices) {
+ if (invalidEnumChoices == null) {
+ invalidEnumChoices = new LinkedHashMap<String, String[]>();
+ }
+ invalidEnumChoices.put(name, choices);
+ }
+
+ public void addInvalidBoolean(String name, String value) {
+ if (invalidBoolean == null) {
+ invalidBoolean = new LinkedHashMap<String, String>();;
+ }
+ invalidBoolean.put(name, value);
+ }
+
+ public void addInvalidInteger(String name, String value) {
+ if (invalidInteger == null) {
+ invalidInteger = new LinkedHashMap<String, String>();;
+ }
+ invalidInteger.put(name, value);
+ }
+
+ public void addInvalidNumber(String name, String value) {
+ if (invalidNumber == null) {
+ invalidNumber = new LinkedHashMap<String, String>();;
+ }
+ invalidNumber.put(name, value);
+ }
+
+ public String getSyntaxError() {
+ return syntaxError;
+ }
+
+ public Set<String> getUnknown() {
+ return unknown;
+ }
+
+ public String getUnknownComponent() {
+ return unknownComponent;
+ }
+
+ public Set<String> getRequired() {
+ return required;
+ }
+
+ public Map<String, String> getInvalidEnum() {
+ return invalidEnum;
+ }
+
+ public Map<String, String> getInvalidBoolean() {
+ return invalidBoolean;
+ }
+
+ public Map<String, String> getInvalidInteger() {
+ return invalidInteger;
+ }
+
+ public Map<String, String> getInvalidNumber() {
+ return invalidNumber;
+ }
+
+ /**
+ * A human readable summary of the validation errors.
+ *
+ * @return the summary, or <tt>null</tt> 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<String, String> options = new LinkedHashMap<String, String>();
+ 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<String, String> 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<String, String> entry : invalidBoolean.entrySet()) {
+ options.put(entry.getKey(), "Invalid boolean value: " + entry.getValue());
+ }
+ }
+ if (invalidInteger != null) {
+ for (Map.Entry<String, String> entry : invalidInteger.entrySet()) {
+ options.put(entry.getKey(), "Invalid integer value: " + entry.getValue());
+ }
+ }
+ if (invalidNumber != null) {
+ for (Map.Entry<String, String> 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<String, String> 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/9aeccdb0/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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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<String> unknown;
- private Set<String> required;
- private Map<String, String> invalidEnum;
- private Map<String, String[]> invalidEnumChoices;
- private Map<String, String> invalidBoolean;
- private Map<String, String> invalidInteger;
- private Map<String, String> 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<String>();
- }
- unknown.add(name);
- }
-
- public void addRequired(String name) {
- if (required == null) {
- required = new LinkedHashSet<String>();
- }
- required.add(name);
- }
-
- public void addInvalidEnum(String name, String value) {
- if (invalidEnum == null) {
- invalidEnum = new LinkedHashMap<String, String>();
- }
- invalidEnum.put(name, value);
- }
-
- public void addInvalidEnumChoices(String name, String[] choices) {
- if (invalidEnumChoices == null) {
- invalidEnumChoices = new LinkedHashMap<String, String[]>();
- }
- invalidEnumChoices.put(name, choices);
- }
-
- public void addInvalidBoolean(String name, String value) {
- if (invalidBoolean == null) {
- invalidBoolean = new LinkedHashMap<String, String>();;
- }
- invalidBoolean.put(name, value);
- }
-
- public void addInvalidInteger(String name, String value) {
- if (invalidInteger == null) {
- invalidInteger = new LinkedHashMap<String, String>();;
- }
- invalidInteger.put(name, value);
- }
-
- public void addInvalidNumber(String name, String value) {
- if (invalidNumber == null) {
- invalidNumber = new LinkedHashMap<String, String>();;
- }
- invalidNumber.put(name, value);
- }
-
- public String getSyntaxError() {
- return syntaxError;
- }
-
- public Set<String> getUnknown() {
- return unknown;
- }
-
- public String getUnknownComponent() {
- return unknownComponent;
- }
-
- public Set<String> getRequired() {
- return required;
- }
-
- public Map<String, String> getInvalidEnum() {
- return invalidEnum;
- }
-
- public Map<String, String> getInvalidBoolean() {
- return invalidBoolean;
- }
-
- public Map<String, String> getInvalidInteger() {
- return invalidInteger;
- }
-
- public Map<String, String> getInvalidNumber() {
- return invalidNumber;
- }
-
- /**
- * A human readable summary of the validation errors.
- *
- * @return the summary, or <tt>null</tt> 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<String, String> options = new LinkedHashMap<String, String>();
- 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<String, String> 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<String, String> entry : invalidBoolean.entrySet()) {
- options.put(entry.getKey(), "Invalid boolean value: " + entry.getValue());
- }
- }
- if (invalidInteger != null) {
- for (Map.Entry<String, String> entry : invalidInteger.entrySet()) {
- options.put(entry.getKey(), "Invalid integer value: " + entry.getValue());
- }
- }
- if (invalidNumber != null) {
- for (Map.Entry<String, String> 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<String, String> 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/9aeccdb0/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);