Skip to content
Snippets Groups Projects
Verified Commit 0016fec6 authored by Ira ¯\_(ツ)_/¯'s avatar Ira ¯\_(ツ)_/¯
Browse files

Add exception testing and message validation

parent 6ac919d1
No related branches found
No related tags found
No related merge requests found
......@@ -54,4 +54,42 @@ public class MailPassResourceIntegrationTest {
assertEquals(201, response.getStatusCode());
}
@Test
public void testMalformedJsonRaisesBadRequestException400() {
Response response = given().header("Authorization", "Bearer " + token).contentType(ContentType.JSON)
.body("{ \"password\"x \"password\" }").when()
.post(MessageFormat.format(ROOT_URI, port) + "/compute-password-hash");
assertEquals(400, response.getStatusCode());
}
@Test
public void testMalformedJsonExceptionMessage() {
Response response = given().header("Authorization", "Bearer " + token).contentType(ContentType.JSON)
.body("{ \"password\"x \"password\" }").when()
.post(MessageFormat.format(ROOT_URI, port) + "/compute-password-hash");
String error = response.jsonPath().getString("error");
assertEquals("provided data is not in valid JSON format", error);
}
@Test
public void testMissingJsonObjectRaisesBadRequestException400() {
Response response = given().header("Authorization", "Bearer " + token).contentType(ContentType.JSON)
.body("{ \"missing_password\": \"password\" }").when()
.post(MessageFormat.format(ROOT_URI, port) + "/compute-password-hash");
assertEquals(400, response.getStatusCode());
}
@Test
public void testMissingJsonObjectExceptionMessage() {
Response response = given().header("Authorization", "Bearer " + token).contentType(ContentType.JSON)
.body("{ \"missing_password\": \"password\" }").when()
.post(MessageFormat.format(ROOT_URI, port) + "/compute-password-hash");
String error = response.jsonPath().getString("error");
assertEquals("password object not detected in provided JSON body", error);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment