From c846bc1dc61ccbd43054c0a22e339149bb61905a Mon Sep 17 00:00:00 2001 From: Piotr Marcinkiewicz Date: Wed, 17 Mar 2021 12:52:34 +0100 Subject: Add test for exception message in response Issue-ID: SDC-3185 Signed-off-by: Piotr Marcinkiewicz Change-Id: Ie632e85c0234b461087262704a0eacbfd830384c --- .../api/ValidationControllerTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/test') diff --git a/src/test/java/org/onap/sdc/helmvalidator/api/ValidationControllerTest.java b/src/test/java/org/onap/sdc/helmvalidator/api/ValidationControllerTest.java index 3c87d7a..c00b75c 100644 --- a/src/test/java/org/onap/sdc/helmvalidator/api/ValidationControllerTest.java +++ b/src/test/java/org/onap/sdc/helmvalidator/api/ValidationControllerTest.java @@ -194,4 +194,32 @@ class ValidationControllerTest { .contains(VERSION_USED); assertThat(mvcResult.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()); } + + @Test + void shouldContainsExceptionMessageInResponse() throws Exception { + MockMultipartFile file = new MockMultipartFile(FILE_KEY, SAMPLE_ORIGINAL_FILENAME, + MediaType.MULTIPART_FORM_DATA_VALUE, "test".getBytes()); + NotSupportedVersionException exception = new NotSupportedVersionException("test"); + + when(validationService.process(SAMPLE_VERSION, file, false, false)) + .thenThrow(exception); + + MvcResult mvcResult = mockMvc.perform( + multipart(VALIDATION_ENDPOINT) + .file(file) + .param(VERSION_PARAM, SAMPLE_VERSION) + .param(IS_LINTED_PARAM, "false") + .param(IS_STRICT_LINTED_PARAM, "false")) + .andReturn(); + String contentAsString = mvcResult.getResponse().getContentAsString(); + + assertThat(contentAsString) + .contains(exception.getMessage()) + .doesNotContain(VALID) + .doesNotContain(RENDER_ERRORS) + .doesNotContain(LINT_WARNING) + .doesNotContain(LINT_ERROR); + assertThat(mvcResult.getResponse().getStatus()).isNotEqualTo(HttpStatus.OK.value()); + } + } -- cgit 1.2.3-korg