Skip to content

Commit

Permalink
VUU86: Add test case for blank layout definition in create layout req…
Browse files Browse the repository at this point in the history
…uest
  • Loading branch information
cfisher-scottlogic committed Oct 31, 2023
1 parent bf7278e commit 45ff964
Showing 1 changed file with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

0 comments on commit 45ff964

Please sign in to comment.