This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
commit 38aa4923c48ef47d2592a7ae4c5631e9cdb4010b Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Fri Jun 19 16:33:45 2020 +0200 Integration should fail when no secret is found #363 --- .../camel/k/support/KubernetesPropertiesFunction.java | 8 +++++--- .../k/listener/PropertiesFunctionsConfigurerTest.java | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/KubernetesPropertiesFunction.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/KubernetesPropertiesFunction.java index 3c8443f..e66c5b1 100644 --- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/KubernetesPropertiesFunction.java +++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/KubernetesPropertiesFunction.java @@ -41,15 +41,17 @@ public class KubernetesPropertiesFunction implements PropertiesFunction { @Override public String apply(String remainder) { + final String defaultValue = StringHelper.after(remainder, ":"); + if (this.root == null) { - return remainder; + return defaultValue; } final String name = StringHelper.before(remainder, "/"); final String property = StringHelper.after(remainder, "/"); if (name == null || property == null) { - return remainder; + return defaultValue; } Path file = this.root.resolve(name.toLowerCase()).resolve(property); @@ -61,6 +63,6 @@ public class KubernetesPropertiesFunction implements PropertiesFunction { } } - return remainder; + return defaultValue; } } diff --git a/camel-k-runtime-core/src/test/java/org/apache/camel/k/listener/PropertiesFunctionsConfigurerTest.java b/camel-k-runtime-core/src/test/java/org/apache/camel/k/listener/PropertiesFunctionsConfigurerTest.java index 0c59dc3..c66a38e 100644 --- a/camel-k-runtime-core/src/test/java/org/apache/camel/k/listener/PropertiesFunctionsConfigurerTest.java +++ b/camel-k-runtime-core/src/test/java/org/apache/camel/k/listener/PropertiesFunctionsConfigurerTest.java @@ -21,21 +21,30 @@ import org.apache.camel.k.Runtime; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class PropertiesFunctionsConfigurerTest { @Test - public void testConfigMapFunction() { - + public void testKubernetesFunction() { Runtime runtime = Runtime.on(new DefaultCamelContext()); runtime.setProperties("my.property", "{{secret:my-secret/my-property}}"); new PropertiesConfigurer().accept(runtime); - assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:my-secret/my-property}}")).isEqualTo("my-secret-property"); - assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:none/my-property}}")).isEqualTo("none/my-property"); + assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:my-secret/my-property}}")) + .isEqualTo("my-secret-property"); + assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:none/my-property:my-default-secret}}")) + .isEqualTo("my-default-secret"); + assertThatThrownBy(() -> runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:none/my-property}}")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("returned null value which is not allowed, from input"); assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:my-cm/my-property}}")).isEqualTo("my-cm-property"); - assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:none/my-property}}")).isEqualTo("none/my-property"); + assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:my-cm/my-property:my-default-cm}}")) + .isEqualTo("my-default-cm"); + assertThatThrownBy(() -> runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:none/my-property}}")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("returned null value which is not allowed, from input"); assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{my.property}}")).isEqualTo("my-secret-property"); }