This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch prefixId
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a1d9d5e47925a311a08d401cdbc8c966307812c1
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Dec 7 08:34:45 2022 +0100

    CAMEL-18798/CAMEL-18771: Allow to configure nodePrefixId on 
route/routeTemplate to prefix all node IDs to make it easier to avoid clash 
with hardcoded IDs.
---
 .../SpringRouteNodePrefixIdDuplicateTest.java      | 30 ++++++++++++
 .../processor/SpringRouteNodePrefixIdTest.java     | 30 ++++++++++++
 .../SpringTemplatedRoutePrefixIdTest.java          | 54 ++++++++++++++++++++++
 .../SpringRouteNodePrefixIdDuplicateTest.xml       | 40 ++++++++++++++++
 .../processor/SpringRouteNodePrefixIdTest.xml      | 51 ++++++++++++++++++++
 .../SpringTemplatedRoutePrefixIdTest.xml           | 53 +++++++++++++++++++++
 .../camel/builder/RouteTemplatePrefixIdTest.java   | 19 ++++++--
 7 files changed, 273 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteNodePrefixIdDuplicateTest.java
 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteNodePrefixIdDuplicateTest.java
new file mode 100644
index 00000000000..9194452c2c9
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteNodePrefixIdDuplicateTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.RouteNodePrefixIdDuplicateTest;
+
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringRouteNodePrefixIdDuplicateTest extends 
RouteNodePrefixIdDuplicateTest {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/SpringRouteNodePrefixIdDuplicateTest.xml");
+    }
+}
diff --git 
a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteNodePrefixIdTest.java
 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteNodePrefixIdTest.java
new file mode 100644
index 00000000000..75ee283cfe9
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteNodePrefixIdTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.RouteNodePrefixIdTest;
+
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringRouteNodePrefixIdTest extends RouteNodePrefixIdTest {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/SpringRouteNodePrefixIdTest.xml");
+    }
+}
diff --git 
a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/SpringTemplatedRoutePrefixIdTest.java
 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/SpringTemplatedRoutePrefixIdTest.java
new file mode 100644
index 00000000000..1b0da5abef3
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/routebuilder/SpringTemplatedRoutePrefixIdTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.spring.routebuilder;
+
+import org.apache.camel.Route;
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class SpringTemplatedRoutePrefixIdTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/routebuilder/SpringTemplatedRoutePrefixIdTest.xml");
+    }
+
+    @Test
+    public void testPrefixId() throws Exception {
+        assertEquals(2, context.getRouteDefinitions().size());
+        assertEquals(2, context.getRoutes().size());
+        assertEquals("Started", 
context.getRouteController().getRouteStatus("first").name());
+        assertEquals("Started", 
context.getRouteController().getRouteStatus("second").name());
+        assertEquals("true", 
context.getRoute("first").getProperties().get(Route.TEMPLATE_PROPERTY));
+        assertEquals("true", 
context.getRoute("second").getProperties().get(Route.TEMPLATE_PROPERTY));
+
+        template.sendBody("direct:one", "Hello Cheese");
+        template.sendBody("direct:two", "Hello Cake");
+
+        assertMockEndpointsSatisfied();
+
+        // all nodes should include prefix
+        Assertions.assertEquals(3, 
context.getRoute("first").filter("aaa*").size());
+        Assertions.assertEquals(3, 
context.getRoute("second").filter("bbb*").size());
+    }
+
+}
diff --git 
a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringRouteNodePrefixIdDuplicateTest.xml
 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringRouteNodePrefixIdDuplicateTest.xml
new file mode 100644
index 00000000000..14499ff4aee
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringRouteNodePrefixIdDuplicateTest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring";>
+    <route id="foo" nodePrefixId="aaa">
+      <from uri="direct:foo"/>
+      <to uri="mock:foo" id="myMock"/>
+      <to uri="seda:foo"/>
+    </route>
+    <route id="bar" nodePrefixId="bbb">
+      <from uri="direct:bar"/>
+      <to uri="mock:bar" id="myMock"/>
+      <to uri="seda:bar"/>
+    </route>
+  </camelContext>
+
+</beans>
diff --git 
a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringRouteNodePrefixIdTest.xml
 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringRouteNodePrefixIdTest.xml
