-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13965 from Postremus/13944-use-rr
Replace resteasy usage with resteasy reactive in hibernate-reactive integration tests
- Loading branch information
Showing
10 changed files
with
174 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/JAXBTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
.../deployment/src/test/java/io/quarkus/hibernate/reactive/panache/test/PanacheJAXBTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><JAXBEntity><id>666</id><name>Eddie</name><serialisationTrick>1</serialisationTrick></JAXBEntity>")); | ||
} | ||
|
||
@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( | ||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><JAXBEntity><name>max</name><serialisationTrick>1</serialisationTrick></JAXBEntity>", | ||
sw.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.