Initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package org.egovframe.cloud.reserveitemservice;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ReserveItemServiceApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package org.egovframe.cloud.reserveitemservice.api.location;
|
||||
|
||||
import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationSaveRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.api.location.dto.LocationUpdateRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.Location;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.LocationRepository;
|
||||
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.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
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.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@EnableConfigurationProperties
|
||||
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
|
||||
@ActiveProfiles("test")
|
||||
@Import({R2dbcConfig.class})
|
||||
class LocationApiControllerTest {
|
||||
|
||||
@MockBean
|
||||
private LocationRepository locationRepository;
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
private final static String API_URL = "/api/v1/locations";
|
||||
|
||||
private Location location = Location.builder()
|
||||
.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));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건조회_성공() throws Exception {
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"/{locationId}", location.getLocationId())
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.locationName").isEqualTo(location.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 조회조건있는경우_페이지목록조회_성공() throws Exception {
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"?keywordType=locationName&keyword=location&page=0&size=3")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].locationName").isEqualTo(location.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 조회조건없는경우_페이지목록조회_성공() throws Exception {
|
||||
webTestClient.get()
|
||||
.uri(API_URL+"?page=0&size=3")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody()
|
||||
.jsonPath("$.totalElements").isEqualTo(1)
|
||||
.jsonPath("$.content[0].locationName").isEqualTo(location.getLocationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건저장_성공() throws Exception {
|
||||
webTestClient.post()
|
||||
.uri(API_URL)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(LocationSaveRequestDto.builder()
|
||||
.locationName(location.getLocationName())
|
||||
.isUse(location.getIsUse())
|
||||
.sortSeq(location.getSortSeq())
|
||||
.build()))
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectBody().jsonPath("$.locationName").isEqualTo(location.getLocationName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건수정_성공() throws Exception {
|
||||
webTestClient.put()
|
||||
.uri(API_URL+"/{locationId}", location.getLocationId())
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(LocationUpdateRequestDto.builder()
|
||||
.locationName("updateLocation")
|
||||
.isUse(location.getIsUse())
|
||||
.sortSeq(location.getSortSeq())
|
||||
.build()))
|
||||
.exchange()
|
||||
.expectStatus().isNoContent();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 한건삭제_참조데이터존재_삭제실패() throws Exception {
|
||||
BDDMockito.when(locationRepository.delete(ArgumentMatchers.any(Location.class)))
|
||||
.thenReturn(Mono.error(new DataIntegrityViolationException("integrity test")));
|
||||
webTestClient.delete()
|
||||
.uri(API_URL+"/{locationId}", 1L)
|
||||
.exchange()
|
||||
.expectStatus().isBadRequest();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package org.egovframe.cloud.reserveitemservice.api.reserveItem;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.egovframe.cloud.reserveitemservice.api.reserveItem.dto.ReserveItemRequestDto;
|
||||
import org.egovframe.cloud.reserveitemservice.config.R2dbcConfig;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.code.Code;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.location.Location;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItem;
|
||||
import org.egovframe.cloud.reserveitemservice.domain.reserveItem.ReserveItemRepository;
|
||||
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.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@EnableConfigurationProperties
|
||||
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
|
||||
@ActiveProfiles(profiles = "test")
|
||||
@Import({R2dbcConfig.class})
|
||||
class ReserveItemApiControllerTest {
|
||||
|
||||
|
||||
@MockBean
|
||||
ReserveItemRepository reserveItemRepository;
|
||||
|
||||
@Autowired
|
||||
WebTestClient webTestClient;
|
||||
|
||||
private final static String API_URL = "/api/v1/reserve-items";
|
||||
|
||||
|
||||
@Test
|
||||
public void 사용자별_검색_목록_조회_성공() throws Exception {
|
||||
LocalDateTime startDate = LocalDateTime.of(2021, 1, 28, 1,1);
|
||||
LocalDateTime endDate = LocalDateTime.of(2021, 12, 6, 1,1);
|
||||
|
||||
Location location = Location.builder()
|
||||
.locationId(1L)
|
||||
.locationName("location")
|
||||
.sortSeq(1)
|
||||
.isUse(true)
|
||||
.build();
|
||||
ReserveItem reserveItem = ReserveItem.builder()
|
||||
.reserveItemId(1L)
|
||||
.location(location)
|
||||
.locationId(location.getLocationId())
|
||||
.reserveItemName("test")
|
||||
.categoryId("education")
|
||||
.categoryName("교육")
|
||||
.totalQty(100)
|
||||
.inventoryQty(80)
|
||||
.operationEndDate(endDate)
|
||||
.operationStartDate(startDate)
|
||||
.isPeriod(false)
|
||||
.isUse(true)
|
||||
.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(),
|
||||
ArgumentMatchers.any(ReserveItemRequestDto.class), ArgumentMatchers.any(Pageable.class)))
|
||||
.thenReturn(Mono.just(1L));
|
||||
|
||||
webTestClient.get()
|
||||
.uri("/api/v1/{categoryId}/reserve-items?keywordType=locationName&keyword=location&page=0&size=3", "education")
|
||||
.exchange()
|
||||
.expectStatus().isOk();
|
||||
|
||||
}
|
||||
@Test
|
||||
public void main_예약물품조회_성공() throws Exception {
|
||||
BDDMockito.when(reserveItemRepository.findCodeDetail(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Flux.fromIterable(Arrays.asList(Code.builder().codeId("education").codeName("교육").build(),
|
||||
Code.builder().codeId("equipment").codeName("장비").build(),
|
||||
Code.builder().codeId("space").codeName("장소").build())));
|
||||
|
||||
LocalDateTime startDate = LocalDateTime.of(2021, 1, 28, 1,1);
|
||||
LocalDateTime endDate = LocalDateTime.of(2021, 12, 6, 1,1);
|
||||
|
||||
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()
|
||||
.expectStatus().isOk();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.egovframe.cloud.reserveitemservice.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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.r2dbc.connection.init.CompositeDatabasePopulator;
|
||||
import org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer;
|
||||
import org.springframework.r2dbc.connection.init.ResourceDatabasePopulator;
|
||||
|
||||
@Profile("test")
|
||||
@TestConfiguration
|
||||
@EnableR2dbcRepositories
|
||||
public class R2dbcConfig{
|
||||
@Bean
|
||||
public H2ConnectionFactory connectionFactory() {
|
||||
return new H2ConnectionFactory(H2ConnectionConfiguration.builder()
|
||||
.tcp("localhost", "~/querydsl")
|
||||
.property(H2ConnectionOption.DB_CLOSE_DELAY, "-1")
|
||||
.username("sa")
|
||||
.build());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConnectionFactoryInitializer initializer(ConnectionFactory connectionFactory) {
|
||||
ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer();
|
||||
initializer.setConnectionFactory(connectionFactory);
|
||||
CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
|
||||
populator.addPopulators(new ResourceDatabasePopulator(new ClassPathResource("schema-h2.sql")));
|
||||
initializer.setDatabasePopulator(populator);
|
||||
|
||||
return initializer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
spring:
|
||||
application:
|
||||
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:
|
||||
console:
|
||||
enabled: true
|
||||
path: /h2
|
||||
|
||||
logging.level:
|
||||
org.hibernate.SQL: debug
|
||||
|
||||
file:
|
||||
directory: ${user.home}/msa-attach-volume
|
||||
messages:
|
||||
directory: ${file.directory}/messages
|
||||
|
||||
# jwt token
|
||||
token:
|
||||
secret: egovframe_user_token
|
||||
|
||||
# ftp server
|
||||
ftp:
|
||||
enabled: false # ftp 사용 여부, FTP 서버에 최상위 디렉토리 자동 생성 및 구현체를 결정하게 된다.
|
||||
|
||||
# eureka 가 포함되면 eureka server 도 등록되므로 해제한다.
|
||||
eureka:
|
||||
client:
|
||||
register-with-eureka: false
|
||||
fetch-registry: false
|
||||
@@ -0,0 +1,19 @@
|
||||
spring:
|
||||
application:
|
||||
name: reserve-item-service
|
||||
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
springramework:
|
||||
data:
|
||||
r2dbc: DEBUG
|
||||
|
||||
|
||||
file:
|
||||
location: ${user.home}/msa-attach-volume
|
||||
|
||||
|
||||
# jwt token
|
||||
token:
|
||||
secret: egovframe_user_token
|
||||
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
uri: http://localhost:8888
|
||||
name: reserve-item-service
|
||||
@@ -0,0 +1,49 @@
|
||||
CREATE TABLE IF NOT EXISTS location(
|
||||
location_id BIGINT AUTO_INCREMENT,
|
||||
location_name VARCHAR(200),
|
||||
use_at tinyint(1) default 1 null,
|
||||
sort_seq smallint(3) null,
|
||||
create_date DATE null,
|
||||
modified_date DATE null,
|
||||
created_by VARCHAR(255) null,
|
||||
last_modified_by VARCHAR(255) null,
|
||||
CONSTRAINT PERSON_PK 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',
|
||||
capacity_count MEDIUMINT(5) 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)
|
||||
);
|
||||
Reference in New Issue
Block a user