Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
# openjdk8 base image
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
# config server uri: dockder run --e 로 변경 가능
|
||||
ENV SPRING_CLOUD_CONFIG_URI https://egov-config.paas-ta.org
|
||||
# jar 파일이 복사되는 위치
|
||||
ENV APP_HOME=/usr/app/
|
||||
# 작업 시작 위치
|
||||
|
||||
@@ -10,7 +10,7 @@ applications:
|
||||
- egov-discovery-provided-service # discovery service binding
|
||||
env:
|
||||
spring_profiles_active: cf
|
||||
spring_cloud_config_uri: https://egov-config.paas-ta.org
|
||||
spring_cloud_config_uri: http://localhost:8888
|
||||
app_name: egov-reserve-request-service # logstash custom app name
|
||||
TZ: Asia/Seoul
|
||||
JAVA_OPTS: -Xss349k
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
package org.egovframe.cloud.reserverequestservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import reactor.blockhound.BlockHound;
|
||||
|
||||
import java.security.Security;
|
||||
|
||||
@ComponentScan({"org.egovframe.cloud.common", "org.egovframe.cloud.reactive", "org.egovframe.cloud.reserverequestservice"}) // org.egovframe.cloud.common package 포함하기 위해
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class ReserveRequestServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TLSv1/v1.1 No longer works after upgrade, "No appropriate protocol" error
|
||||
String property = Security.getProperty("jdk.tls.disabledAlgorithms").replace(", TLSv1", "").replace(", TLSv1.1", "");
|
||||
Security.setProperty("jdk.tls.disabledAlgorithms", property);
|
||||
|
||||
//blocking 코드 감지
|
||||
BlockHound.builder()
|
||||
//mysql r2dbc 에서 호출되는 FileInputStream.readBytes() 가 블로킹코드인데 이를 허용해주도록 한다.
|
||||
//해당 코드가 어디서 호출되는지 알지 못하는 상태에서 FileInputStream.readBytes() 자체를 허용해주는 것은 좋지 않다.
|
||||
// 누군가 무분별하게 사용하게 되면 검출해 낼 수ㅂ 없어 시스템의 위험요소로 남게 된다.
|
||||
// r2dbc를 사용하기 위해 해당 호출부분만 허용하고 나머지는 여전히 검출대상으로 남기도록 한다.
|
||||
.allowBlockingCallsInside("dev.miku.r2dbc.mysql.client.ReactorNettyClient", "init")
|
||||
.install();
|
||||
|
||||
SpringApplication.run(ReserveRequestServiceApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
package org.egovframe.cloud.reserverequestservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
//import reactor.blockhound.BlockHound;
|
||||
|
||||
import java.security.Security;
|
||||
|
||||
@ComponentScan({"org.egovframe.cloud.common", "org.egovframe.cloud.reactive", "org.egovframe.cloud.reserverequestservice"}) // org.egovframe.cloud.common package 포함하기 위해
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class ReserveRequestServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TLSv1/v1.1 No longer works after upgrade, "No appropriate protocol" error
|
||||
String property = Security.getProperty("jdk.tls.disabledAlgorithms").replace(", TLSv1", "").replace(", TLSv1.1", "");
|
||||
Security.setProperty("jdk.tls.disabledAlgorithms", property);
|
||||
|
||||
//blocking 코드 감지
|
||||
// BlockHound.builder()
|
||||
// //mysql r2dbc 에서 호출되는 FileInputStream.readBytes() 가 블로킹코드인데 이를 허용해주도록 한다.
|
||||
// //해당 코드가 어디서 호출되는지 알지 못하는 상태에서 FileInputStream.readBytes() 자체를 허용해주는 것은 좋지 않다.
|
||||
// // 누군가 무분별하게 사용하게 되면 검출해 낼 수ㅂ 없어 시스템의 위험요소로 남게 된다.
|
||||
// // r2dbc를 사용하기 위해 해당 호출부분만 허용하고 나머지는 여전히 검출대상으로 남기도록 한다.
|
||||
// .allowBlockingCallsInside("dev.miku.r2dbc.mysql.client.ReactorNettyClient", "init")
|
||||
// .install();
|
||||
|
||||
SpringApplication.run(ReserveRequestServiceApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,13 +10,17 @@ import org.egovframe.cloud.reserverequestservice.service.ReserveService;
|
||||
import org.springframework.amqp.core.AmqpAdmin;
|
||||
import org.springframework.amqp.core.MessageListener;
|
||||
import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.ServerSentEvent;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxSink;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* org.egovframe.cloud.reserverequestservice.api.ReserveApiController
|
||||
@@ -44,13 +48,28 @@ public class ReserveApiController {
|
||||
private final MessageListenerContainerFactory messageListenerContainerFactory;
|
||||
private final AmqpAdmin amqpAdmin;
|
||||
|
||||
private final Environment env;
|
||||
|
||||
/**
|
||||
* 서비스 상태 확인
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/actuator/health-info")
|
||||
public String status() {
|
||||
return String.format("GET Reserve Request Service on" +
|
||||
"\n local.server.port :" + env.getProperty("local.server.port")
|
||||
+ "\n egov.message :" + env.getProperty("egov.message")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 예약 신청 - 심사
|
||||
*
|
||||
* @param saveRequestDtoMono
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/api/v1/requests/audit")
|
||||
@PostMapping("/api/v1/requests/evaluates")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public Mono<ReserveResponseDto> create(@RequestBody Mono<ReserveSaveRequestDto> saveRequestDtoMono) {
|
||||
return saveRequestDtoMono.flatMap(reserveService::create);
|
||||
@@ -79,10 +98,12 @@ public class ReserveApiController {
|
||||
* @param reserveId
|
||||
* @return
|
||||
*/
|
||||
@CrossOrigin()
|
||||
@GetMapping(value = "/api/v1/requests/direct/{reserveId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public Flux<?> receiveReservationResult(@PathVariable String reserveId) {
|
||||
public Flux<String> receiveReservationResult(@PathVariable String reserveId) {
|
||||
MessageListenerContainer mlc = messageListenerContainerFactory.createMessageListenerContainer(reserveId);
|
||||
Flux<String> f = Flux.create(emitter -> {
|
||||
|
||||
mlc.setupMessageListener((MessageListener) m -> {
|
||||
String qname = m.getMessageProperties().getConsumerQueue();
|
||||
log.info("message received, queue={}", qname);
|
||||
@@ -118,7 +139,9 @@ public class ReserveApiController {
|
||||
.map(v -> {
|
||||
log.info("sending keepalive message...");
|
||||
return "no news is good news";
|
||||
}).mergeWith(f);
|
||||
})
|
||||
.mergeWith(f)
|
||||
.delayElements(Duration.ofSeconds(5));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
public interface ReserveRepositoryCustom {
|
||||
Mono<Reserve> insert(Reserve reserve);
|
||||
Flux<Reserve> findAllByReserveDateWithoutSelf(String reserveId, Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate);
|
||||
Mono<Long> findAllByReserveDateWithoutSelfCount(String reserveId, Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate);
|
||||
Flux<Reserve> findAllByReserveDate(Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate);
|
||||
Mono<Long> findAllByReserveDateCount(Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate);
|
||||
}
|
||||
|
||||
@@ -54,12 +54,11 @@ public class ReserveRepositoryImpl implements ReserveRepositoryCustom {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Flux<Reserve> findAllByReserveDateWithoutSelf(String reserveId, Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
public Flux<Reserve> findAllByReserveDate(Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
return entityTemplate.select(Reserve.class)
|
||||
.matching(Query.query(where("reserve_item_id").is(reserveItemId)
|
||||
.and ("reserve_start_date").lessThanOrEquals(endDate)
|
||||
.and("reserve_end_date").greaterThanOrEquals(startDate)
|
||||
.and("reserve_id").not(reserveId)
|
||||
))
|
||||
.all();
|
||||
}
|
||||
@@ -74,12 +73,11 @@ public class ReserveRepositoryImpl implements ReserveRepositoryCustom {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> findAllByReserveDateWithoutSelfCount(String reserveId, Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
public Mono<Long> findAllByReserveDateCount(Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
return entityTemplate.select(Reserve.class)
|
||||
.matching(Query.query(where("reserve_item_id").is(reserveItemId)
|
||||
.and ("reserve_start_date").lessThanOrEquals(endDate)
|
||||
.and("reserve_end_date").greaterThanOrEquals(startDate)
|
||||
.and("reserve_id").not(reserveId)
|
||||
))
|
||||
.count();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.egovframe.cloud.reserverequestservice.service;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.egovframe.cloud.common.config.GlobalConstant;
|
||||
import org.egovframe.cloud.common.dto.AttachmentEntityMessage;
|
||||
import org.egovframe.cloud.common.exception.BusinessMessageException;
|
||||
import org.egovframe.cloud.reactive.service.ReactiveAbstractService;
|
||||
import org.egovframe.cloud.reserverequestservice.api.dto.ReserveResponseDto;
|
||||
@@ -99,6 +100,12 @@ public class ReserveService extends ReactiveAbstractService {
|
||||
return Mono.just(tuple.getT1());
|
||||
})
|
||||
.flatMap(reserveRepository::insert)
|
||||
.doOnNext(reserve -> sendAttachmentEntityInfo(streamBridge,
|
||||
AttachmentEntityMessage.builder()
|
||||
.attachmentCode(reserve.getAttachmentCode())
|
||||
.entityName(reserve.getClass().getName())
|
||||
.entityId(reserve.getReserveId())
|
||||
.build()))
|
||||
.flatMap(this::convertReserveResponseDto);
|
||||
}
|
||||
|
||||
@@ -164,7 +171,8 @@ public class ReserveService extends ReactiveAbstractService {
|
||||
}else if (Category.SPACE.isEquals(saveRequestDto.getCategoryId())) {
|
||||
return checkSpace(saveRequestDto);
|
||||
}
|
||||
return Mono.error(new BusinessMessageException("저장 할 수 없습니다."));
|
||||
//해당 날짜에는 예약할 수 없습니다.
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.reserve_date")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,17 +188,23 @@ public class ReserveService extends ReactiveAbstractService {
|
||||
saveRequestDto.getRequestEndDate() : saveRequestDto.getOperationEndDate();
|
||||
|
||||
if (saveRequestDto.getReserveStartDate().isBefore(startDate)) {
|
||||
return Mono.error(new BusinessMessageException("시작일이 운영/예약 시작일 이전입니다."));
|
||||
//{0}이 {1} 보다 빠릅니다. 시작일, 운영/예약 시작일
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.to_be_fast.format", new Object[]{getMessage("common.start_date"),
|
||||
getMessage("reserve_item.operation")+getMessage("reserve")+" "+getMessage("common.start_date")})));
|
||||
}
|
||||
|
||||
if (saveRequestDto.getReserveEndDate().isAfter(endDate)) {
|
||||
return Mono.error(new BusinessMessageException("종료일이 운영/예약 종료일 이후입니다."));
|
||||
//{0}이 {1} 보다 늦습니다. 종료일, 운영/예약 종료일
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.to_be_slow.format", new Object[]{getMessage("common.end_date"),
|
||||
getMessage("reserve_item.operation")+getMessage("reserve")+" "+getMessage("common.end_date")})));
|
||||
}
|
||||
|
||||
if (saveRequestDto.getIsPeriod()) {
|
||||
long between = ChronoUnit.DAYS.between(saveRequestDto.getReserveStartDate(),
|
||||
saveRequestDto.getReserveEndDate());
|
||||
if (saveRequestDto.getPeriodMaxCount() < between) {
|
||||
return Mono.error(new BusinessMessageException("최대 예약 가능 일수보다 예약기간이 깁니다. (최대 예약 가능일 수 : "+saveRequestDto.getPeriodMaxCount()+")"));
|
||||
//최대 예약 가능 일수보다 예약기간이 깁니다. (최대 예약 가능일 수 : {0})
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.reserve_period", new Object[]{saveRequestDto.getPeriodMaxCount()})));
|
||||
}
|
||||
}
|
||||
return Mono.just(saveRequestDto);
|
||||
@@ -204,14 +218,14 @@ public class ReserveService extends ReactiveAbstractService {
|
||||
*/
|
||||
private Mono<ReserveSaveRequestDto> checkSpace(ReserveSaveRequestDto saveRequestDto) {
|
||||
return this.checkReserveDate(saveRequestDto)
|
||||
.flatMap(result -> reserveRepository.findAllByReserveDateWithoutSelfCount(
|
||||
result.getReserveId(),
|
||||
.flatMap(result -> reserveRepository.findAllByReserveDateCount(
|
||||
result.getReserveItemId(),
|
||||
result.getReserveStartDate(),
|
||||
result.getReserveEndDate())
|
||||
.flatMap(count -> {
|
||||
if (count > 0) {
|
||||
return Mono.error(new BusinessMessageException("해당 날짜에는 예약할 수 없습니다."));
|
||||
//해당 날짜에는 예약할 수 없습니다.
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.reserve_date")));
|
||||
}
|
||||
return Mono.just(result);
|
||||
})
|
||||
@@ -226,8 +240,7 @@ public class ReserveService extends ReactiveAbstractService {
|
||||
*/
|
||||
private Mono<ReserveSaveRequestDto> checkEquipment(ReserveSaveRequestDto saveRequestDto) {
|
||||
return this.checkReserveDate(saveRequestDto)
|
||||
.flatMap(result -> this.getMaxByReserveDateWithoutSelf(
|
||||
result.getReserveId(),
|
||||
.flatMap(result -> this.getMaxByReserveDate(
|
||||
result.getReserveItemId(),
|
||||
result.getReserveStartDate(),
|
||||
result.getReserveEndDate())
|
||||
@@ -239,7 +252,8 @@ public class ReserveService extends ReactiveAbstractService {
|
||||
})
|
||||
.flatMap(isValid -> {
|
||||
if (!isValid) {
|
||||
return Mono.error(new BusinessMessageException("해당 날짜에 예약할 수 있는 재고수량이 없습니다."));
|
||||
//해당 날짜에 예약할 수 있는 재고수량이 없습니다.
|
||||
return Mono.error(new BusinessMessageException(getMessage("valid.reserve_count")));
|
||||
}
|
||||
return Mono.just(saveRequestDto);
|
||||
})
|
||||
@@ -255,8 +269,8 @@ public class ReserveService extends ReactiveAbstractService {
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
private Mono<Integer> getMaxByReserveDateWithoutSelf(String reserveId, Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
Flux<Reserve> reserveFlux = reserveRepository.findAllByReserveDateWithoutSelf(reserveId, reserveItemId, startDate, endDate)
|
||||
private Mono<Integer> getMaxByReserveDate( Long reserveItemId, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
Flux<Reserve> reserveFlux = reserveRepository.findAllByReserveDate(reserveItemId, startDate, endDate)
|
||||
.switchIfEmpty(Flux.empty());
|
||||
|
||||
if (reserveFlux.equals(Flux.empty())) {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.egovframe.cloud.reserverequestservice.api;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.egovframe.cloud.common.domain.Role;
|
||||
import org.egovframe.cloud.reserverequestservice.api.dto.ReserveResponseDto;
|
||||
import org.egovframe.cloud.reserverequestservice.api.dto.ReserveSaveRequestDto;
|
||||
import org.egovframe.cloud.reserverequestservice.config.WithCustomMockUser;
|
||||
import org.egovframe.cloud.reserverequestservice.domain.Reserve;
|
||||
import org.egovframe.cloud.reserverequestservice.domain.ReserveRepository;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@EnableConfigurationProperties
|
||||
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
|
||||
@ActiveProfiles(profiles = "test")
|
||||
class ReserveApiControllerTest {
|
||||
|
||||
@Autowired
|
||||
private ReserveRepository reserveRepository;
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
private Reserve reserve;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
|
||||
reserve = Reserve.builder()
|
||||
.reserveId("1")
|
||||
.reserveQty(50)
|
||||
.reservePurposeContent("test")
|
||||
.reserveStatusId("request")
|
||||
.reserveStartDate(LocalDateTime.of(2021, 9, 9, 1, 1))
|
||||
.reserveEndDate(LocalDateTime.of(2021, 9, 20, 1, 1))
|
||||
.build();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
reserveRepository.deleteAll().block();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithCustomMockUser(userId = "user", role = Role.USER)
|
||||
public void 사용자_예약_성공() throws Exception {
|
||||
|
||||
ReserveSaveRequestDto saveRequestDto =
|
||||
ReserveSaveRequestDto.builder()
|
||||
.reserveItemId(reserve.getReserveItemId())
|
||||
.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();
|
||||
|
||||
ReserveResponseDto responseBody = webTestClient.post()
|
||||
.uri("/api/v1/requests/evaluates")
|
||||
.bodyValue(saveRequestDto)
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectBody(ReserveResponseDto.class)
|
||||
.returnResult().getResponseBody();
|
||||
|
||||
assertThat(responseBody.getReserveQty()).isEqualTo(reserve.getReserveQty());
|
||||
assertThat(responseBody.getReservePurposeContent()).isEqualTo(reserve.getReservePurposeContent());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.egovframe.cloud.reserverequestservice.config;
|
||||
|
||||
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.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.r2dbc.connection.init.CompositeDatabasePopulator;
|
||||
import org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer;
|
||||
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")
|
||||
@TestConfiguration
|
||||
@EnableR2dbcRepositories
|
||||
public class R2dbcConfig {
|
||||
@Bean
|
||||
public H2ConnectionFactory connectionFactory() {
|
||||
return new H2ConnectionFactory(H2ConnectionConfiguration.builder()
|
||||
.inMemory("testdb")
|
||||
.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,16 @@
|
||||
package org.egovframe.cloud.reserverequestservice.config;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.egovframe.cloud.common.domain.Role;
|
||||
import org.springframework.security.test.context.support.WithSecurityContext;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@WithSecurityContext(factory = WithMockCustomUserSecurityContextFactory.class)
|
||||
public @interface WithCustomMockUser {
|
||||
|
||||
String userId() default "user";
|
||||
Role role() default Role.ADMIN;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.egovframe.cloud.reserverequestservice.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.test.context.support.WithSecurityContextFactory;
|
||||
|
||||
public class WithMockCustomUserSecurityContextFactory implements WithSecurityContextFactory<WithCustomMockUser> {
|
||||
|
||||
@Override
|
||||
public SecurityContext createSecurityContext(WithCustomMockUser mockUser) {
|
||||
SecurityContext context = SecurityContextHolder.createEmptyContext();
|
||||
List<SimpleGrantedAuthority> roleList = new ArrayList<>();
|
||||
roleList.add(new SimpleGrantedAuthority(mockUser.role().getKey()));
|
||||
UsernamePasswordAuthenticationToken authenticationToken =
|
||||
new UsernamePasswordAuthenticationToken(mockUser.userId(), null, roleList);
|
||||
context.setAuthentication(authenticationToken);
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,7 @@
|
||||
spring:
|
||||
application:
|
||||
name: reserve-request-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:
|
||||
console:
|
||||
enabled: true
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
uri: http://localhost:8888
|
||||
name: reserve-request-service
|
||||
@@ -0,0 +1,23 @@
|
||||
-- reserve Table Create SQL
|
||||
CREATE TABLE IF NOT EXISTS reserve
|
||||
(
|
||||
reserve_id VARCHAR(255) NOT 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_purpose_content VARCHAR(4000) NULL COMMENT '예약신청 목적',
|
||||
attachment_code VARCHAR(255) NULL COMMENT '첨부파일 코드',
|
||||
reserve_start_date DATETIME NULL COMMENT '예약 신청 시작일',
|
||||
reserve_end_date DATETIME NULL COMMENT '예약 신청 종료일',
|
||||
reserve_status_id VARCHAR(20) NULL COMMENT '예약상태 - 공통코드(reserve-status)',
|
||||
reason_cancel_content VARCHAR(4000) NULL COMMENT '예약 취소 사유',
|
||||
user_id VARCHAR(255) NULL COMMENT '예약자 id',
|
||||
user_contact_no VARCHAR(50) NULL COMMENT '예약자 연락처',
|
||||
user_email_addr VARCHAR(500) 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_id)
|
||||
) ;
|
||||
Reference in New Issue
Block a user