This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 3486490 CAMEL-17606: Add property to route builder to refer to a
property placeholder using {{ }} syntax. And also useable for EndpointDSL.
3486490 is described below
commit 34864901f5da846d4a98dab7a788eae8e7808c6e
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Feb 7 10:03:49 2022 +0100
CAMEL-17606: Add property to route builder to refer to a property
placeholder using {{ }} syntax. And also useable for EndpointDSL.
---
.../org/apache/camel/builder/RouteBuilder.java | 10 ++
.../properties/PropertiesPropertyTest.java | 33 ++++++
.../builder/endpoint/PropertyPlaceholderTest.java | 121 +++++++++++++++++++++
3 files changed, 164 insertions(+)
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
index b1a760e..026a4ba 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -385,6 +385,16 @@ public abstract class RouteBuilder extends BuilderSupport
implements RoutesBuild
}
/**
+ * Refers to the property placeholder
+ *
+ * @param key the property key
+ * @return the reference to the property using syntax {{key}}
+ */
+ public String property(String key) {
+ return PropertiesComponent.PREFIX_TOKEN + key +
PropertiesComponent.SUFFIX_TOKEN;
+ }
+
+ /**
* Adds a route for an interceptor that intercepts every processing step.
*
* @return the builder
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesPropertyTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesPropertyTest.java
new file mode 100644
index 0000000..753934f
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesPropertyTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.component.properties;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class PropertiesPropertyTest extends PropertiesRouteFromTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from(property("cool.start")).routeId("foo").to(property("cool.end"));
+ }
+ };
+ }
+
+}
diff --git
a/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/PropertyPlaceholderTest.java
b/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/PropertyPlaceholderTest.java
new file mode 100644
index 0000000..888d8fc
--- /dev/null
+++
b/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/PropertyPlaceholderTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.builder.endpoint;
+
+import java.util.Properties;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class PropertyPlaceholderTest extends BaseEndpointDslTest {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ public void testQueryOptionalNotPresent() throws Exception {
+ context.addRoutes(new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from(direct("start")).to(mock("result").retainFirst(property("?maxKeep")).failFast(false));
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(2);
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Bye World");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(2,
getMockEndpoint("mock:result").getReceivedExchanges().size());
+ }
+
+ @Test
+ public void testQueryOptionalPresent() throws Exception {
+ Properties prop = new Properties();
+ prop.put("maxKeep", "1");
+ prop.put("fast", "false");
+ context.getPropertiesComponent().setInitialProperties(prop);
+
+ context.addRoutes(new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from(direct("start")).to(mock("result").retainFirst(property("?maxKeep")).failFast(property("fast")));
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result?retainFirst=1").expectedMessageCount(2);
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Bye World");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(1,
getMockEndpoint("mock:result?retainFirst=1").getReceivedExchanges().size());
+ }
+
+ @Test
+ public void testPathOptionalNotPresent() throws Exception {
+ context.addRoutes(new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from(direct("start")).to(mock("res{{?whereTo}}ult").failFast(false));
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(2);
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Bye World");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(2,
getMockEndpoint("mock:result").getReceivedExchanges().size());
+ }
+
+ @Test
+ public void testPathOptionalPresent() throws Exception {
+ Properties prop = new Properties();
+ prop.put("whereTo", "result");
+ context.getPropertiesComponent().setInitialProperties(prop);
+
+ context.addRoutes(new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
from(direct("start")).to(mock(property("?whereTo")).failFast(false));
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(2);
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Bye World");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(2,
getMockEndpoint("mock:result").getReceivedExchanges().size());
+ }
+
+}