Skip to content

Commit

Permalink
Add tests for valid and invalid request body xml
Browse files Browse the repository at this point in the history
  • Loading branch information
ketola committed Mar 23, 2024
1 parent d779c2c commit 072156e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public Response postBook(Book book) {
}
}

// test for marshalling and unmarshalling with jaxb
@Path("/book/xml")
@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public Book postBookXml(Book book) {
return book;
}

@GET
@Path("/see-also")
@Produces(MediaType.APPLICATION_XML)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,35 @@ public void seeAlso() {
.body("response.evenMoreZeep", is(equalTo("ZEEEP")));
}

@Test
public void testMarshallingAndUnmarshalling() {
given().when()
.contentType(ContentType.XML)
.body(new Book("1984", null))
.post("/jaxb/book/xml")
.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>
<cover/>
</boo>
""";
given().when()
.contentType(ContentType.XML)
.body(invalidXml)
.post("/jaxb/book/xml")
.then()
.statusCode(400);
}

}

0 comments on commit 072156e

Please sign in to comment.