close #14
This commit is contained in:
1 parent
4d5e096e11
commit
523908750c
1 file changed
+54
-54
@@ -26,68 +26,68 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
public class ImageControllerTests {
|
public class ImageControllerTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void reset() {
|
public static void reset() {
|
||||||
// reset Image class static counter
|
// reset Image class static counter
|
||||||
ReflectionTestUtils.setField(Image.class, "count", Long.valueOf(0));
|
ReflectionTestUtils.setField(Image.class, "count", Long.valueOf(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public void getImageListShouldReturnSuccess() throws Exception {
|
public void getImageListShouldReturnSuccess() throws Exception {
|
||||||
this.mockMvc.perform(get("/images")).andDo(print()).andExpect(status().isOk())
|
this.mockMvc.perform(get("/images")).andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
public void getImageShouldReturnNotFound() throws Exception {
|
public void getImageShouldReturnNotFound() throws Exception {
|
||||||
this.mockMvc.perform(get("/images/1")).andDo(print()).andExpect(status().isNotFound());
|
this.mockMvc.perform(get("/images/1000")).andDo(print()).andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
public void getImageShouldReturnSuccess() throws Exception {
|
public void getImageShouldReturnSuccess() throws Exception {
|
||||||
this.mockMvc.perform(get("/images/0")).andExpect(status().isOk());
|
this.mockMvc.perform(get("/images/0")).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void deleteImagesShouldReturnMethodNotAllowed() throws Exception {
|
public void deleteImagesShouldReturnMethodNotAllowed() throws Exception {
|
||||||
this.mockMvc.perform(delete("/images")).andDo(print()).andExpect(status().isMethodNotAllowed());
|
this.mockMvc.perform(delete("/images")).andDo(print()).andExpect(status().isMethodNotAllowed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(5)
|
@Order(5)
|
||||||
public void deleteImageShouldReturnNotFound() throws Exception {
|
public void deleteImageShouldReturnNotFound() throws Exception {
|
||||||
this.mockMvc.perform(delete("/images/1")).andDo(print()).andExpect(status().isNotFound());
|
this.mockMvc.perform(delete("/images/1")).andDo(print()).andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(6)
|
@Order(6)
|
||||||
public void deleteImageShouldReturnSuccess() throws Exception {
|
public void deleteImageShouldReturnSuccess() throws Exception {
|
||||||
this.mockMvc.perform(delete("/images/0")).andDo(print()).andExpect(status().isOk());
|
this.mockMvc.perform(delete("/images/0")).andDo(print()).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(7)
|
@Order(7)
|
||||||
public void createImageShouldReturnSuccess() throws Exception {
|
public void createImageShouldReturnSuccess() throws Exception {
|
||||||
final ClassPathResource imgFile = new ClassPathResource("test.jpg");
|
final ClassPathResource imgFile = new ClassPathResource("test.jpg");
|
||||||
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "image/jpeg",
|
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "image/jpeg",
|
||||||
imgFile.getInputStream());
|
imgFile.getInputStream());
|
||||||
this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print())
|
this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print())
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(8)
|
@Order(8)
|
||||||
public void createImageShouldReturnUnsupportedMediaType() throws Exception {
|
public void createImageShouldReturnUnsupportedMediaType() throws Exception {
|
||||||
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "text/plain", "Test".getBytes());
|
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "text/plain", "Test".getBytes());
|
||||||
this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print())
|
this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print())
|
||||||
.andExpect(status().isUnsupportedMediaType());
|
.andExpect(status().isUnsupportedMediaType());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user