From 2ab678fdea261a44935c21e134c4d85c6c4db462 Mon Sep 17 00:00:00 2001 From: Justin Lee Date: Wed, 6 Jul 2022 12:18:34 -0400 Subject: [PATCH] reenable tests on Windows --- .github/native-tests.json | 2 +- extensions/mongodb-client/deployment/pom.xml | 1 - .../mongodb/NamedMongoClientConfigTest.java | 1 - extensions/mongodb-client/runtime/pom.xml | 2 - integration-tests/liquibase-mongodb/pom.xml | 2 - integration-tests/mongodb-client/pom.xml | 28 ---- .../io/quarkus/it/mongodb/BookResource.java | 19 --- .../src/main/resources/application.properties | 3 - integration-tests/mongodb-devservices/pom.xml | 144 ++++++++++++++++++ .../main/java/io/quarkus/it/mongodb/Book.java | 64 ++++++++ .../java/io/quarkus/it/mongodb/BookCodec.java | 75 +++++++++ .../quarkus/it/mongodb/BookCodecProvider.java | 26 ++++ .../io/quarkus/it/mongodb/BookDetail.java | 29 ++++ .../io/quarkus/it/mongodb/BookResource.java | 66 ++++++++ .../BookResourceWithParameterInjection.java | 64 ++++++++ .../it/mongodb/ReactiveBookResource.java | 45 ++++++ .../src/main/resources/application.properties | 1 + .../quarkus/it/mongodb/BookResourceTest.java | 60 ++++++++ ...ookResourceWithParameterInjectionTest.java | 36 +++++ .../it/mongodb/NativeBookResourceIT.java | 8 + ...eBookResourceWithParameterInjectionIT.java | 8 + .../java/io/quarkus/it/mongodb/Utils.java | 94 ++++++++++++ integration-tests/pom.xml | 1 + 23 files changed, 722 insertions(+), 57 deletions(-) create mode 100644 integration-tests/mongodb-devservices/pom.xml create mode 100644 integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/Book.java create mode 100644 integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodec.java create mode 100644 integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodecProvider.java create mode 100644 integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookDetail.java create mode 100644 integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResource.java create mode 100644 integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResourceWithParameterInjection.java create mode 100644 integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/ReactiveBookResource.java create mode 100644 integration-tests/mongodb-devservices/src/main/resources/application.properties create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceTest.java create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceWithParameterInjectionTest.java create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceIT.java create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceWithParameterInjectionIT.java create mode 100644 integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/Utils.java diff --git a/.github/native-tests.json b/.github/native-tests.json index 42b2bb72aa43b..0b156500b0696 100644 --- a/.github/native-tests.json +++ b/.github/native-tests.json @@ -27,7 +27,7 @@ { "category": "Data4", "timeout": 55, - "test-modules": "mongodb-client, mongodb-panache, mongodb-rest-data-panache, mongodb-panache-kotlin, redis-client, hibernate-orm-rest-data-panache", + "test-modules": "mongodb-client, mongodb-devservices, mongodb-panache, mongodb-rest-data-panache, mongodb-panache-kotlin, redis-client, hibernate-orm-rest-data-panache", "os-name": "ubuntu-latest" }, { diff --git a/extensions/mongodb-client/deployment/pom.xml b/extensions/mongodb-client/deployment/pom.xml index 0e560af6b43af..0b0278fa0db2c 100644 --- a/extensions/mongodb-client/deployment/pom.xml +++ b/extensions/mongodb-client/deployment/pom.xml @@ -136,5 +136,4 @@ - diff --git a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedMongoClientConfigTest.java b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedMongoClientConfigTest.java index 35c2796f90fd4..f832a61d377b4 100644 --- a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedMongoClientConfigTest.java +++ b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedMongoClientConfigTest.java @@ -24,7 +24,6 @@ import io.quarkus.test.QuarkusUnitTest; public class NamedMongoClientConfigTest extends MongoWithReplicasTestBase { - @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar.addClasses(MongoTestBase.class)) diff --git a/extensions/mongodb-client/runtime/pom.xml b/extensions/mongodb-client/runtime/pom.xml index 797068f992ec8..818bfa801a333 100644 --- a/extensions/mongodb-client/runtime/pom.xml +++ b/extensions/mongodb-client/runtime/pom.xml @@ -160,6 +160,4 @@ - - \ No newline at end of file diff --git a/integration-tests/liquibase-mongodb/pom.xml b/integration-tests/liquibase-mongodb/pom.xml index dc1d8393d2d02..1ac94cf7a9ce6 100644 --- a/integration-tests/liquibase-mongodb/pom.xml +++ b/integration-tests/liquibase-mongodb/pom.xml @@ -101,6 +101,4 @@ - - \ No newline at end of file diff --git a/integration-tests/mongodb-client/pom.xml b/integration-tests/mongodb-client/pom.xml index 263b83df131bd..cdc3233a1939f 100644 --- a/integration-tests/mongodb-client/pom.xml +++ b/integration-tests/mongodb-client/pom.xml @@ -113,32 +113,4 @@ - - - - no-windows - - - windows - - - - - - maven-surefire-plugin - - true - - - - maven-failsafe-plugin - - true - - - - - - - diff --git a/integration-tests/mongodb-client/src/main/java/io/quarkus/it/mongodb/BookResource.java b/integration-tests/mongodb-client/src/main/java/io/quarkus/it/mongodb/BookResource.java index c0a0f3be966ca..6cd9516fad11e 100644 --- a/integration-tests/mongodb-client/src/main/java/io/quarkus/it/mongodb/BookResource.java +++ b/integration-tests/mongodb-client/src/main/java/io/quarkus/it/mongodb/BookResource.java @@ -25,25 +25,10 @@ public class BookResource { @MongoClientName("parameter-injection") MongoClient client; - @Inject - @MongoClientName("dev-services") - MongoClient devServiced; - @Inject - @MongoClientName("dev-services2") - MongoClient devServiced2; - private MongoCollection getCollection() { return client.getDatabase("books").getCollection("my-collection", Book.class); } - private MongoCollection getServicedCollection() { - return devServiced.getDatabase("books").getCollection("my-collection", Book.class); - } - - private MongoCollection getServiced2Collection() { - return devServiced.getDatabase("books").getCollection("my-collection", Book.class); - } - @GET public List getBooks() { FindIterable iterable = getCollection().find(); @@ -61,16 +46,12 @@ public List getBooks() { @POST public Response addBook(Book book) { getCollection().insertOne(book); - getServicedCollection().insertOne(book); - getServiced2Collection().insertOne(book); return Response.accepted().build(); } @GET @Path("/{author}") public List getBooksByAuthor(@PathParam("author") String author) { - getServicedCollection().find(eq("author", author)); - getServiced2Collection().find(eq("author", author)); FindIterable iterable = getCollection().find(eq("author", author)); List books = new ArrayList<>(); for (Book doc : iterable) { diff --git a/integration-tests/mongodb-client/src/main/resources/application.properties b/integration-tests/mongodb-client/src/main/resources/application.properties index 7a4459055e559..a96bcf0f1e841 100644 --- a/integration-tests/mongodb-client/src/main/resources/application.properties +++ b/integration-tests/mongodb-client/src/main/resources/application.properties @@ -2,6 +2,3 @@ quarkus.mongodb.connection-string=mongodb://localhost:27017 quarkus.mongodb.write-concern.journal=false quarkus.mongodb.parameter-injection.connection-string=mongodb://localhost:27017 quarkus.mongodb.parameter-injection.write-concern.journal=true - -quarkus.mongodb.dev-services.write-concern.journal=false -quarkus.mongodb.dev-services2.write-concern.journal=false diff --git a/integration-tests/mongodb-devservices/pom.xml b/integration-tests/mongodb-devservices/pom.xml new file mode 100644 index 0000000000000..27bab79ef5145 --- /dev/null +++ b/integration-tests/mongodb-devservices/pom.xml @@ -0,0 +1,144 @@ + + + 4.0.0 + + + io.quarkus + quarkus-integration-tests-parent + 999-SNAPSHOT + + + quarkus-integration-test-mongodb-devservices + + Quarkus - Integration Tests - MongoDB DevServices + + + + io.quarkus + quarkus-resteasy-reactive-jsonb + + + io.quarkus + quarkus-mongodb-client + + + + io.quarkus + quarkus-smallrye-health + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + com.fasterxml.jackson.core + jackson-databind + test + + + io.quarkus + quarkus-test-mongodb + test + + + + + io.quarkus + quarkus-mongodb-client-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-resteasy-reactive-jsonb-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-smallrye-health-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + src/main/resources + true + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + + + + + no-windows + + + windows + + + + + + maven-surefire-plugin + + true + + + + maven-failsafe-plugin + + true + + + + + + + + diff --git a/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/Book.java b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/Book.java new file mode 100644 index 0000000000000..fa7c69d0ab4e9 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/Book.java @@ -0,0 +1,64 @@ +package io.quarkus.it.mongodb; + +import java.util.ArrayList; +import java.util.List; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class Book { + + private String id; + + private String title; + private String author; + + private List categories = new ArrayList<>(); + + private BookDetail details; + + public String getTitle() { + return title; + } + + public Book setTitle(String title) { + this.title = title; + return this; + } + + public String getId() { + return id; + } + + public Book setId(String id) { + this.id = id; + return this; + } + + public String getAuthor() { + return author; + } + + public Book setAuthor(String author) { + this.author = author; + return this; + } + + public List getCategories() { + return categories; + } + + public Book setCategories(List categories) { + this.categories = categories; + return this; + } + + public BookDetail getDetails() { + return details; + } + + public Book setDetails(BookDetail details) { + this.details = details; + return this; + } +} diff --git a/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodec.java b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodec.java new file mode 100644 index 0000000000000..5455d27e962f7 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodec.java @@ -0,0 +1,75 @@ +package io.quarkus.it.mongodb; + +import java.util.Collections; +import java.util.UUID; + +import org.bson.*; +import org.bson.codecs.Codec; +import org.bson.codecs.CollectibleCodec; +import org.bson.codecs.DecoderContext; +import org.bson.codecs.EncoderContext; + +import com.mongodb.MongoClientSettings; + +public class BookCodec implements CollectibleCodec { + + private final Codec documentCodec; + + public BookCodec() { + this.documentCodec = MongoClientSettings.getDefaultCodecRegistry().get(Document.class); + } + + @Override + public void encode(BsonWriter writer, Book book, EncoderContext encoderContext) { + Document doc = new Document(); + doc.put("author", book.getAuthor()); + doc.put("title", book.getTitle()); + doc.put("categories", book.getCategories()); + Document details = new Document(); + details.put("summary", book.getDetails().getSummary()); + details.put("rating", book.getDetails().getRating()); + doc.put("details", details); + documentCodec.encode(writer, doc, encoderContext); + } + + @Override + public Class getEncoderClass() { + return Book.class; + } + + @Override + public Book generateIdIfAbsentFromDocument(Book document) { + if (!documentHasId(document)) { + document.setId(UUID.randomUUID().toString()); + } + return document; + } + + @Override + public boolean documentHasId(Book document) { + return document.getId() != null; + } + + @Override + public BsonValue getDocumentId(Book document) { + return new BsonString(document.getId()); + } + + @Override + public Book decode(BsonReader reader, DecoderContext decoderContext) { + Document document = documentCodec.decode(reader, decoderContext); + Book book = new Book(); + if (document.getString("id") != null) { + book.setId(document.getString("id")); + } + book.setTitle(document.getString("title")); + book.setAuthor(document.getString("author")); + book.setCategories(document.getList("categories", String.class)); + BookDetail details = new BookDetail(); + Document embedded = document.getEmbedded(Collections.singletonList("details"), Document.class); + details.setRating(embedded.getInteger("rating")); + details.setSummary(embedded.getString("summary")); + book.setDetails(details); + return book; + } +} diff --git a/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodecProvider.java b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodecProvider.java new file mode 100644 index 0000000000000..5a02e74d82f2d --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookCodecProvider.java @@ -0,0 +1,26 @@ +package io.quarkus.it.mongodb; + +import javax.json.bind.Jsonb; + +import org.bson.codecs.Codec; +import org.bson.codecs.configuration.CodecProvider; +import org.bson.codecs.configuration.CodecRegistry; + +public class BookCodecProvider implements CodecProvider { + + // this is just to verify that this class is a bean and is properly instantiated by the CDI container + private final Jsonb jsonb; + + public BookCodecProvider(Jsonb jsonb) { + this.jsonb = jsonb; + } + + @Override + public Codec get(Class clazz, CodecRegistry registry) { + if (clazz == Book.class) { + return (Codec) new BookCodec(); + } + return null; + } + +} diff --git a/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookDetail.java b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookDetail.java new file mode 100644 index 0000000000000..434e5606d0122 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookDetail.java @@ -0,0 +1,29 @@ +package io.quarkus.it.mongodb; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class BookDetail { + + private String summary; + + private int rating; + + public String getSummary() { + return summary; + } + + public BookDetail setSummary(String summary) { + this.summary = summary; + return this; + } + + public int getRating() { + return rating; + } + + public BookDetail setRating(int rating) { + this.rating = rating; + return this; + } +} diff --git a/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResource.java b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResource.java new file mode 100644 index 0000000000000..2ace7845a9407 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResource.java @@ -0,0 +1,66 @@ +package io.quarkus.it.mongodb; + +import static com.mongodb.client.model.Filters.eq; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; + +import org.bson.BsonObjectId; + +import com.mongodb.WriteConcern; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.result.InsertOneResult; + +import io.smallrye.common.annotation.Blocking; + +@Path("/books") +@Blocking +public class BookResource { + + @Inject + MongoClient client; + + private MongoCollection getCollection() { + return client.getDatabase("books").getCollection("my-collection", Book.class); + } + + @GET + public List getBooks() { + FindIterable iterable = getCollection().find(); + List books = new ArrayList<>(); + WriteConcern writeConcern = client.getDatabase("temp").getWriteConcern(); + // force a test failure if we're not getting the correct, and correctly configured named mongodb client + for (Book doc : iterable) { + books.add(doc); + } + return books; + } + + @POST + public Response addBook(Book book) { + InsertOneResult insertOneResult = getCollection().insertOne(book); + BsonObjectId insertedId = (BsonObjectId) insertOneResult.getInsertedId(); + return Response.accepted() + .entity(insertedId.getValue().toString()) + .build(); + } + + @GET + @Path("/{author}") + public List getBooksByAuthor(@PathParam("author") String author) { + FindIterable iterable = getCollection().find(eq("author", author)); + List books = new ArrayList<>(); + for (Book doc : iterable) { + String title = doc.getTitle(); + books.add(new Book().setTitle(title).setAuthor(author)); + } + return books; + } + +} diff --git a/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResourceWithParameterInjection.java b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResourceWithParameterInjection.java new file mode 100644 index 0000000000000..f834311622d0e --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/BookResourceWithParameterInjection.java @@ -0,0 +1,64 @@ +package io.quarkus.it.mongodb; + +import static com.mongodb.client.model.Filters.eq; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoCollection; + +import io.quarkus.mongodb.MongoClientName; +import io.smallrye.common.annotation.Blocking; + +@Path("/books-with-parameter-injection") +@Blocking +public class BookResourceWithParameterInjection { + private final MongoClient client; + + @Inject + public BookResourceWithParameterInjection(@MongoClientName("parameter-injection") MongoClient client) { + this.client = client; + } + + private MongoCollection getCollection() { + return client.getDatabase("books").getCollection("books-with-parameter-injection", Book.class); + } + + @GET + public List getBooks() { + FindIterable iterable = getCollection().find(); + List books = new ArrayList<>(); + for (Book doc : iterable) { + books.add(doc); + } + return books; + } + + @POST + public Response addBook(Book book) { + getCollection().insertOne(book); + return Response.accepted().build(); + } + + @GET + @Path("/{author}") + public List getBooksByAuthor(@PathParam("author") String author) { + FindIterable iterable = getCollection().find(eq("author", author)); + List books = new ArrayList<>(); + for (Book doc : iterable) { + String title = doc.getTitle(); + books.add(new Book().setTitle(title).setAuthor(author)); + } + return books; + } + +} diff --git a/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/ReactiveBookResource.java b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/ReactiveBookResource.java new file mode 100644 index 0000000000000..940e0ae46505c --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/java/io/quarkus/it/mongodb/ReactiveBookResource.java @@ -0,0 +1,45 @@ +package io.quarkus.it.mongodb; + +import static com.mongodb.client.model.Filters.eq; + +import java.util.List; +import java.util.concurrent.CompletionStage; + +import javax.inject.Inject; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; + +import io.quarkus.mongodb.reactive.ReactiveMongoClient; +import io.quarkus.mongodb.reactive.ReactiveMongoCollection; + +@Path("/reactive-books") +public class ReactiveBookResource { + + @Inject + ReactiveMongoClient client; + + private ReactiveMongoCollection getCollection() { + return client.getDatabase("books").getCollection("my-reactive-collection", Book.class); + } + + @GET + public CompletionStage> getBooks() { + return getCollection().find().collect().asList().subscribeAsCompletionStage(); + } + + @POST + public CompletionStage addBook(Book book) { + return getCollection().insertOne(book) + .onItem().transform(x -> Response.accepted().build()) + .subscribeAsCompletionStage(); + } + + @GET + @Path("/{author}") + public CompletionStage> getBooksByAuthor(@PathParam("author") String author) { + return getCollection().find(eq("author", author)) + .collect().asList() + .subscribeAsCompletionStage(); + } + +} diff --git a/integration-tests/mongodb-devservices/src/main/resources/application.properties b/integration-tests/mongodb-devservices/src/main/resources/application.properties new file mode 100644 index 0000000000000..1f3eb22132370 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/main/resources/application.properties @@ -0,0 +1 @@ +quarkus.mongodb.parameter-injection.write-concern.journal=true diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceTest.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceTest.java new file mode 100644 index 0000000000000..06c7ec0952eda --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceTest.java @@ -0,0 +1,60 @@ +package io.quarkus.it.mongodb; + +import static io.restassured.RestAssured.get; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.is; + +import javax.json.bind.Jsonb; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; + +import io.quarkus.mongodb.health.MongoHealthCheck; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.mongodb.MongoTestResource; +import io.restassured.RestAssured; + +@QuarkusTest +@QuarkusTestResource(MongoTestResource.class) +@DisabledOnOs(OS.WINDOWS) +public class BookResourceTest { + private static Jsonb jsonb; + + @BeforeAll + public static void giveMeAMapper() { + jsonb = Utils.initialiseJsonb(); + } + + @AfterAll + public static void releaseMapper() throws Exception { + jsonb.close(); + } + + @Test + public void testBlockingClient() { + Utils.callTheEndpoint("/books"); + } + + @Test + public void testReactiveClients() { + Utils.callTheEndpoint("/reactive-books"); + } + + @Test + public void health() throws Exception { + // trigger (lazy) creation of the client, otherwise the health check would fail + get("/books"); + RestAssured.when().get("/q/health/ready").then() + .body("status", is("UP"), + "checks.data", containsInAnyOrder(hasKey(MongoHealthCheck.CLIENT_DEFAULT)), + "checks.data", containsInAnyOrder(hasKey(MongoHealthCheck.CLIENT_DEFAULT_REACTIVE)), + "checks.status", containsInAnyOrder("UP"), + "checks.name", containsInAnyOrder("MongoDB connection health check")); + } + +} diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceWithParameterInjectionTest.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceWithParameterInjectionTest.java new file mode 100644 index 0000000000000..ad3d182e6e8ba --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/BookResourceWithParameterInjectionTest.java @@ -0,0 +1,36 @@ +package io.quarkus.it.mongodb; + +import javax.json.bind.Jsonb; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.mongodb.MongoTestResource; + +@QuarkusTest +@QuarkusTestResource(MongoTestResource.class) +@DisabledOnOs(OS.WINDOWS) +public class BookResourceWithParameterInjectionTest { + + private static Jsonb jsonb; + + @BeforeAll + public static void giveMeAMapper() { + jsonb = Utils.initialiseJsonb(); + } + + @AfterAll + public static void releaseMapper() throws Exception { + jsonb.close(); + } + + @Test + public void testInjectedClient() { + Utils.callTheEndpoint("/books-with-parameter-injection"); + } +} diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceIT.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceIT.java new file mode 100644 index 0000000000000..e5214f022df38 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceIT.java @@ -0,0 +1,8 @@ +package io.quarkus.it.mongodb; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class NativeBookResourceIT extends BookResourceTest { + +} diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceWithParameterInjectionIT.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceWithParameterInjectionIT.java new file mode 100644 index 0000000000000..c399ad0ecde93 --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/NativeBookResourceWithParameterInjectionIT.java @@ -0,0 +1,8 @@ +package io.quarkus.it.mongodb; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class NativeBookResourceWithParameterInjectionIT extends BookResourceWithParameterInjectionTest { + +} diff --git a/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/Utils.java b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/Utils.java new file mode 100644 index 0000000000000..726c22d22b95c --- /dev/null +++ b/integration-tests/mongodb-devservices/src/test/java/io/quarkus/it/mongodb/Utils.java @@ -0,0 +1,94 @@ +package io.quarkus.it.mongodb; + +import static io.restassured.RestAssured.get; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import javax.json.bind.Jsonb; +import javax.json.bind.JsonbBuilder; + +import org.junit.jupiter.api.Assertions; + +import io.restassured.RestAssured; +import io.restassured.common.mapper.TypeRef; +import io.restassured.config.ObjectMapperConfig; +import io.restassured.mapper.ObjectMapper; +import io.restassured.mapper.ObjectMapperDeserializationContext; +import io.restassured.mapper.ObjectMapperSerializationContext; +import io.restassured.response.Response; + +class Utils { + static Jsonb initialiseJsonb() { + Jsonb jsonb = JsonbBuilder.create(); + ObjectMapper mapper = new ObjectMapper() { + @Override + public Object deserialize(ObjectMapperDeserializationContext context) { + return jsonb.fromJson(context.getDataToDeserialize().asString(), context.getType()); + } + + @Override + public Object serialize(ObjectMapperSerializationContext context) { + return jsonb.toJson(context.getObjectToSerialize()); + } + }; + RestAssured.config().objectMapperConfig(ObjectMapperConfig.objectMapperConfig().defaultObjectMapper(mapper)); + + return jsonb; + } + + static void callTheEndpoint(String endpoint) { + List list = get(endpoint).as(new TypeRef>() { + }); + Assertions.assertEquals(0, list.size()); + + Book book1 = new Book().setAuthor("Victor Hugo").setTitle("Les Misérables") + .setCategories(Arrays.asList("long", "very long")) + .setDetails(new BookDetail().setRating(3).setSummary("A very long book")); + Response response = RestAssured + .given() + .header("Content-Type", "application/json") + .body(book1) + .post(endpoint) + .andReturn(); + Assertions.assertEquals(202, response.statusCode()); + Assertions.assertNotNull(response.getBody().asString()); + + Book book2 = new Book().setAuthor("Victor Hugo").setTitle("Notre-Dame de Paris") + .setCategories(Arrays.asList("long", "quasimodo")) + .setDetails(new BookDetail().setRating(4).setSummary("quasimodo and esmeralda")); + response = RestAssured + .given() + .header("Content-Type", "application/json") + .body(book2) + .post(endpoint) + .andReturn(); + Assertions.assertEquals(202, response.statusCode()); + Assertions.assertNotNull(response.getBody().asString()); + + list = get(endpoint).as(new TypeRef>() { + }); + Assertions.assertEquals(2, list.size()); + + Book book3 = new Book().setAuthor("Charles Baudelaire").setTitle("Les fleurs du mal") + .setCategories(Collections.singletonList("poem")) + .setDetails(new BookDetail().setRating(2).setSummary("Les Fleurs du mal is a volume of poetry.")); + response = RestAssured + .given() + .header("Content-Type", "application/json") + .body(book3) + .post(endpoint) + .andReturn(); + Assertions.assertEquals(202, response.statusCode()); + + list = get(endpoint).as(new TypeRef>() { + }); + Assertions.assertEquals(3, list.size()); + + list = get(endpoint + "/Victor Hugo").as(new TypeRef>() { + }); + Assertions.assertEquals(2, list.size()); + } + +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index f89de80a68b31..cc25f038c085e 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -248,6 +248,7 @@ kubernetes-service-binding-reactive openshift-client mongodb-client + mongodb-devservices jackson jsonb resteasy-jackson