This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 4dc6269 CAMEL-16242: Added unit test 4dc6269 is described below commit 4dc62695a8ad33976823f4b6d9801a0293df0847 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Mar 6 18:48:18 2021 +0100 CAMEL-16242: Added unit test --- .../apache/camel/jsonpath/JsonPathHeaderNameTest.java | 2 +- .../apache/camel/jsonpath/JsonPathLanguageTest.java | 3 ++- .../org/apache/camel/jsonpath/JsonPathSplitTest.java | 2 +- ...erNameTest.java => JsonPathTransformONielTest.java} | 18 +++++++++++------- .../camel-jsonpath/src/test/resources/books.json | 7 +++++++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathHeaderNameTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathHeaderNameTest.java index 3c80739..2f836e6 100644 --- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathHeaderNameTest.java +++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathHeaderNameTest.java @@ -39,7 +39,7 @@ public class JsonPathHeaderNameTest extends CamelTestSupport { @Test public void testAuthors() throws Exception { getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); - getMockEndpoint("mock:result").expectedHeaderReceived("number", "2"); + getMockEndpoint("mock:result").expectedHeaderReceived("number", "3"); Object file = new File("src/test/resources/books.json"); template.sendBodyAndHeader("direct:start", "Hello World", "myHeader", file); diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java index e6bea51..d27a10e 100644 --- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java +++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java @@ -58,9 +58,10 @@ public class JsonPathLanguageTest extends CamelTestSupport { LOG.debug("Authors {}", authors); assertNotNull(authors); - assertEquals(2, authors.size()); + 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); diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitTest.java index 4a63c1b..a392985 100644 --- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitTest.java +++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathSplitTest.java @@ -57,7 +57,7 @@ public class JsonPathSplitTest extends CamelTestSupport { @Test public void testSplit() throws Exception { - getMockEndpoint("mock:authors").expectedMessageCount(2); + getMockEndpoint("mock:authors").expectedMessageCount(3); String out = template.requestBody("direct:start", new File("src/test/resources/books.json"), String.class); assertNotNull(out); diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathHeaderNameTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathTransformONielTest.java similarity index 68% copy from components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathHeaderNameTest.java copy to components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathTransformONielTest.java index 3c80739..a9543c7 100644 --- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathHeaderNameTest.java +++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathTransformONielTest.java @@ -17,12 +17,15 @@ package org.apache.camel.jsonpath; import java.io.File; +import java.util.List; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; -public class JsonPathHeaderNameTest extends CamelTestSupport { +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class JsonPathTransformONielTest extends CamelTestSupport { @Override protected RouteBuilder createRouteBuilder() throws Exception { @@ -30,21 +33,22 @@ public class JsonPathHeaderNameTest extends CamelTestSupport { @Override public void configure() throws Exception { from("direct:start") - .setHeader("number").jsonpath("$..store.book.length()", false, int.class, "myHeader") - .to("mock:result"); + .transform().jsonpath("$.store.book[?(@.author == \"John O'Niel\")].title") + .to("mock:authors"); } }; } @Test public void testAuthors() throws Exception { - getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); - getMockEndpoint("mock:result").expectedHeaderReceived("number", "2"); + getMockEndpoint("mock:authors").expectedMessageCount(1); - Object file = new File("src/test/resources/books.json"); - template.sendBodyAndHeader("direct:start", "Hello World", "myHeader", file); + template.sendBody("direct:start", new File("src/test/resources/books.json")); assertMockEndpointsSatisfied(); + + List<?> titles = getMockEndpoint("mock:authors").getReceivedExchanges().get(0).getIn().getBody(List.class); + assertEquals("Camel in Space", titles.get(0)); } } diff --git a/components/camel-jsonpath/src/test/resources/books.json b/components/camel-jsonpath/src/test/resources/books.json index 6d4594f..a412426 100644 --- a/components/camel-jsonpath/src/test/resources/books.json +++ b/components/camel-jsonpath/src/test/resources/books.json @@ -13,6 +13,13 @@ "title": "Sword of Honour", "price": 12.99, "isbn": "0-553-21311-3" + }, + { + "category": "fiction", + "author": "John O'Niel", + "title": "Camel in Space", + "price": 9.99, + "isbn": "0-555-12345-6" } ], "bicycle": {