✅ update test file (reserve-request-service)
This commit is contained in:
@@ -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