diff --git a/galasa-parent/dev.galasa.framework.api.resources/src/main/java/dev/galasa/framework/api/resources/routes/ResourcesRoute.java b/galasa-parent/dev.galasa.framework.api.resources/src/main/java/dev/galasa/framework/api/resources/routes/ResourcesRoute.java index bf0efecd9..f5f95fd85 100644 --- a/galasa-parent/dev.galasa.framework.api.resources/src/main/java/dev/galasa/framework/api/resources/routes/ResourcesRoute.java +++ b/galasa-parent/dev.galasa.framework.api.resources/src/main/java/dev/galasa/framework/api/resources/routes/ResourcesRoute.java @@ -106,9 +106,10 @@ private void checkJsonElementIsValidJSON(JsonElement element) throws InternalSer } /** + * Convert the List of Error Strings into JSON Objects + * and add them to a JSON array to be sent in the response to the client * - * - * @param errorsList + * @param errorsList List of Errors to be converted to JSON objects * @return String containing the JSON Array of Errors */ protected String getErrorsAsJson(List errorsList){ diff --git a/galasa-parent/dev.galasa.framework.api.resources/src/test/java/dev/galasa/framework/api/resources/routes/TestResourcesRoute.java b/galasa-parent/dev.galasa.framework.api.resources/src/test/java/dev/galasa/framework/api/resources/routes/TestResourcesRoute.java index e3b164577..e879e329f 100644 --- a/galasa-parent/dev.galasa.framework.api.resources/src/test/java/dev/galasa/framework/api/resources/routes/TestResourcesRoute.java +++ b/galasa-parent/dev.galasa.framework.api.resources/src/test/java/dev/galasa/framework/api/resources/routes/TestResourcesRoute.java @@ -24,6 +24,7 @@ import dev.galasa.framework.api.resources.ResourcesServletTest; import dev.galasa.framework.api.resources.mocks.MockResourcesServlet; import dev.galasa.framework.spi.IFramework; +import dev.galasa.framework.spi.utils.GalasaGson; public class TestResourcesRoute extends ResourcesServletTest{ @@ -1336,10 +1337,20 @@ public void TestGetErrorsAsJsonReturnsJsonString() throws Exception{ // When... String json = resourcesRoute.getErrorsAsJson(errors); - + // Then... - String expectedJson = "[\n {\n \"error_code\": 5030,\n \"error_message\": \"GAL5030E: Error occured when trying to delete Property 'property.5'. Report the problem to your Galasa Ecosystem owner.\"\n }," - +"\n {\n \"error_code\": 5030,\n \"error_message\": \"GAL5030E: Error occured when trying to delete Property 'property.1'. Report the problem to your Galasa Ecosystem owner.\"\n }\n]"; + // Generate Expected JSON + JsonArray expectedJsonArray = new JsonArray(); + JsonObject errorProp5 = new JsonObject(); + errorProp5.addProperty("error_code" , 5030); + errorProp5.addProperty("error_message" , "GAL5030E: Error occured when trying to delete Property 'property.5'. Report the problem to your Galasa Ecosystem owner."); + JsonObject errorProp1 = new JsonObject(); + errorProp1.addProperty("error_code" , 5030); + errorProp1.addProperty("error_message" , "GAL5030E: Error occured when trying to delete Property 'property.1'. Report the problem to your Galasa Ecosystem owner."); + expectedJsonArray.add(errorProp5); + expectedJsonArray.add(errorProp1); + GalasaGson gson = new GalasaGson(); + String expectedJson =gson.toJson(expectedJsonArray); assertThat(json).isEqualTo(expectedJson); @@ -1370,8 +1381,19 @@ public void TestHandlePOSTwithDeleteMultipleExistingPropertiesRaisesExceptionsRe servlet.doPost(req, resp); // Then... - String expectedJson = "[\n {\n \"error_code\": 5030,\n \"error_message\": \"GAL5030E: Error occured when trying to delete Property 'property.5'. Report the problem to your Galasa Ecosystem owner.\"\n }," - +"\n {\n \"error_code\": 5030,\n \"error_message\": \"GAL5030E: Error occured when trying to delete Property 'property.1'. Report the problem to your Galasa Ecosystem owner.\"\n }\n]"; + // Generate Expected JSON + JsonArray expectedJsonArray = new JsonArray(); + JsonObject errorProp5 = new JsonObject(); + errorProp5.addProperty("error_code" , 5030); + errorProp5.addProperty("error_message" , "GAL5030E: Error occured when trying to delete Property 'property.5'. Report the problem to your Galasa Ecosystem owner."); + JsonObject errorProp1 = new JsonObject(); + errorProp1.addProperty("error_code" , 5030); + errorProp1.addProperty("error_message" , "GAL5030E: Error occured when trying to delete Property 'property.1'. Report the problem to your Galasa Ecosystem owner."); + expectedJsonArray.add(errorProp5); + expectedJsonArray.add(errorProp1); + GalasaGson gson = new GalasaGson(); + String expectedJson =gson.toJson(expectedJsonArray); + Integer status = resp.getStatus(); String output = outStream.toString(); assertThat(status).isEqualTo(400);