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 2023/02/08 10:00:20 UTC
[camel-quarkus] 06/40: Workaround #4490 REST-Assured does not support JSON-B 3.0/Jakarta EE 10
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
commit 41881285b6d45e2ac04d16429345914982513b98
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Mon Feb 6 09:14:08 2023 +0100
Workaround #4490 REST-Assured does not support JSON-B 3.0/Jakarta EE 10
---
.../component/atlasmap/it/AtlasmapTest.java | 16 +++++++++--
.../camel/quarkus/component/jpa/it/JpaTest.java | 32 ++++++++++++----------
.../camel/quarkus/component/mail/MailTest.java | 29 +++++++++++---------
.../messaging/it/AbstractMessagingTest.java | 3 +-
4 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java b/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java
index 1a1e11508b..fba6f7944f 100644
--- a/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java
+++ b/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.quarkus.component.atlasmap.it;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
@@ -36,7 +38,7 @@ class AtlasmapTest {
Person person = new Person("foo", "bar", 35);
given()
.contentType(ContentType.JSON)
- .body(person)
+ .body(toJson(person))
.when()
.get("/json/java2json")
.then()
@@ -104,13 +106,21 @@ class AtlasmapTest {
String expectedResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><tns:Person xmlns:tns=\"http://hl7.org/fhir\"><tns:firstName value=\"foo\"/><tns:lastName value=\"bar\"/><tns:age value=\"35\"/></tns:Person>";
given()
.contentType(ContentType.JSON)
- .body(request)
+ .body(toJson(request))
.when()
.get("/json/java2xml")
.then()
.body(equalTo(expectedResponse));
}
+ static String toJson(Object request) {
+ try {
+ return new ObjectMapper().writeValueAsString(request);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Could not serialize " + request.getClass().getName() + " " + request, e);
+ }
+ }
+
@Test
void testXml2JavaWithJson() {
String request = "<tns:Person xmlns:tns=\"http://hl7.org/fhir\"><tns:firstName value=\"foo\"/><tns:lastName value=\"bar\"/><tns:age value=\"35\"/></tns:Person>";
@@ -268,7 +278,7 @@ class AtlasmapTest {
Account person = new Account("1", "user");
given()
.contentType(ContentType.JSON)
- .body(person)
+ .body(toJson(person))
.when()
.post("/json/java2csv")
.then()
diff --git a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java
index 55bea5834f..5bfd83e592 100644
--- a/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java
+++ b/integration-tests/jpa/src/test/java/org/apache/camel/quarkus/component/jpa/it/JpaTest.java
@@ -22,6 +22,7 @@ import java.util.stream.IntStream;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
+import jakarta.json.bind.JsonbBuilder;
import org.apache.camel.quarkus.component.jpa.it.model.Fruit;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
@@ -49,7 +50,7 @@ class JpaTest {
for (String fruit : FRUITS) {
RestAssured.given()
.contentType(ContentType.JSON)
- .body(new Fruit(fruit))
+ .body(JsonbBuilder.create().toJson(new Fruit(fruit)))
.post("/jpa/fruit")
.then()
.statusCode(201);
@@ -94,39 +95,38 @@ class JpaTest {
@Test
public void testTransaction() {
- Fruit accepted = new Fruit("Grapes");
- Fruit rejected = new Fruit("Potato");
+ final Fruit rejected = new Fruit("Potato");
- accepted = RestAssured.given()
+ final int acceptedId = RestAssured.given()
.contentType(ContentType.JSON)
- .body(accepted)
+ .body(JsonbBuilder.create().toJson(new Fruit("Grapes")))
.post("/jpa/direct/transaction")
.then()
.statusCode(200)
.body("id", notNullValue())
.body("name", is("Grapes"))
- .extract().body().as(Fruit.class);
+ .extract().jsonPath().getInt("id");
try {
RestAssured.given()
.contentType(ContentType.JSON)
- .body(rejected)
+ .body(JsonbBuilder.create().toJson(rejected))
.header("rollback", true)
.post("/jpa/direct/transaction")
.then()
.statusCode(500);
- RestAssured.get("/jpa/fruit/named/" + accepted.getName())
+ RestAssured.get("/jpa/fruit/named/Grapes")
.then()
.statusCode(200)
- .body("name", contains(accepted.getName()));
+ .body("name", contains("Grapes"));
RestAssured.get("/jpa/fruit/named/" + rejected.getName())
.then()
.statusCode(200)
.body("$.size()", is(0));
} finally {
- RestAssured.delete("/jpa/fruit/" + accepted.getId())
+ RestAssured.delete("/jpa/fruit/" + acceptedId)
.then()
.statusCode(200);
}
@@ -137,7 +137,7 @@ class JpaTest {
IntStream.of(1, 2, 1, 3, 2).forEach((id) -> {
RestAssured.given()
.contentType(ContentType.JSON)
- .body(new Fruit(Integer.toString(id)))
+ .body(JsonbBuilder.create().toJson(new Fruit(Integer.toString(id))))
.header("messageId", id)
.post("/jpa/direct/idempotent")
.then()
@@ -160,9 +160,11 @@ class JpaTest {
}
public Fruit findFruit(int id) {
- return RestAssured.get("/jpa/fruit/" + id)
- .then()
- .statusCode(200)
- .extract().body().as(Fruit.class);
+ return JsonbBuilder.create().fromJson(
+ RestAssured.get("/jpa/fruit/" + id)
+ .then()
+ .statusCode(200)
+ .extract().body().asString(),
+ Fruit.class);
}
}
diff --git a/integration-tests/mail/src/test/java/org/apache/camel/quarkus/component/mail/MailTest.java b/integration-tests/mail/src/test/java/org/apache/camel/quarkus/component/mail/MailTest.java
index 3503fea28e..5750046c91 100644
--- a/integration-tests/mail/src/test/java/org/apache/camel/quarkus/component/mail/MailTest.java
+++ b/integration-tests/mail/src/test/java/org/apache/camel/quarkus/component/mail/MailTest.java
@@ -34,6 +34,7 @@ import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
+import jakarta.json.bind.JsonbBuilder;
import org.apache.camel.ExchangePropertyKey;
import org.apache.camel.ServiceStatus;
import org.eclipse.microprofile.config.Config;
@@ -136,10 +137,10 @@ public class MailTest {
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
//receive
- return (List<Map<String, Object>>) RestAssured.get("/mail/getReceived/")
+ return (List<Map<String, Object>>) JsonbBuilder.create().fromJson(RestAssured.get("/mail/getReceived/")
.then()
.statusCode(200)
- .extract().as(List.class);
+ .extract().body().asString(), List.class);
}, list -> list.size() == 1
&& "Hi how are you".equals(list.get(0).get("content"))
&& "Hello World".equals(list.get(0).get("subject")));
@@ -208,10 +209,10 @@ public class MailTest {
.statusCode(204);
Awaitility.await().atMost(20, TimeUnit.SECONDS).until(() -> {
- return (List<Map<String, Object>>) RestAssured.get("/mail/getReceived/")
+ return (List<Map<String, Object>>) JsonbBuilder.create().fromJson(RestAssured.get("/mail/getReceived/")
.then()
.statusCode(200)
- .extract().as(List.class);
+ .extract().body().asString(), List.class);
},
list -> {
if (list.size() == 2) {
@@ -261,10 +262,10 @@ public class MailTest {
Awaitility.await().atMost(20, TimeUnit.SECONDS).until(() -> {
//receive
- return (List<Map<String, Object>>) RestAssured.get("/mail/getReceived/")
+ return (List<Map<String, Object>>) JsonbBuilder.create().fromJson(RestAssured.get("/mail/getReceived/")
.then()
.statusCode(200)
- .extract().as(List.class);
+ .extract().body().asString(), List.class);
}, list -> list.size() == 4
&& "message 1".equals(list.get(0).get("content"))
@@ -306,10 +307,12 @@ public class MailTest {
Awaitility.await().atMost(20, TimeUnit.SECONDS).until(() -> {
//receive
- return (List<Map<String, Object>>) RestAssured.get("/mail/getReceivedAsString/")
- .then()
- .statusCode(200)
- .extract().as(List.class);
+ return (List<Map<String, Object>>) JsonbBuilder.create().fromJson(
+ RestAssured.get("/mail/getReceivedAsString/")
+ .then()
+ .statusCode(200)
+ .extract().body().asString(),
+ List.class);
}, list -> list.size() == 1
&& ((String) list.get(0).get("body")).matches("Hello World\\s*"));
}
@@ -320,13 +323,13 @@ public class MailTest {
//messages will be sent in reverse order
Collections.reverse(msgs);
- List<String> sorted = RestAssured.given()
+ List<String> sorted = JsonbBuilder.create().fromJson(RestAssured.given()
.contentType(ContentType.JSON)
- .body(msgs)
+ .body(JsonbBuilder.create().toJson(msgs))
.post("/mail/sort")
.then()
.statusCode(200)
- .extract().as(List.class);
+ .extract().body().asString(), List.class);
Assertions.assertEquals(4, sorted.size());
Assertions.assertTrue(sorted.get(0).contains("message 1"));
diff --git a/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java b/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java
index e5fdafc5cd..592c952532 100644
--- a/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java
+++ b/integration-tests/messaging/common/src/test/java/org/apache/camel/quarkus/component/messaging/it/AbstractMessagingTest.java
@@ -24,6 +24,7 @@ import java.util.Map;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
+import jakarta.json.bind.JsonbBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
@@ -78,7 +79,7 @@ public abstract class AbstractMessagingTest {
RestAssured.given()
.contentType(ContentType.JSON)
- .body(message)
+ .body(JsonbBuilder.create().toJson(message))
.post("/messaging/map")
.then()
.statusCode(200)