Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
updated to use json objects for array tests
Browse files Browse the repository at this point in the history
Signed-off-by: Savvas Kyriacou <[email protected]>
  • Loading branch information
KirbyKatcher committed Jul 25, 2024
1 parent f91bdd4 commit 10c6e13
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> errorsList){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 10c6e13

Please sign in to comment.