You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/10/31 16:06:16 UTC
(camel) branch main updated (cff7971a048 -> 756de9ade27)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from cff7971a048 Upgrade debezium 3.0.1
new 5308773e385 CAMEL-21402: Added unit test how to test with xpath in mock endpoints
new 756de9ade27 CAMEL-21412: camel-test - Make it easy to use expression outside route builder
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/camel/test/junit5/CamelTestSupport.java | 14 +++++++++
.../camel/test/junit5/CamelTestSupportTest.java | 10 ++++++
.../java/org/apache/camel/ContextTestSupport.java | 14 +++++++++
...pTest.java => MockExpectedHeaderXPathTest.java} | 36 +++++++++++++---------
4 files changed, 59 insertions(+), 15 deletions(-)
copy core/camel-core/src/test/java/org/apache/camel/issues/{MockExpectedHeaderRegexpTest.java => MockExpectedHeaderXPathTest.java} (63%)
(camel) 02/02: CAMEL-21412: camel-test - Make it easy to use expression outside route builder
Posted by da...@apache.org.
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
commit 756de9ade271641ac81730ed74b0e15a4dffebe3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 31 17:04:50 2024 +0100
CAMEL-21412: camel-test - Make it easy to use expression outside route builder
---
.../org/apache/camel/test/junit5/CamelTestSupport.java | 14 ++++++++++++++
.../org/apache/camel/test/junit5/CamelTestSupportTest.java | 10 ++++++++++
2 files changed, 24 insertions(+)
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
index 79ac56eab57..88966d5d193 100644
--- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
@@ -24,6 +24,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.Processor;
import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.LanguageBuilderFactory;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.model.ProcessorDefinition;
@@ -313,6 +314,19 @@ public abstract class CamelTestSupport extends AbstractTestSupport
// noop
}
+ /**
+ * A utility method allowing to build any language using a fluent syntax as shown in the next example:
+ *
+ * <pre>
+ * var exp = expression().tokenize().token("\n").end()
+ * </pre>
+ *
+ * @return an entry point to the builder of all supported languages.
+ */
+ protected LanguageBuilderFactory expression() {
+ return new LanguageBuilderFactory();
+ }
+
/**
* Override to use a custom {@link Registry}.
* <p>
diff --git a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
index d1e935306b8..34dd529ce42 100644
--- a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
+++ b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
@@ -56,6 +56,16 @@ public class CamelTestSupportTest extends CamelTestSupport {
assertNotNull(mock);
}
+ @Test
+ public void testExpression() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.message(0).body().matches(expression().simple().expression("${body} contains ' foo '").trim(false).end());
+
+ template.sendBody("direct:start", " foo ");
+
+ mock.assertIsSatisfied();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
(camel) 01/02: CAMEL-21402: Added unit test how to test with xpath in mock endpoints
Posted by da...@apache.org.
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
commit 5308773e385397159c19175cfe591da56d3a434c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 31 16:58:05 2024 +0100
CAMEL-21402: Added unit test how to test with xpath in mock endpoints
---
.../java/org/apache/camel/ContextTestSupport.java | 14 +++++
.../camel/issues/MockExpectedHeaderXPathTest.java | 61 ++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/core/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java b/core/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
index c4972b3a267..cff391bb199 100644
--- a/core/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
+++ b/core/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
@@ -29,6 +29,7 @@ import javax.naming.Context;
import org.apache.camel.builder.AdviceWith;
import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.LanguageBuilderFactory;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.InterceptSendToMockEndpointStrategy;
@@ -288,6 +289,19 @@ public abstract class ContextTestSupport extends TestSupport
return consumer;
}
+ /**
+ * A utility method allowing to build any language using a fluent syntax as shown in the next example:
+ *
+ * <pre>
+ * var exp = expression().tokenize().token("\n").end()
+ * </pre>
+ *
+ * @return an entry point to the builder of all supported languages.
+ */
+ public LanguageBuilderFactory expression() {
+ return new LanguageBuilderFactory();
+ }
+
/**
* Allows a service to be registered a separate lifecycle service to start and stop the context; such as for Spring
* when the ApplicationContext is started and stopped, rather than directly stopping the CamelContext
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/MockExpectedHeaderXPathTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/MockExpectedHeaderXPathTest.java
new file mode 100644
index 00000000000..0d71d912634
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/MockExpectedHeaderXPathTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.support.builder.PredicateBuilder.not;
+
+public class MockExpectedHeaderXPathTest extends ContextTestSupport {
+
+ protected String matchingBody = "<person name='James' city='London'/>";
+ protected String notMatchingBody = "<person name='Hiram' city='Tampa'/>";
+ protected String notMatchingBody2 = "<person name='Jack' city='Houston'/>";
+
+ @Test
+ public void testHeaderXPath() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(3);
+
+ // xpath that takes input from a header
+ var xpath = expression().xpath().expression("/person[@name='James']").source("header:cheese").end();
+
+ // validate that some of the headers match and others do not
+ mock.message(0).predicate(not(xpath));
+ mock.message(1).predicate(xpath);
+ mock.message(2).predicate(not(xpath));
+
+ template.sendBodyAndHeader("direct:test", "message 1", "cheese", notMatchingBody);
+ template.sendBodyAndHeader("direct:test", "message 2", "cheese", matchingBody);
+ template.sendBodyAndHeader("direct:test", "message 3", "cheese", notMatchingBody2);
+
+ mock.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:test").to("mock:result");
+ }
+ };
+ }
+}