new file mode 100644
index 00000000000..48ad6f5deaf
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringRouteNodePrefixIdTest.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring";>
+    <route id="foo" nodePrefixId="aaa">
+      <from uri="direct:foo"/>
+      <to uri="mock:foo" id="myFoo"/>
+      <to uri="seda:foo"/>
+    </route>
+    <route id="bar" nodePrefixId="bbb">
+      <from uri="direct:bar"/>
+      <to uri="mock:bar" id="myBar"/>
+      <to uri="seda:bar"/>
+    </route>
+    <route nodePrefixId="ccc">
+      <from uri="direct:cheese"/>
+      <choice>
+        <when><header>cheese</header>
+          <to uri="mock:cheese" id="myCheese"/>
+        </when>
+        <otherwise>
+          <to uri="mock:gauda"/>
+        </otherwise>
+      </choice>
+    </route>
+  </camelContext>
+
+</beans>
diff --git 
a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/routebuilder/SpringTemplatedRoutePrefixIdTest.xml
 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/routebuilder/SpringTemplatedRoutePrefixIdTest.xml
new file mode 100644
index 00000000000..76c86bd0c49
--- /dev/null
+++ 
b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/routebuilder/SpringTemplatedRoutePrefixIdTest.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+            http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+            http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd";>
+
+    <camelContext id="foo" xmlns="http://camel.apache.org/schema/spring";>
+        <routeTemplate id="myTemplate">
+            <templateParameter name="foo"/>
+            <templateParameter name="bar"/>
+            <route>
+                <from uri="direct:{{foo}}"/>
+                <choice>
+                    <when>
+                        <header>foo</header>
+                        <log message="${body}" id="myLog"/>
+                    </when>
+                    <otherwise>
+                        <to uri="mock:{{bar}}" id="end"/>
+                    </otherwise>
+                </choice>
+            </route>
+        </routeTemplate>
+        <templatedRoute routeTemplateRef="myTemplate" routeId="first" 
prefixId="aaa">
+            <parameter name="foo" value="one"/>
+            <parameter name="bar" value="cheese"/>
+        </templatedRoute>
+        <templatedRoute routeTemplateRef="myTemplate" routeId="second" 
prefixId="bbb">
+            <parameter name="foo" value="two"/>
+            <parameter name="bar" value="cake"/>
+        </templatedRoute>
+    </camelContext>
+
+</beans>
\ No newline at end of file
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplatePrefixIdTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplatePrefixIdTest.java
index eadba72450a..f7fd2012780 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplatePrefixIdTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplatePrefixIdTest.java
@@ -22,6 +22,7 @@ import java.util.Map;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Route;
 import org.apache.camel.model.RouteTemplateDefinition;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -30,10 +31,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class RouteTemplatePrefixIdTest extends ContextTestSupport {
 
-    // TODO: docs
-    // TODO: <xml> tests
-    // TODO: regen
-
     @Test
     public void testDefineRouteTemplate() throws Exception {
         assertEquals(1, context.getRouteTemplateDefinitions().size());
@@ -74,6 +71,10 @@ public class RouteTemplatePrefixIdTest extends 
ContextTestSupport {
         template.sendBody("direct:two", "Hello Cake");
 
         assertMockEndpointsSatisfied();
+
+        // all nodes should include prefix
+        Assertions.assertEquals(3, 
context.getRoute("first").filter("aaa*").size());
+        Assertions.assertEquals(3, 
context.getRoute("second").filter("bbb*").size());
     }
 
     @Test
@@ -112,6 +113,10 @@ public class RouteTemplatePrefixIdTest extends 
ContextTestSupport {
         template.sendBody("direct:two", "Hello Cake");
 
         assertMockEndpointsSatisfied();
+
+        // all nodes should include prefix
+        Assertions.assertEquals(3, 
context.getRoute("first").filter("aaa*").size());
+        Assertions.assertEquals(3, 
context.getRoute("second").filter("bbb*").size());
     }
 
     @Test
@@ -138,6 +143,9 @@ public class RouteTemplatePrefixIdTest extends 
ContextTestSupport {
         template.sendBody("direct:one", "Hello Cheese");
 
         assertMockEndpointsSatisfied();
+
+        // all nodes should include prefix
+        Assertions.assertEquals(3, 
context.getRoute(routeId).filter("aaa*").size());
     }
 
     @Test
@@ -174,6 +182,9 @@ public class RouteTemplatePrefixIdTest extends 
ContextTestSupport {
         template.sendBody("direct:one", "Hello Cheese");
 
         assertMockEndpointsSatisfied();
+
+        // all nodes should include prefix
+        Assertions.assertEquals(3, 
context.getRoute(routeId).filter("aaa*").size());
     }
 
     @Override

Reply via email to