You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/01/02 23:31:40 UTC
[camel-quarkus] branch master updated: Add tests for #543
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new c317614 Add tests for #543
new 8fd7a41 Merge pull request #581 from lburgazzoli/github-543
c317614 is described below
commit c3176144d66a0172ca07e253dedd0f93c8acbf4d
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Thu Jan 2 10:55:00 2020 +0100
Add tests for #543
---
integration-tests/jackson/pom.xml | 8 ++++
.../quarkus/component/jackson/CamelResource.java | 12 ++++++
.../quarkus/component/jackson/CamelRoute.java | 20 +---------
.../component/jackson/model/DummyObject.java} | 33 +++++++----------
.../src/main/resources/application.properties | 10 ++++-
.../src/main/resources/routes/my-routes.xml | 43 ++++++++++++++++++++++
.../quarkus/component/jackson/JacksonTest.java | 21 +++++++++++
7 files changed, 109 insertions(+), 38 deletions(-)
diff --git a/integration-tests/jackson/pom.xml b/integration-tests/jackson/pom.xml
index 0551e3b..0e17502 100644
--- a/integration-tests/jackson/pom.xml
+++ b/integration-tests/jackson/pom.xml
@@ -32,6 +32,10 @@
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-core-xml</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jackson</artifactId>
</dependency>
<dependency>
@@ -55,6 +59,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxb</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy-jsonb</artifactId>
+ </dependency>
<!-- test dependencies -->
<dependency>
diff --git a/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelResource.java b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelResource.java
index 3233076..48734d3 100644
--- a/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelResource.java
+++ b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelResource.java
@@ -18,9 +18,11 @@ package org.apache.camel.quarkus.component.jackson;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
+import javax.json.bind.JsonbBuilder;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@@ -53,4 +55,14 @@ public class CamelResource {
return consumer.receive("vm:out").getMessage().getBody().toString();
}
+ @Path("/unmarshal/{direct-id}")
+ @POST
+ @Consumes(MediaType.TEXT_PLAIN)
+ @Produces(MediaType.APPLICATION_JSON)
+ public String testXmlUnmarshalDefinition(@PathParam("direct-id") String directId, String statement) {
+ Object object = template.requestBody("direct:" + directId, statement);
+ String answer = JsonbBuilder.create().toJson(object);
+
+ return answer;
+ }
}
diff --git a/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelRoute.java b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelRoute.java
index 2e11fc2..5ac49f8 100644
--- a/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelRoute.java
+++ b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/CamelRoute.java
@@ -16,9 +16,9 @@
*/
package org.apache.camel.quarkus.component.jackson;
-import io.quarkus.runtime.annotations.RegisterForReflection;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
+import org.apache.camel.quarkus.component.jackson.model.DummyObject;
public class CamelRoute extends RouteBuilder {
@@ -26,6 +26,7 @@ public class CamelRoute extends RouteBuilder {
public void configure() {
JacksonDataFormat format = new JacksonDataFormat(DummyObject.class);
format.useList();
+
from("direct:in")
.wireTap("direct:tap")
.setBody(constant("ok"));
@@ -38,21 +39,4 @@ public class CamelRoute extends RouteBuilder {
.to("vm:out");
}
- @RegisterForReflection
- public static class DummyObject {
-
- private String dummy;
-
- public DummyObject() {
- }
-
- public String getDummy() {
- return dummy;
- }
-
- public void setDummy(String dummy) {
- this.dummy = dummy;
- }
- }
-
}
diff --git a/integration-tests/jackson/src/test/java/org/apache/camel/quarkus/component/jackson/JacksonTest.java b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
similarity index 52%
copy from integration-tests/jackson/src/test/java/org/apache/camel/quarkus/component/jackson/JacksonTest.java
copy to integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
index e72f21d..4d6caed 100644
--- a/integration-tests/jackson/src/test/java/org/apache/camel/quarkus/component/jackson/JacksonTest.java
+++ b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
@@ -14,28 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.quarkus.component.jackson;
+package org.apache.camel.quarkus.component.jackson.model;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import io.restassured.http.ContentType;
-import org.junit.jupiter.api.Test;
+import io.quarkus.runtime.annotations.RegisterForReflection;
-import static org.hamcrest.Matchers.equalTo;
+@RegisterForReflection
+public class DummyObject {
-@QuarkusTest
-public class JacksonTest {
- @Test
- public void testRoutes() {
- RestAssured.given().contentType(ContentType.TEXT)
- .body("[{\"dummy\": \"value1\"}, {\"dummy\": \"value2\"}]")
- .post("/jackson/in");
- RestAssured.post("/jackson/out")
- .then()
- .body(equalTo("{\"dummy\":\"value1\"}"));
- RestAssured.post("/jackson/out")
- .then()
- .body(equalTo("{\"dummy\":\"value2\"}"));
+ private String dummy;
+
+ public DummyObject() {
+ }
+
+ public String getDummy() {
+ return dummy;
}
+ public void setDummy(String dummy) {
+ this.dummy = dummy;
+ }
}
diff --git a/integration-tests/jackson/src/main/resources/application.properties b/integration-tests/jackson/src/main/resources/application.properties
index c07be89..20d3577 100644
--- a/integration-tests/jackson/src/main/resources/application.properties
+++ b/integration-tests/jackson/src/main/resources/application.properties
@@ -20,7 +20,15 @@
quarkus.ssl.native=true
quarkus.log.file.enable = false
+# include xml routes in native image
+quarkus.native.additional-build-args = -H:IncludeResources=routes/my-routes.xml
+
#
# Camel
#
-camel.context.name = quarkus-camel-example
\ No newline at end of file
+camel.context.name = quarkus-camel-example
+
+#
+# Main
+#
+camel.main.xml-routes = classpath:routes/my-routes.xml
\ No newline at end of file
diff --git a/integration-tests/jackson/src/main/resources/routes/my-routes.xml b/integration-tests/jackson/src/main/resources/routes/my-routes.xml
new file mode 100644
index 0000000..6592d59
--- /dev/null
+++ b/integration-tests/jackson/src/main/resources/routes/my-routes.xml
@@ -0,0 +1,43 @@
+<?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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <route>
+ <from uri="direct:type-as-attribute"/>
+ <unmarshal>
+ <json library="Jackson" unmarshalTypeName="org.apache.camel.quarkus.component.jackson.model.DummyObject"/>
+ </unmarshal>
+ </route>
+
+ <route>
+ <from uri="direct:type-as-header"/>
+ <setHeader name="CamelJacksonUnmarshalType">
+ <constant>org.apache.camel.quarkus.component.jackson.model.DummyObject</constant>
+ </setHeader>
+ <unmarshal>
+ <json library="Jackson" allowUnmarshallType="true"/>
+ </unmarshal>
+ </route>
+
+</routes>
\ No newline at end of file
diff --git a/integration-tests/jackson/src/test/java/org/apache/camel/quarkus/component/jackson/JacksonTest.java b/integration-tests/jackson/src/test/java/org/apache/camel/quarkus/component/jackson/JacksonTest.java
index e72f21d..606344d 100644
--- a/integration-tests/jackson/src/test/java/org/apache/camel/quarkus/component/jackson/JacksonTest.java
+++ b/integration-tests/jackson/src/test/java/org/apache/camel/quarkus/component/jackson/JacksonTest.java
@@ -16,12 +16,20 @@
*/
package org.apache.camel.quarkus.component.jackson;
+import java.util.UUID;
+
+import javax.json.bind.JsonbBuilder;
+
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
+import org.apache.camel.quarkus.component.jackson.model.DummyObject;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
@QuarkusTest
public class JacksonTest {
@@ -38,4 +46,17 @@ public class JacksonTest {
.body(equalTo("{\"dummy\":\"value2\"}"));
}
+ @ParameterizedTest
+ @ValueSource(strings = { "type-as-attribute", "type-as-header" })
+ public void testUnmarshal(String directId) {
+ DummyObject object = new DummyObject();
+ object.setDummy(UUID.randomUUID().toString());
+
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .body(JsonbBuilder.create().toJson(object))
+ .post("/jackson/unmarshal/{direct-id}", directId)
+ .then()
+ .body("dummy", is(object.getDummy()));
+ }
}