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 b61d3e8d1..b45c679eb 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 @@ -168,26 +168,24 @@ void createLayout_validLayout_returnsCreatedLayoutAndLayoutIsPersisted() } @Test - void createLayout_invalidLayout_returns400() throws Exception { - String invalidLayout = "invalidLayout"; + void createLayout_invalidRequestBodyDefinitionsIsBlank_returns400AndDoesNotCreateLayout() + throws Exception { + LayoutRequestDTO layoutRequest = createValidLayoutRequest(); + layoutRequest.setDefinition(""); mockMvc.perform(post("/layouts") - .content(invalidLayout) + .content(objectMapper.writeValueAsString(layoutRequest)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect(content().string( - "JSON parse error: Unrecognized token 'invalidLayout': was expecting (JSON " - + "String, Number, Array, Object or token 'null', 'true' or 'false'); nested " - + "exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized " - + "token 'invalidLayout': was expecting (JSON String, Number, Array, Object " - + "or token 'null', 'true' or 'false')\n" - + " at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream);" - + " line: 1, column: 14]")); + "[definition: Definition must not be blank]")); + + assertThat(layoutRepository.findAll()).isEmpty(); + assertThat(metadataRepository.findAll()).isEmpty(); } @Test - void createLayout_validLayoutButInvalidMetadata_returns400AndDoesNotCreateLayout() - throws Exception { + void createLayout_invalidRequestBodyMetadataIsNull_returns400AndDoesNotCreateLayout() throws Exception { LayoutRequestDTO layoutRequest = createValidLayoutRequest(); layoutRequest.setMetadata(null); @@ -202,6 +200,25 @@ void createLayout_validLayoutButInvalidMetadata_returns400AndDoesNotCreateLayout assertThat(metadataRepository.findAll()).isEmpty(); } + + @Test + void createLayout_invalidRequestBodyUnexpectedFormat_returns400() throws Exception { + String invalidLayout = "invalidLayout"; + + mockMvc.perform(post("/layouts") + .content(invalidLayout) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(content().string( + "JSON parse error: Unrecognized token 'invalidLayout': was expecting (JSON " + + "String, Number, Array, Object or token 'null', 'true' or 'false'); nested " + + "exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized " + + "token 'invalidLayout': was expecting (JSON String, Number, Array, Object " + + "or token 'null', 'true' or 'false')\n" + + " at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream);" + + " line: 1, column: 14]")); + } + @Test void updateLayout_validIdAndValidRequest_returns204AndLayoutHasChanged() throws Exception { Layout layout = createDefaultLayoutInDatabase();