파일 통합 컨트롤러 테스트시 @MockMember 로 로그인 후 업로드 된 파일에서 body에 있는 내용을 가지고 단일 삭제를 하고 싶을 때 JSON형태로 되어있기때문에 데이터를 가져올 수 있게
JSONData data = om.readValue(body, JSONData.class);
로 데이터를 받아오는데 이때는 LinkedHashMap 형태이기 때문에 List<FileINfo> FileINfo형태로 변환 불가함.
그래서 해결법은 LinkedHashmap을 string으로 변경한 후 List<FileInfo>로 해서 형태를 변형시켜야 함.
@DisplayName("파일 통합 테스트")
@Test
@MockMember(authority = {Authority.USER, Authority.ADMIN})
void uploadTest() throws Exception {
MockMultipartFile file1 = new MockMultipartFile("file", "test1.png", "image/png", "abc".getBytes());
MockMultipartFile file2 = new MockMultipartFile("file", "test2.png", "image/png", "abc".getBytes());
String body = mockMvc.perform(multipart("/upload")
.file(file1)
.file(file2)
.param("gid", "testgid")
.param("testlocation", "testlocation")
).andDo(print()).andReturn().getResponse().getContentAsString(StandardCharsets.UTF_8);
JSONData data = om.readValue(body, JSONData.class);
System.out.println(data.getData()); // LinkedHashMap -> List<FileINfo> 변환 불가, LinkedHashmap -> string -> List<FileInfo>
List<FileInfo> items = om.readValue(om.writeValueAsString(data.getData()), new TypeReference<>() {});
//System.out.println("----- 확인 -------");
//items.forEach(System.out::println);
/* 파일 단일 삭제 테스트 */
mockMvc.perform(delete("/delete/" + items.get(0).getSeq()))
.andDo(print());
/* 파일 삭제 통합 테스트 */
mockMvc.perform(delete("/deletes/testgid/testlocation"))
.andDo(print());
/* 파일 조회 통합 테스트 */
mockMvc.perform(get("/list/testgid/testlocation"))
.andDo(print());
}
LinkedHashMap -> List<FileINfo> 변환 불가
LinkedHashmap -> string -> List<FileInfo>