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 5ca5e08a26b CAMEL-21135: camel-core - AdviceWith using toUri pattern 
should also … (#15353)
5ca5e08a26b is described below

commit 5ca5e08a26b0d5d100843f1e2e9297bf07b6fbed
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Aug 28 14:44:12 2024 +0200

    CAMEL-21135: camel-core - AdviceWith using toUri pattern should also … 
(#15353)
    
    * CAMEL-21135: camel-core - AdviceWith using toUri pattern should also 
support poll/enrich/pollEnrich EIPs
    
    * CAMEL-21135: camel-core - AdviceWith using toUri pattern should also 
support poll/enrich/pollEnrich EIPs
---
 .../org/apache/camel/builder/AdviceWithTasks.java  | 14 ++++
 .../org/apache/camel/model/PollDefinition.java     |  2 +-
 .../issues/AdviceWithWeaveByToUriEnrichTest.java   | 81 ++++++++++++++++++++++
 .../AdviceWithWeaveByToUriPollEnrichTest.java      | 77 ++++++++++++++++++++
 .../issues/AdviceWithWeaveByToUriPollTest.java     | 77 ++++++++++++++++++++
 5 files changed, 250 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
index 43b76424323..240f35984ce 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
@@ -25,12 +25,14 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.model.AdviceWithDefinition;
 import org.apache.camel.model.ChoiceDefinition;
 import org.apache.camel.model.EndpointRequiredDefinition;
+import org.apache.camel.model.EnrichDefinition;
 import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.InterceptDefinition;
 import org.apache.camel.model.InterceptSendToEndpointDefinition;
 import org.apache.camel.model.OnCompletionDefinition;
 import org.apache.camel.model.OnExceptionDefinition;
 import org.apache.camel.model.PipelineDefinition;
+import org.apache.camel.model.PollEnrichDefinition;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.ProcessorDefinitionHelper;
 import org.apache.camel.model.RouteDefinition;
@@ -133,6 +135,18 @@ public final class AdviceWithTasks {
             } else if (processor instanceof ToDynamicDefinition 
toDynamicDefinition) {
                 String uri = toDynamicDefinition.getUri();
                 return PatternHelper.matchPattern(uri, toUri);
+            } else if (processor instanceof EnrichDefinition enrichDefinition) 
{
+                var exp = enrichDefinition.getExpression();
+                if (exp != null) {
+                    String uri = exp.getExpression();
+                    return PatternHelper.matchPattern(uri, toUri);
+                }
+            } else if (processor instanceof PollEnrichDefinition 
pollEnrichDefinition) {
+                var exp = pollEnrichDefinition.getExpression();
+                if (exp != null) {
+                    String uri = exp.getExpression();
+                    return PatternHelper.matchPattern(uri, toUri);
+                }
             }
             return false;
         }
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/PollDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/PollDefinition.java
index e4b03c43876..7aba6bc2543 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/PollDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/PollDefinition.java
@@ -34,7 +34,7 @@ import org.apache.camel.util.URISupport;
 @Metadata(label = "eip,routing")
 @XmlRootElement(name = "poll")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class PollDefinition extends NoOutputDefinition<PollDefinition> {
+public class PollDefinition extends NoOutputDefinition<PollDefinition> 
implements EndpointRequiredDefinition {
 
     @XmlTransient
     private String endpointUriToString;
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriEnrichTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriEnrichTest.java
new file mode 100644
index 00000000000..f5200869a13
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriEnrichTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.junit.jupiter.api.Test;
+
+public class AdviceWithWeaveByToUriEnrichTest extends ContextTestSupport {
+
+    @Test
+    public void testAdviceEnrichToString() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        AdviceWith.adviceWith(route, context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByToString("enrich*").replace().to("mock:foo");
+                mockEndpointsAndSkip("direct:foo*");
+            }
+        });
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testAdviceEnrichToUri() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        AdviceWith.adviceWith(route, context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByToUri("direct:bar").replace().to("mock:foo");
+                mockEndpointsAndSkip("direct:foo*");
+            }
+        });
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:bar").expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start")
+                        .enrich("direct:bar").to("mock:result");
+
+                from("direct:bar").to("mock:bar").setBody().constant("Hello 
Bar");
+            }
+        };
+    }
+
+}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriPollEnrichTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriPollEnrichTest.java
new file mode 100644
index 00000000000..03f927d4612
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriPollEnrichTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.junit.jupiter.api.Test;
+
+public class AdviceWithWeaveByToUriPollEnrichTest extends ContextTestSupport {
+
+    @Test
+    public void testAdvicePollEnrichToString() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        AdviceWith.adviceWith(route, context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByToString("pollEnrich*").replace().to("mock:foo");
+                mockEndpointsAndSkip("direct:foo*");
+            }
+        });
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testAdvicePollEnrichToUri() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        AdviceWith.adviceWith(route, context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByToUri("seda:bar").replace().to("mock:foo");
+                mockEndpointsAndSkip("direct:foo*");
+            }
+        });
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start")
+                        .pollEnrich("seda:bar", 1000).to("mock:result");
+            }
+        };
+    }
+
+}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriPollTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriPollTest.java
new file mode 100644
index 00000000000..6b3e1d8cbc7
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithWeaveByToUriPollTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.junit.jupiter.api.Test;
+
+public class AdviceWithWeaveByToUriPollTest extends ContextTestSupport {
+
+    @Test
+    public void testAdvicePollToString() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        AdviceWith.adviceWith(route, context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByToString("poll*").replace().to("mock:foo");
+                mockEndpointsAndSkip("direct:foo*");
+            }
+        });
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testAdvicePollToUri() throws Exception {
+        RouteDefinition route = context.getRouteDefinitions().get(0);
+        AdviceWith.adviceWith(route, context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                weaveByToUri("seda:bar").replace().to("mock:foo");
+                mockEndpointsAndSkip("direct:foo*");
+            }
+        });
+
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start")
+                        .poll("seda:bar").to("mock:result");
+            }
+        };
+    }
+
+}

Reply via email to