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 2019/12/23 13:53:50 UTC
[camel] branch master updated: CAMEL-14311: Add validate
configuration properties to camel-catalog.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 017dcbd CAMEL-14311: Add validate configuration properties to camel-catalog.
017dcbd is described below
commit 017dcbd3fdb93a34fb4eb0dda3006f8ea9c6ccba
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 23 14:51:22 2019 +0100
CAMEL-14311: Add validate configuration properties to camel-catalog.
---
.../org/apache/camel/catalog/CamelCatalogTest.java | 14 ++++---
.../runtimecatalog/impl/AbstractCamelCatalog.java | 49 +++++++++++++---------
.../impl/RuntimeCamelCatalogTest.java | 1 -
3 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index ddc9c84..8b5ab18 100644
--- a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -1507,9 +1507,12 @@ public class CamelCatalogTest {
result = catalog.validateConfigurationProperty(text);
assertFalse(result.isSuccess());
assertEquals("12x5", result.getInvalidNumber().get("camel.resilience4j.slow-call-rate-threshold"));
+ }
- text = "camel.rest.api-properties=#foo";
- result = catalog.validateConfigurationProperty(text);
+ @Test
+ public void testValidateConfigurationPropertyMainMap() throws Exception {
+ String text = "camel.rest.api-properties=#foo";
+ ConfigurationPropertiesValidationResult result = catalog.validateConfigurationProperty(text);
assertTrue(result.isSuccess());
text = "camel.rest.api-properties=bar";
@@ -1529,10 +1532,9 @@ public class CamelCatalogTest {
result = catalog.validateConfigurationProperty(text);
assertTrue(result.isSuccess());
- // TODO: add support for [] maps for main
-// text = "camel.rest.api-properties[drink]=no";
-// result = catalog.validateConfigurationProperty(text);
-// assertTrue(result.isSuccess());
+ text = "camel.rest.api-properties[drink]=no";
+ result = catalog.validateConfigurationProperty(text);
+ assertTrue(result.isSuccess());
}
}
diff --git a/core/camel-base/src/main/java/org/apache/camel/runtimecatalog/impl/AbstractCamelCatalog.java b/core/camel-base/src/main/java/org/apache/camel/runtimecatalog/impl/AbstractCamelCatalog.java
index 4b3bdbe..3c5b0b6 100644
--- a/core/camel-base/src/main/java/org/apache/camel/runtimecatalog/impl/AbstractCamelCatalog.java
+++ b/core/camel-base/src/main/java/org/apache/camel/runtimecatalog/impl/AbstractCamelCatalog.java
@@ -112,7 +112,7 @@ public abstract class AbstractCamelCatalog {
if (dfName != null) {
String dfJson = jsonSchemaResolver.getDataFormatJSonSchema(dfName);
List<Map<String, String>> dfRows = parseJsonSchema("properties", dfJson, true);
- if (dfRows != null && !dfRows.isEmpty()) {
+ if (!dfRows.isEmpty()) {
rows.addAll(dfRows);
}
}
@@ -214,8 +214,7 @@ public abstract class AbstractCamelCatalog {
result.addInvalidEnum(name, value);
result.addInvalidEnumChoices(name, choices);
if (suggestionStrategy != null) {
- Set<String> names = new LinkedHashSet<>();
- names.addAll(Arrays.asList(choices));
+ Set<String> names = new LinkedHashSet<>(Arrays.asList(choices));
String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value);
if (suggestions != null) {
result.addInvalidEnumSuggestions(name, suggestions);
@@ -350,7 +349,7 @@ public abstract class AbstractCamelCatalog {
if (dfName != null) {
String dfJson = jsonSchemaResolver.getDataFormatJSonSchema(dfName);
List<Map<String, String>> dfRows = parseJsonSchema("properties", dfJson, true);
- if (dfRows != null && !dfRows.isEmpty()) {
+ if (!dfRows.isEmpty()) {
rows.addAll(dfRows);
}
}
@@ -450,8 +449,7 @@ public abstract class AbstractCamelCatalog {
result.addInvalidEnum(name, value);
result.addInvalidEnumChoices(name, choices);
if (suggestionStrategy != null) {
- Set<String> names = new LinkedHashSet<>();
- names.addAll(Arrays.asList(choices));
+ Set<String> names = new LinkedHashSet<>(Arrays.asList(choices));
String[] suggestions = suggestionStrategy.suggestEndpointOptions(names, value);
if (suggestions != null) {
result.addInvalidEnumSuggestions(name, suggestions);
@@ -997,22 +995,22 @@ public abstract class AbstractCamelCatalog {
List<String> tokens = new ArrayList<>();
if (syntax != null) {
- String current = "";
+ StringBuilder current = new StringBuilder();
for (int i = 0; i < syntax.length(); i++) {
char ch = syntax.charAt(i);
if (Character.isLetterOrDigit(ch)) {
- current += ch;
+ current.append(ch);
} else {
// reset for new current tokens
if (current.length() > 0) {
- tokens.add(current);
- current = "";
+ tokens.add(current.toString());
+ current = new StringBuilder();
}
}
}
// anything left over?
if (current.length() > 0) {
- tokens.add(current);
+ tokens.add(current.toString());
}
}
@@ -1102,17 +1100,28 @@ public abstract class AbstractCamelCatalog {
List<Map<String, String>> rows = parseMainJsonSchema(json);
// lower case option and remove dash
- String lookupKey = longKey.replaceAll("-", "").toLowerCase(Locale.US);
+ String nOption = longKey.replaceAll("-", "").toLowerCase(Locale.US);
+
+ // look for suffix or array index after 2nd dot
+ int secondDot = nOption.indexOf('.');
+ secondDot = nOption.indexOf('.', secondDot + 1) + 1;
+
String suffix = null;
- int pos = option.indexOf('.');
- // TODO: add support for [] maps for main
- if (pos > 0 && option.length() > pos) {
- suffix = option.substring(pos + 1);
- // remove .suffix from lookup key
- int len = lookupKey.length() - suffix.length() - 1;
- lookupKey = lookupKey.substring(0, len);
+ int posDot = nOption.indexOf('.', secondDot);
+ int posBracket = nOption.indexOf('[', secondDot);
+ if (posDot > 0 && posBracket > 0) {
+ int first = Math.min(posDot, posBracket);
+ suffix = nOption.substring(first);
+ nOption = nOption.substring(0, first);
+ } else if (posDot > 0) {
+ suffix = nOption.substring(posDot);
+ nOption = nOption.substring(0, posDot);
+ } else if (posBracket > 0) {
+ suffix = nOption.substring(posBracket);
+ nOption = nOption.substring(0, posBracket);
}
- doValidateConfigurationProperty(result, rows, name, value, longKey, lookupKey, suffix);
+
+ doValidateConfigurationProperty(result, rows, name, value, longKey, nOption, suffix);
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java b/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java
index 93693f3..93a79c5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java
@@ -29,7 +29,6 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import static org.junit.Assert.*;
public class RuntimeCamelCatalogTest {