From 523908750c047a90b918e160f36cb27cd3d0b48a Mon Sep 17 00:00:00 2001 From: keahorvath Date: Fri, 10 Mar 2023 16:36:56 +0100 Subject: [PATCH] close #14 --- .../pdl/backend/ImageControllerTests.java | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/backend/src/test/java/pdl/backend/ImageControllerTests.java b/backend/src/test/java/pdl/backend/ImageControllerTests.java index 5165217..1391eab 100644 --- a/backend/src/test/java/pdl/backend/ImageControllerTests.java +++ b/backend/src/test/java/pdl/backend/ImageControllerTests.java @@ -26,68 +26,68 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @TestMethodOrder(OrderAnnotation.class) public class ImageControllerTests { - @Autowired - private MockMvc mockMvc; + @Autowired + private MockMvc mockMvc; - @BeforeAll - public static void reset() { - // reset Image class static counter - ReflectionTestUtils.setField(Image.class, "count", Long.valueOf(0)); - } + @BeforeAll + public static void reset() { + // reset Image class static counter + ReflectionTestUtils.setField(Image.class, "count", Long.valueOf(0)); + } - @Test - @Order(1) - public void getImageListShouldReturnSuccess() throws Exception { - this.mockMvc.perform(get("/images")).andDo(print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)); - } + @Test + @Order(1) + public void getImageListShouldReturnSuccess() throws Exception { + this.mockMvc.perform(get("/images")).andDo(print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); + } - @Test - @Order(2) - public void getImageShouldReturnNotFound() throws Exception { - this.mockMvc.perform(get("/images/1")).andDo(print()).andExpect(status().isNotFound()); - } + @Test + @Order(2) + public void getImageShouldReturnNotFound() throws Exception { + this.mockMvc.perform(get("/images/1000")).andDo(print()).andExpect(status().isNotFound()); + } - @Test - @Order(3) - public void getImageShouldReturnSuccess() throws Exception { - this.mockMvc.perform(get("/images/0")).andExpect(status().isOk()); - } + @Test + @Order(3) + public void getImageShouldReturnSuccess() throws Exception { + this.mockMvc.perform(get("/images/0")).andExpect(status().isOk()); + } - @Test - @Order(4) - public void deleteImagesShouldReturnMethodNotAllowed() throws Exception { - this.mockMvc.perform(delete("/images")).andDo(print()).andExpect(status().isMethodNotAllowed()); - } + @Test + @Order(4) + public void deleteImagesShouldReturnMethodNotAllowed() throws Exception { + this.mockMvc.perform(delete("/images")).andDo(print()).andExpect(status().isMethodNotAllowed()); + } - @Test - @Order(5) - public void deleteImageShouldReturnNotFound() throws Exception { - this.mockMvc.perform(delete("/images/1")).andDo(print()).andExpect(status().isNotFound()); - } + @Test + @Order(5) + public void deleteImageShouldReturnNotFound() throws Exception { + this.mockMvc.perform(delete("/images/1")).andDo(print()).andExpect(status().isNotFound()); + } - @Test - @Order(6) - public void deleteImageShouldReturnSuccess() throws Exception { - this.mockMvc.perform(delete("/images/0")).andDo(print()).andExpect(status().isOk()); - } + @Test + @Order(6) + public void deleteImageShouldReturnSuccess() throws Exception { + this.mockMvc.perform(delete("/images/0")).andDo(print()).andExpect(status().isOk()); + } - @Test - @Order(7) - public void createImageShouldReturnSuccess() throws Exception { - final ClassPathResource imgFile = new ClassPathResource("test.jpg"); - MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "image/jpeg", - imgFile.getInputStream()); - this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print()) - .andExpect(status().isOk()); - } + @Test + @Order(7) + public void createImageShouldReturnSuccess() throws Exception { + final ClassPathResource imgFile = new ClassPathResource("test.jpg"); + MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "image/jpeg", + imgFile.getInputStream()); + this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print()) + .andExpect(status().isOk()); + } - @Test - @Order(8) - public void createImageShouldReturnUnsupportedMediaType() throws Exception { - MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "text/plain", "Test".getBytes()); - this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print()) - .andExpect(status().isUnsupportedMediaType()); - } + @Test + @Order(8) + public void createImageShouldReturnUnsupportedMediaType() throws Exception { + MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "text/plain", "Test".getBytes()); + this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print()) + .andExpect(status().isUnsupportedMediaType()); + } }