Skip to content

Commit

Permalink
Merge pull request #1 from KwonYH-sky/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
LineYK authored Dec 1, 2023
2 parents 3f42fa0 + b077942 commit ddbec4a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/resources/templates/board/boardDetail.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
max-height: 100%;
}

p iframe {
div iframe {
max-width: 100%;
max-height: 100%;
}
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/com/milk/milkweb/controller/BoardControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
import org.springframework.context.annotation.Import;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import java.io.IOException;
import java.util.ArrayList;

import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -298,4 +301,45 @@ void getLikeFailTest() throws Exception {
.andExpect(content().contentType(MediaType.parseMediaType("text/plain;charset=UTF-8")))
.andExpect(jsonPath("$").value("Not Found"));
}


@Test
@WithMockUser
@DisplayName("Board 이미지 저장 테스트")
void postImgTest() throws Exception {
// given
MockMultipartFile mockMultipartFile = new MockMultipartFile("img", "test.jpg", "image/jpeg", "test image".getBytes());
BoardImgUploadDto boardImgUploadDto = BoardImgUploadDto.builder()
.boardImgID(1L)
.imgName(mockMultipartFile.getName())
.build();

given(boardImgService.uploadImg(mockMultipartFile)).willReturn(boardImgUploadDto);

// when, then
mockMvc.perform(MockMvcRequestBuilders.multipart("/board/uploadImg")
.file(mockMultipartFile)
.with(csrf()))
.andExpect(status().isOk());

verify(boardImgService, times(1)).uploadImg(mockMultipartFile);
}

@Test
@WithMockUser
@DisplayName("Board 이미지 저장 실패 테스트")
void postImgFailTest() throws Exception {
// given
MockMultipartFile mockMultipartFile = new MockMultipartFile("img", "test.jpg", "image/jpeg", "test image".getBytes());

doThrow(new IOException("Error")).when(boardImgService).uploadImg(mockMultipartFile);

// when, then
mockMvc.perform(MockMvcRequestBuilders.multipart("/board/uploadImg")
.file(mockMultipartFile)
.with(csrf()))
.andExpect(status().isBadRequest());

verify(boardImgService, times(1)).uploadImg(mockMultipartFile);
}
}

0 comments on commit ddbec4a

Please sign in to comment.