Repository: camel Updated Branches: refs/heads/camel-2.18.x a35771d0d -> bb2264d8f refs/heads/master d023026af -> da0645994
camel-catalog - improve endpoint validation around lenient vs non lenient components. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/da064599 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/da064599 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/da064599 Branch: refs/heads/master Commit: da06459945615b173118e0e97544d9c91d8cb3ee Parents: d023026 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Jan 16 12:23:50 2017 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Jan 16 12:27:08 2017 +0100 ---------------------------------------------------------------------- .../camel/catalog/DefaultCamelCatalog.java | 29 +++++++++++++------- .../camel/catalog/EndpointValidationResult.java | 14 ++++++++++ .../apache/camel/catalog/CamelCatalogTest.java | 25 +++++++++++++++++ 3 files changed, 58 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/da064599/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 7c5ad30..7efa230 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 @@ -1142,9 +1142,13 @@ public class DefaultCamelCatalog implements CamelCatalog { } rows = JSonSchemaHelper.parseJsonSchema("component", json, false); - // only enable lenient properties if we should not ignore - lenientProperties = !ignoreLenientProperties && isComponentLenientProperties(rows); - + if (consumerOnly) { + // lenient properties is not support in consumer only mode + lenientProperties = false; + } else { + // only enable lenient properties if we should not ignore + lenientProperties = !ignoreLenientProperties && isComponentLenientProperties(rows); + } rows = JSonSchemaHelper.parseJsonSchema("properties", json, true); properties = endpointProperties(uri); } catch (URISyntaxException e) { @@ -1198,13 +1202,18 @@ public class DefaultCamelCatalog implements CamelCatalog { // only add as error if the component is not lenient properties, or not stub component // and the name is not a property placeholder for one or more values - // as if we are lenient then the option is a dynamic extra option which we cannot validate - if (!namePlaceholder && !lenientProperties && !"stub".equals(scheme)) { - result.addUnknown(name); - if (suggestionStrategy != null) { - String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name); - if (suggestions != null) { - result.addUnknownSuggestions(name, suggestions); + if (!namePlaceholder && !"stub".equals(scheme)) { + if (lenientProperties) { + // as if we are lenient then the option is a dynamic extra option which we cannot validate + result.addLenient(name); + } else { + // its unknown + result.addUnknown(name); + if (suggestionStrategy != null) { + String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name); + if (suggestions != null) { + result.addUnknownSuggestions(name, suggestions); + } } } } http://git-wip-us.apache.org/repos/asf/camel/blob/da064599/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 fa2515e..11e2c5e 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 @@ -41,6 +41,7 @@ public class EndpointValidationResult implements Serializable { // options private Set<String> unknown; private Map<String, String[]> unknownSuggestions; + private Set<String> lenient; private Set<String> notConsumerOnly; private Set<String> notProducerOnly; private Set<String> required; @@ -110,6 +111,15 @@ public class EndpointValidationResult implements Serializable { unknownSuggestions.put(name, suggestions); } + public void addLenient(String name) { + if (lenient == null) { + lenient = new LinkedHashSet<String>(); + } + if (!lenient.contains(name)) { + lenient.add(name); + } + } + public void addRequired(String name) { if (required == null) { required = new LinkedHashSet<String>(); @@ -223,6 +233,10 @@ public class EndpointValidationResult implements Serializable { return unknown; } + public Set<String> getLenient() { + return lenient; + } + public Map<String, String[]> getUnknownSuggestions() { return unknownSuggestions; } http://git-wip-us.apache.org/repos/asf/camel/blob/da064599/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 a541d24..97cb5a3 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 @@ -599,6 +599,31 @@ public class CamelCatalogTest { assertFalse(result.isSuccess()); assertTrue(result.getUnknown().contains("foo")); + // lenient off consumer only + result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", false, true, false); + assertFalse(result.isSuccess()); + // consumer should still fail because we cannot use lenient option in consumer mode + assertEquals("foo", result.getUnknown().iterator().next()); + assertNull(result.getLenient()); + // lenient off producer only + result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", false, false, true); + assertTrue(result.isSuccess()); + // foo is the lenient option + assertEquals(1, result.getLenient().size()); + assertEquals("foo", result.getLenient().iterator().next()); + + // lenient on consumer only + result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", true, true, false); + assertFalse(result.isSuccess()); + // consumer should still fail because we cannot use lenient option in consumer mode + assertEquals("foo", result.getUnknown().iterator().next()); + assertNull(result.getLenient()); + // lenient on producer only + result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", true, false, true); + assertFalse(result.isSuccess()); + assertEquals("foo", result.getUnknown().iterator().next()); + assertNull(result.getLenient()); + // data format result = catalog.validateEndpointProperties("dataformat:string:marshal?charset=utf-8", true); assertTrue(result.isSuccess());