You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2021/08/31 20:21:44 UTC

[camel-quarkus] branch main updated: [#3028] Increase test coverage of a binding mode of camel-rest component

This is an automated email from the ASF dual-hosted git repository.

ppalaga 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 021ed03  [#3028] Increase test coverage of a binding mode of camel-rest component
021ed03 is described below

commit 021ed03b8b2e3e57e8228415af1a7120df325706
Author: Vratislav Hais <vh...@redhat.com>
AuthorDate: Mon Aug 30 05:04:02 2021 +0200

    [#3028] Increase test coverage of a binding mode of camel-rest component
---
 .../camel/quarkus/component/rest/it/Person.java    |  9 +++++
 .../quarkus/component/rest/it/RestResource.java    | 22 +++++++++++++
 .../quarkus/component/rest/it/RestRoutes.java      | 12 +++++++
 .../camel/quarkus/component/rest/it/RestTest.java  | 38 ++++++++++++++++------
 4 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/Person.java b/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/Person.java
index 563feed..b168210 100644
--- a/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/Person.java
+++ b/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/Person.java
@@ -30,6 +30,15 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
 @XmlAccessorType(XmlAccessType.FIELD)
 public class Person {
 
+    public Person() {
+    }
+
+    public Person(String firstName, String lastName, int age) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.age = age;
+    }
+
     @XmlAttribute
     private String firstName;
 
diff --git a/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestResource.java b/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestResource.java
index 751c8e8..fb221a7 100644
--- a/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestResource.java
+++ b/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestResource.java
@@ -68,4 +68,26 @@ public class RestResource {
         return producerTemplate.requestBodyAndHeaders(
                 "rest:get:/rest/template/{messageStart}/{messageEnd}?host=localhost:" + port, null, headers, String.class);
     }
+
+    @Path("/producer/binding/mode/json")
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public Person restProducerBindingModeJson(@QueryParam("port") int port) {
+        String query = "rest:get:/rest/binding/json/producer" +
+                "?bindingMode=json" +
+                "&outType=org.apache.camel.quarkus.component.rest.it.Person" +
+                "&host=localhost:" + port;
+        return producerTemplate.requestBody(query, null, Person.class);
+    }
+
+    @Path("/producer/binding/mode/xml")
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public Person restProducerBindingModeXml(@QueryParam("port") int port) {
+        String query = "rest:get:/rest/binding/xml/producer" +
+                "?bindingMode=xml" +
+                "&outType=org.apache.camel.quarkus.component.rest.it.Person" +
+                "&host=localhost:" + port;
+        return producerTemplate.requestBody(query, null, Person.class);
+    }
 }
diff --git a/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestRoutes.java b/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestRoutes.java
index dc2c079..88189f2 100644
--- a/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestRoutes.java
+++ b/integration-tests/rest/src/main/java/org/apache/camel/quarkus/component/rest/it/RestRoutes.java
@@ -27,6 +27,8 @@ public class RestRoutes extends RouteBuilder {
 
     @Override
     public void configure() {
+        final String personJson = "{\"firstName\": \"John\", \"lastName\": \"Doe\", \"age\": 64}";
+        final String personXml = "<person firstName=\"John\" lastName=\"Doe\" age=\"64\"/>";
         restConfiguration()
                 .enableCORS(true)
                 .corsAllowCredentials(true)
@@ -68,6 +70,11 @@ public class RestRoutes extends RouteBuilder {
                 .setHeader(Exchange.CONTENT_TYPE, constant("text/plain"))
                 .endRest()
 
+                .get("/binding/json/producer")
+                .route()
+                .setBody(constant(personJson))
+                .endRest()
+
                 .post("/pojo/binding/xml")
                 .bindingMode(RestBindingMode.xml)
                 .type(Person.class)
@@ -77,6 +84,11 @@ public class RestRoutes extends RouteBuilder {
                 .setHeader(Exchange.CONTENT_TYPE, constant("text/plain"))
                 .endRest()
 
+                .get("/binding/xml/producer")
+                .route()
+                .setBody(constant(personXml))
+                .endRest()
+
                 .post("/log")
                 .route()
                 .log("Hello ${body}")
diff --git a/integration-tests/rest/src/test/java/org/apache/camel/quarkus/component/rest/it/RestTest.java b/integration-tests/rest/src/test/java/org/apache/camel/quarkus/component/rest/it/RestTest.java
index 7104371..be25dca 100644
--- a/integration-tests/rest/src/test/java/org/apache/camel/quarkus/component/rest/it/RestTest.java
+++ b/integration-tests/rest/src/test/java/org/apache/camel/quarkus/component/rest/it/RestTest.java
@@ -25,9 +25,11 @@ import org.junit.jupiter.api.Test;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.matchesPattern;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 @QuarkusTest
 class RestTest {
+    private static final Person person = new Person("John", "Doe", 64);
 
     @Test
     public void inspectConfiguration() {
@@ -107,11 +109,6 @@ class RestTest {
 
     @Test
     public void jsonBinding() {
-        Person person = new Person();
-        person.setFirstName("John");
-        person.setLastName("Doe");
-        person.setAge(64);
-
         String result = String.format(
                 "Name: %s %s, Age: %d",
                 person.getFirstName(),
@@ -128,12 +125,20 @@ class RestTest {
     }
 
     @Test
-    public void xmlBinding() {
-        Person person = new Person();
-        person.setFirstName("John");
-        person.setLastName("Doe");
-        person.setAge(64);
+    public void jsonBindingProducer() {
+        Person respondPerson = RestAssured.given()
+                .queryParam("port", RestAssured.port)
+                .get("/rest/producer/binding/mode/json")
+                .then()
+                .statusCode(200)
+                .extract()
+                .body()
+                .as(Person.class);
+        assertEquals(respondPerson, person);
+    }
 
+    @Test
+    public void xmlBinding() {
         String result = String.format(
                 "Name: %s %s, Age: %d",
                 person.getFirstName(),
@@ -150,6 +155,19 @@ class RestTest {
     }
 
     @Test
+    public void xmlBindingProducer() {
+        Person respondPerson = RestAssured.given()
+                .queryParam("port", RestAssured.port)
+                .get("/rest/producer/binding/mode/xml")
+                .then()
+                .statusCode(200)
+                .extract()
+                .body()
+                .as(Person.class);
+        assertEquals(respondPerson, person);
+    }
+
+    @Test
     public void testRestProducer() {
         RestAssured.given()
                 .queryParam("port", RestAssured.port)