You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ff...@apache.org on 2022/03/02 22:08:52 UTC
[camel-spring-boot] branch main updated: [CAMEL-17729]add tests in camel-jsonpath-starter (#448)
This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new bdefada [CAMEL-17729]add tests in camel-jsonpath-starter (#448)
bdefada is described below
commit bdefada4c9ded807baaf4a5963cecda8d0cd2521
Author: Freeman(Yue) Fang <fr...@gmail.com>
AuthorDate: Wed Mar 2 17:08:39 2022 -0500
[CAMEL-17729]add tests in camel-jsonpath-starter (#448)
---
components-starter/camel-jsonpath-starter/pom.xml | 11 ++
.../test/EasyJsonPathWithRootSimpleCBRTest.java | 138 +++++++++++++++
.../test/EasyJsonPathWithSimpleCBRTest.java | 139 +++++++++++++++
.../test/JsonPathBeanStreamCachingTest.java | 100 +++++++++++
.../test/JsonPathBeanSuppressExceptionsTest.java | 103 +++++++++++
.../jsonpath/springboot/test/JsonPathBeanTest.java | 118 +++++++++++++
.../jsonpath/springboot/test/JsonPathCBRTest.java | 178 +++++++++++++++++++
.../springboot/test/JsonPathCharsetTest.java | 174 +++++++++++++++++++
.../test/JsonPathExchangePropertyTest.java | 90 ++++++++++
.../springboot/test/JsonPathHeaderNameTest.java | 86 +++++++++
.../springboot/test/JsonPathLanguageTest.java | 170 ++++++++++++++++++
.../springboot/test/JsonPathMapTransformTest.java | 104 +++++++++++
.../springboot/test/JsonPathMockMatchesTest.java | 110 ++++++++++++
.../springboot/test/JsonPathPlatformHttpTest.java | 137 +++++++++++++++
.../springboot/test/JsonPathPojoTransformTest.java | 89 ++++++++++
.../springboot/test/JsonPathSourceTest.java | 157 +++++++++++++++++
.../springboot/test/JsonPathSplitTest.java | 157 +++++++++++++++++
.../test/JsonPathSplitWriteAsStringMapTest.java | 96 ++++++++++
.../test/JsonPathSplitWriteAsStringTest.java | 92 ++++++++++
.../test/JsonPathStreamCachingCBRTest.java | 193 +++++++++++++++++++++
.../springboot/test/JsonPathSuppressTest.java | 109 ++++++++++++
.../test/JsonPathTransformHeaderNameTest.java | 91 ++++++++++
.../test/JsonPathTransformONielEscapedTest.java | 89 ++++++++++
.../JsonPathTransformONielPlaceholderTest.java | 120 +++++++++++++
.../test/JsonPathTransformONielTest.java | 89 ++++++++++
.../test/JsonPathTransformResultTypeTest.java | 95 ++++++++++
.../springboot/test/JsonPathTransformTest.java | 90 ++++++++++
.../springboot/test/JsonPathWithSimpleCBRTest.java | 142 +++++++++++++++
.../jsonpath/springboot/test/MyPojoType.java | 39 +++++
.../springboot/test/SpringJsonPathCBRTest.java | 104 +++++++++++
.../test/SpringJsonPathSplitWriteAsStringTest.java | 71 ++++++++
.../test/SpringJsonPathSuppressTest.java | 88 ++++++++++
.../SpringJsonPathTransformHeaderNameTest.java | 73 ++++++++
.../SpringJsonPathTransformResultTypeTest.java | 76 ++++++++
.../test/SpringJsonPathTransformTest.java | 73 ++++++++
.../src/test/resources/average.json | 17 ++
.../src/test/resources/books.json | 30 ++++
.../src/test/resources/booksUTF16BE.json | Bin 0 -> 1106 bytes
.../src/test/resources/booksUTF16LE.json | Bin 0 -> 1106 bytes
.../src/test/resources/cheap.json | 16 ++
.../src/test/resources/content-map.json | 14 ++
.../src/test/resources/content.json | 14 ++
.../src/test/resources/expensive.json | 17 ++
.../src/test/resources/germanbooks-iso-8859-1.json | 23 +++
.../src/test/resources/germanbooks-utf8.json | 23 +++
.../resources/routes/SpringJsonPathCBTTest.xml | 39 +++++
.../SpringJsonPathSplitWriteAsStringTest.xml | 31 ++++
.../routes/SpringJsonPathSuppressTest.xml | 35 ++++
.../SpringJsonPathTransformHeaderNameTest.xml | 30 ++++
.../SpringJsonPathTransformResultTypeTest.xml | 36 ++++
.../routes/SpringJsonPathTransformTest.xml | 30 ++++
.../src/test/resources/type.json | 4 +
52 files changed, 4150 insertions(+)
diff --git a/components-starter/camel-jsonpath-starter/pom.xml b/components-starter/camel-jsonpath-starter/pom.xml
index 59d325c..9a09920 100644
--- a/components-starter/camel-jsonpath-starter/pom.xml
+++ b/components-starter/camel-jsonpath-starter/pom.xml
@@ -39,6 +39,17 @@
<artifactId>camel-jsonpath</artifactId>
<version>${camel-version}</version>
</dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <version>${rest-assured-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-platform-http-vertx</artifactId>
+ <scope>test</scope>
+ </dependency>
<!--START OF GENERATED CODE-->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/EasyJsonPathWithRootSimpleCBRTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/EasyJsonPathWithRootSimpleCBRTest.java
new file mode 100644
index 0000000..fb8d62c
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/EasyJsonPathWithRootSimpleCBRTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ EasyJsonPathWithRootSimpleCBRTest.class,
+ EasyJsonPathWithRootSimpleCBRTest.TestConfiguration.class
+ }
+)
+public class EasyJsonPathWithRootSimpleCBRTest {
+
+ @Autowired
+ CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:cheap")
+ MockEndpoint mockCheap;
+
+ @EndpointInject("mock:average")
+ MockEndpoint mockAverage;
+
+ @EndpointInject("mock:expensive")
+ MockEndpoint mockExpensive;
+
+ FluentProducerTemplate fluentTemplate;
+
+ @Test
+ public void testCheap() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/cheap.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testAverage() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(1);
+ mockExpensive.expectedMessageCount(0);
+
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/average.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testExpensive() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(1);
+
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/expensive.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when().jsonpath("price < ${header.cheap}")
+ .to("mock:cheap")
+ .when().jsonpath("price < ${header.average}")
+ .to("mock:average")
+ .otherwise()
+ .to("mock:expensive");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/EasyJsonPathWithSimpleCBRTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/EasyJsonPathWithSimpleCBRTest.java
new file mode 100644
index 0000000..6a5dce7
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/EasyJsonPathWithSimpleCBRTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ EasyJsonPathWithSimpleCBRTest.class,
+ EasyJsonPathWithSimpleCBRTest.TestConfiguration.class
+ }
+)
+public class EasyJsonPathWithSimpleCBRTest {
+
+ @Autowired
+ CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:cheap")
+ MockEndpoint mockCheap;
+
+ @EndpointInject("mock:average")
+ MockEndpoint mockAverage;
+
+ @EndpointInject("mock:expensive")
+ MockEndpoint mockExpensive;
+
+ FluentProducerTemplate fluentTemplate;
+
+ @Test
+ public void testCheap() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/cheap.json"))
+ .to("direct:start").send();
+
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testAverage() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(1);
+ mockExpensive.expectedMessageCount(0);
+
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/average.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testExpensive() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(1);
+
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/expensive.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when().jsonpath("store.book.price < ${header.cheap}")
+ .to("mock:cheap")
+ .when().jsonpath("store.book.price < ${header.average}")
+ .to("mock:average")
+ .otherwise()
+ .to("mock:expensive");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanStreamCachingTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanStreamCachingTest.java
new file mode 100644
index 0000000..fa9d9dd
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanStreamCachingTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.ByteArrayInputStream;
+
+import com.jayway.jsonpath.Option;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.jsonpath.JsonPath;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathBeanStreamCachingTest.class,
+ JsonPathBeanStreamCachingTest.TestConfiguration.class
+ }
+)
+public class JsonPathBeanStreamCachingTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ MockEndpoint mock;
+
+ @Test
+ public void testFullName() throws Exception {
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"middlename\" : \"foo2\", \"lastname\" : \"bar\"}}";
+ mock.expectedBodiesReceived("foo foo2 bar");
+
+ template.sendBody("direct:start", new ByteArrayInputStream(json.getBytes()));
+
+ mock.assertIsSatisfied();
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").streamCaching()
+ .bean(FullNameBean.class).to("mock:result");
+ }
+ };
+ }
+ }
+
+ protected static class FullNameBean {
+ // middle name is optional
+ public static String getName(
+ @JsonPath("person.firstname") String first,
+ @JsonPath(value = "person.middlename", options = Option.SUPPRESS_EXCEPTIONS) String middle,
+ @JsonPath("person.lastname") String last) {
+ if (middle != null) {
+ return first + " " + middle + " " + last;
+ }
+ return first + " " + last;
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanSuppressExceptionsTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanSuppressExceptionsTest.java
new file mode 100644
index 0000000..d451385
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanSuppressExceptionsTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.jsonpath.JsonPath;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathBeanSuppressExceptionsTest.class,
+ JsonPathBeanSuppressExceptionsTest.TestConfiguration.class
+ }
+)
+public class JsonPathBeanSuppressExceptionsTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ MockEndpoint mock;
+
+ @Test
+ public void testFullName() throws Exception {
+ mock.reset();
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"middlename\" : \"foo2\", \"lastname\" : \"bar\"}}";
+ mock.expectedBodiesReceived("foo foo2 bar");
+ template.sendBody("direct:start", json);
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testFirstAndLastName() throws Exception {
+ mock.reset();
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"lastname\" : \"bar\"}}";
+ mock.expectedBodiesReceived("foo bar");
+ template.sendBody("direct:start", json);
+ mock.assertIsSatisfied();
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").bean(FullNameBean.class).to("mock:result");
+ }
+ };
+ }
+ }
+
+ protected static class FullNameBean {
+ // middle name is optional
+ public static String getName(
+ @JsonPath("person.firstname") String first,
+ @JsonPath(value = "person.middlename", suppressExceptions = true) String middle,
+ @JsonPath("person.lastname") String last) {
+ if (middle != null) {
+ return first + " " + middle + " " + last;
+ }
+ return first + " " + last;
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanTest.java
new file mode 100644
index 0000000..71f1e95
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathBeanTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+
+import com.jayway.jsonpath.Option;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.jsonpath.JsonPath;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathBeanTest.class,
+ JsonPathBeanTest.TestConfiguration.class
+ }
+)
+public class JsonPathBeanTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ MockEndpoint mock;
+
+ @Test
+ public void testFullName() throws Exception {
+ mock.reset();
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"middlename\" : \"foo2\", \"lastname\" : \"bar\"}}";
+ mock.expectedBodiesReceived("foo foo2 bar");
+ template.sendBody("direct:start", json);
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testFullNameTwo() throws Exception {
+ mock.reset();
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"middlename\" : \"foo2\", \"lastname\" : \"bar\"}}";
+ String json2 = "{\"person\" : {\"firstname\" : \"bar\", \"middlename\" : \"bar2\", \"lastname\" : \"foo\"}}";
+ mock.expectedBodiesReceived("foo foo2 bar", "bar bar2 foo");
+ template.sendBody("direct:start", json);
+ template.sendBody("direct:start", json2);
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testFirstAndLastName() throws Exception {
+ mock.reset();
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"lastname\" : \"bar\"}}";
+ mock.expectedBodiesReceived("foo bar");
+ template.sendBody("direct:start", json);
+ mock.assertIsSatisfied();
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").bean(FullNameBean.class).to("mock:result");
+ }
+ };
+ }
+ }
+
+ protected static class FullNameBean {
+ // middle name is optional
+ public static String getName(
+ @JsonPath("person.firstname") String first,
+ @JsonPath(value = "person.middlename", options = Option.SUPPRESS_EXCEPTIONS) String middle,
+ @JsonPath("person.lastname") String last) {
+ if (middle != null) {
+ return first + " " + middle + " " + last;
+ }
+ return first + " " + last;
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathCBRTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathCBRTest.java
new file mode 100644
index 0000000..e9a7ac6
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathCBRTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.PredicateBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.jsonpath.JsonPath;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathCBRTest.class,
+ JsonPathCBRTest.TestConfiguration.class
+ }
+)
+public class JsonPathCBRTest {
+
+ @Autowired
+ CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:cheap")
+ MockEndpoint mockCheap;
+
+ @EndpointInject("mock:average")
+ MockEndpoint mockAverage;
+
+ @EndpointInject("mock:expensive")
+ MockEndpoint mockExpensive;
+
+
+
+ public static class BeanPredicate {
+ public boolean checkPrice(@JsonPath("$.store.bicycle.price") double price) {
+ return price < 100;
+ }
+ }
+
+ @Test
+ public void testCheapBicycle() throws Exception {
+ sendMessageToBicycleRoute("direct:bicycle");
+ MockEndpoint.resetMocks(context);
+ sendMessageToBicycleRoute("direct:bicycle2");
+ }
+
+ private void sendMessageToBicycleRoute(String startPoint) throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+
+ template.sendBody(startPoint, new FileInputStream(new File("src/test/resources/cheap.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testCheap() throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/cheap.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testAverage() throws Exception {
+
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(1);
+ mockExpensive.expectedMessageCount(0);
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/average.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testExpensive() throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(1);
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/expensive.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .streamCaching()
+ .choice()
+ .when().jsonpath("$.store.book[?(@.price < 10)]")
+ .to("mock:cheap")
+ .when().jsonpath("$.store.book[?(@.price < 30)]")
+ .to("mock:average")
+ .otherwise()
+ .to("mock:expensive");
+
+ from("direct:bicycle")
+ .streamCaching()
+ .choice()
+ .when().method(new BeanPredicate())
+ .to("mock:cheap")
+ .otherwise()
+ .to("mock:expensive");
+
+ from("direct:bicycle2")
+ .streamCaching()
+ .choice()
+ .when(PredicateBuilder.isLessThan(
+ ExpressionBuilder.languageExpression("jsonpath", "$.store.bicycle.price"),
+ ExpressionBuilder.constantExpression(100)))
+ .to("mock:cheap")
+ .otherwise()
+ .to("mock:expensive");
+ }
+ };
+ }
+ }
+
+
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathCharsetTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathCharsetTest.java
new file mode 100644
index 0000000..d8589f9
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathCharsetTest.java
@@ -0,0 +1,174 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.jsonpath.JsonPathConstants;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathCharsetTest.class,
+ JsonPathCharsetTest.TestConfiguration.class
+ }
+)
+public class JsonPathCharsetTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @Test
+ public void testUTF16BEFile() throws Exception {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ sendBody("direct:start", new File("src/test/resources/booksUTF16BE.json"));
+
+ mock.assertIsSatisfied();
+
+ check();
+ }
+
+ @Test
+ public void testUTF16LEFile() throws Exception {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ sendBody("direct:start", new File("src/test/resources/booksUTF16LE.json"));
+
+ mock.assertIsSatisfied();
+
+ check();
+ }
+
+ @Test
+ public void testUTF16BEInputStream() throws Exception {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ InputStream input = JsonPathCharsetTest.class.getClassLoader().getResourceAsStream("booksUTF16BE.json");
+ assertNotNull(input);
+ sendBody("direct:start", input);
+
+ mock.assertIsSatisfied();
+
+ check();
+ }
+
+ @Test
+ public void testUTF16BEURL() throws Exception {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ URL url = new URL("file:src/test/resources/booksUTF16BE.json");
+ assertNotNull(url);
+ sendBody("direct:start", url);
+
+ check();
+ }
+
+ @Test
+ public void testISO8859WithJsonHeaderCamelJsonInputEncoding() throws Exception {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ URL url = new URL("file:src/test/resources/germanbooks-iso-8859-1.json");
+ assertNotNull(url);
+ sendBody("direct:start", url,
+ Collections.<String, Object> singletonMap(JsonPathConstants.HEADER_JSON_ENCODING, "ISO-8859-1"));
+
+ check("Joseph und seine Brüder", "Götzendämmerung");
+ }
+
+ private void check() throws InterruptedException {
+ check("Sayings of the Century", "Sword of Honour");
+ }
+
+ private void check(String title1, String title2) throws InterruptedException {
+ mock.assertIsSatisfied();
+
+ List<?> authors = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+
+ assertEquals(title1, authors.get(0));
+ assertEquals(title2, authors.get(1));
+ }
+
+ private void sendBody(String endpointUri, final Object body) {
+ template.send(endpointUri, exchange -> {
+ Message in = exchange.getIn();
+ in.setBody(body);
+ });
+ }
+
+ private void sendBody(String endpointUri, final Object body, final Map<String, Object> headers) {
+ template.send(endpointUri, exchange -> {
+ Message in = exchange.getIn();
+ in.setBody(body);
+ for (Map.Entry<String, Object> entry : headers.entrySet()) {
+ in.setHeader(entry.getKey(), entry.getValue());
+ }
+ });
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").transform().jsonpath("$.store.book[*].title").to("mock:authors");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathExchangePropertyTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathExchangePropertyTest.java
new file mode 100644
index 0000000..da33399
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathExchangePropertyTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathExchangePropertyTest.class,
+ JsonPathExchangePropertyTest.TestConfiguration.class
+ }
+)
+public class JsonPathExchangePropertyTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:color")
+ MockEndpoint mock;
+
+ @Test
+ public void testExchangeProperty() throws Exception {
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ Object foo = mock.getReceivedExchanges().get(0).getProperty("foo");
+ Assertions.assertTrue(foo instanceof String);
+ Assertions.assertEquals("red", foo);
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .setProperty("foo").jsonpath("$.store.bicycle.color", String.class)
+ .log("${exchangeProperty.foo}")
+ .to("mock:color");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathHeaderNameTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathHeaderNameTest.java
new file mode 100644
index 0000000..22aecff
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathHeaderNameTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathHeaderNameTest.class,
+ JsonPathHeaderNameTest.TestConfiguration.class
+ }
+)
+public class JsonPathHeaderNameTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ MockEndpoint mock;
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedBodiesReceived("Hello World");
+ mock.expectedHeaderReceived("number", "3");
+
+ Object file = new File("src/test/resources/books.json");
+ template.sendBodyAndHeader("direct:start", "Hello World", "myHeader", file);
+
+ mock.assertIsSatisfied();
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .setHeader("number").jsonpath("$..store.book.length()", false, int.class, "myHeader")
+ .to("mock:result");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathLanguageTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathLanguageTest.java
new file mode 100644
index 0000000..fe25c04
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathLanguageTest.java
@@ -0,0 +1,170 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.jayway.jsonpath.Option;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.jsonpath.JsonPathLanguage;
+import org.apache.camel.spi.Language;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.support.DefaultExchange;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathLanguageTest.class
+ }
+)
+public class JsonPathLanguageTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(JsonPathLanguageTest.class);
+
+ @Autowired
+ CamelContext context;
+
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @Test
+ public void testExpressionArray() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getIn().setBody(new File("src/test/resources/books.json"));
+
+ Language lan = context.resolveLanguage("jsonpath");
+ Expression exp = lan.createExpression("$.store.book[*].author");
+ List<?> authors = exp.evaluate(exchange, List.class);
+ LOG.debug("Authors {}", authors);
+
+ assertNotNull(authors);
+ assertEquals(3, authors.size());
+ assertEquals("Nigel Rees", authors.get(0));
+ assertEquals("Evelyn Waugh", authors.get(1));
+ assertEquals("John O'Niel", authors.get(2));
+
+ exp = lan.createExpression("$.store.bicycle.price");
+ String price = exp.evaluate(exchange, String.class);
+ assertEquals("19.95", price, "Got a wrong result");
+ }
+
+ @Test
+ public void testExpressionField() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getIn().setBody(new File("src/test/resources/type.json"));
+
+ Language lan = context.resolveLanguage("jsonpath");
+ Expression exp = lan.createExpression("$.kind");
+ String kind = exp.evaluate(exchange, String.class);
+
+ assertNotNull(kind);
+ assertEquals("full", kind);
+
+ exp = lan.createExpression("$.type");
+ String type = exp.evaluate(exchange, String.class);
+ assertNotNull(type);
+ assertEquals("customer", type);
+ }
+
+ @Test
+ public void testExpressionPojo() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ Map<String, String> pojo = new HashMap<String, String>();
+ pojo.put("kind", "full");
+ pojo.put("type", "customer");
+ exchange.getIn().setBody(pojo);
+
+ Language lan = context.resolveLanguage("jsonpath");
+ Expression exp = lan.createExpression("$.kind");
+ String kind = exp.evaluate(exchange, String.class);
+
+ assertNotNull(kind);
+ assertEquals("full", kind);
+
+ exp = lan.createExpression("$.type");
+ String type = exp.evaluate(exchange, String.class);
+ assertNotNull(type);
+ assertEquals("customer", type);
+ }
+
+ @Test
+ public void testPredicate() throws Exception {
+ // Test books.json file
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getIn().setBody(new File("src/test/resources/books.json"));
+
+ Language lan = context.resolveLanguage("jsonpath");
+ Predicate pre = lan.createPredicate("$.store.book[?(@.price < 10)]");
+ boolean cheap = pre.matches(exchange);
+ assertTrue(cheap, "Should have cheap books");
+
+ pre = lan.createPredicate("$.store.book[?(@.price > 30)]");
+ boolean expensive = pre.matches(exchange);
+ assertFalse(expensive, "Should not have expensive books");
+ }
+
+ @Test
+ public void testSuppressException() throws Exception {
+ Exchange exchange = new DefaultExchange(context);
+ exchange.getIn().setBody(new File("src/test/resources/type.json"));
+
+ JsonPathLanguage lan = (JsonPathLanguage) context.resolveLanguage("jsonpath");
+ lan.setOptions(Option.SUPPRESS_EXCEPTIONS);
+
+ Expression exp = lan.createExpression("$.foo");
+ String nofoo = exp.evaluate(exchange, String.class);
+
+ assertNull(nofoo);
+ }
+
+
+
+
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathMapTransformTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathMapTransformTest.java
new file mode 100644
index 0000000..87199ed
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathMapTransformTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
+
+import java.io.FileInputStream;
+import java.util.List;
+import java.util.Map;
+
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
+import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathMapTransformTest.class,
+ JsonPathMapTransformTest.TestConfiguration.class
+ }
+)
+public class JsonPathMapTransformTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedMessageCount(1);
+
+ // should be a map
+ Configuration.ConfigurationBuilder builder = Configuration.builder();
+ builder.jsonProvider(new JacksonJsonProvider());
+ builder.mappingProvider(new JacksonMappingProvider());
+ Object document = builder.build().jsonProvider()
+ .parse(new FileInputStream("src/test/resources/books.json"), "utf-8");
+ assertIsInstanceOf(Map.class, document);
+
+ template.sendBody("direct:start", document);
+
+ mock.assertIsSatisfied();
+
+ List<?> authors = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals("Nigel Rees", authors.get(0));
+ assertEquals("Evelyn Waugh", authors.get(1));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @org.springframework.context.annotation.Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[*].author")
+ .to("mock:authors");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathMockMatchesTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathMockMatchesTest.java
new file mode 100644
index 0000000..fe5f56b
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathMockMatchesTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathMockMatchesTest.class,
+ JsonPathMockMatchesTest.TestConfiguration.class
+ }
+)
+public class JsonPathMockMatchesTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ MockEndpoint mock;
+
+ @Test
+ public void testMockMatches() throws Exception {
+ mock.reset();
+ mock.expectedMessageCount(3);
+ // cheap
+ mock.message(0).predicate().jsonpath("$.store.book[?(@.price < 10)]");
+ // average
+ mock.message(2).predicate().jsonpath("$.store.book[?(@.price < 30)]");
+ // expensive
+ mock.message(1).predicate().jsonpath("$.store.book[?(@.price > 30)]");
+
+ template.sendBody("direct:start", new File("src/test/resources/cheap.json"));
+ template.sendBody("direct:start", new File("src/test/resources/expensive.json"));
+ template.sendBody("direct:start", new File("src/test/resources/average.json"));
+
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testMockNotMatches() throws Exception {
+ mock.reset();
+ mock.expectedMessageCount(3);
+ // cheap
+ mock.message(0).predicate().jsonpath("$.store.book[?(@.price < 10)]");
+ // average
+ mock.message(1).predicate().jsonpath("$.store.book[?(@.price < 30)]");
+ // expensive
+ mock.message(2).predicate().jsonpath("$.store.book[?(@.price > 30)]");
+
+ template.sendBody("direct:start", new File("src/test/resources/cheap.json"));
+ template.sendBody("direct:start", new File("src/test/resources/expensive.json"));
+ template.sendBody("direct:start", new File("src/test/resources/average.json"));
+
+ mock.assertIsNotSatisfied();
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("mock:result");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathPlatformHttpTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathPlatformHttpTest.java
new file mode 100644
index 0000000..4612bf8
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathPlatformHttpTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServer;
+import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServerConfiguration;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.CamelContextConfiguration;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathPlatformHttpTest.class,
+ JsonPathPlatformHttpTest.TestConfiguration.class
+ }
+)
+public class JsonPathPlatformHttpTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+
+
+ public static final String BODY = "{\"room\":{\"temperature\":30}}";
+ public static final String JSON_PATH = "$.room[?(@.temperature > 20)]";
+ public static final String RESULT = "HOT";
+
+ private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+ @Bean
+ CamelContextConfiguration contextConfiguration() {
+ return new CamelContextConfiguration() {
+ @Override
+ public void beforeApplicationStart(CamelContext context) {
+ VertxPlatformHttpServerConfiguration conf = new VertxPlatformHttpServerConfiguration();
+ conf.setBindPort(PORT);
+
+ try {
+ context.addService(new VertxPlatformHttpServer(conf));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void afterApplicationStart(CamelContext camelContext) {
+ //do nothing here
+ }
+ };
+ }
+
+ @Test
+ public void testWithPlatformHttp() {
+ String result = RestAssured.given()
+ .port(PORT)
+ .contentType(ContentType.JSON)
+ .body(BODY)
+ .post("/getTemperature")
+ .then()
+ .statusCode(200)
+ .extract().asString();
+
+ assertEquals(RESULT, result);
+ }
+
+ @Test
+ public void testWithoutPlatformHttp() {
+ String result = template.requestBody("direct:getTemperature", BODY, String.class);
+
+ assertEquals(RESULT, result);
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
+ addRoute("platform-http:/getTemperature");
+
+ addRoute("direct:getTemperature");
+ }
+
+ private ProcessorDefinition<?> addRoute(String from) {
+ return from(from).choice().when().jsonpath(JSON_PATH).setBody(simple("HOT"))
+ .otherwise().setBody(constant("WARM")).end();
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathPojoTransformTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathPojoTransformTest.java
new file mode 100644
index 0000000..8b2d9a7
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathPojoTransformTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathPojoTransformTest.class,
+ JsonPathPojoTransformTest.TestConfiguration.class
+ }
+)
+public class JsonPathPojoTransformTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:type")
+ MockEndpoint mock;
+
+ @Test
+ public void testPojo() throws Exception {
+ mock.expectedBodiesReceived("customer");
+
+ // this will be read using jackson if its on the classpath
+ MyPojoType pojo = new MyPojoType();
+ pojo.setKind("full");
+ pojo.setType("customer");
+
+ template.sendBody("direct:start", pojo);
+
+ mock.assertIsSatisfied();
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.type")
+ .to("mock:type");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSourceTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSourceTest.java
new file mode 100644
index 0000000..8d9a4b9
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSourceTest.java
@@ -0,0 +1,157 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.nio.charset.Charset;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.FileConsumer;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathSourceTest.class,
+ JsonPathSourceTest.TestConfiguration.class
+ }
+)
+public class JsonPathSourceTest {
+
+ private static final String MESSAGE1 = "Joseph und seine Br\u00fcder";
+ private static final String MESSAGE2 = "G\u00f6tzend\u00e4mmerung";
+ private static final Charset DEFAULT_CHARSET = Charset.defaultCharset();
+
+ @AfterAll
+ public static void setDefaultCharsetBack() {
+ switchToDefaultCharset(DEFAULT_CHARSET.displayName());
+ }
+
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:title")
+ MockEndpoint mock;
+
+ @Test
+ public void testPriceResultTypeOnGenericFileUTF8() throws Exception {
+ switchToDefaultCharset("UTF-8");
+ mock.reset();
+ mock.expectedMessageCount(2);
+ mock.message(0).body().isEqualTo(MESSAGE1);
+ mock.message(1).body().isEqualTo(MESSAGE2);
+
+ template.sendBody("direct:start", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8", false));
+ template.sendBody("direct:second", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8", false));
+
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileUTF8OnWindows() throws Exception {
+ switchToDefaultCharset("windows-1252");
+ mock.reset();
+ mock.expectedMessageCount(2);
+ mock.message(0).body().isEqualTo(MESSAGE1);
+ mock.message(1).body().isEqualTo(MESSAGE2);
+
+ template.sendBody("direct:start", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8", false));
+ template.sendBody("direct:second", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-utf8.json",
+ new File("src/test/resources/germanbooks-utf8.json"), "UTF-8", false));
+
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testPriceResultTypeOnGenericFileISO88591() throws Exception {
+ switchToDefaultCharset("ISO-8859-1");
+ mock.reset();
+ mock.expectedMessageCount(2);
+ mock.message(0).body().isEqualTo(MESSAGE1);
+ mock.message(1).body().isEqualTo(MESSAGE2);
+
+ template.sendBody("direct:start", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-iso-8859-1.json",
+ new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1", false));
+ template.sendBody("direct:second", FileConsumer
+ .asGenericFile("src/test/resources/germanbooks-iso-8859-1.json",
+ new File("src/test/resources/germanbooks-iso-8859-1.json"), "ISO-8859-1", false));
+
+ mock.assertIsSatisfied();
+ }
+
+ private static void switchToDefaultCharset(String charset) {
+ try {
+ Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
+ defaultCharset.setAccessible(true);
+ defaultCharset.set(null, Charset.forName(charset));
+ } catch (Exception e) {
+ // Do nothing here
+ }
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").transform().jsonpath("$.store.book[0].title", String.class)
+ .to("mock:title");
+
+ from("direct:second").transform().jsonpath("$.store.book[1].title", String.class)
+ .to("mock:title");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitTest.java
new file mode 100644
index 0000000..454a57b
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitTest.java
@@ -0,0 +1,157 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathSplitTest.class,
+ JsonPathSplitTest.TestConfiguration.class
+ }
+)
+public class JsonPathSplitTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @EndpointInject("mock:result-1")
+ MockEndpoint mock1;
+
+ @EndpointInject("mock:result-2")
+ MockEndpoint mock2;
+
+ @EndpointInject("mock:result-3")
+ MockEndpoint mock3;
+
+ @Test
+ public void testSplit() throws Exception {
+ mock.expectedMessageCount(3);
+
+ String out = template.requestBody("direct:start", new File("src/test/resources/books.json"), String.class);
+ assertNotNull(out);
+
+ mock.assertIsSatisfied();
+
+ Map row = mock.getReceivedExchanges().get(0).getIn().getBody(Map.class);
+ assertEquals("Nigel Rees", row.get("author"));
+ assertEquals(Double.valueOf("8.95"), row.get("price"));
+
+ row = mock.getReceivedExchanges().get(1).getIn().getBody(Map.class);
+ assertEquals("Evelyn Waugh", row.get("author"));
+ assertEquals(Double.valueOf("12.99"), row.get("price"));
+
+ // should preserve quotes etc
+ assertTrue(out.contains("\"author\": \"Nigel Rees\""));
+ assertTrue(out.contains("\"price\": 8.95"));
+ assertTrue(out.contains("\"title\": \"Sword's of Honour\""));
+ assertTrue(out.contains("\"price\": 12.99,"));
+ }
+
+ @Test
+ public void testJsonPathSplitDelimiterDisable() throws Exception {
+ // CAMEL-15769
+ String json = "{ \"text\": { \"div\": \"some , text\" } }";
+
+ mock1.expectedPropertyReceived("CamelSplitSize", 1);
+ mock1.expectedBodiesReceived("some , text");
+ template.sendBody("direct:start-1", json);
+ mock1.assertIsSatisfied();
+ }
+
+ @Test
+ public void testJsonPathSplitDelimiterDefault() throws Exception {
+ // CAMEL-15769
+ String json = "{ \"text\": { \"div\": \"some , text\" } }";
+
+ mock2.expectedPropertyReceived("CamelSplitSize", 2);
+ mock2.expectedBodiesReceived("some ", " text");
+ template.sendBody("direct:start-2", json);
+ mock2.assertIsSatisfied();
+ }
+
+ @Test
+ public void testJsonPathSplitDelimiter() throws Exception {
+ // CAMEL-15769
+ String json = "{ \"text\": { \"div\": \"some ,# text\" } }";
+
+ mock3.expectedPropertyReceived("CamelSplitSize", 2);
+ mock3.expectedBodiesReceived("some ,", " text");
+ template.sendBody("direct:start-3", json);
+ mock3.assertIsSatisfied();
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .split().jsonpath("$.store.book[*]")
+ .to("mock:authors")
+ .convertBodyTo(String.class);
+
+ from("direct:start-1")
+ .split(jsonpath("text.div", String.class), "false")
+ .to("mock:result-1");
+
+ from("direct:start-2")
+ .split(jsonpath("text.div", String.class))
+ .to("mock:result-2");
+
+ from("direct:start-3")
+ .split(jsonpath("text.div", String.class), "#")
+ .to("mock:result-3");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitWriteAsStringMapTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitWriteAsStringMapTest.java
new file mode 100644
index 0000000..983c3ac
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitWriteAsStringMapTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathSplitWriteAsStringMapTest.class,
+ JsonPathSplitWriteAsStringMapTest.TestConfiguration.class
+ }
+)
+public class JsonPathSplitWriteAsStringMapTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:line")
+ MockEndpoint mock;
+
+ @Test
+ public void testSplitToJSon() throws Exception {
+
+ mock.expectedMessageCount(2);
+
+ template.sendBody("direct:start", new File("src/test/resources/content-map.json"));
+
+ mock.assertIsSatisfied();
+
+ Map.Entry<?, ?> row = mock.getReceivedExchanges().get(0).getIn().getBody(Map.Entry.class);
+ assertEquals("foo", row.getKey());
+ assertEquals("{\"action\":\"CU\",\"id\":123,\"modifiedTime\":\"2015-07-28T11:40:09.520+02:00\"}", row.getValue());
+
+ row = mock.getReceivedExchanges().get(1).getIn().getBody(Map.Entry.class);
+ assertEquals("bar", row.getKey());
+ assertEquals("{\"action\":\"CU\",\"id\":456,\"modifiedTime\":\"2015-07-28T11:42:29.510+02:00\"}", row.getValue());
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .split().jsonpathWriteAsString("$.content")
+ .to("mock:line")
+ .to("log:line")
+ .end();
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitWriteAsStringTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitWriteAsStringTest.java
new file mode 100644
index 0000000..c664632
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSplitWriteAsStringTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathSplitWriteAsStringTest.class,
+ JsonPathSplitWriteAsStringTest.TestConfiguration.class
+ }
+)
+public class JsonPathSplitWriteAsStringTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:line")
+ MockEndpoint mock;
+
+ @Test
+ public void testSplitToJSon() throws Exception {
+
+ mock.expectedMessageCount(2);
+ // we want the output as JSON string
+ mock.allMessages().body().isInstanceOf(String.class);
+ mock.message(0).body().isEqualTo("{\"action\":\"CU\",\"id\":123,\"modifiedTime\":\"2015-07-28T11:40:09.520+02:00\"}");
+ mock.message(1).body().isEqualTo("{\"action\":\"CU\",\"id\":456,\"modifiedTime\":\"2015-07-28T11:42:29.510+02:00\"}");
+
+ template.sendBody("direct:start", new File("src/test/resources/content.json"));
+
+ mock.assertIsSatisfied();
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .split().jsonpathWriteAsString("$.content")
+ .to("mock:line")
+ .to("log:line")
+ .end();
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathStreamCachingCBRTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathStreamCachingCBRTest.java
new file mode 100644
index 0000000..d96eac9
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathStreamCachingCBRTest.java
@@ -0,0 +1,193 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.builder.PredicateBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.jsonpath.JsonPath;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.CamelContextConfiguration;
+
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathStreamCachingCBRTest.class,
+ JsonPathStreamCachingCBRTest.TestConfiguration.class
+ }
+)
+public class JsonPathStreamCachingCBRTest {
+
+ @Autowired
+ CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:cheap")
+ MockEndpoint mockCheap;
+
+ @EndpointInject("mock:average")
+ MockEndpoint mockAverage;
+
+ @EndpointInject("mock:expensive")
+ MockEndpoint mockExpensive;
+
+ @Bean
+ CamelContextConfiguration contextConfiguration() {
+ return new CamelContextConfiguration() {
+ @Override
+ public void beforeApplicationStart(CamelContext context) {
+ context.getStreamCachingStrategy().setSpoolDirectory("target/tmp");
+ context.getStreamCachingStrategy().setSpoolThreshold(-1);
+
+
+ }
+
+ @Override
+ public void afterApplicationStart(CamelContext camelContext) {
+ //do nothing here
+ }
+ };
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
+ from("direct:start")
+ .streamCaching()
+ .choice()
+ .when().jsonpath("$.store.book[?(@.price < 10)]")
+ .to("mock:cheap")
+ .when().jsonpath("$.store.book[?(@.price < 30)]")
+ .to("mock:average")
+ .otherwise()
+ .to("mock:expensive");
+
+ from("direct:bicycle")
+ .streamCaching()
+ .choice()
+ .when().method(new BeanPredicate())
+ .to("mock:cheap")
+ .otherwise()
+ .to("mock:expensive");
+
+ from("direct:bicycle2")
+ .streamCaching()
+ .choice()
+ .when(PredicateBuilder.isLessThan(
+ ExpressionBuilder.languageExpression("jsonpath", "$.store.bicycle.price"),
+ ExpressionBuilder.constantExpression(100)))
+ .to("mock:cheap")
+ .otherwise()
+ .to("mock:expensive");
+ }
+ };
+ }
+ }
+
+ public static class BeanPredicate {
+ public boolean checkPrice(@JsonPath("$.store.bicycle.price") double price) {
+ return price < 100;
+ }
+ }
+
+ @Test
+ public void testCheapBicycle() throws Exception {
+ sendMessageToBicycleRoute("direct:bicycle");
+ MockEndpoint.resetMocks(context);
+ sendMessageToBicycleRoute("direct:bicycle2");
+ }
+
+ private void sendMessageToBicycleRoute(String startPoint) throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+
+ template.sendBody(startPoint, new FileInputStream(new File("src/test/resources/cheap.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testCheap() throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/cheap.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testAverage() throws Exception {
+
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(1);
+ mockExpensive.expectedMessageCount(0);
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/average.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testExpensive() throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(1);
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/expensive.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSuppressTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSuppressTest.java
new file mode 100644
index 0000000..bb71071
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathSuppressTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathSuppressTest.class,
+ JsonPathSuppressTest.TestConfiguration.class
+ }
+)
+public class JsonPathSuppressTest {
+
+ @Autowired
+ CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:middle")
+ MockEndpoint mockMiddle;
+
+ @EndpointInject("mock:other")
+ MockEndpoint mockOther;
+
+ @Test
+ public void testMiddle() throws Exception {
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"middlename\" : \"foo2\", \"lastname\" : \"bar\"}}";
+ MockEndpoint.resetMocks(context);
+ mockMiddle.expectedMessageCount(1);
+ mockOther.expectedMessageCount(0);
+
+ template.sendBody("direct:start", json);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testNoMiddle() throws Exception {
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"lastname\" : \"bar\"}}";
+ MockEndpoint.resetMocks(context);
+ mockMiddle.expectedMessageCount(0);
+ mockOther.expectedMessageCount(1);
+
+ template.sendBody("direct:start", json);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when().jsonpath("person.middlename", true)
+ .to("mock:middle")
+ .otherwise()
+ .to("mock:other");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformHeaderNameTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformHeaderNameTest.java
new file mode 100644
index 0000000..235789e
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformHeaderNameTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathTransformHeaderNameTest.class,
+ JsonPathTransformHeaderNameTest.TestConfiguration.class
+ }
+)
+public class JsonPathTransformHeaderNameTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedMessageCount(1);
+
+ Object file = new File("src/test/resources/books.json");
+ template.sendBodyAndHeader("direct:start", "Hello World", "myHeader", file);
+
+ mock.assertIsSatisfied();
+
+ List<?> authors = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals("Nigel Rees", authors.get(0));
+ assertEquals("Evelyn Waugh", authors.get(1));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[*].author", false, null, "myHeader")
+ .to("mock:authors");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielEscapedTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielEscapedTest.java
new file mode 100644
index 0000000..cee1874
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielEscapedTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathTransformONielEscapedTest.class,
+ JsonPathTransformONielEscapedTest.TestConfiguration.class
+ }
+)
+public class JsonPathTransformONielEscapedTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ List<?> titles = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals("Camels in Space", titles.get(0));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[?(@.author == 'John O\\'Niel')].title")
+ .to("mock:authors");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielPlaceholderTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielPlaceholderTest.java
new file mode 100644
index 0000000..616ca2d
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielPlaceholderTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.PropertiesComponent;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.CamelContextConfiguration;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathTransformONielPlaceholderTest.class,
+ JsonPathTransformONielPlaceholderTest.TestConfiguration.class
+ }
+)
+public class JsonPathTransformONielPlaceholderTest {
+
+
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+
+ @Bean
+ CamelContextConfiguration contextConfiguration() {
+ return new CamelContextConfiguration() {
+ @Override
+ public void beforeApplicationStart(CamelContext context) {
+ PropertiesComponent pc = context.getPropertiesComponent();
+ Properties props = new Properties();
+ props.put("who", "John O'Niel");
+ props.put("search", "Sword's of Honour");
+ pc.setInitialProperties(props);
+
+ }
+
+ @Override
+ public void afterApplicationStart(CamelContext camelContext) {
+ //do nothing here
+ }
+ };
+ }
+
+
+ @Test
+ public void testAuthors() throws Exception {
+
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ List<?> titles = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(2, titles.size());
+ assertEquals("Sword's of Honour", titles.get(0));
+ assertEquals("Camels in Space", titles.get(1));
+ }
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[?(@.author == '{{who}}' || @.title == '{{search}}')].title")
+ .to("mock:authors");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielTest.java
new file mode 100644
index 0000000..b20bce5
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformONielTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathTransformONielTest.class,
+ JsonPathTransformONielTest.TestConfiguration.class
+ }
+)
+public class JsonPathTransformONielTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ List<?> titles = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals("Camels in Space", titles.get(0));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[?(@.author == \"John O'Niel\")].title")
+ .to("mock:authors");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformResultTypeTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformResultTypeTest.java
new file mode 100644
index 0000000..1dfd4e0
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformResultTypeTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathTransformResultTypeTest.class,
+ JsonPathTransformResultTypeTest.TestConfiguration.class
+ }
+)
+public class JsonPathTransformResultTypeTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:price")
+ MockEndpoint mock;
+
+ @Test
+ public void testPriceResultType() throws Exception {
+ mock.expectedMessageCount(4);
+ mock.message(0).body().isInstanceOf(Float.class);
+ mock.message(1).body().isInstanceOf(Double.class);
+ mock.message(2).body().isInstanceOf(Float.class);
+ mock.message(3).body().isInstanceOf(Double.class);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+ template.sendBody("direct:second", new File("src/test/resources/books.json"));
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+ template.sendBody("direct:second", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[0].price", Float.class)
+ .to("mock:price");
+
+ from("direct:second")
+ .transform().jsonpath("$.store.book[0].price", Double.class)
+ .to("mock:price");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformTest.java
new file mode 100644
index 0000000..0e5d1f1
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathTransformTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathTransformTest.class,
+ JsonPathTransformTest.TestConfiguration.class
+ }
+)
+public class JsonPathTransformTest {
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ List<?> authors = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals("Nigel Rees", authors.get(0));
+ assertEquals("Evelyn Waugh", authors.get(1));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .transform().jsonpath("$.store.book[*].author")
+ .to("mock:authors");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathWithSimpleCBRTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathWithSimpleCBRTest.java
new file mode 100644
index 0000000..7467225
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/JsonPathWithSimpleCBRTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ JsonPathWithSimpleCBRTest.class,
+ JsonPathWithSimpleCBRTest.TestConfiguration.class
+ }
+)
+public class JsonPathWithSimpleCBRTest {
+
+ @Autowired
+ CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:cheap")
+ MockEndpoint mockCheap;
+
+ @EndpointInject("mock:average")
+ MockEndpoint mockAverage;
+
+ @EndpointInject("mock:expensive")
+ MockEndpoint mockExpensive;
+
+ FluentProducerTemplate fluentTemplate;
+
+
+
+ @Test
+ public void testCheap() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/cheap.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testAverage() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(1);
+ mockExpensive.expectedMessageCount(0);
+
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/average.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testExpensive() throws Exception {
+ fluentTemplate = context.createFluentProducerTemplate();
+ fluentTemplate.start();
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(1);
+
+ fluentTemplate.withHeader("cheap", 10).withHeader("average", 30).withBody(new File("src/test/resources/expensive.json"))
+ .to("direct:start").send();
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when().jsonpath("$.store.book[?(@.price < ${header.cheap})]")
+ .to("mock:cheap")
+ .when().jsonpath("$.store.book[?(@.price < ${header.average})]")
+ .to("mock:average")
+ .otherwise()
+ .to("mock:expensive");
+ }
+ };
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/MyPojoType.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/MyPojoType.java
new file mode 100644
index 0000000..de4709d
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/MyPojoType.java
@@ -0,0 +1,39 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+public class MyPojoType {
+
+ private String kind;
+ private String type;
+
+ public String getKind() {
+ return kind;
+ }
+
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathCBRTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathCBRTest.java
new file mode 100644
index 0000000..b47ee54
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathCBRTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SpringJsonPathCBRTest.class
+ },
+ properties = {
+ "camel.springboot.routes-include-pattern=file:src/test/resources/routes/SpringJsonPathCBTTest.xml"}
+
+)
+public class SpringJsonPathCBRTest {
+
+ @Autowired
+ CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:cheap")
+ MockEndpoint mockCheap;
+
+ @EndpointInject("mock:average")
+ MockEndpoint mockAverage;
+
+ @EndpointInject("mock:expensive")
+ MockEndpoint mockExpensive;
+
+
+
+
+
+ @Test
+ public void testCheap() throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(1);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(0);
+
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/cheap.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testAverage() throws Exception {
+
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(1);
+ mockExpensive.expectedMessageCount(0);
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/average.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testExpensive() throws Exception {
+ MockEndpoint.resetMocks(context);
+ mockCheap.expectedMessageCount(0);
+ mockAverage.expectedMessageCount(0);
+ mockExpensive.expectedMessageCount(1);
+ template.sendBody("direct:start", new FileInputStream(new File("src/test/resources/expensive.json")));
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathSplitWriteAsStringTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathSplitWriteAsStringTest.java
new file mode 100644
index 0000000..a21e86f
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathSplitWriteAsStringTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SpringJsonPathSplitWriteAsStringTest.class
+ },
+ properties = {
+ "camel.springboot.routes-include-pattern=file:src/test/resources/routes/SpringJsonPathSplitWriteAsStringTest.xml"}
+
+)
+public class SpringJsonPathSplitWriteAsStringTest {
+
+
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:line")
+ MockEndpoint mock;
+
+
+
+
+ @Test
+ public void testSplitToJSon() throws Exception {
+ mock.expectedMessageCount(2);
+ // we want the output as JSON string
+ mock.allMessages().body().isInstanceOf(String.class);
+ mock.message(0).body().isEqualTo("{\"action\":\"CU\",\"id\":123,\"modifiedTime\":\"2015-07-28T11:40:09.520+02:00\"}");
+ mock.message(1).body().isEqualTo("{\"action\":\"CU\",\"id\":456,\"modifiedTime\":\"2015-07-28T11:42:29.510+02:00\"}");
+
+ template.sendBody("direct:start", new File("src/test/resources/content.json"));
+
+ mock.assertIsSatisfied();
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathSuppressTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathSuppressTest.java
new file mode 100644
index 0000000..90959ca
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathSuppressTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SpringJsonPathSuppressTest.class
+ },
+ properties = {
+ "camel.springboot.routes-include-pattern=file:src/test/resources/routes/SpringJsonPathSuppressTest.xml"}
+
+)
+public class SpringJsonPathSuppressTest {
+
+ @Autowired
+ private CamelContext context;
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:middle")
+ MockEndpoint mockMiddle;
+
+ @EndpointInject("mock:other")
+ MockEndpoint mockOther;
+
+
+
+
+ @Test
+ public void testMiddle() throws Exception {
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"middlename\" : \"foo2\", \"lastname\" : \"bar\"}}";
+ mockMiddle.reset();
+ mockOther.reset();
+ mockMiddle.expectedMessageCount(1);
+ mockOther.expectedMessageCount(0);
+
+ template.sendBody("direct:start", json);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testNoMiddle() throws Exception {
+ String json = "{\"person\" : {\"firstname\" : \"foo\", \"lastname\" : \"bar\"}}";
+ mockMiddle.reset();
+ mockOther.reset();
+ mockMiddle.expectedMessageCount(0);
+ mockOther.expectedMessageCount(1);
+
+ template.sendBody("direct:start", json);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformHeaderNameTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformHeaderNameTest.java
new file mode 100644
index 0000000..af44156
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformHeaderNameTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.List;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SpringJsonPathTransformHeaderNameTest.class
+ },
+ properties = {
+ "camel.springboot.routes-include-pattern=file:src/test/resources/routes/SpringJsonPathTransformHeaderNameTest.xml"}
+
+)
+public class SpringJsonPathTransformHeaderNameTest {
+
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+
+
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "myHeader", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ List<?> authors = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals("Nigel Rees", authors.get(0));
+ assertEquals("Evelyn Waugh", authors.get(1));
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformResultTypeTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformResultTypeTest.java
new file mode 100644
index 0000000..14534ed
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformResultTypeTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SpringJsonPathTransformResultTypeTest.class
+ },
+ properties = {
+ "camel.springboot.routes-include-pattern=file:src/test/resources/routes/SpringJsonPathTransformResultTypeTest.xml"}
+
+)
+public class SpringJsonPathTransformResultTypeTest {
+
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:price")
+ MockEndpoint mock;
+
+
+
+
+
+ @Test
+ public void testPriceResultType() throws Exception {
+ mock.expectedMessageCount(4);
+ mock.message(0).body().isInstanceOf(Float.class);
+ mock.message(1).body().isInstanceOf(Double.class);
+ mock.message(2).body().isInstanceOf(Float.class);
+ mock.message(3).body().isInstanceOf(Double.class);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+ template.sendBody("direct:second", new File("src/test/resources/books.json"));
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+ template.sendBody("direct:second", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformTest.java b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformTest.java
new file mode 100644
index 0000000..775003e
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/java/org/apache/camel/component/jsonpath/springboot/test/SpringJsonPathTransformTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.jsonpath.springboot.test;
+
+
+import java.io.File;
+import java.util.List;
+
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ CamelAutoConfiguration.class,
+ SpringJsonPathTransformTest.class
+ },
+ properties = {
+ "camel.springboot.routes-include-pattern=file:src/test/resources/routes/SpringJsonPathTransformTest.xml"}
+
+)
+public class SpringJsonPathTransformTest {
+
+
+ @Autowired
+ ProducerTemplate template;
+
+ @EndpointInject("mock:authors")
+ MockEndpoint mock;
+
+
+
+
+ @Test
+ public void testAuthors() throws Exception {
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:start", new File("src/test/resources/books.json"));
+
+ mock.assertIsSatisfied();
+
+ List<?> authors = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals("Nigel Rees", authors.get(0));
+ assertEquals("Evelyn Waugh", authors.get(1));
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/average.json b/components-starter/camel-jsonpath-starter/src/test/resources/average.json
new file mode 100644
index 0000000..cd71d97
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/average.json
@@ -0,0 +1,17 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "fiction",
+ "author": "Evelyn Waugh",
+ "title": "Sword of Honour",
+ "price": 12.99,
+ "isbn": "0-553-21311-3"
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 99.95
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/books.json b/components-starter/camel-jsonpath-starter/src/test/resources/books.json
new file mode 100644
index 0000000..ff2a384
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/books.json
@@ -0,0 +1,30 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "reference",
+ "author": "Nigel Rees",
+ "title": "Sayings of the Century",
+ "price": 8.95
+ },
+ {
+ "category": "fiction",
+ "author": "Evelyn Waugh",
+ "title": "Sword's of Honour",
+ "price": 12.99,
+ "isbn": "0-553-21311-3"
+ },
+ {
+ "category": "fiction",
+ "author": "John O'Niel",
+ "title": "Camels in Space",
+ "price": 9.99,
+ "isbn": "0-555-12345-6"
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 19.95
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/booksUTF16BE.json b/components-starter/camel-jsonpath-starter/src/test/resources/booksUTF16BE.json
new file mode 100644
index 0000000..cd4c3ed
Binary files /dev/null and b/components-starter/camel-jsonpath-starter/src/test/resources/booksUTF16BE.json differ
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/booksUTF16LE.json b/components-starter/camel-jsonpath-starter/src/test/resources/booksUTF16LE.json
new file mode 100644
index 0000000..7e066b1
Binary files /dev/null and b/components-starter/camel-jsonpath-starter/src/test/resources/booksUTF16LE.json differ
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/cheap.json b/components-starter/camel-jsonpath-starter/src/test/resources/cheap.json
new file mode 100644
index 0000000..a9783a7
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/cheap.json
@@ -0,0 +1,16 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "reference",
+ "author": "Nigel Rees",
+ "title": "Sayings of the Century",
+ "price": 8.95
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 99.95
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/content-map.json b/components-starter/camel-jsonpath-starter/src/test/resources/content-map.json
new file mode 100644
index 0000000..a3ac667
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/content-map.json
@@ -0,0 +1,14 @@
+{
+ "content": {
+ "foo": {
+ "action": "CU",
+ "id": 123,
+ "modifiedTime": "2015-07-28T11:40:09.520+02:00"
+ },
+ "bar": {
+ "action": "CU",
+ "id": 456,
+ "modifiedTime": "2015-07-28T11:42:29.510+02:00"
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/content.json b/components-starter/camel-jsonpath-starter/src/test/resources/content.json
new file mode 100644
index 0000000..94d2572
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/content.json
@@ -0,0 +1,14 @@
+{
+ "content": [
+ {
+ "action": "CU",
+ "id": 123,
+ "modifiedTime": "2015-07-28T11:40:09.520+02:00"
+ },
+ {
+ "action": "CU",
+ "id": 456,
+ "modifiedTime": "2015-07-28T11:42:29.510+02:00"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/expensive.json b/components-starter/camel-jsonpath-starter/src/test/resources/expensive.json
new file mode 100644
index 0000000..df24270
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/expensive.json
@@ -0,0 +1,17 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "programming",
+ "author": "Claus Ibsen,Jonathan Anstey",
+ "title": "Camel in Action",
+ "price": 39.99,
+ "isbn": "978-193-518-236-8"
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 99.95
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/germanbooks-iso-8859-1.json b/components-starter/camel-jsonpath-starter/src/test/resources/germanbooks-iso-8859-1.json
new file mode 100644
index 0000000..c7aa2dc
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/germanbooks-iso-8859-1.json
@@ -0,0 +1,23 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "novel",
+ "author": "Thomas Mann",
+ "title": "Joseph und seine Br�der",
+ "price": 25.00
+ },
+ {
+ "category": "fiction",
+ "author": "Friedrich Nietzsche",
+ "title": "G�tzend�mmerung",
+ "price": 9.00,
+ "isbn": "3-458-32522-0"
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 19.95
+ }
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/germanbooks-utf8.json b/components-starter/camel-jsonpath-starter/src/test/resources/germanbooks-utf8.json
new file mode 100644
index 0000000..0ba544a
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/germanbooks-utf8.json
@@ -0,0 +1,23 @@
+{
+ "store": {
+ "book": [
+ {
+ "category": "novel",
+ "author": "Thomas Mann",
+ "title": "Joseph und seine Brüder",
+ "price": 25.00
+ },
+ {
+ "category": "fiction",
+ "author": "Friedrich Nietzsche",
+ "title": "Götzendämmerung",
+ "price": 9.00,
+ "isbn": "3-458-32522-0"
+ }
+ ],
+ "bicycle": {
+ "color": "red",
+ "price": 19.95
+ }
+ }
+}
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathCBTTest.xml b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathCBTTest.xml
new file mode 100644
index 0000000..6f47694
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathCBTTest.xml
@@ -0,0 +1,39 @@
+<?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.
+
+-->
+
+ <routes id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route streamCache="true">
+ <from uri="direct:start"/>
+ <choice>
+ <when>
+ <jsonpath>$.store.book[?(@.price < 10)]</jsonpath>
+ <to uri="mock:cheap"/>
+ </when>
+ <when>
+ <jsonpath>$.store.book[?(@.price < 30)]</jsonpath>
+ <to uri="mock:average"/>
+ </when>
+ <otherwise>
+ <to uri="mock:expensive"/>
+ </otherwise>
+ </choice>
+ </route>
+ </routes>
+
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathSplitWriteAsStringTest.xml b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathSplitWriteAsStringTest.xml
new file mode 100644
index 0000000..13085d0
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathSplitWriteAsStringTest.xml
@@ -0,0 +1,31 @@
+<?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.
+
+-->
+
+ <routes id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <split>
+ <jsonpath writeAsString="true">$.content</jsonpath>
+ <to uri="mock:line"/>
+ <to uri="log:line"/>
+ </split>
+ </route>
+ </routes>
+
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathSuppressTest.xml b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathSuppressTest.xml
new file mode 100644
index 0000000..3b583a2
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathSuppressTest.xml
@@ -0,0 +1,35 @@
+<?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.
+
+-->
+
+ <routes id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <choice>
+ <when>
+ <jsonpath suppressExceptions="true">person.middlename</jsonpath>
+ <to uri="mock:middle"/>
+ </when>
+ <otherwise>
+ <to uri="mock:other"/>
+ </otherwise>
+ </choice>
+ </route>
+ </routes>
+
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformHeaderNameTest.xml b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformHeaderNameTest.xml
new file mode 100644
index 0000000..6bc7616
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformHeaderNameTest.xml
@@ -0,0 +1,30 @@
+<?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.
+
+-->
+
+ <routes id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <transform>
+ <jsonpath headerName="myHeader">$.store.book[*].author</jsonpath>
+ </transform>
+ <to uri="mock:authors"/>
+ </route>
+ </routes>
+
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformResultTypeTest.xml b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformResultTypeTest.xml
new file mode 100644
index 0000000..ee5223f
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformResultTypeTest.xml
@@ -0,0 +1,36 @@
+<?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.
+
+-->
+ <routes id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <transform>
+ <jsonpath resultType="Float">$.store.book[0].price</jsonpath>
+ </transform>
+ <to uri="mock:price"/>
+ </route>
+ <route>
+ <from uri="direct:second"/>
+ <transform>
+ <jsonpath resultType="Double">$.store.book[0].price</jsonpath>
+ </transform>
+ <to uri="mock:price"/>
+ </route>
+ </routes>
+
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformTest.xml b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformTest.xml
new file mode 100644
index 0000000..9c152f3
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/routes/SpringJsonPathTransformTest.xml
@@ -0,0 +1,30 @@
+<?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.
+
+-->
+
+ <routes id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <transform>
+ <jsonpath>$.store.book[*].author</jsonpath>
+ </transform>
+ <to uri="mock:authors"/>
+ </route>
+ </routes>
+
diff --git a/components-starter/camel-jsonpath-starter/src/test/resources/type.json b/components-starter/camel-jsonpath-starter/src/test/resources/type.json
new file mode 100644
index 0000000..a2a75df
--- /dev/null
+++ b/components-starter/camel-jsonpath-starter/src/test/resources/type.json
@@ -0,0 +1,4 @@
+{
+ "kind": "full",
+ "type": "customer"
+}
\ No newline at end of file