This is an automated email from the ASF dual-hosted git repository.
aldettinger pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new f1cc006 Expand jsonpath test coverage #2783
f1cc006 is described below
commit f1cc006063214eddb7e047fc2580a932bbd8531f
Author: aldettinger <[email protected]>
AuthorDate: Thu Jun 17 13:23:24 2021 +0200
Expand jsonpath test coverage #2783
---
integration-tests/jsonpath/pom.xml | 9 ++-
.../component/json/path/it/JsonPathResource.java | 79 +++++++++++++++++++--
.../component/json/path/it/JsonPathTestRoute.java | 7 ++
.../component/json/path/it/JsonPathCharsetsIT.java | 24 +++++++
.../json/path/it/JsonPathCharsetsTest.java | 61 ++++++++++++++++
.../json/path/it/JsonPathSetHeaderIT.java | 24 +++++++
.../json/path/it/JsonPathSetHeaderTest.java | 32 +++++++++
.../component/json/path/it/JsonPathSplitIT.java | 24 +++++++
.../component/json/path/it/JsonPathSplitTest.java | 32 +++++++++
.../jsonpath/src/test/resources/booksUTF16BE.json | Bin 0 -> 1106 bytes
.../jsonpath/src/test/resources/booksUTF16LE.json | Bin 0 -> 1106 bytes
.../src/test/resources/germanbooks-iso-8859-1.json | 23 ++++++
12 files changed, 308 insertions(+), 7 deletions(-)
diff --git a/integration-tests/jsonpath/pom.xml
b/integration-tests/jsonpath/pom.xml
index 7d77d6f..65a1324 100644
--- a/integration-tests/jsonpath/pom.xml
+++ b/integration-tests/jsonpath/pom.xml
@@ -46,13 +46,16 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
-
- <!-- test dependencies -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mock</artifactId>
+ </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
- <scope>test</scope>
</dependency>
+
+ <!-- test dependencies -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
diff --git
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
index 15ae702..f1e0caf2 100644
---
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
+++
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
@@ -16,17 +16,31 @@
*/
package org.apache.camel.quarkus.component.json.path.it;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
import org.jboss.logging.Logger;
+import static org.apache.camel.jsonpath.JsonPathConstants.HEADER_JSON_ENCODING;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
@Path("/jsonpath")
@ApplicationScoped
public class JsonPathResource {
@@ -34,6 +48,9 @@ public class JsonPathResource {
private static final Logger LOG = Logger.getLogger(JsonPathResource.class);
@Inject
+ CamelContext context;
+
+ @Inject
ProducerTemplate producerTemplate;
@Path("/getBookPriceLevel")
@@ -41,7 +58,7 @@ public class JsonPathResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String getBookPriceLevel(String storeRequestJson) {
- LOG.infof("Getting book price level from json store request: %s",
storeRequestJson);
+ LOG.debugf("Getting book price level from json store request: %s",
storeRequestJson);
return producerTemplate.requestBody("direct:getBookPriceLevel",
storeRequestJson, String.class);
}
@@ -50,7 +67,7 @@ public class JsonPathResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String getBookPrice(String storeRequestJson) {
- LOG.infof("Getting book price from json store request: %s",
storeRequestJson);
+ LOG.debugf("Getting book price from json store request: %s",
storeRequestJson);
return producerTemplate.requestBody("direct:getBookPrice",
storeRequestJson, String.class);
}
@@ -59,7 +76,7 @@ public class JsonPathResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String getFullName(String personRequestJson) {
- LOG.infof("Getting person full name from json person request: %s",
personRequestJson);
+ LOG.debugf("Getting person full name from json person request: %s",
personRequestJson);
return producerTemplate.requestBody("direct:getFullName",
personRequestJson, String.class);
}
@@ -68,7 +85,61 @@ public class JsonPathResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String getAllCarColors(String carsRequestJson) {
- LOG.infof("Getting all car colors from json cars request: %s",
carsRequestJson);
+ LOG.debugf("Getting all car colors from json cars request: %s",
carsRequestJson);
return producerTemplate.requestBody("direct:getAllCarColors",
carsRequestJson, String.class);
}
+
+ @Path("/splitBooksShouldReturnTwoPrices")
+ @GET
+ public void splitBooksShouldReturnThreePrices() throws
InterruptedException {
+ LOG.debugf("Calling splitBooksShouldReturnThreePrices()");
+
+ String body = "{\"books\": [{\"price\": 30},{ \"price\": 20}]}";
+ MockEndpoint mockPrices = context.getEndpoint("mock:prices",
MockEndpoint.class);
+ mockPrices.expectedMessageCount(2);
+ producerTemplate.requestBody("direct:splitBooks", body, String.class);
+ mockPrices.assertIsSatisfied();
+
+ List<Exchange> exchanges = mockPrices.getReceivedExchanges();
+ assertNotNull(exchanges);
+ assertEquals(2, exchanges.size());
+
+ Map<?, ?> firstRow = exchanges.get(0).getIn().getBody(Map.class);
+ assertNotNull(firstRow);
+ assertEquals(30, firstRow.get("price"));
+
+ Map<?, ?> secondRow = exchanges.get(1).getIn().getBody(Map.class);
+ assertNotNull(secondRow);
+ assertEquals(20, secondRow.get("price"));
+ }
+
+
@Path("/setHeaderWithJsonPathExpressionEvaluatingAnotherHeaderShouldSucceed")
+ @GET
+ public void
setHeaderWithJsonPathExpressionEvaluatingAnotherHeaderShouldSucceed() throws
InterruptedException {
+ LOG.debugf("Calling
setHeaderWithJsonPathExpressionEvaluatingAnotherHeaderShouldSucceed()");
+
+ String json = "{\"book\": {\"price\": 25} }";
+ MockEndpoint mockSetHeader = context.getEndpoint("mock:setHeader",
MockEndpoint.class);
+ mockSetHeader.expectedMessageCount(1);
+ mockSetHeader.expectedHeaderReceived("price", 25);
+ producerTemplate.requestBodyAndHeader("direct:setHeader", null,
"jsonBookHeader", json, Message.class);
+ mockSetHeader.assertIsSatisfied();
+ }
+
+ @Path("/getAuthorsFromJsonStream")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_OCTET_STREAM)
+ public List<?> getAuthorsFromJsonStream(byte[] jsonBytes,
@QueryParam("encoding") String encoding) throws IOException {
+ LOG.debugf("Getting authors from JsonStream with encoding '%s' and %d
bytes", encoding, jsonBytes.length);
+
+ try (ByteArrayInputStream jsonStream = new
ByteArrayInputStream(jsonBytes)) {
+ if (encoding == null) {
+ return
producerTemplate.requestBody("direct:getAuthorsFromJsonStream", jsonStream,
List.class);
+ } else {
+ return
producerTemplate.requestBodyAndHeader("direct:getAuthorsFromJsonStream",
jsonStream,
+ HEADER_JSON_ENCODING, encoding, List.class);
+ }
+ }
+ }
}
diff --git
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
index ffca272..549512a 100644
---
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
+++
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
@@ -39,6 +39,13 @@ public class JsonPathTestRoute extends RouteBuilder {
from("direct:getFullName").bean(FullNameBean.class);
from("direct:getAllCarColors").transform().jsonpath("$.cars[*].color");
+
+
from("direct:splitBooks").split().jsonpath("$.books[*]").to("mock:prices");
+
+ from("direct:setHeader").setHeader("price").jsonpath("$.book.price",
false, int.class, "jsonBookHeader")
+ .to("mock:setHeader");
+
+
from("direct:getAuthorsFromJsonStream").transform().jsonpath("$.store.book[*].title");
}
@RegisterForReflection
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathCharsetsIT.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathCharsetsIT.java
new file mode 100644
index 0000000..0b078d2
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathCharsetsIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.quarkus.component.json.path.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class JsonPathCharsetsIT extends JsonPathCharsetsTest {
+
+}
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathCharsetsTest.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathCharsetsTest.java
new file mode 100644
index 0000000..94a9b30
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathCharsetsTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.json.path.it;
+
+import java.io.IOException;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.apache.commons.io.IOUtils;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@QuarkusTest
+class JsonPathCharsetsTest {
+
+ @Test
+ public void transformBooksUTF16BEShouldReturnTwoAuthors() throws
IOException {
+ byte[] body = IOUtils.resourceToByteArray("/booksUTF16BE.json");
+ String[] authors =
given().body(body).get("/jsonpath/getAuthorsFromJsonStream").then().statusCode(200).extract()
+ .as(String[].class);
+ assertEquals(2, authors.length);
+ assertEquals("Sayings of the Century", authors[0]);
+ assertEquals("Sword of Honour", authors[1]);
+ }
+
+ @Test
+ public void transformBooksUTF16LEShouldReturnTwoAuthors() throws
IOException {
+ byte[] body = IOUtils.resourceToByteArray("/booksUTF16LE.json");
+ String[] authors =
given().body(body).get("/jsonpath/getAuthorsFromJsonStream").then().statusCode(200).extract()
+ .as(String[].class);
+ assertEquals(2, authors.length);
+ assertEquals("Sayings of the Century", authors[0]);
+ assertEquals("Sword of Honour", authors[1]);
+ }
+
+ @Test
+ public void transformBooksIso_8859_1_ShouldReturnTwoAuthors() throws
IOException {
+ byte[] body =
IOUtils.resourceToByteArray("/germanbooks-iso-8859-1.json");
+ String[] authors = given().queryParam("encoding",
"ISO-8859-1").body(body).get("/jsonpath/getAuthorsFromJsonStream")
+ .then().statusCode(200).extract().as(String[].class);
+ assertEquals(2, authors.length);
+ assertEquals("Joseph und seine Brüder", authors[0]);
+ assertEquals("Götzendämmerung", authors[1]);
+ }
+
+}
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSetHeaderIT.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSetHeaderIT.java
new file mode 100644
index 0000000..113f359
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSetHeaderIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.quarkus.component.json.path.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class JsonPathSetHeaderIT extends JsonPathSetHeaderTest {
+
+}
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSetHeaderTest.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSetHeaderTest.java
new file mode 100644
index 0000000..621cf27
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSetHeaderTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.quarkus.component.json.path.it;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.get;
+
+@QuarkusTest
+class JsonPathSetHeaderTest {
+
+ @Test
+ public void
setHeaderWithJsonPathExpressionEvaluatingAnotherHeaderShouldSucceed() {
+
get("/jsonpath/setHeaderWithJsonPathExpressionEvaluatingAnotherHeaderShouldSucceed").then().statusCode(204);
+ }
+
+}
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSplitIT.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSplitIT.java
new file mode 100644
index 0000000..817d21a
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSplitIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.quarkus.component.json.path.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class JsonPathSplitIT extends JsonPathSplitTest {
+
+}
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSplitTest.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSplitTest.java
new file mode 100644
index 0000000..9875c0c
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathSplitTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.quarkus.component.json.path.it;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.get;
+
+@QuarkusTest
+class JsonPathSplitTest {
+
+ @Test
+ public void splitBooksShouldReturnTwoPrices() {
+
get("/jsonpath/splitBooksShouldReturnTwoPrices").then().statusCode(204);
+ }
+
+}
diff --git a/integration-tests/jsonpath/src/test/resources/booksUTF16BE.json
b/integration-tests/jsonpath/src/test/resources/booksUTF16BE.json
new file mode 100644
index 0000000..cd4c3ed
Binary files /dev/null and
b/integration-tests/jsonpath/src/test/resources/booksUTF16BE.json differ
diff --git a/integration-tests/jsonpath/src/test/resources/booksUTF16LE.json
b/integration-tests/jsonpath/src/test/resources/booksUTF16LE.json
new file mode 100644
index 0000000..7e066b1
Binary files /dev/null and
b/integration-tests/jsonpath/src/test/resources/booksUTF16LE.json differ
diff --git
a/integration-tests/jsonpath/src/test/resources/germanbooks-iso-8859-1.json
b/integration-tests/jsonpath/src/test/resources/germanbooks-iso-8859-1.json
new file mode 100644
index 0000000..c7aa2dc
--- /dev/null
+++ b/integration-tests/jsonpath/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