From af3e6aeb4efcd189093181bfd95459ddfae7b232 Mon Sep 17 00:00:00 2001 From: Cara Fisher Date: Thu, 23 Nov 2023 13:59:26 +0000 Subject: [PATCH] SLVUU: Add tests for invalid JSON for definition in application layout request --- .../ApplicationLayoutIntegrationTest.java | 40 ++++++++++++++++++- .../integration/LayoutIntegrationTest.java | 1 - 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/ApplicationLayoutIntegrationTest.java b/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/ApplicationLayoutIntegrationTest.java index 0f862b852..154b407bd 100644 --- a/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/ApplicationLayoutIntegrationTest.java +++ b/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/ApplicationLayoutIntegrationTest.java @@ -19,10 +19,15 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.iterableWithSize; +import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -140,6 +145,37 @@ public void persistApplicationLayout_noUserInHeader_returns400() throws Exceptio assertThat(actualError).isEqualTo(MISSING_USERNAME_ERROR_MESSAGE); } + @Test + void persistApplicationLayout_definitionIsNotValidJSON_returns400AndDoesNotPersistLayout() + throws Exception { + String user = "user"; + String layoutRequestString = + "{\n" + + " \"definition\": invalidJson,\n" + + " \"metadata\": {\n" + + " \"name\": \"string\",\n" + + " \"group\": \"string\",\n" + + " \"screenshot\": \"string\",\n" + + " \"user\": \"string\"\n" + + " }\n" + + "}"; + + mockMvc.perform(put(BASE_URL).header("username", user) + .content(layoutRequestString) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.messages", iterableWithSize(1))) + .andExpect(jsonPath("$.messages", contains( + "JSON parse error: Unrecognized token 'invalidJson': was expecting (JSON String, " + + "Number, Array, Object or token 'null', 'true' or 'false'); nested " + + "exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized " + + "token 'invalidJson': was expecting (JSON String, Number, Array, Object or " + + "token 'null', 'true' or 'false')\n at [Source: (org.springframework.util" + + ".StreamUtils$NonClosingInputStream); line: 2, column: 29]"))); + + assertThat(repository.findAll()).isEmpty(); + } + @Test public void deleteApplicationLayout_noLayoutExists_returns404() throws Exception { String user = "user"; diff --git a/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java b/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java index 93d4c5c01..9c4a8e552 100644 --- a/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java +++ b/layout-server/src/test/java/org/finos/vuu/layoutserver/integration/LayoutIntegrationTest.java @@ -257,7 +257,6 @@ void createLayout_invalidRequestBodyDefinitionIsNotValidJSON_returns400AndDoesNo assertThat(metadataRepository.findAll()).isEmpty(); } - @Test void createLayout_invalidRequestBodyMetadataIsNull_returns400AndDoesNotCreateLayout() throws Exception {