Fixing db indexing integration tests (#10229)
Co-authored-by: Gilvan Ornelas Fernandes Filho <gilvan.fernandes@bairesdev.com>
This commit is contained in:
parent
54b5f68302
commit
bd6e3a5328
|
@ -22,6 +22,10 @@ class Image {
|
|||
public Image() {
|
||||
}
|
||||
|
||||
public Image(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Image(String name, String location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
|
|
|
@ -35,8 +35,12 @@ class FileSystemImageIntegrationTest {
|
|||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
InputStream image = classLoader.getResourceAsStream("baeldung.jpeg");
|
||||
|
||||
MockMultipartFile jpegImage = new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image);
|
||||
MockMultipartHttpServletRequestBuilder multipartRequest = MockMvcRequestBuilders.multipart("/file-system/image")
|
||||
.file(new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image));
|
||||
.file(jpegImage);
|
||||
|
||||
given(fileLocationService.save(jpegImage.getBytes(), "baeldung"))
|
||||
.willReturn(1L);
|
||||
|
||||
MvcResult result = mockMvc.perform(multipartRequest)
|
||||
.andExpect(status().isOk())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.db.indexing;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
|
@ -34,13 +35,10 @@ class ImageIntegrationTest {
|
|||
|
||||
@Test
|
||||
void givenBaeldungJpegImage_whenUploadIt_thenReturnItsId() throws Exception {
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
InputStream image = classLoader.getResourceAsStream("baeldung.jpeg");
|
||||
given(imageRepository.save(any()))
|
||||
.willReturn(new Image(1L));
|
||||
|
||||
MockMultipartHttpServletRequestBuilder multipartRequest = MockMvcRequestBuilders.multipart("/image")
|
||||
.file(new MockMultipartFile("image", "baeldung", MediaType.TEXT_PLAIN_VALUE, image));
|
||||
|
||||
MvcResult result = mockMvc.perform(multipartRequest)
|
||||
MvcResult result = mockMvc.perform(createUploadImageRequest())
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
|
||||
|
@ -60,6 +58,14 @@ class ImageIntegrationTest {
|
|||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
private MockMultipartHttpServletRequestBuilder createUploadImageRequest() throws IOException {
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
InputStream image = classLoader.getResourceAsStream("baeldung.jpeg");
|
||||
|
||||
return MockMvcRequestBuilders.multipart("/image")
|
||||
.file(new MockMultipartFile("multipartImage", "baeldung", MediaType.TEXT_PLAIN_VALUE, image));
|
||||
}
|
||||
|
||||
private Image baeldungImage() throws IOException {
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
|
|
Loading…
Reference in New Issue