Skip to content

Commit

Permalink
add test for custom serializer usage when reflection free serializati…
Browse files Browse the repository at this point in the history
…on is enabled
  • Loading branch information
mariofusco committed Oct 14, 2024
1 parent 8d1764e commit 18ccfcf
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.it.mongodb.panache.product;

import org.bson.types.ObjectId;

public class Product {

private ObjectId id;

public ObjectId getId() {
return id;
}

public void setId(ObjectId id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.mongodb.panache.product;

import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import org.bson.types.ObjectId;

@Path("/products")
@RequestScoped
public class ProductResource {

public static final String PRODUCT_ID = "66fe4c9df58b4c036cc92298";

@GET
public Product get() {
var product = new Product();
product.setId(new ObjectId(PRODUCT_ID));
return product;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.it.mongodb.panache;

import java.util.Map;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import io.quarkus.it.mongodb.panache.product.ProductResource;
import io.quarkus.it.mongodb.panache.reactive.ReactiveMongodbPanacheResourceTest;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.restassured.RestAssured;

@QuarkusTest
@TestProfile(ReflectionFreeSerializationTest.ReflectionFreeSerializationProfile.class)
public class ReflectionFreeSerializationTest {

@Test
void testObjectICustomSerialization() {
RestAssured.get("/products")
.then()
.statusCode(200)
.body("id", Matchers.equalTo(ProductResource.PRODUCT_ID));
}

@Test
void testReactiveBookEntity() throws InterruptedException {
ReactiveMongodbPanacheResourceTest.callReactiveBookEndpoint("/reactive/books/entity");
}

public static class ReflectionFreeSerializationProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Map.of("quarkus.rest.jackson.optimization.enable-reflection-free-serializers", "true");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import io.restassured.response.Response;

@QuarkusTest
class ReactiveMongodbPanacheResourceTest {
public class ReactiveMongodbPanacheResourceTest {
private static final TypeRef<List<BookDTO>> LIST_OF_BOOK_TYPE_REF = new TypeRef<List<BookDTO>>() {
};
private static final TypeRef<List<Person>> LIST_OF_PERSON_TYPE_REF = new TypeRef<List<Person>>() {
Expand All @@ -67,7 +67,7 @@ public void testReactivePersonRepository() {
callReactivePersonEndpoint("/reactive/persons/repository");
}

private void callReactiveBookEndpoint(String endpoint) throws InterruptedException {
public static void callReactiveBookEndpoint(String endpoint) throws InterruptedException {
RestAssured.defaultParser = Parser.JSON;
ObjectMapper objectMapper = new ObjectMapper()
.registerModule(new Jdk8Module())
Expand Down Expand Up @@ -333,7 +333,7 @@ private void callReactivePersonEndpoint(String endpoint) {
assertEquals(0, count);
}

private Date yearToDate(int year) {
private static Date yearToDate(int year) {
Calendar cal = new GregorianCalendar();
cal.set(year, 1, 1);
return cal.getTime();
Expand Down

0 comments on commit 18ccfcf

Please sign in to comment.