From 8645fa0e669b6d2eeb117503e938f0b0cbc5d3e2 Mon Sep 17 00:00:00 2001 From: Martin Panzer Date: Fri, 18 Dec 2020 23:59:45 +0100 Subject: [PATCH] Replace any resteasy usage with resteasy reactive in hibernate-reactive integration tests --- .../deployment/pom.xml | 5 + .../reactive/panache/test}/JAXBEntity.java | 24 +++- .../panache/test/JAXBTestResource.java | 31 +++++ .../panache/test/PanacheJAXBTest.java | 107 ++++++++++++++++++ .../hibernate-reactive-db2/pom.xml | 21 +--- .../hibernate-reactive-mysql/pom.xml | 21 +--- .../hibernate-reactive-panache/pom.xml | 93 +-------------- .../it/panache/reactive/TestEndpoint.java | 59 ---------- .../reactive/PanacheFunctionalityTest.java | 39 +------ .../hibernate-reactive-postgresql/pom.xml | 21 +--- 10 files changed, 174 insertions(+), 247 deletions(-) rename {integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive => extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test}/JAXBEntity.java (52%) create mode 100644 extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBTestResource.java create mode 100644 extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/PanacheJAXBTest.java diff --git a/extensions/panache/hibernate-reactive-panache/deployment/pom.xml b/extensions/panache/hibernate-reactive-panache/deployment/pom.xml index 2f9782c9e4e22..affa7c936abe2 100644 --- a/extensions/panache/hibernate-reactive-panache/deployment/pom.xml +++ b/extensions/panache/hibernate-reactive-panache/deployment/pom.xml @@ -69,6 +69,11 @@ quarkus-resteasy-jsonb-deployment test + + io.quarkus + quarkus-resteasy-jaxb-deployment + test + io.rest-assured rest-assured diff --git a/integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/JAXBEntity.java b/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBEntity.java similarity index 52% rename from integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/JAXBEntity.java rename to extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBEntity.java index a98da19147b32..04750e3fc2341 100644 --- a/integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/JAXBEntity.java +++ b/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBEntity.java @@ -1,8 +1,7 @@ -package io.quarkus.it.panache.reactive; +package io.quarkus.hibernate.reactive.panache.test; import javax.persistence.Entity; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; +import javax.persistence.Transient; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElements; @@ -13,7 +12,6 @@ @Entity @XmlRootElement(name = "JAXBEntity") -@XmlAccessorType(XmlAccessType.NONE) public class JAXBEntity extends PanacheEntity { @XmlAttribute(name = "Named") @@ -32,4 +30,22 @@ public class JAXBEntity extends PanacheEntity { public String arrayAnnotatedProp; public String unAnnotatedProp; + + // note that this annotation is automatically added for mapped fields, which is not the case here + // so we do it manually to emulate a mapped field situation + @XmlTransient + @Transient + public int serialisationTrick; + + public String name; + + // For JAXB: both getter and setter are required + // Here we make sure the field is not used by Hibernate, but the accessor is used by jaxb, jsonb and jackson + public int getSerialisationTrick() { + return ++serialisationTrick; + } + + public void setSerialisationTrick(int serialisationTrick) { + this.serialisationTrick = serialisationTrick; + } } diff --git a/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBTestResource.java b/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBTestResource.java new file mode 100644 index 0000000000000..b0f09cb86f10b --- /dev/null +++ b/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBTestResource.java @@ -0,0 +1,31 @@ +package io.quarkus.hibernate.reactive.panache.test; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.junit.jupiter.api.Assertions; + +@Path("test") +public class JAXBTestResource { + + @Produces(MediaType.APPLICATION_XML) + @GET + @Path("ignored-properties") + public JAXBEntity ignoredProperties() throws NoSuchMethodException, SecurityException { + JAXBEntity.class.getMethod("$$_hibernate_read_id"); + JAXBEntity.class.getMethod("$$_hibernate_read_name"); + try { + JAXBEntity.class.getMethod("$$_hibernate_read_persistent"); + Assertions.fail(); + } catch (NoSuchMethodException e) { + } + + // no need to persist it, we can fake it + JAXBEntity entity = new JAXBEntity(); + entity.id = 666l; + entity.name = "Eddie"; + return entity; + } +} diff --git a/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/PanacheJAXBTest.java b/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/PanacheJAXBTest.java new file mode 100644 index 0000000000000..6bddad2cbb999 --- /dev/null +++ b/extensions/panache/hibernate-reactive-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/PanacheJAXBTest.java @@ -0,0 +1,107 @@ +package io.quarkus.hibernate.reactive.panache.test; + +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlTransient; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; + +public class PanacheJAXBTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClasses(JAXBEntity.class, JAXBTestResource.class) + .addAsResource("application.properties")); + + @Test + public void testJaxbAnnotationTransfer() throws Exception { + // Test for fix to this bug: https://github.com/quarkusio/quarkus/issues/6021 + + // Ensure that any JAX-B annotations are properly moved to generated getters + Method m = JAXBEntity.class.getMethod("getNamedAnnotatedProp"); + XmlAttribute anno = m.getAnnotation(XmlAttribute.class); + assertNotNull(anno); + assertEquals("Named", anno.name()); + assertNull(m.getAnnotation(XmlTransient.class)); + + m = JAXBEntity.class.getMethod("getDefaultAnnotatedProp"); + anno = m.getAnnotation(XmlAttribute.class); + assertNotNull(anno); + assertEquals("##default", anno.name()); + assertNull(m.getAnnotation(XmlTransient.class)); + + m = JAXBEntity.class.getMethod("getUnAnnotatedProp"); + assertNull(m.getAnnotation(XmlAttribute.class)); + assertNull(m.getAnnotation(XmlTransient.class)); + + m = JAXBEntity.class.getMethod("getTransientProp"); + assertNull(m.getAnnotation(XmlAttribute.class)); + assertNotNull(m.getAnnotation(XmlTransient.class)); + + m = JAXBEntity.class.getMethod("getArrayAnnotatedProp"); + assertNull(m.getAnnotation(XmlTransient.class)); + XmlElements elementsAnno = m.getAnnotation(XmlElements.class); + assertNotNull(elementsAnno); + assertNotNull(elementsAnno.value()); + assertEquals(2, elementsAnno.value().length); + assertEquals("array1", elementsAnno.value()[0].name()); + assertEquals("array2", elementsAnno.value()[1].name()); + + // Ensure that all original fields were labeled @XmlTransient and had their original JAX-B annotations removed + ensureFieldSanitized("namedAnnotatedProp"); + ensureFieldSanitized("transientProp"); + ensureFieldSanitized("defaultAnnotatedProp"); + ensureFieldSanitized("unAnnotatedProp"); + ensureFieldSanitized("arrayAnnotatedProp"); + } + + private void ensureFieldSanitized(String fieldName) throws Exception { + Field f = JAXBEntity.class.getDeclaredField(fieldName); + assertNull(f.getAnnotation(XmlAttribute.class)); + assertNotNull(f.getAnnotation(XmlTransient.class)); + } + + @Test + public void testPanacheSerialisation() { + RestAssured.given().accept(ContentType.XML) + .when().get("/test/ignored-properties") + .then().body(is( + "666Eddie1")); + } + + @Test + public void jaxbDeserializationHasAllFields() throws JAXBException { + // set Up + JAXBEntity person = new JAXBEntity(); + person.name = "max"; + // do + JAXBContext jaxbContext = JAXBContext.newInstance(JAXBEntity.class); + + Marshaller marshaller = jaxbContext.createMarshaller(); + StringWriter sw = new StringWriter(); + marshaller.marshal(person, sw); + assertEquals( + "max1", + sw.toString()); + } +} diff --git a/integration-tests/hibernate-reactive-db2/pom.xml b/integration-tests/hibernate-reactive-db2/pom.xml index 310f59e0c81f3..072ded1685fe7 100644 --- a/integration-tests/hibernate-reactive-db2/pom.xml +++ b/integration-tests/hibernate-reactive-db2/pom.xml @@ -28,11 +28,7 @@ io.quarkus - quarkus-resteasy-jsonb - - - io.quarkus - quarkus-resteasy-mutiny + quarkus-resteasy-reactive-jsonb @@ -76,20 +72,7 @@ io.quarkus - quarkus-resteasy-jsonb-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-resteasy-mutiny-deployment + quarkus-resteasy-reactive-jsonb-deployment ${project.version} pom test diff --git a/integration-tests/hibernate-reactive-mysql/pom.xml b/integration-tests/hibernate-reactive-mysql/pom.xml index 83277fc3b763f..9bdfbc65fbf62 100644 --- a/integration-tests/hibernate-reactive-mysql/pom.xml +++ b/integration-tests/hibernate-reactive-mysql/pom.xml @@ -29,11 +29,7 @@ io.quarkus - quarkus-resteasy-jsonb - - - io.quarkus - quarkus-resteasy-mutiny + quarkus-resteasy-reactive-jsonb @@ -77,20 +73,7 @@ io.quarkus - quarkus-resteasy-jsonb-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-resteasy-mutiny-deployment + quarkus-resteasy-reactive-jsonb-deployment ${project.version} pom test diff --git a/integration-tests/hibernate-reactive-panache/pom.xml b/integration-tests/hibernate-reactive-panache/pom.xml index 71d551aa4ddb5..a49acc2d83fa0 100644 --- a/integration-tests/hibernate-reactive-panache/pom.xml +++ b/integration-tests/hibernate-reactive-panache/pom.xml @@ -29,27 +29,11 @@ io.quarkus - quarkus-hibernate-reactive + quarkus-resteasy-reactive-jsonb io.quarkus - quarkus-resteasy - - - io.quarkus - quarkus-resteasy-mutiny - - - io.quarkus - quarkus-resteasy-jsonb - - - io.quarkus - quarkus-resteasy-jaxb - - - io.quarkus - quarkus-resteasy-jackson + quarkus-jackson org.checkerframework @@ -108,11 +92,6 @@ - - com.fasterxml.jackson.module - jackson-module-jaxb-annotations - test - org.assertj assertj-core @@ -137,19 +116,6 @@ - - io.quarkus - quarkus-hibernate-reactive-deployment - ${project.version} - pom - test - - - * - * - - - io.quarkus quarkus-hibernate-reactive-panache-deployment @@ -191,59 +157,7 @@ io.quarkus - quarkus-resteasy-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-resteasy-jackson-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-resteasy-jaxb-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-resteasy-jsonb-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-resteasy-mutiny-deployment + quarkus-resteasy-reactive-jsonb-deployment ${project.version} pom test @@ -254,6 +168,7 @@ + diff --git a/integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/TestEndpoint.java b/integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/TestEndpoint.java index 0845080491614..57b0874c258a6 100644 --- a/integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/TestEndpoint.java +++ b/integration-tests/hibernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/TestEndpoint.java @@ -3,10 +3,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; @@ -19,11 +17,6 @@ import javax.persistence.NonUniqueResultException; import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElements; -import javax.xml.bind.annotation.XmlTransient; import org.hibernate.engine.spi.SelfDirtinessTracker; import org.junit.jupiter.api.Assertions; @@ -1467,7 +1460,6 @@ public Uni testModel3() { })); } - @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @GET @Path("ignored-properties") public Person ignoredProperties() throws NoSuchMethodException, SecurityException { @@ -1507,57 +1499,6 @@ public Uni testBug5885() { .map(v -> "OK"); } - @GET - @Path("testJaxbAnnotationTransfer") - public String testJaxbAnnotationTransfer() throws Exception { - // Test for fix to this bug: https://github.com/quarkusio/quarkus/issues/6021 - - // Ensure that any JAX-B annotations are properly moved to generated getters - Method m = JAXBEntity.class.getMethod("getNamedAnnotatedProp"); - XmlAttribute anno = m.getAnnotation(XmlAttribute.class); - assertNotNull(anno); - assertEquals("Named", anno.name()); - assertNull(m.getAnnotation(XmlTransient.class)); - - m = JAXBEntity.class.getMethod("getDefaultAnnotatedProp"); - anno = m.getAnnotation(XmlAttribute.class); - assertNotNull(anno); - assertEquals("##default", anno.name()); - assertNull(m.getAnnotation(XmlTransient.class)); - - m = JAXBEntity.class.getMethod("getUnAnnotatedProp"); - assertNull(m.getAnnotation(XmlAttribute.class)); - assertNull(m.getAnnotation(XmlTransient.class)); - - m = JAXBEntity.class.getMethod("getTransientProp"); - assertNull(m.getAnnotation(XmlAttribute.class)); - assertNotNull(m.getAnnotation(XmlTransient.class)); - - m = JAXBEntity.class.getMethod("getArrayAnnotatedProp"); - assertNull(m.getAnnotation(XmlTransient.class)); - XmlElements elementsAnno = m.getAnnotation(XmlElements.class); - assertNotNull(elementsAnno); - assertNotNull(elementsAnno.value()); - assertEquals(2, elementsAnno.value().length); - assertEquals("array1", elementsAnno.value()[0].name()); - assertEquals("array2", elementsAnno.value()[1].name()); - - // Ensure that all original fields were labeled @XmlTransient and had their original JAX-B annotations removed - ensureFieldSanitized("namedAnnotatedProp"); - ensureFieldSanitized("transientProp"); - ensureFieldSanitized("defaultAnnotatedProp"); - ensureFieldSanitized("unAnnotatedProp"); - ensureFieldSanitized("arrayAnnotatedProp"); - - return "OK"; - } - - private void ensureFieldSanitized(String fieldName) throws Exception { - Field f = JAXBEntity.class.getDeclaredField(fieldName); - assertNull(f.getAnnotation(XmlAttribute.class)); - assertNotNull(f.getAnnotation(XmlTransient.class)); - } - @GET @Path("composite") public Uni testCompositeKey() { diff --git a/integration-tests/hibernate-reactive-panache/src/test/java/io/quarkus/it/panache/reactive/PanacheFunctionalityTest.java b/integration-tests/hibernate-reactive-panache/src/test/java/io/quarkus/it/panache/reactive/PanacheFunctionalityTest.java index 3ed4ee280e815..62f4a5559d963 100644 --- a/integration-tests/hibernate-reactive-panache/src/test/java/io/quarkus/it/panache/reactive/PanacheFunctionalityTest.java +++ b/integration-tests/hibernate-reactive-panache/src/test/java/io/quarkus/it/panache/reactive/PanacheFunctionalityTest.java @@ -3,14 +3,9 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.StringWriter; - import javax.json.bind.Jsonb; import javax.json.bind.JsonbBuilder; import javax.transaction.Transactional; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -56,10 +51,6 @@ public void testPanacheSerialisation() { .when().get("/test/ignored-properties") .then() .body(is("{\"id\":666,\"dogs\":[],\"name\":\"Eddie\",\"serialisationTrick\":1,\"status\":\"DECEASED\"}")); - RestAssured.given().accept(ContentType.XML) - .when().get("/test/ignored-properties") - .then().body(is( - "666Eddie1DECEASED")); } @DisabledOnNativeImage @@ -78,18 +69,10 @@ public void testBug5885() { RestAssured.when().get("/test/5885").then().body(is("OK")); } - @Test - public void testJaxbAnnotationTransfer() { - RestAssured.when() - .get("/test/testJaxbAnnotationTransfer") - .then() - .body(is("OK")); - } - /** * _PanacheEntityBase_ has the method _isPersistent_. This method is used by Jackson to serialize the attribute *peristent* * in the JSON which is not intended. This test ensures that the attribute *persistent* is not generated when using Jackson. - * + * * This test does not interact with the Quarkus application itself. It is just using the Jackson ObjectMapper with a * PanacheEntity. Thus this test is disabled in native mode. The test code runs the JVM and not native. */ @@ -111,26 +94,6 @@ public void jacksonDeserializationIgnoresPersistentAttribute() throws JsonProces personAsString); } - /** - * This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint. - */ - @DisabledOnNativeImage - @Test - public void jaxbDeserializationHasAllFields() throws JsonProcessingException, JAXBException { - // set Up - Person person = new Person(); - person.name = "max"; - // do - JAXBContext jaxbContext = JAXBContext.newInstance(Person.class); - - Marshaller marshaller = jaxbContext.createMarshaller(); - StringWriter sw = new StringWriter(); - marshaller.marshal(person, sw); - assertEquals("" - + "max1", - sw.toString()); - } - /** * This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint. */ diff --git a/integration-tests/hibernate-reactive-postgresql/pom.xml b/integration-tests/hibernate-reactive-postgresql/pom.xml index cd017952c7fa3..56be1eefe6972 100644 --- a/integration-tests/hibernate-reactive-postgresql/pom.xml +++ b/integration-tests/hibernate-reactive-postgresql/pom.xml @@ -29,11 +29,7 @@ io.quarkus - quarkus-resteasy-jsonb - - - io.quarkus - quarkus-resteasy-mutiny + quarkus-resteasy-reactive-jsonb @@ -77,20 +73,7 @@ io.quarkus - quarkus-resteasy-jsonb-deployment - ${project.version} - pom - test - - - * - * - - - - - io.quarkus - quarkus-resteasy-mutiny-deployment + quarkus-resteasy-reactive-jsonb-deployment ${project.version} pom test