Merge pull request #581 from lburgazzoli/github-543
Add tests for #543
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 @@
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 @@
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 void configure() {
JacksonDataFormat format = new JacksonDataFormat(DummyObject.class);
format.useList();
+
from("direct:in")
.wireTap("direct:tap")
.setBody(constant("ok"));
@@ -38,21 +39,4 @@
.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/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
new file mode 100644
index 0000000..4d6caed
--- /dev/null
+++ b/integration-tests/jackson/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
@@ -0,0 +1,36 @@
+/*
+ * 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.jackson.model;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+public 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/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 @@
.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()));
+ }
}