Skip to content

Commit

Permalink
Enhance the cycle error message to become a JSON (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrizzi authored Apr 27, 2021
1 parent d16ae2e commit 1cf01ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import java.util.Collections;

/**
* {@link ExceptionMapper} created to provide a customized message for {@link ApplicationsInventoryException}
Expand All @@ -25,7 +26,7 @@ public Response toResponse(RestDataPanacheException exception) {
if (exception.getCause() instanceof ApplicationsInventoryException) {
ApplicationsInventoryException adce = (ApplicationsInventoryException) exception.getCause();
LOGGER.warnf(adce, "Mapping an %s", ApplicationsInventoryException.class.getSimpleName());
return Response.status(adce.getResponse().getStatus()).entity(adce.getMessage()).build();
return Response.status(adce.getResponse().getStatus()).entity(Collections.singletonMap("errorMessage", adce.getMessage())).build();
} else {
return super.toResponse(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testCreateApplicationsDependencies() {
.post(PATH)
.then()
.statusCode(409)
.body(is("Dependencies cycle created from applications 'Credit Cards BS', 'Application Test 1', 'Test Application', 'Application Test 0', 'Home Banking BU', 'Online Investments service'"));
.body("errorMessage", is("Dependencies cycle created from applications 'Credit Cards BS', 'Application Test 1', 'Test Application', 'Application Test 0', 'Home Banking BU', 'Online Investments service'"));

// now that the cycle detection has been tested successfully
// it's fine to remove the 'firstDependency'
Expand Down Expand Up @@ -224,7 +224,7 @@ public void testCreateApplicationsDependenciesWithWrongValues() {
.post(PATH)
.then()
.statusCode(409)
.body(is("Dependencies cycle created from applications 'Online Investments service', 'Home Banking BU'"));
.body("errorMessage", is("Dependencies cycle created from applications 'Online Investments service', 'Home Banking BU'"));

db.id = 2L;
given()
Expand All @@ -235,7 +235,7 @@ public void testCreateApplicationsDependenciesWithWrongValues() {
.post(PATH)
.then()
.statusCode(409)
.body(is("'from' and 'to' values are the same: an application can not be a dependency of itself"));
.body("errorMessage", is("'from' and 'to' values are the same: an application can not be a dependency of itself"));

db.id = 98765L;
given()
Expand All @@ -246,7 +246,7 @@ public void testCreateApplicationsDependenciesWithWrongValues() {
.post(PATH)
.then()
.statusCode(404)
.body(is("Not found the application with id 98765"));
.body("errorMessage", is("Not found the application with id 98765"));

frontend.id = 12345L;
given()
Expand All @@ -257,7 +257,7 @@ public void testCreateApplicationsDependenciesWithWrongValues() {
.post(PATH)
.then()
.statusCode(404)
.body(is("Not found the application with id 12345"));
.body("errorMessage", is("Not found the application with id 12345"));

dependency.to = null;
given()
Expand All @@ -268,7 +268,7 @@ public void testCreateApplicationsDependenciesWithWrongValues() {
.post(PATH)
.then()
.statusCode(400)
.body(is("Not valid application reference provided"));
.body("errorMessage", is("Not valid application reference provided"));

dependency.from = null;
given()
Expand All @@ -279,7 +279,7 @@ public void testCreateApplicationsDependenciesWithWrongValues() {
.post(PATH)
.then()
.statusCode(400)
.body(is("Not valid application reference provided"));
.body("errorMessage", is("Not valid application reference provided"));
}

@Test
Expand Down

0 comments on commit 1cf01ee

Please sign in to comment.