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") @PostMapping("/api/v1/policies")
public Long save(@RequestBody PolicySaveRequestDto saveRequestDto) { public Long save(@RequestBody PolicySaveRequestDto saveRequestDto) {
System.out.println(saveRequestDto.toString());
return policyService.save(saveRequestDto); return policyService.save(saveRequestDto);
} }

View File

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

View File

@@ -1,17 +1,530 @@
package org.egovframe.cloud.reservechecksevice.api; package org.egovframe.cloud.reservechecksevice.api;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDateTime;
import org.egovframe.cloud.common.domain.Role;
import org.egovframe.cloud.common.exception.dto.ErrorCode;
import org.egovframe.cloud.common.exception.dto.ErrorResponse;
import org.egovframe.cloud.reservechecksevice.api.reserve.dto.ReserveCancelRequestDto;
import org.egovframe.cloud.reservechecksevice.api.reserve.dto.ReserveListResponseDto;
import org.egovframe.cloud.reservechecksevice.api.reserve.dto.ReserveSaveRequestDto;
import org.egovframe.cloud.reservechecksevice.api.reserve.dto.ReserveUpdateRequestDto;
import org.egovframe.cloud.reservechecksevice.client.ReserveItemServiceClient;
import org.egovframe.cloud.reservechecksevice.client.UserServiceClient;
import org.egovframe.cloud.reservechecksevice.client.dto.ReserveItemRelationResponseDto;
import org.egovframe.cloud.reservechecksevice.client.dto.ReserveItemResponseDto;
import org.egovframe.cloud.reservechecksevice.client.dto.UserResponseDto;
import org.egovframe.cloud.reservechecksevice.domain.location.Location;
import org.egovframe.cloud.reservechecksevice.domain.reserve.Reserve;
import org.egovframe.cloud.reservechecksevice.domain.reserve.ReserveItem;
import org.egovframe.cloud.reservechecksevice.domain.reserve.ReserveRepository;
import org.egovframe.cloud.reservechecksevice.domain.reserve.ReserveStatus;
import org.egovframe.cloud.reservechecksevice.util.RestResponsePage;
import org.egovframe.cloud.reservechecksevice.util.WithCustomMockUser;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties @EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"}) @TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test") @ActiveProfiles(profiles = "test")
class ReserveApiControllerTest { public class ReserveApiControllerTest {
@Autowired
private ReserveRepository reserveRepository;
@MockBean
private ReserveItemServiceClient reserveItemServiceClient;
@MockBean
private UserServiceClient userServiceClient;
@Autowired
private WebTestClient webTestClient;
private static final String API_URL = "/api/v1/reserves";
private UserResponseDto user;
private Location location;
private ReserveItem reserveItem;
private Reserve reserve;
@BeforeEach
public void setup() {
user = UserResponseDto.builder()
.roleId(Role.ADMIN.getKey())
.userId("user")
.build();
location = Location.builder()
.locationId(1L)
.locationName("location")
.build();
reserveItem = ReserveItem.builder()
.reserveItemId(1L)
.reserveItemName("test")
.locationId(location.getLocationId())
.location(location)
.categoryId("place")
.inventoryQty(100)
.totalQty(100)
.reserveMethodId("internet")
.reserveMeansId("realtime")
.requestStartDate(LocalDateTime.of(2021, 1, 1, 1, 1))
.requestEndDate(LocalDateTime.of(2021, 12, 31, 23, 59))
.operationStartDate(LocalDateTime.of(2021, 1, 1, 1, 1))
.operationEndDate(LocalDateTime.of(2021, 12, 31, 23, 59))
.build();
reserve = Reserve.builder()
.reserveId("1")
.reserveItemId(reserveItem.getReserveItemId())
.reserveQty(50)
.reservePurposeContent("test")
.reserveStatusId("request")
.reserveStartDate(LocalDateTime.of(2021, 9, 9, 1, 1))
.reserveEndDate(LocalDateTime.of(2021, 9, 20, 1, 1))
.userId(user.getUserId())
.userEmail("user@email.com")
.userContactNo("contact")
.build();
reserve.setReserveItem(reserveItem);
reserve.setUser(user);
}
@AfterEach
public void tearDown() {
reserveRepository.deleteAll().block();
}
@Test
public void 예약신청관리_목록_조회_성공() throws Exception {
//given
BDDMockito.when(userServiceClient.findByUserId(ArgumentMatchers.anyString()))
.thenReturn(Mono.just(user));
BDDMockito.when(reserveItemServiceClient.findByIdWithRelations(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemRelationResponseDto.builder().entity(reserveItem).build()));
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
//when
webTestClient.get()
.uri(API_URL + "?page=0&size=5")
.exchange()
.expectStatus().isOk()
.expectBody(new ParameterizedTypeReference<RestResponsePage<ReserveListResponseDto>>() {
})
.value(page -> {
//then
assertThat(page.getTotalElements()).isEqualTo(1L);
assertThat(page.getContent().get(0).getReserveId()).isEqualTo(reserve.getReserveId());
page.getContent().stream().forEach(System.out::println);
});
}
@Test
@WithCustomMockUser(userId = "admin", role = Role.ADMIN)
public void 관리자_취소_성공() throws Exception {
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
webTestClient.put()
.uri(API_URL + "/cancel/{reserveId}", saved.getReserveId())
.bodyValue(ReserveCancelRequestDto.builder().reasonCancelContent("reason for cancellation").build())
.exchange()
.expectStatus().isNoContent();
Reserve updated = reserveRepository.findById(saved.getReserveId()).block();
assertThat(updated.getReserveStatusId()).isEqualTo("cancel");
assertThat(updated.getReasonCancelContent()).isEqualTo("reason for cancellation");
}
@Test
@WithCustomMockUser(userId = "user", role = Role.USER)
public void 사용자_취소_성공() {
//given
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
//when
webTestClient.put()
.uri(API_URL + "/cancel/{reserveId}", saved.getReserveId())
.bodyValue(ReserveCancelRequestDto.builder().reasonCancelContent("reason for cancellation").build())
.exchange()
.expectStatus().isNoContent()
;
Reserve updated = reserveRepository.findById(saved.getReserveId()).block();
assertThat(updated.getReserveStatusId()).isEqualTo("cancel");
assertThat(updated.getReasonCancelContent()).isEqualTo("reason for cancellation");
}
@Test
@WithCustomMockUser(userId = "test", role = Role.USER)
public void 다른사용자_예약_취소_실패() throws Exception {
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
webTestClient.put()
.uri(API_URL + "/cancel/{reserveId}", saved.getReserveId())
.bodyValue(ReserveCancelRequestDto.builder().reasonCancelContent("reason for cancellation").build())
.exchange()
.expectStatus().isBadRequest()
.expectBody(ErrorResponse.class)
.value(response -> {
assertThat(response.getMessage()).isEqualTo("해당 예약은 취소할 수 없습니다.");
assertThat(response.getCode()).isEqualTo(ErrorCode.BUSINESS_CUSTOM_MESSAGE.getCode());
});
}
@Test
@WithCustomMockUser(userId = "user", role = Role.USER)
public void 예약상태_완료_취소_실패() throws Exception {
Reserve done = reserve.updateStatus(ReserveStatus.DONE.getKey());
Reserve saved = reserveRepository.insert(done).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
webTestClient.put()
.uri(API_URL + "/cancel/{reserveId}", saved.getReserveId())
.bodyValue(ReserveCancelRequestDto.builder().reasonCancelContent("reason for cancellation").build())
.exchange()
.expectBody(ErrorResponse.class)
.value(response -> {
assertThat(response.getMessage()).isEqualTo("해당 예약은 이미 실행되어 취소할 수 없습니다.");
assertThat(response.getCode()).isEqualTo(ErrorCode.BUSINESS_CUSTOM_MESSAGE.getCode());
});
;
}
@Test
@WithCustomMockUser(userId = "user", role = Role.USER)
public void 관리자가_아닌_경우_승인_실패() throws Exception {
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(reserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
webTestClient.put()
.uri(API_URL + "/approve/{reserveId}", saved.getReserveId())
.exchange()
.expectStatus().isBadRequest()
.expectBody(ErrorResponse.class)
.value(response -> {
assertThat(response.getMessage()).isEqualTo("관리자만 승인할 수 있습니다.");
});
}
@Test
@WithCustomMockUser(userId = "admin", role = Role.ADMIN)
public void 예약승인_성공() throws Exception {
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(reserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
webTestClient.put()
.uri(API_URL + "/approve/{reserveId}", saved.getReserveId())
.exchange()
.expectStatus().isNoContent();
Reserve updated = reserveRepository.findById(saved.getReserveId()).block();
assertThat(updated.getReserveStatusId()).isEqualTo("approve");
}
@Test
@WithCustomMockUser(userId = "admin", role = Role.ADMIN)
public void 예약승인_실패_재고부족() throws Exception {
ReserveItem failReserveItem = ReserveItem.builder()
.reserveItemId(1L)
.reserveItemName("test")
.locationId(location.getLocationId())
.location(location)
.categoryId("equipment")
.totalQty(20)
.inventoryQty(10)
.reserveMethodId("internet")
.reserveMeansId("realtime")
.isPeriod(false)
.requestStartDate(LocalDateTime.of(2021, 1, 1, 1, 1))
.requestEndDate(LocalDateTime.of(2021, 12, 31, 23, 59))
.operationStartDate(LocalDateTime.of(2021, 1, 1, 1, 1))
.operationEndDate(LocalDateTime.of(2021, 12, 31, 23, 59))
.build();
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(failReserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(false));
webTestClient.put()
.uri(API_URL + "/approve/{reserveId}", saved.getReserveId())
.exchange()
.expectStatus().isBadRequest()
.expectBody(ErrorResponse.class)
.value(response -> {
assertThat(response.getMessage()).isEqualTo("해당 날짜에 예약할 수 있는 재고수량이 없습니다.");
});
}
@Test
@WithCustomMockUser(userId = "admin", role = Role.ADMIN)
public void 관리자_예약정보_수정_성공() throws Exception {
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(reserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
ReserveUpdateRequestDto updateRequestDto =
ReserveUpdateRequestDto.builder()
.reserveItemId(saved.getReserveItemId())
.categoryId(saved.getReserveItem().getCategoryId())
.reservePurposeContent("purpose")
.reserveQty(10)
.reserveStartDate(saved.getReserveStartDate())
.reserveEndDate(saved.getReserveEndDate())
.attachmentCode(saved.getAttachmentCode())
.userId(saved.getUserId())
.userContactNo("contact update")
.userEmail(saved.getUserEmail())
.build();
webTestClient.put()
.uri(API_URL + "/{reserveId}", saved.getReserveId())
.bodyValue(updateRequestDto)
.exchange()
.expectStatus().isNoContent()
;
Reserve updated = reserveRepository.findById(saved.getReserveId()).block();
assertThat(updated.getReservePurposeContent()).isEqualTo("purpose");
assertThat(updated.getReserveQty()).isEqualTo(10);
assertThat(updated.getUserContactNo()).isEqualTo("contact update");
}
@Test
@WithCustomMockUser(userId = "test", role = Role.USER)
public void 다른사용자_예약정보_수정_실패() throws Exception {
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(reserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
ReserveUpdateRequestDto updateRequestDto =
ReserveUpdateRequestDto.builder()
.reserveItemId(saved.getReserveItemId())
.categoryId(saved.getReserveItem().getCategoryId())
.reservePurposeContent("purpose")
.reserveQty(10)
.reserveStartDate(saved.getReserveStartDate())
.reserveEndDate(saved.getReserveEndDate())
.attachmentCode(saved.getAttachmentCode())
.userId(saved.getUserId())
.userContactNo("contact update")
.userEmail(saved.getUserEmail())
.build();
webTestClient.put()
.uri(API_URL + "/{reserveId}", saved.getReserveId())
.bodyValue(updateRequestDto)
.exchange()
.expectStatus().isBadRequest()
.expectBody(ErrorResponse.class)
.value(response -> {
assertThat(response.getMessage()).isEqualTo("해당 예약은 수정할 수 없습니다.");
});
}
@Test
@WithCustomMockUser(userId = "user", role = Role.USER)
public void 사용자_예약정보_수정_성공() throws Exception {
Reserve saved = reserveRepository.insert(reserve).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(reserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
ReserveUpdateRequestDto updateRequestDto =
ReserveUpdateRequestDto.builder()
.reserveItemId(saved.getReserveItemId())
.categoryId(saved.getReserveItem().getCategoryId())
.reservePurposeContent("purpose")
.reserveQty(10)
.reserveStartDate(saved.getReserveStartDate())
.reserveEndDate(saved.getReserveEndDate())
.attachmentCode(saved.getAttachmentCode())
.userId(saved.getUserId())
.userContactNo("contact update")
.userEmail(saved.getUserEmail())
.build();
webTestClient.put()
.uri(API_URL + "/{reserveId}", saved.getReserveId())
.bodyValue(updateRequestDto)
.exchange()
.expectStatus().isNoContent()
;
Reserve updated = reserveRepository.findById(saved.getReserveId()).block();
assertThat(updated.getReservePurposeContent()).isEqualTo("purpose");
assertThat(updated.getReserveQty()).isEqualTo(10);
assertThat(updated.getUserContactNo()).isEqualTo("contact update");
}
@Test
@WithCustomMockUser(userId = "user", role = Role.USER)
public void 사용자_상태승인인예약정보_수정_실패() throws Exception {
Reserve failedReserve = reserve.withReserveStatusId(ReserveStatus.APPROVE.getKey());
Reserve saved = reserveRepository.insert(failedReserve).block();
assertNotNull(saved);
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(reserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(false));
ReserveUpdateRequestDto updateRequestDto =
ReserveUpdateRequestDto.builder()
.reserveItemId(saved.getReserveItemId())
.categoryId(saved.getReserveItem().getCategoryId())
.reservePurposeContent("purpose")
.reserveQty(10)
.reserveStartDate(saved.getReserveStartDate())
.reserveEndDate(saved.getReserveEndDate())
.attachmentCode(saved.getAttachmentCode())
.userId(saved.getUserId())
.userContactNo("contact update")
.userEmail(saved.getUserEmail())
.build();
webTestClient.put()
.uri(API_URL + "/{reserveId}", saved.getReserveId())
.bodyValue(updateRequestDto)
.exchange()
.expectStatus().isBadRequest()
.expectBody(ErrorResponse.class)
.value(response -> {
assertThat(response.getMessage()).isEqualTo("예약 신청 상태인 경우에만 수정 가능합니다.");
});
}
@Test
public void 관리자_예약_성공() throws Exception {
BDDMockito.when(reserveItemServiceClient.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(ReserveItemResponseDto.builder().reserveItem(reserveItem).build()));
BDDMockito.when(reserveItemServiceClient.updateInventory(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt()))
.thenReturn(Mono.just(true));
ReserveSaveRequestDto saveRequestDto =
ReserveSaveRequestDto.builder()
.reserveItemId(reserve.getReserveItemId())
.categoryId(reserve.getReserveItem().getCategoryId())
.reservePurposeContent(reserve.getReservePurposeContent())
.reserveQty(reserve.getReserveQty())
.reserveStartDate(reserve.getReserveStartDate())
.reserveEndDate(reserve.getReserveEndDate())
.attachmentCode(reserve.getAttachmentCode())
.userId(reserve.getUserId())
.userContactNo(reserve.getUserContactNo())
.userEmail(reserve.getUserEmail())
.build();
webTestClient.post()
.uri(API_URL)
.bodyValue(saveRequestDto)
.exchange()
.expectStatus().isCreated();
Reserve saved = reserveRepository.findById(reserve.getReserveId()).block();
System.out.println(saved);
}
@Test
public void 예약신청_valid_실패() throws Exception {
ReserveItem validReserveItem = ReserveItem.builder()
.reserveItemId(1L)
.reserveItemName("test")
.locationId(location.getLocationId())
.location(location)
.categoryId("equipment")
.totalQty(100)
.inventoryQty(10)
.operationStartDate(LocalDateTime.of(2021, 10, 1, 1, 1))
.operationEndDate(LocalDateTime.of(2021, 10, 31, 23, 59))
.build();
reserve.setReserveItem(validReserveItem);
ReserveSaveRequestDto saveRequestDto =
ReserveSaveRequestDto.builder()
.reserveItemId(reserve.getReserveItemId())
.categoryId(reserve.getReserveItem().getCategoryId())
.reservePurposeContent(reserve.getReservePurposeContent())
.reserveQty(null)
.reserveStartDate(LocalDateTime.of(2021, 11, 1, 1, 1))
.reserveEndDate(reserve.getReserveEndDate())
.attachmentCode(reserve.getAttachmentCode())
.userId(reserve.getUserId())
.userContactNo(reserve.getUserContactNo())
.userEmail(reserve.getUserEmail())
.build();
webTestClient.post()
.uri(API_URL)
.bodyValue(saveRequestDto)
.exchange()
.expectStatus().isBadRequest()
;
}
} }

View File

@@ -1,9 +1,5 @@
package org.egovframe.cloud.reservechecksevice.config; package org.egovframe.cloud.reservechecksevice.config;
import io.r2dbc.h2.H2ConnectionConfiguration;
import io.r2dbc.h2.H2ConnectionFactory;
import io.r2dbc.h2.H2ConnectionOption;
import io.r2dbc.spi.ConnectionFactory;
import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
@@ -13,6 +9,11 @@ import org.springframework.r2dbc.connection.init.CompositeDatabasePopulator;
import org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer; import org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer;
import org.springframework.r2dbc.connection.init.ResourceDatabasePopulator; import org.springframework.r2dbc.connection.init.ResourceDatabasePopulator;
import io.r2dbc.h2.H2ConnectionConfiguration;
import io.r2dbc.h2.H2ConnectionFactory;
import io.r2dbc.h2.H2ConnectionOption;
import io.r2dbc.spi.ConnectionFactory;
@Profile("test") @Profile("test")
@TestConfiguration @TestConfiguration
@EnableR2dbcRepositories @EnableR2dbcRepositories
@@ -20,7 +21,7 @@ public class R2dbcConfig {
@Bean @Bean
public H2ConnectionFactory connectionFactory() { public H2ConnectionFactory connectionFactory() {
return new H2ConnectionFactory(H2ConnectionConfiguration.builder() return new H2ConnectionFactory(H2ConnectionConfiguration.builder()
.tcp("localhost", "~/querydsl") .inMemory("testdb")
.property(H2ConnectionOption.DB_CLOSE_DELAY, "-1") .property(H2ConnectionOption.DB_CLOSE_DELAY, "-1")
.username("sa") .username("sa")
.build()); .build());

View File

@@ -1,14 +1,15 @@
package org.egovframe.cloud.reservechecksevice.util; package org.egovframe.cloud.reservechecksevice.util;
import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collections;
import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import java.util.Collections; import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
/** /**
* org.egovframe.cloud.boardservice.util.RestResponsePage * org.egovframe.cloud.boardservice.util.RestResponsePage

View File

@@ -1,11 +1,11 @@
package org.egovframe.cloud.reservechecksevice.util; package org.egovframe.cloud.reservechecksevice.util;
import org.egovframe.cloud.common.domain.Role;
import org.springframework.security.test.context.support.WithSecurityContext;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import org.egovframe.cloud.common.domain.Role;
import org.springframework.security.test.context.support.WithSecurityContext;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@WithSecurityContext(factory = WithMockCustomUserSecurityContextFactory.class) @WithSecurityContext(factory = WithMockCustomUserSecurityContextFactory.class)
public @interface WithCustomMockUser { public @interface WithCustomMockUser {

View File

@@ -1,14 +1,14 @@
package org.egovframe.cloud.reservechecksevice.util; package org.egovframe.cloud.reservechecksevice.util;
import java.util.ArrayList;
import java.util.List;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.test.context.support.WithSecurityContextFactory; import org.springframework.security.test.context.support.WithSecurityContextFactory;
import java.util.ArrayList;
import java.util.List;
public class WithMockCustomUserSecurityContextFactory implements WithSecurityContextFactory<WithCustomMockUser> { public class WithMockCustomUserSecurityContextFactory implements WithSecurityContextFactory<WithCustomMockUser> {
@Override @Override

View File

@@ -2,20 +2,6 @@ spring:
application: application:
name: reserve-check-service name: reserve-check-service
datasource:
url: jdbc:h2:mem:testdb;MODE=MYSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
hibernate:
generate-ddl: true
ddl-auto: create-drop
properties:
hibernate:
format_sql: true
default_batch_fetch_size: 1000
show-sql: true
h2: h2:
console: console:
enabled: true enabled: true

View File

@@ -1,72 +1,17 @@
-- location Table Create SQL
CREATE TABLE IF NOT EXISTS location
(
location_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '지역 id',
location_name VARCHAR(200) NULL COMMENT '지역 이름',
sort_seq SMALLINT(3) NULL COMMENT '정렬 순서',
use_at TINYINT(1) NULL DEFAULT 1 COMMENT '사용 여부',
created_by VARCHAR(255) NULL COMMENT '생성자',
create_date DATETIME NULL COMMENT '생성일',
last_modified_by VARCHAR(255) NULL COMMENT '수정자',
modified_date DATETIME NULL COMMENT '수정일',
PRIMARY KEY (location_id)
) ;
-- reserve_item Table Create SQL
CREATE TABLE IF NOT EXISTS reserve_item
(
reserve_item_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '예약 물품 id',
reserve_item_name VARCHAR(200) NULL COMMENT '예약 물품 이름',
location_id BIGINT NULL COMMENT '지역 id',
category_id VARCHAR(20) NULL COMMENT '예약유형 - 공통코드 reserve-category',
total_qty BIGINT(18) NULL COMMENT '총 재고/수용인원 수',
inventory_qty BIGINT(18) NULL COMMENT '현재 남은 재고/수용인원 수',
operation_start_date DATETIME NULL COMMENT '운영 시작 일',
operation_end_date DATETIME NULL COMMENT '운영 종료 일',
reserve_method_id VARCHAR(20) NULL COMMENT '예약 방법 - 공통코드 reserve-method',
reserve_means_id VARCHAR(20) NULL COMMENT '예약 구분 (인터넷 예약 시) - 공통코드 reserve-means',
request_start_date DATETIME NULL COMMENT '예약 신청 시작 일시',
request_end_date DATETIME NULL COMMENT '예약 신청 종료 일시',
period_at TINYINT(1) NULL DEFAULT 0 COMMENT '기간 지정 가능 여부 - true: 지정 가능, false: 지정 불가',
period_max_count SMALLINT(3) NULL COMMENT '최대 예약 가능 일 수',
external_url VARCHAR(500) NULL COMMENT '외부링크',
selection_means_id VARCHAR(20) NULL COMMENT '선별 방법 - 공통코드 reserve-selection-means',
free_at TINYINT(1) NULL DEFAULT 1 COMMENT '유/무료 - true: 무료, false: 유료',
usage_cost DECIMAL(18, 0) NULL COMMENT '이용 요금',
use_at TINYINT(1) NULL DEFAULT 1 COMMENT '사용 여부',
purpose_content VARCHAR(4000) NULL COMMENT '용도',
item_addr VARCHAR(500) NULL COMMENT '주소',
target_id VARCHAR(20) NULL COMMENT '이용 대상 - 공통코드 reserve-target',
excluded_content VARCHAR(2000) NULL COMMENT '사용허가 제외대상',
homepage_url VARCHAR(500) NULL COMMENT '홈페이지 url',
contact_no VARCHAR(50) NULL COMMENT '문의처',
manager_dept_name VARCHAR(200) NULL COMMENT '담당자 소속',
manager_name VARCHAR(200) NULL COMMENT '담당자 이름',
manager_contact_no VARCHAR(50) NULL COMMENT '담당자 연락처',
create_date DATETIME NULL COMMENT '생성일',
created_by VARCHAR(255) NULL COMMENT '생성자',
modified_date DATETIME NULL COMMENT '수정일',
last_modified_by VARCHAR(255) NULL COMMENT '수정자',
PRIMARY KEY (reserve_item_id),
CONSTRAINT FK_reserve_item_location_id FOREIGN KEY (location_id)
REFERENCES location (location_id) ON DELETE RESTRICT ON UPDATE RESTRICT
) ;
-- reserve Table Create SQL -- reserve Table Create SQL
CREATE TABLE IF NOT EXISTS reserve CREATE TABLE IF NOT EXISTS reserve
( (
reserve_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '예약 id', reserve_id VARCHAR(255) NOT NULL COMMENT '예약 id',
reserve_item_id BIGINT NULL COMMENT '예약 물품 id', reserve_item_id BIGINT NULL COMMENT '예약 물품 id',
location_id BIGINT NULL COMMENT '예약 물품-지역 id',
category_id VARCHAR(255) NULL COMMENT '예약 물품-유형 id',
reserve_qty BIGINT(18) NULL COMMENT '예약 신청인원/수량', reserve_qty BIGINT(18) NULL COMMENT '예약 신청인원/수량',
reserve_purpose_content VARCHAR(4000) NULL COMMENT '예약신청 목적', reserve_purpose_content VARCHAR(4000) NULL COMMENT '예약신청 목적',
attachment_code VARCHAR(255) NULL COMMENT '첨부파일 코드', attachment_code VARCHAR(255) NULL COMMENT '첨부파일 코드',
reserve_start_date DATETIME NULL COMMENT '예약 신청 시작일', reserve_start_date DATETIME NULL COMMENT '예약 신청 시작일',
reserve_end_date DATETIME NULL COMMENT '예약 신청 종료일', reserve_end_date DATETIME NULL COMMENT '예약 신청 종료일',
reserve_status_id VARCHAR(20) NULL COMMENT '예약상태 - 공통코드(reserve-status)', reserve_status_id VARCHAR(20) NULL COMMENT '예약상태 - 공통코드(reserve-status)',
reason_cancel_content VARCHAR(4000) NULL COMMENT '예약 취소 사유',
user_id VARCHAR(255) NULL COMMENT '예약자 id', user_id VARCHAR(255) NULL COMMENT '예약자 id',
user_contact_no VARCHAR(50) NULL COMMENT '예약자 연락처', user_contact_no VARCHAR(50) NULL COMMENT '예약자 연락처',
user_email_addr VARCHAR(500) NULL COMMENT '예약자 이메일', user_email_addr VARCHAR(500) NULL COMMENT '예약자 이메일',
@@ -74,8 +19,5 @@ CREATE TABLE IF NOT EXISTS reserve
created_by VARCHAR(255) NULL COMMENT '생성자', created_by VARCHAR(255) NULL COMMENT '생성자',
modified_date DATETIME NULL COMMENT '수정일', modified_date DATETIME NULL COMMENT '수정일',
last_modified_by VARCHAR(255) NULL COMMENT '수정자', last_modified_by VARCHAR(255) NULL COMMENT '수정자',
PRIMARY KEY (reserve_id), PRIMARY KEY (reserve_id)
CONSTRAINT FK_reserve_reserve_item_id FOREIGN KEY (reserve_item_id)
REFERENCES reserve_item (reserve_item_id) ON DELETE RESTRICT ON UPDATE RESTRICT
) ; ) ;

View File

@@ -113,7 +113,6 @@ public class ReserveItemApiController {
@GetMapping("/api/v1/reserve-items/{reserveItemId}") @GetMapping("/api/v1/reserve-items/{reserveItemId}")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Mono<ReserveItemResponseDto> findById(@PathVariable Long reserveItemId) { public Mono<ReserveItemResponseDto> findById(@PathVariable Long reserveItemId) {
System.out.println("findById : " + reserveItemId);
return reserveItemService.findById(reserveItemId); return reserveItemService.findById(reserveItemId);
} }
@@ -177,7 +176,6 @@ public class ReserveItemApiController {
@PutMapping("/api/v1/reserve-items/{reserveItemId}/inventories") @PutMapping("/api/v1/reserve-items/{reserveItemId}/inventories")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Mono<Boolean> updateInventory(@PathVariable Long reserveItemId, @RequestBody Integer reserveQty) { public Mono<Boolean> updateInventory(@PathVariable Long reserveItemId, @RequestBody Integer reserveQty) {
System.out.println("update inventories : " + reserveItemId+" : " + reserveQty);
return reserveItemService.updateInventory(reserveItemId, reserveQty); return reserveItemService.updateInventory(reserveItemId, reserveQty);
} }

View File

@@ -1,5 +1,6 @@
package org.egovframe.cloud.reserveitemservice.api.reserveItem.dto; package org.egovframe.cloud.reserveitemservice.api.reserveItem.dto;
import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
@@ -92,6 +93,43 @@ public class ReserveItemSaveRequestDto {
@Size(max = 50) @Size(max = 50)
private String managerContact; //담당자 연락처 private String managerContact; //담당자 연락처
@Builder
public ReserveItemSaveRequestDto(String reserveItemName, Long locationId, String categoryId, Integer totalQty,
Integer inventoryQty, LocalDateTime operationStartDate, LocalDateTime operationEndDate,
String reserveMethodId, String reserveMeansId, LocalDateTime requestStartDate,
LocalDateTime requestEndDate, Boolean isPeriod, Integer periodMaxCount, String externalUrl,
String selectionMeansId, Boolean isPaid, BigDecimal usageCost, Boolean isUse, String purpose,
String address, String targetId, String excluded, String homepage, String contact, String managerDept,
String managerName, String managerContact) {
this.reserveItemName = reserveItemName;
this.locationId = locationId;
this.categoryId = categoryId;
this.totalQty = totalQty;
this.inventoryQty = inventoryQty;
this.operationStartDate = operationStartDate;
this.operationEndDate = operationEndDate;
this.reserveMethodId = reserveMethodId;
this.reserveMeansId = reserveMeansId;
this.requestStartDate = requestStartDate;
this.requestEndDate = requestEndDate;
this.isPeriod = isPeriod;
this.periodMaxCount = periodMaxCount;
this.externalUrl = externalUrl;
this.selectionMeansId = selectionMeansId;
this.isPaid = isPaid;
this.usageCost = usageCost;
this.isUse = isUse;
this.purpose = purpose;
this.address = address;
this.targetId = targetId;
this.excluded = excluded;
this.homepage = homepage;
this.contact = contact;
this.managerDept = managerDept;
this.managerName = managerName;
this.managerContact = managerContact;
}
public ReserveItem toEntity() { public ReserveItem toEntity() {
return ReserveItem.builder() return ReserveItem.builder()
.reserveItemName(this.reserveItemName) .reserveItemName(this.reserveItemName)

View File

@@ -1,5 +1,6 @@
package org.egovframe.cloud.reserveitemservice.api.reserveItem.dto; package org.egovframe.cloud.reserveitemservice.api.reserveItem.dto;
import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
@@ -61,7 +62,6 @@ public class ReserveItemUpdateRequestDto {
private String externalUrl; //외부링크 private String externalUrl; //외부링크
@NotBlank @NotBlank
private String selectionMeansId; //선별 방법 - 공통코드 reserve-selection private String selectionMeansId; //선별 방법 - 공통코드 reserve-selection
@NotNull
private Boolean isPaid; // 유/무료 - false: 무료, true: 유료 private Boolean isPaid; // 유/무료 - false: 무료, true: 유료
private BigDecimal usageCost; //이용 요금 private BigDecimal usageCost; //이용 요금
private Boolean isUse; //사용여부 private Boolean isUse; //사용여부
@@ -83,6 +83,43 @@ public class ReserveItemUpdateRequestDto {
@Size(max = 50) @Size(max = 50)
private String managerContact; //담당자 연락처 private String managerContact; //담당자 연락처
@Builder
public ReserveItemUpdateRequestDto(String reserveItemName, Long locationId, String categoryId,
Integer totalQty, Integer inventoryQty, LocalDateTime operationStartDate, LocalDateTime operationEndDate,
String reserveMethodId, String reserveMeansId, LocalDateTime requestStartDate,
LocalDateTime requestEndDate, Boolean isPeriod, Integer periodMaxCount, String externalUrl,
String selectionMeansId, Boolean isPaid, BigDecimal usageCost, Boolean isUse, String purpose,
String address, String targetId, String excluded, String homepage, String contact, String managerDept,
String managerName, String managerContact) {
this.reserveItemName = reserveItemName;
this.locationId = locationId;
this.categoryId = categoryId;
this.totalQty = totalQty;
this.inventoryQty = inventoryQty;
this.operationStartDate = operationStartDate;
this.operationEndDate = operationEndDate;
this.reserveMethodId = reserveMethodId;
this.reserveMeansId = reserveMeansId;
this.requestStartDate = requestStartDate;
this.requestEndDate = requestEndDate;
this.isPeriod = isPeriod;
this.periodMaxCount = periodMaxCount;
this.externalUrl = externalUrl;
this.selectionMeansId = selectionMeansId;
this.isPaid = isPaid;
this.usageCost = usageCost;
this.isUse = isUse;
this.purpose = purpose;
this.address = address;
this.targetId = targetId;
this.excluded = excluded;
this.homepage = homepage;
this.contact = contact;
this.managerDept = managerDept;
this.managerName = managerName;
this.managerContact = managerContact;
}
public ReserveItem toEntity() { public ReserveItem toEntity() {
return ReserveItem.builder() return ReserveItem.builder()
.reserveItemName(this.reserveItemName) .reserveItemName(this.reserveItemName)

View File

@@ -278,7 +278,6 @@ public class ReserveItem extends BaseEntity {
* @return * @return
*/ */
public ReserveItem update(ReserveItemUpdateRequestDto updateRequestDto) { public ReserveItem update(ReserveItemUpdateRequestDto updateRequestDto) {
System.out.println("============ ?? : " + updateRequestDto.toString());
this.reserveItemName = updateRequestDto.getReserveItemName(); this.reserveItemName = updateRequestDto.getReserveItemName();
this.locationId = updateRequestDto.getLocationId(); this.locationId = updateRequestDto.getLocationId();
this.categoryId = updateRequestDto.getCategoryId(); this.categoryId = updateRequestDto.getCategoryId();

View File

@@ -235,7 +235,6 @@ public class ReserveItemRepositoryImpl implements ReserveItemRepositoryCustom{
whereCriteria.add(where("use_at").isTrue()); whereCriteria.add(where("use_at").isTrue());
whereCriteria.add(where("reserve_method_id").is("internet")); whereCriteria.add(where("reserve_method_id").is("internet"));
} }
System.out.println(whereCriteria.toString());
return whereCriteria; return whereCriteria;
} }

View File

@@ -1,102 +1,104 @@
package org.egovframe.cloud.reserveitemservice.api.location; package org.egovframe.cloud.reserveitemservice.api.location;
import static org.junit.jupiter.api.Assertions.*;
import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationSaveRequestDto; import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationSaveRequestDto;
import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationUpdateRequestDto; import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationUpdateRequestDto;
import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig; import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig;
import org.egovframe.cloud.reserveitemservice.domain.location.Location; import org.egovframe.cloud.reserveitemservice.domain.location.Location;
import org.egovframe.cloud.reserveitemservice.domain.location.LocationRepository; import org.egovframe.cloud.reserveitemservice.domain.location.LocationRepository;
import org.junit.jupiter.api.BeforeEach; import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItem;
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItemRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.BodyInserters;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties @EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"}) @TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles("test") @ActiveProfiles("test")
@Import({R2dbcConfig.class}) @Import({R2dbcConfig.class})
class LocationApiControllerTest { public class LocationApiControllerTest {
@MockBean @Autowired
private LocationRepository locationRepository; private LocationRepository locationRepository;
@Autowired @Autowired
private WebTestClient webTestClient; private ReserveItemRepository reserveItemRepository;
private final static String API_URL = "/api/v1/locations"; @Autowired
WebTestClient webTestClient;
private Location location = Location.builder() private static final String API_URL = "/api/v1/locations";
.locationId(1L)
.locationName("location")
.isUse(true)
.sortSeq(1)
.build();
@BeforeEach
public void setup() {
BDDMockito.when(locationRepository.findById(ArgumentMatchers.anyLong()))
.thenReturn(Mono.just(location));
//조회조건 있는 경우
BDDMockito.when(locationRepository.findAllByLocationNameContainingOrderBySortSeq(
ArgumentMatchers.anyString(), ArgumentMatchers.any(Pageable.class)))
.thenReturn(Flux.just(location));
BDDMockito.when(locationRepository.countAllByLocationNameContaining(ArgumentMatchers.anyString()))
.thenReturn(Mono.just(1L));
//조회조건 없는 경우
BDDMockito.when(locationRepository.findAllByOrderBySortSeq(ArgumentMatchers.any(Pageable.class)))
.thenReturn(Flux.just(location));
BDDMockito.when(locationRepository.count()).thenReturn(Mono.just(1L));
BDDMockito.when(locationRepository.save(ArgumentMatchers.any(Location.class)))
.thenReturn(Mono.just(location));
@AfterEach
public void tearDown() {
reserveItemRepository.deleteAll().block();
locationRepository.deleteAll().block();
} }
@Test @Test
public void 한건조회_성공() throws Exception { public void 한건조회_성공() throws Exception {
Location location1 = locationRepository.save(Location.builder()
.locationName("location1")
.isUse(true)
.sortSeq(1)
.build()).block();
assertNotNull(location1);
webTestClient.get() webTestClient.get()
.uri(API_URL+"/{locationId}", location.getLocationId()) .uri(API_URL+"/{locationId}", location1.getLocationId())
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
.expectBody() .expectBody()
.jsonPath("$.locationName").isEqualTo(location.getLocationName()); .jsonPath("$.locationName").isEqualTo(location1.getLocationName());
} }
@Test @Test
public void 조회조건있는경우_페이지목록조회_성공() throws Exception { public void 조회조건있는경우_페이지목록조회_성공() throws Exception {
Location location1 = locationRepository.save(Location.builder()
.locationName("location1")
.isUse(true)
.sortSeq(1)
.build()).block();
assertNotNull(location1);
webTestClient.get() webTestClient.get()
.uri(API_URL+"?keywordType=locationName&keyword=location&page=0&size=3") .uri(API_URL+"?keywordType=locationName&keyword=location&page=0&size=3")
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
.expectBody() .expectBody()
.jsonPath("$.totalElements").isEqualTo(1) .jsonPath("$.totalElements").isEqualTo(1)
.jsonPath("$.content[0].locationName").isEqualTo(location.getLocationName()); .jsonPath("$.content[0].locationName").isEqualTo(location1.getLocationName());
} }
@Test @Test
public void 조회조건없는경우_페이지목록조회_성공() throws Exception { public void 조회조건없는경우_페이지목록조회_성공() throws Exception {
Location location1 = locationRepository.save(Location.builder()
.locationName("location1")
.isUse(true)
.sortSeq(1)
.build()).block();
assertNotNull(location1);
webTestClient.get() webTestClient.get()
.uri(API_URL+"?page=0&size=3") .uri(API_URL+"?page=0&size=3")
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
.expectBody() .expectBody()
.jsonPath("$.totalElements").isEqualTo(1) .jsonPath("$.totalElements").isEqualTo(1)
.jsonPath("$.content[0].locationName").isEqualTo(location.getLocationName()); .jsonPath("$.content[0].locationName").isEqualTo(location1.getLocationName());
} }
@Test @Test
@@ -105,40 +107,77 @@ class LocationApiControllerTest {
.uri(API_URL) .uri(API_URL)
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(LocationSaveRequestDto.builder() .body(BodyInserters.fromValue(LocationSaveRequestDto.builder()
.locationName(location.getLocationName()) .locationName("location1")
.isUse(location.getIsUse()) .isUse(true)
.sortSeq(location.getSortSeq()) .sortSeq(1)
.build())) .build()))
.exchange() .exchange()
.expectStatus().isCreated() .expectStatus().isCreated()
.expectBody().jsonPath("$.locationName").isEqualTo(location.getLocationName()); .expectBody().jsonPath("$.locationName").isEqualTo("location1");
} }
@Test @Test
public void 한건수정_성공() throws Exception { public void 한건수정_성공() throws Exception {
Location location1 = locationRepository.save(Location.builder()
.locationName("location1")
.isUse(true)
.sortSeq(1)
.build()).block();
assertNotNull(location1);
webTestClient.put() webTestClient.put()
.uri(API_URL+"/{locationId}", location.getLocationId()) .uri(API_URL+"/{locationId}", location1.getLocationId())
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(LocationUpdateRequestDto.builder() .body(BodyInserters.fromValue(LocationUpdateRequestDto.builder()
.locationName("updateLocation") .locationName("updateLocation")
.isUse(location.getIsUse()) .isUse(location1.getIsUse())
.sortSeq(location.getSortSeq()) .sortSeq(location1.getSortSeq())
.build())) .build()))
.exchange() .exchange()
.expectStatus().isNoContent(); .expectStatus().isNoContent();
Location updatedLocation = locationRepository.findById(location1.getLocationId()).block();
assertNotNull(updatedLocation);
assertEquals(updatedLocation.getLocationName(), "updateLocation");
} }
@Test @Test
public void 한건삭제_참조데이터존재_삭제실패() throws Exception { public void 한건삭제_참조데이터존재_삭제실패() throws Exception {
BDDMockito.when(locationRepository.delete(ArgumentMatchers.any(Location.class))) Location location1 = locationRepository.save(Location.builder()
.thenReturn(Mono.error(new DataIntegrityViolationException("integrity test"))); .locationName("location1")
.isUse(true)
.sortSeq(1)
.build()).block();
assertNotNull(location1);
reserveItemRepository.save(ReserveItem.builder()
.locationId(location1.getLocationId())
.categoryId("test")
.build()).block();
webTestClient.delete() webTestClient.delete()
.uri(API_URL+"/{locationId}", 1L) .uri(API_URL+"/{locationId}", location1.getLocationId())
.exchange() .exchange()
.expectStatus().isBadRequest(); .expectStatus().isBadRequest();
} }
@Test
public void 한건삭제_성공() throws Exception {
Location location1 = locationRepository.save(Location.builder()
.locationName("location1")
.isUse(true)
.sortSeq(1)
.build()).block();
assertNotNull(location1);
webTestClient.delete()
.uri(API_URL+"/{locationId}", location1.getLocationId())
.exchange()
.expectStatus().isNoContent();
}
} }

View File

@@ -1,14 +1,30 @@
package org.egovframe.cloud.reserveitemservice.api.reserveItem; package org.egovframe.cloud.reserveitemservice.api.reserveItem;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.egovframe.cloud.common.exception.dto.ErrorCode;
import org.egovframe.cloud.common.exception.dto.ErrorResponse;
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemMainResponseDto;
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemRequestDto; import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemRequestDto;
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemResponseDto;
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemSaveRequestDto;
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemUpdateRequestDto;
import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig; import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig;
import org.egovframe.cloud.reserveitemservice.domain.code.Code; import org.egovframe.cloud.reserveitemservice.domain.code.Code;
import org.egovframe.cloud.reserveitemservice.domain.location.Location; import org.egovframe.cloud.reserveitemservice.domain.location.Location;
import org.egovframe.cloud.reserveitemservice.domain.location.LocationRepository;
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItem; import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItem;
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItemRepository; import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItemRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.mockito.BDDMockito; import org.mockito.BDDMockito;
@@ -17,7 +33,10 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient;
@@ -29,136 +48,243 @@ import reactor.core.publisher.Mono;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties @EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"}) @TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test") @ActiveProfiles("test")
@Import({R2dbcConfig.class}) @Import({R2dbcConfig.class})
class ReserveItemApiControllerTest { class ReserveItemApiControllerTest {
@Autowired
private LocationRepository locationRepository;
@MockBean @Autowired
ReserveItemRepository reserveItemRepository; private ReserveItemRepository reserveItemRepository;
@Autowired
private R2dbcEntityTemplate entityTemplate;
@Autowired @Autowired
WebTestClient webTestClient; WebTestClient webTestClient;
private final static String API_URL = "/api/v1/reserve-items"; private final static String API_URL = "/api/v1/reserve-items";
Code category = null;
Location location = null;
ReserveItem reserveItem = ReserveItem.builder().build();
@Test @AfterEach
public void 사용자별_검색_목록_조회_성공() throws Exception { public void tearDown() {
LocalDateTime startDate = LocalDateTime.of(2021, 1, 28, 1,1); entityTemplate.delete(Code.class).all().block();
LocalDateTime endDate = LocalDateTime.of(2021, 12, 6, 1,1); reserveItemRepository.deleteAll().block();
locationRepository.deleteAll().block();
}
Location location = Location.builder() @BeforeEach
.locationId(1L) public void setUp() {
.locationName("location") category = Code.builder().codeName("category").codeId("category").parentCodeId("reserve-category").build();
.sortSeq(1) entityTemplate.insert(Code.class)
.using(category).block();
location = locationRepository.save(Location.builder()
.locationName("location1")
.isUse(true) .isUse(true)
.build(); .sortSeq(1)
ReserveItem reserveItem = ReserveItem.builder() .build()).block();
.reserveItemId(1L) assertNotNull(location);
.location(location) reserveItem = ReserveItem.builder()
.categoryId(category.getCodeId())
.locationId(location.getLocationId()) .locationId(location.getLocationId())
.reserveItemName("test") .reserveItemName("test")
.categoryId("education") .isUse(Boolean.TRUE)
.categoryName("교육") .operationStartDate(LocalDateTime.of(2021, 10, 1, 1, 1))
.operationEndDate(LocalDateTime.of(2021, 10, 31, 23, 59))
.reserveMethodId("internet")
.reserveMeansId("realtime")
.requestStartDate(LocalDateTime.of(2021, 10, 1, 1, 1))
.requestEndDate(LocalDateTime.of(2021, 10, 31, 23, 59))
.totalQty(100) .totalQty(100)
.inventoryQty(80) .inventoryQty(100)
.operationEndDate(endDate) .isPeriod(Boolean.FALSE)
.operationStartDate(startDate) .selectionMeansId("evaluate")
.isPeriod(false)
.isUse(true)
.build(); .build();
}
BDDMockito.when(reserveItemRepository.searchForUser(ArgumentMatchers.anyString(),
ArgumentMatchers.any(ReserveItemRequestDto.class), ArgumentMatchers.any(Pageable.class)))
.thenReturn(Flux.just(reserveItem));
BDDMockito.when(reserveItemRepository.searchCountForUser(ArgumentMatchers.anyString(), @Test
ArgumentMatchers.any(ReserveItemRequestDto.class), ArgumentMatchers.any(Pageable.class))) public void 사용자목록조회_성공() throws Exception {
.thenReturn(Mono.just(1L));
webTestClient.get() ReserveItem saved = reserveItemRepository.save(reserveItem).block();
.uri("/api/v1/{categoryId}/reserve-items?keywordType=locationName&keyword=location&page=0&size=3", "education") assertNotNull(saved);
webTestClient.method(HttpMethod.GET)
.uri("/api/v1/"+category.getCodeId()+"/reserve-items"+"?page=0&size=3&isUse=true")
.exchange() .exchange()
.expectStatus().isOk(); .expectStatus().isOk()
.expectBody()
.jsonPath("$.totalElements").isEqualTo(1)
.jsonPath("$.content[0].reserveItemName").isEqualTo(reserveItem.getReserveItemName());
}
@Test
public void 관리자목록조회_성공() throws Exception {
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
assertNotNull(saved);
webTestClient.method(HttpMethod.GET)
.uri(API_URL+"?page=0&size=3&isUse=false")
.exchange()
.expectStatus().isOk()
.expectBody()
.jsonPath("$.totalElements").isEqualTo(1)
.jsonPath("$.content[0].reserveItemName").isEqualTo(reserveItem.getReserveItemName());
}
@Test
public void 한건조회_성공() throws Exception {
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
assertNotNull(saved);
ReserveItemResponseDto responseBody = webTestClient.get()
.uri(API_URL+"/{reserveItemId}", saved.getReserveItemId())
.exchange()
.expectStatus().isOk()
.expectBody(ReserveItemResponseDto.class)
.returnResult().getResponseBody();
assertThat(responseBody.getCategoryId()).isEqualTo(category.getCodeId());
assertThat(responseBody.getReserveItemName()).isEqualTo(saved.getReserveItemName());
} }
@Test @Test
public void main_예약물품조회_성공() throws Exception { public void 사용자_포털_메인_예약목록_조회_성공() throws Exception {
BDDMockito.when(reserveItemRepository.findCodeDetail(ArgumentMatchers.anyString())) ReserveItem saved = reserveItemRepository.save(reserveItem).block();
.thenReturn(Flux.fromIterable(Arrays.asList(Code.builder().codeId("education").codeName("교육").build(), assertNotNull(saved);
Code.builder().codeId("equipment").codeName("장비").build(),
Code.builder().codeId("space").codeName("장소").build())));
LocalDateTime startDate = LocalDateTime.of(2021, 1, 28, 1,1); Map<String, Collection<ReserveItemMainResponseDto>> responseBody = webTestClient.get()
LocalDateTime endDate = LocalDateTime.of(2021, 12, 6, 1,1); .uri(API_URL+"/latest/3")
Location location = Location.builder()
.locationId(1L)
.locationName("location")
.sortSeq(1)
.isUse(true)
.build();
ReserveItem reserveItem1 = ReserveItem.builder()
.reserveItemId(1L)
.location(location)
.locationId(location.getLocationId())
.reserveItemName("test")
.categoryId("education")
.categoryName("교육")
.totalQty(100)
.inventoryQty(80)
.operationEndDate(endDate)
.operationStartDate(startDate)
.reserveMethodId("visit")
.isPeriod(false)
.isUse(true)
.build();
ReserveItem reserveItem2 = ReserveItem.builder()
.reserveItemId(1L)
.location(location)
.locationId(location.getLocationId())
.reserveItemName("test")
.categoryId("education")
.categoryName("장비")
.totalQty(100)
.inventoryQty(80)
.operationEndDate(endDate)
.operationStartDate(startDate)
.reserveMethodId("visit")
.isPeriod(false)
.isUse(true)
.build();
ReserveItem reserveItem3 = ReserveItem.builder()
.reserveItemId(1L)
.location(location)
.locationId(location.getLocationId())
.reserveItemName("test")
.categoryId("education")
.categoryName("공간")
.totalQty(100)
.inventoryQty(80)
.operationEndDate(endDate)
.operationStartDate(startDate)
.reserveMethodId("visit")
.isPeriod(false)
.isUse(true)
.build();
reserveItem1.setCreateDate(LocalDateTime.now());
reserveItem2.setCreateDate(LocalDateTime.now());
reserveItem3.setCreateDate(LocalDateTime.now());
BDDMockito.when(reserveItemRepository.findLatestByCategory(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString()))
.thenReturn(Flux.fromIterable(Arrays.asList(reserveItem1, reserveItem2, reserveItem3)));
webTestClient.get()
.uri("/api/v1/reserve-items/latest/3")
.exchange() .exchange()
.expectStatus().isOk(); .expectStatus().isOk()
.expectBody(new ParameterizedTypeReference<Map<String, Collection<ReserveItemMainResponseDto>>>() {
})
.returnResult().getResponseBody();
assertThat(responseBody.keySet().size()).isEqualTo(1);
assertThat(responseBody.keySet().contains(category.getCodeId())).isTrue();
Collection<ReserveItemMainResponseDto> reserveItemMainResponseDtos = responseBody.get(category.getCodeId());
reserveItemMainResponseDtos.stream().forEach(reserveItemMainResponseDto -> {
assertThat(reserveItemMainResponseDto.getReserveItemName().equals(saved.getReserveItemName()));
});
}
@Test
public void 한건_등록_성공() throws Exception {
ReserveItemSaveRequestDto requestDto = ReserveItemSaveRequestDto.builder()
.reserveItemName(reserveItem.getReserveItemName())
.categoryId(reserveItem.getCategoryId())
.locationId(reserveItem.getLocationId())
.inventoryQty(reserveItem.getInventoryQty())
.totalQty(reserveItem.getTotalQty())
.operationStartDate(reserveItem.getOperationStartDate())
.operationEndDate(reserveItem.getOperationEndDate())
.reserveMethodId(reserveItem.getReserveMethodId())
.reserveMeansId(reserveItem.getReserveMeansId())
.isUse(reserveItem.getIsUse())
.requestStartDate(reserveItem.getRequestStartDate())
.requestEndDate(reserveItem.getRequestEndDate())
.isPeriod(reserveItem.getIsPeriod())
.selectionMeansId(reserveItem.getSelectionMeansId())
.build();
ReserveItemResponseDto responseBody = webTestClient.post()
.uri(API_URL)
.bodyValue(requestDto)
.exchange()
.expectStatus().isCreated()
.expectBody(ReserveItemResponseDto.class)
.returnResult().getResponseBody();
System.out.println(responseBody);
assertThat(responseBody.getReserveItemName()).isEqualTo(requestDto.getReserveItemName());
}
@Test
public void 한건_수정_성공() throws Exception {
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
assertNotNull(saved);
ReserveItemUpdateRequestDto requestDto = ReserveItemUpdateRequestDto.builder()
.reserveItemName("update")
.categoryId(reserveItem.getCategoryId())
.locationId(reserveItem.getLocationId())
.inventoryQty(reserveItem.getInventoryQty())
.totalQty(reserveItem.getTotalQty())
.operationStartDate(reserveItem.getOperationStartDate())
.operationEndDate(reserveItem.getOperationEndDate())
.reserveMethodId(reserveItem.getReserveMethodId())
.reserveMeansId(reserveItem.getReserveMeansId())
.isUse(reserveItem.getIsUse())
.requestStartDate(reserveItem.getRequestStartDate())
.requestEndDate(reserveItem.getRequestEndDate())
.isPeriod(reserveItem.getIsPeriod())
.selectionMeansId(reserveItem.getSelectionMeansId())
.build();
webTestClient.put()
.uri(API_URL+"/"+saved.getReserveItemId())
.bodyValue(requestDto)
.exchange()
.expectStatus().isNoContent();
ReserveItem findbyid = reserveItemRepository.findById(saved.getReserveItemId()).block();
assertThat(findbyid.getReserveItemName()).isEqualTo("update");
}
@Test
public void 사용여부_false_수정_성공() throws Exception {
ReserveItem saved = reserveItemRepository.save(reserveItem).block();
assertNotNull(saved);
webTestClient.put()
.uri(API_URL+"/"+saved.getReserveItemId()+"/false")
.exchange()
.expectStatus().isNoContent();
ReserveItem findbyid = reserveItemRepository.findById(saved.getReserveItemId()).block();
assertThat(findbyid.getIsUse()).isEqualTo(Boolean.FALSE);
}
@Test
public void 한건_저장_validation_실패() throws Exception {
ReserveItemSaveRequestDto requestDto = ReserveItemSaveRequestDto.builder()
.reserveItemName(reserveItem.getReserveItemName())
.categoryId(reserveItem.getCategoryId())
.locationId(reserveItem.getLocationId())
.inventoryQty(reserveItem.getInventoryQty())
.totalQty(reserveItem.getTotalQty())
.operationStartDate(reserveItem.getOperationStartDate())
.operationEndDate(reserveItem.getOperationEndDate())
.reserveMethodId(reserveItem.getReserveMethodId())
.reserveMeansId(reserveItem.getReserveMeansId())
.isUse(reserveItem.getIsUse())
.isPeriod(reserveItem.getIsPeriod())
.selectionMeansId(reserveItem.getSelectionMeansId())
.build();
ErrorResponse responseBody = webTestClient.post()
.uri(API_URL)
.bodyValue(requestDto)
.exchange()
.expectStatus().isBadRequest()
.expectBody(ErrorResponse.class)
.returnResult().getResponseBody();
assertThat(responseBody.getCode()).isEqualTo(ErrorCode.INVALID_INPUT_VALUE.getCode());
assertThat(responseBody.getErrors().size()).isEqualTo(1);
responseBody.getErrors().stream().forEach(fieldError -> {
assertThat(fieldError.getField()).isEqualTo("requestStartDate");
System.out.println(fieldError.getMessage());
});
} }
} }

View File

@@ -21,7 +21,7 @@ public class R2dbcConfig{
@Bean @Bean
public H2ConnectionFactory connectionFactory() { public H2ConnectionFactory connectionFactory() {
return new H2ConnectionFactory(H2ConnectionConfiguration.builder() return new H2ConnectionFactory(H2ConnectionConfiguration.builder()
.tcp("localhost", "~/querydsl") .inMemory("testdb")
.property(H2ConnectionOption.DB_CLOSE_DELAY, "-1") .property(H2ConnectionOption.DB_CLOSE_DELAY, "-1")
.username("sa") .username("sa")
.build()); .build());

View File

@@ -2,20 +2,6 @@ spring:
application: application:
name: reserve-item-service name: reserve-item-service
datasource:
url: jdbc:h2:mem:testdb;MODE=MYSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
hibernate:
generate-ddl: true
ddl-auto: create-drop
properties:
hibernate:
format_sql: true
default_batch_fetch_size: 1000
show-sql: true
h2: h2:
console: console:
enabled: true enabled: true

View File

@@ -1,14 +1,25 @@
CREATE TABLE IF NOT EXISTS location( CREATE TABLE IF NOT EXISTS `code` (
location_id BIGINT AUTO_INCREMENT, `code_id` varchar(20) NOT NULL COMMENT '코드 id',
location_name VARCHAR(200), `code_name` varchar(500) NOT NULL COMMENT '코드 명',
use_at tinyint(1) default 1 null, `parent_code_id` varchar(20) DEFAULT NULL COMMENT '부모 코드 id',
sort_seq smallint(3) null, use_at BOOLEAN NULL DEFAULT TRUE COMMENT '사용 여부',
create_date DATE null, PRIMARY KEY (`code_id`)
modified_date DATE null, ) ;
created_by VARCHAR(255) null,
last_modified_by VARCHAR(255) null, -- location Table Create SQL
CONSTRAINT PERSON_PK PRIMARY KEY (location_id) CREATE TABLE IF NOT EXISTS location
); (
location_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '지역 id',
location_name VARCHAR(200) NULL COMMENT '지역 이름',
sort_seq SMALLINT(3) NULL COMMENT '정렬 순서',
use_at BOOLEAN NULL DEFAULT TRUE COMMENT '사용 여부',
created_by VARCHAR(255) NULL COMMENT '생성자',
create_date DATETIME NULL COMMENT '생성일',
last_modified_by VARCHAR(255) NULL COMMENT '수정자',
modified_date DATETIME NULL COMMENT '수정일',
PRIMARY KEY (location_id)
) ;
-- reserve_item Table Create SQL -- reserve_item Table Create SQL
@@ -18,20 +29,21 @@ CREATE TABLE IF NOT EXISTS reserve_item
reserve_item_name VARCHAR(200) NULL COMMENT '예약 물품 이름', reserve_item_name VARCHAR(200) NULL COMMENT '예약 물품 이름',
location_id BIGINT NULL COMMENT '지역 id', location_id BIGINT NULL COMMENT '지역 id',
category_id VARCHAR(20) NULL COMMENT '예약유형 - 공통코드 reserve-category', category_id VARCHAR(20) NULL COMMENT '예약유형 - 공통코드 reserve-category',
capacity_count MEDIUMINT(5) NULL COMMENT '재고/수용인원 수', total_qty BIGINT(18) NULL COMMENT '재고/수용인원 수',
inventory_qty BIGINT(18) NULL COMMENT '현재 남은 재고/수용인원 수',
operation_start_date DATETIME NULL COMMENT '운영 시작 일', operation_start_date DATETIME NULL COMMENT '운영 시작 일',
operation_end_date DATETIME NULL COMMENT '운영 종료 일', operation_end_date DATETIME NULL COMMENT '운영 종료 일',
reserve_method_id VARCHAR(20) NULL COMMENT '예약 방법 - 공통코드 reserve-method', reserve_method_id VARCHAR(20) NULL COMMENT '예약 방법 - 공통코드 reserve-method',
reserve_means_id VARCHAR(20) NULL COMMENT '예약 구분 (인터넷 예약 시) - 공통코드 reserve-means', reserve_means_id VARCHAR(20) NULL COMMENT '예약 구분 (인터넷 예약 시) - 공통코드 reserve-means',
request_start_date DATETIME NULL COMMENT '예약 신청 시작 일시', request_start_date DATETIME NULL COMMENT '예약 신청 시작 일시',
request_end_date DATETIME NULL COMMENT '예약 신청 종료 일시', request_end_date DATETIME NULL COMMENT '예약 신청 종료 일시',
period_at TINYINT(1) NULL DEFAULT 0 COMMENT '기간 지정 가능 여부 - true: 지정 가능, false: 지정 불가', period_at BOOLEAN NULL DEFAULT FALSE COMMENT '기간 지정 가능 여부 - true: 지정 가능, false: 지정 불가',
period_max_count SMALLINT(3) NULL COMMENT '최대 예약 가능 일 수', period_max_count SMALLINT(3) NULL COMMENT '최대 예약 가능 일 수',
external_url VARCHAR(500) NULL COMMENT '외부링크', external_url VARCHAR(500) NULL COMMENT '외부링크',
selection_means_id VARCHAR(20) NULL COMMENT '선별 방법 - 공통코드 reserve-selection-means', selection_means_id VARCHAR(20) NULL COMMENT '선별 방법 - 공통코드 reserve-selection-means',
free_at TINYINT(1) NULL DEFAULT 1 COMMENT '유/무료 - true: 무료, false: 유료', paid_at BOOLEAN NULL DEFAULT FALSE COMMENT '유/무료 - false: 무료, true: 유료',
usage_cost DECIMAL(18, 0) NULL COMMENT '이용 요금', usage_cost DECIMAL(18, 0) NULL COMMENT '이용 요금',
use_at TINYINT(1) NULL DEFAULT 1 COMMENT '사용 여부', use_at BOOLEAN NULL DEFAULT TRUE COMMENT '사용 여부',
purpose_content VARCHAR(4000) NULL COMMENT '용도', purpose_content VARCHAR(4000) NULL COMMENT '용도',
item_addr VARCHAR(500) NULL COMMENT '주소', item_addr VARCHAR(500) NULL COMMENT '주소',
target_id VARCHAR(20) NULL COMMENT '이용 대상 - 공통코드 reserve-target', target_id VARCHAR(20) NULL COMMENT '이용 대상 - 공통코드 reserve-target',
@@ -45,5 +57,10 @@ CREATE TABLE IF NOT EXISTS reserve_item
created_by VARCHAR(255) NULL COMMENT '생성자', created_by VARCHAR(255) NULL COMMENT '생성자',
modified_date DATETIME NULL COMMENT '수정일', modified_date DATETIME NULL COMMENT '수정일',
last_modified_by VARCHAR(255) NULL COMMENT '수정자', last_modified_by VARCHAR(255) NULL COMMENT '수정자',
PRIMARY KEY (reserve_item_id) PRIMARY KEY (reserve_item_id),
); CONSTRAINT FK_reserve_item_location_id FOREIGN KEY (location_id)
REFERENCES location (location_id) ON DELETE RESTRICT ON UPDATE RESTRICT
) ;