Merge branch 'besoin1' of gitlab.emi.u-bordeaux.fr:pdl-l3/teams/2023/v1/v1d into besoin1
This commit is contained in:
commit
8c50100f21
2 files changed
+4
-5
No files matched your search
@@ -65,16 +65,15 @@ public class ImageController {
|
|||||||
public ResponseEntity<?> addImage(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
public ResponseEntity<?> addImage(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
||||||
|
|
||||||
String contentType = file.getContentType();
|
String contentType = file.getContentType();
|
||||||
if (!contentType.equals(MediaType.IMAGE_JPEG.toString())) {
|
if (contentType != null && !contentType.equals(MediaType.IMAGE_JPEG.toString())) {
|
||||||
return new ResponseEntity<>("Only JPEG file format supported", HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
return new ResponseEntity<>("Only JPEG file format supported", HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
imageDao.create(new Image(file.getOriginalFilename(), file.getBytes()));
|
imageDao.create(new Image(file.getOriginalFilename(), file.getBytes()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return new ResponseEntity<>("Failure to read file", HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>("Failure to read file", HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>("Image uploaded", HttpStatus.OK);
|
return new ResponseEntity<>("Image uploaded", HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/images", produces = "application/json")
|
@GetMapping(value = "/images", produces = "application/json")
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ public class ImageControllerTests {
|
|||||||
@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("images/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().isCreated());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in new issue
Block a user