Skip to content

Commit

Permalink
Add tests for apache#543
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jan 2, 2020
1 parent 3bd3938 commit 9396669
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 19 deletions.
8 changes: 8 additions & 0 deletions integration-tests/jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<description>Integration tests for Camel Jackson extension</description>

<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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -53,4 +55,14 @@ public String testOrder() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
*/
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 {

@Override
public void configure() {
JacksonDataFormat format = new JacksonDataFormat(DummyObject.class);
format.useList();

from("direct:in")
.wireTap("direct:tap")
.setBody(constant("ok"));
Expand All @@ -38,21 +39,4 @@ public void configure() {
.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;
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
camel.context.name = quarkus-camel-example

#
# Main
#
camel.main.xml-routes = classpath:routes/my-routes.xml
43 changes: 43 additions & 0 deletions integration-tests/jackson/src/main/resources/routes/my-routes.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@
*/
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.Tag;
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 {
Expand All @@ -38,4 +47,18 @@ public void testRoutes() {
.body(equalTo("{\"dummy\":\"value2\"}"));
}

@Tag("quarkus-platform-ignore")
@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()));
}
}

0 comments on commit 9396669

Please sign in to comment.