Compare commits

...

2 Commits

Author SHA1 Message Date
dongHyo
e0c6c46a01 refactor: testImplementation 와 다른 게 없어서 통합 2022-06-30 22:21:23 +09:00
dongHyo
2fc17bb9ce refactor: 통합테스트, 유닛테스트 환경 분리 2022-06-30 21:48:15 +09:00
16 changed files with 84 additions and 92 deletions

View File

@@ -23,8 +23,6 @@ repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
@@ -32,14 +30,15 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("org.projectlombok:lombok:1.18.20")
implementation("org.projectlombok:lombok:1.18.24")
implementation("io.springfox:springfox-boot-starter:3.0.0")
implementation("io.springfox:springfox-swagger-ui:3.0.0")
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
implementation("com.lmax:disruptor:3.4.2")
implementation("io.jsonwebtoken:jjwt-api:0.11.2")
implementation("com.lmax:disruptor:3.4.4")
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
implementation("com.googlecode.json-simple:json-simple:1.1.1")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("com.google.code.findbugs:jsr305:3.0.2")
modules {
module("org.springframework.boot:spring-boot-starter-logging") {
@@ -47,18 +46,14 @@ dependencies {
}
}
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
compileOnly("org.projectlombok:lombok")
runtimeOnly("mysql:mysql-connector-java")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.2")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.2")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
annotationProcessor("org.projectlombok:lombok")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
}
@@ -66,3 +61,28 @@ dependencies {
tasks.withType<Test> {
useJUnitPlatform()
}
sourceSets {
create("intTest") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}
val intTestImplementation by configurations.getting {
extendsFrom(configurations.implementation.get())
}
configurations["intTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())
configurations["intTestImplementation"].extendsFrom(configurations.testImplementation.get())
val integrationTest = task<Test>("integrationTest") {
description = "Runs integration tests."
group = "verification"
testClassesDirs = sourceSets["intTest"].output.classesDirs
classpath = sourceSets["intTest"].runtimeClasspath
shouldRunAfter("test")
}
tasks.check { dependsOn(integrationTest) }

View File

@@ -31,6 +31,7 @@ class AuthControllerTest {
private static final String LOGIN_URL = "/api/auth/token";
private static final String REGISTER_URL = "/api/users";
private static final String USER_EMAIL = "ticketing@gmail.com";
@Autowired
WebApplicationContext context;
@@ -53,7 +54,7 @@ class AuthControllerTest {
@DisplayName("로그인 인증 성공")
void loginSuccess() throws Exception {
// given
LoginRequest request = new LoginRequest("ticketing@gmail.com", "qwe123");
LoginRequest request = new LoginRequest(USER_EMAIL, "qwe123");
// when
ResultActions actions = mvc.perform(post(LOGIN_URL)
@@ -69,7 +70,7 @@ class AuthControllerTest {
@DisplayName("로그인 패스워드 인증 실패")
void loginPasswordFail() throws Exception {
// given
LoginRequest request = new LoginRequest("ticketing@gmail.com", "qwe1234");
LoginRequest request = new LoginRequest(USER_EMAIL, "qwe1234");
// when
ResultActions actions = mvc.perform(post(LOGIN_URL)
@@ -81,10 +82,6 @@ class AuthControllerTest {
.andExpect(status().isUnauthorized());
}
private String asJsonString(Object object) throws JsonProcessingException {
return objectMapper.writeValueAsString(object);
}
@BeforeEach
void init() throws Exception {
mvc = MockMvcBuilders
@@ -92,7 +89,7 @@ class AuthControllerTest {
.apply(springSecurity())
.build();
SignUpRequest signUpRequest = new SignUpRequest("ticketing", "ticketing@gmail.com", "qwe123", "010-2240-7920");
SignUpRequest signUpRequest = new SignUpRequest("ticketing", USER_EMAIL, "qwe123", "010-1234-5678");
mvc.perform(post(REGISTER_URL)
.content(asJsonString(signUpRequest))
@@ -104,4 +101,8 @@ class AuthControllerTest {
refreshRedisRepository.deleteAll();
}
private String asJsonString(Object object) throws JsonProcessingException {
return objectMapper.writeValueAsString(object);
}
}

View File

@@ -0,0 +1,7 @@
package com.ticketing.server.user.application;
import static org.junit.jupiter.api.Assertions.*;
class UserControllerTest {
}

View File

@@ -0,0 +1,37 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/ticketing_test?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
username: ENC(LowN1n4w0Ep/DqLD8+q5Bq6AXM4b8e3V)
password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
driver-class-name: com.mysql.cj.jdbc.Driver
redis:
host: localhost
port: 6379
jpa:
properties:
hibernate:
show_sql: true
format_sql: true
hibernate:
ddl-auto: create
mvc:
pathmatch:
matching-strategy: ant_path_matcher
jasypt:
encryptor:
bean: jasyptStringEncryptor
jwt:
access-header: Authorization
refresh-header: REFRESH_TOKEN
prefix: Bearer
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
access-token-validity-in-seconds: 60
refresh-token-validity-in-seconds: 259200
tmdb:
api-key: 0d1503b6dcbfe1c514299b5564c649b8
read-access-token: eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwZDE1MDNiNmRjYmZlMWM1MTQyOTliNTU2NGM2NDliOCIsInN1YiI6IjYyOWYwODRlNzI2ZmIxMTA2NDA4MjI2NCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.rs8KZea8QLyashILiggWFx2s46lgUtzo-xSWoDgE58A

View File

@@ -1,13 +0,0 @@
package com.ticketing.server;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ServerApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -1,31 +0,0 @@
package com.ticketing.server.user.domain.repository;
import static org.assertj.core.api.Assertions.assertThat;
import com.ticketing.server.user.domain.User;
import com.ticketing.server.user.domain.UserGrade;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
@SpringBootTest
@Transactional
class UserRepositoryTest {
@Autowired
UserRepository userRepository;
@Test
void 유저레포지토리테스트() {
// given
User user = new User("유저1", "email@gmail.com", "testPassword01", UserGrade.GUEST, "010-1234-5678");
// when
userRepository.save(user);
// then
assertThat(user).isNotNull();
}
}

View File

@@ -1,28 +1,3 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/ticketing_test?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
username: ENC(LowN1n4w0Ep/DqLD8+q5Bq6AXM4b8e3V)
password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
driver-class-name: com.mysql.cj.jdbc.Driver
redis:
host: localhost
port: 6379
jpa:
properties:
hibernate:
show_sql: true
format_sql: true
hibernate:
ddl-auto: create
mvc:
pathmatch:
matching-strategy: ant_path_matcher
jasypt:
encryptor:
bean: jasyptStringEncryptor
jwt:
access-header: Authorization
@@ -31,7 +6,3 @@ jwt:
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
access-token-validity-in-seconds: 60
refresh-token-validity-in-seconds: 259200
tmdb:
api-key: 0d1503b6dcbfe1c514299b5564c649b8
read-access-token: eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwZDE1MDNiNmRjYmZlMWM1MTQyOTliNTU2NGM2NDliOCIsInN1YiI6IjYyOWYwODRlNzI2ZmIxMTA2NDA4MjI2NCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.rs8KZea8QLyashILiggWFx2s46lgUtzo-xSWoDgE58A