Skip to content

Commit

Permalink
Add integration tests for jaxb-resteasy-reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
ketola committed Mar 23, 2024
1 parent 072156e commit 359a8ab
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 0 deletions.
79 changes: 79 additions & 0 deletions integration-tests/jaxb-resteasy-reactive/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-integration-tests-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-integration-test-jaxb-resteasy-reactive</artifactId>
<name>Quarkus - Integration Tests - JAXB - Resteasy Reactive</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jaxb</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.it.reactive.jaxb;

import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Book {

@XmlElement
private String title;

public Book() {
}

public Book(String title) {
this.title = title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.it.reactive.jaxb;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/jaxb")
@ApplicationScoped
public class JaxbResource {

@Path("/book")
@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Book postBookXml(Book book) {
return book;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.it.reactive.jaxb;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;

@QuarkusTest
public class JaxbTest {
@Test
public void testMarshallingAndUnmarshalling() {
given().when()
.contentType(ContentType.XML)
.body(new Book("1984"))
.post("/jaxb/book")
.then()
.statusCode(200)
.contentType(ContentType.XML)
.log().ifValidationFails()
.body(is(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><book><title>1984</title></book>"));
}

@Test
public void testInvalidXmlInRequestBody() {
String invalidXml = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<book>
<title>1984</title>
</boo>
""";
given().when()
.contentType(ContentType.XML)
.body(invalidXml)
.post("/jaxb/book")
.then()
.statusCode(400);
}

}
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@
<module>opentelemetry-reactive-messaging</module>
<module>logging-json</module>
<module>jaxb</module>
<module>jaxb-resteasy-reactive</module>
<module>jaxp</module>
<module>mailer</module>
<module>native-config-profile</module>
Expand Down

0 comments on commit 359a8ab

Please sign in to comment.