I am trying to test an endpoint that I have using rest assured with quarkus. the endpoint is like this:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/check/{anagram}")
fun getAnagrams(@PathParam("anagram") anagram: String): Response {
val anagrams = service.getCorrespondentAnagrams(anagram) ?: emptySet()
return Response.ok(anagrams).build()
}
while the test is like this:
@Test
fun `getAnagrams with existing anagram`() {
anagramService.validateAnagramAndSave("listen", "silent")
given()
.pathParam("anagram", "listen")
.`when`()
.get("/anagram/check/{anagram}")
.then()
.statusCode(200)
.contentType(MediaType.APPLICATION_JSON)
.body(org.hamcrest.Matchers.equalTo(setOf("silent")))
}
the problem is this test case is producing the following error:
1 expectation failed.
Response body doesn't match expectation.
Expected: <[silent]>
Actual: [silent]
java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: <[silent]>
Actual: [silent]
the question is how to get exact response to match the expected side and lose these '<' '>'
I have tried a lot of workarounds for the body method to set a working matcher but failed. I also have used the one in the answer above but also failed.
this workaround worked for me, it is far from ideal but this is what I managed to get, my conclusion, I would never use rest assured every on production level with such inconsistency
the workaround:
@Test
fun `getAnagrams with existing anagram`() {
anagramService.validateAnagramAndSave("listen", "silent")
val response = given()
.pathParam("anagram", "listen")
.`when`()
.get("/anagram/check/{anagram}")
.then()
.statusCode(200)
.contentType(MediaType.APPLICATION_JSON)
.extract().response()
assertTrue(response.body.asString().equals("[silent]"))
}