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)
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user