update test file

This commit is contained in:
shinmj
2021-10-28 10:52:11 +09:00
parent f0fe0ed6ff
commit c03f875162
20 changed files with 1057 additions and 398 deletions

View File

@@ -77,7 +77,6 @@ public class PolicyApiController {
*/
@PostMapping("/api/v1/policies")
public Long save(@RequestBody PolicySaveRequestDto saveRequestDto) {
System.out.println(saveRequestDto.toString());
return policyService.save(saveRequestDto);
}

View File

@@ -428,8 +428,6 @@ public class AttachmentService extends AbstractService {
* @return
*/
public String updateEntity(String attachmentCode, AttachmentUploadRequestDto uploadRequestDto) {
System.out.println(" ====attachmentCode : " + attachmentCode);
System.out.println(" ====uploadRequestDto : " + uploadRequestDto);
List<Attachment> attachments = attachmentRepository.findByCode(attachmentCode);
for (Attachment attachment : attachments) {
attachment.updateEntity(uploadRequestDto.getEntityName(), uploadRequestDto.getEntityId());

View File

@@ -10,6 +10,7 @@ import org.egovframe.cloud.portalservice.service.attachment.AttachmentService;
import org.egovframe.cloud.portalservice.util.RestResponsePage;
import org.egovframe.cloud.portalservice.utils.FileStorageUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -36,6 +37,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
@@ -70,6 +72,7 @@ class AttachmentApiControllerTest {
}
}
/**
* file to byte[]
*
@@ -169,16 +172,15 @@ class AttachmentApiControllerTest {
//given
String url = "/api/v1/upload/editor";
Path testFile = Paths.get("/Users/violet/Desktop/test/300.jpg")
.toAbsolutePath().normalize();
Resource testFile = getTestFile();
String base64data = Base64.toBase64String(getByteFile(testFile.toFile()));
String base64data = Base64.toBase64String(getByteFile(testFile.getFile()));
AttachmentBase64RequestDto requestDto = AttachmentBase64RequestDto.builder()
.fieldName("upload")
.fileType("image/jpg")
.fileType("text")
.fileBase64(base64data)
.originalName("300.jpg")
.size(testFile.toFile().length())
.originalName(testFile.getFilename())
.size(testFile.getFile().length())
.build();
@@ -186,7 +188,7 @@ class AttachmentApiControllerTest {
restTemplate.postForEntity(url, requestDto, AttachmentEditorResponseDto.class);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getBody().getOriginalFileName()).isEqualTo("300.jpg");
assertThat(responseEntity.getBody().getOriginalFileName()).isEqualTo(testFile.getFilename());
}
@Test
@@ -239,16 +241,15 @@ class AttachmentApiControllerTest {
@Test
public void 에디터이미지업로드_후_이미지태그에서_이미지파일_조회_정상() throws Exception {
//given
Path testFile = Paths.get("/Users/violet/Desktop/test/300.jpg")
.toAbsolutePath().normalize();
Resource testFile = getTestFile();
String base64data = Base64.toBase64String(getByteFile(testFile.toFile()));
String base64data = Base64.toBase64String(getByteFile(testFile.getFile()));
AttachmentBase64RequestDto requestDto = AttachmentBase64RequestDto.builder()
.fieldName("upload")
.fileType("image/jpg")
.fileType("text")
.fileBase64(base64data)
.originalName("300.jpg")
.size(testFile.toFile().length())
.originalName(testFile.getFilename())
.size(testFile.contentLength())
.build();
AttachmentEditorResponseDto responseDto = attachmentService.uploadEditor(requestDto);
@@ -266,7 +267,7 @@ class AttachmentApiControllerTest {
//given
List<AttachmentTempSaveRequestDto> saveRequestDtoList = getTempSaveDto(2);
String url = "/api/v1/attachments/temp";
String url = "/api/v1/attachments/file";
//when
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, saveRequestDtoList, String.class);
@@ -324,7 +325,7 @@ class AttachmentApiControllerTest {
HttpEntity<List<AttachmentTempSaveRequestDto>> requestEntity = new HttpEntity<>(updateRequestDtoList);
//when
String url = "/api/v1/attachments/temp/"+attachmentCode;
String url = "/api/v1/attachments/file/"+attachmentCode;
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class);
@@ -341,7 +342,7 @@ class AttachmentApiControllerTest {
List<AttachmentTempSaveRequestDto> saveRequestDtoList2 = getTempSaveDto(3);
attachmentService.save(saveRequestDtoList2);
String url = "/api/v1/attachments/admin";
String url = "/api/v1/attachments";
//when
ResponseEntity<RestResponsePage<AttachmentResponseDto>> responseEntity = restTemplate.exchange(
@@ -370,7 +371,7 @@ class AttachmentApiControllerTest {
List<AttachmentTempSaveRequestDto> saveRequestDtoList2 = getTempSaveDto(3);
String attachmentCode = attachmentService.save(saveRequestDtoList2);
String url = "/api/v1/attachments/admin?keywordType=id&keyword="+attachmentCode;
String url = "/api/v1/attachments?keywordType=id&keyword="+attachmentCode;
//when
ResponseEntity<RestResponsePage<AttachmentResponseDto>> responseEntity = restTemplate.exchange(
@@ -399,7 +400,7 @@ class AttachmentApiControllerTest {
List<AttachmentResponseDto> results = attachmentService.findByCode(attachmentCode);
String uniqueId = results.get(1).getId();
String url = "/api/v1/attachments/admin/"+uniqueId+"/true";
String url = "/api/v1/attachments/"+uniqueId+"/true";
//when
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.PUT, null, String.class);
@@ -407,10 +408,10 @@ class AttachmentApiControllerTest {
//then
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
List<AttachmentResponseDto> saved = attachmentService.findByCode(attachmentCode);
AttachmentResponseDto updated = saved.stream()
.filter(attachmentResponseDto -> attachmentResponseDto.getId().equals(uniqueId))
.findAny().get();
assertThat(updated.getIsDelete()).isTrue();
Optional<AttachmentResponseDto> any = saved.stream()
.filter(attachmentResponseDto -> attachmentResponseDto.getId().equals(uniqueId))
.findAny();
assertThat(any.isPresent()).isFalse();
}
@Test
@@ -420,7 +421,7 @@ class AttachmentApiControllerTest {
String attachmentCode = attachmentService.save(saveRequestDtoList2);
List<AttachmentResponseDto> results = attachmentService.findByCode(attachmentCode);
String url = "/api/v1/attachments/admin/"+results.get(1).getId();
String url = "/api/v1/attachments/"+results.get(1).getId();
//when
restTemplate.delete(url);
@@ -487,7 +488,6 @@ class AttachmentApiControllerTest {
);
}
saveRequestDtoList.stream().forEach(System.out::println);
//2개 첨부파일 더하기
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
@@ -557,24 +557,4 @@ class AttachmentApiControllerTest {
}
//
// @Test
// public void 첨부파일_다운로드_정상() throws Exception {
// //given
// List<AttachmentSaveRequestDto> saveRequestDtoList2 = getTempSaveDto(1);
// String attachmentCode = attachmentService.save(saveRequestDtoList2);
//
// List<AttachmentResponseDto> byCode = attachmentService.findByCode(attachmentCode);
//
// String uniqueId = byCode.get(0).getUniqueId();
// String url = "/api/v1/download/"+uniqueId;
//
// //when
// ResponseEntity<ResponseEntity> responseEntity = restTemplate.getForEntity(url, ResponseEntity.class);
//
// //then
// re
//
// }
}