refactor: 통합테스트, 유닛테스트 환경 분리 (#45)
* refactor: 통합테스트, 유닛테스트 환경 분리 * refactor: testImplementation 와 다른 게 없어서 통합
This commit is contained in:
@@ -23,8 +23,6 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
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-web")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-log4j2")
|
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-boot-starter:3.0.0")
|
||||||
implementation("io.springfox:springfox-swagger-ui: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.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
||||||
implementation("com.lmax:disruptor:3.4.2")
|
implementation("com.lmax:disruptor:3.4.4")
|
||||||
implementation("io.jsonwebtoken:jjwt-api:0.11.2")
|
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
|
||||||
implementation("com.googlecode.json-simple:json-simple:1.1.1")
|
implementation("com.googlecode.json-simple:json-simple:1.1.1")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
||||||
|
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||||
|
|
||||||
modules {
|
modules {
|
||||||
module("org.springframework.boot:spring-boot-starter-logging") {
|
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")
|
compileOnly("org.projectlombok:lombok")
|
||||||
runtimeOnly("mysql:mysql-connector-java")
|
runtimeOnly("mysql:mysql-connector-java")
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.2")
|
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.2")
|
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
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.boot:spring-boot-starter-test")
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation("org.springframework.security:spring-security-test")
|
||||||
}
|
}
|
||||||
@@ -66,3 +61,28 @@ dependencies {
|
|||||||
tasks.withType<Test> {
|
tasks.withType<Test> {
|
||||||
useJUnitPlatform()
|
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) }
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.ticketing.server.movie.domain.repository;
|
||||||
|
|
||||||
|
public class MovieTimesRepositoryTest {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package com.ticketing.server.movie.service;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class TMDBServiceImplTest {
|
||||||
|
|
||||||
|
@Value("${tmdb.api-key}")
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
@Value("${tmdb.read-access-token}")
|
||||||
|
private String readAccessToken;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("TMDB Service Test - Get [Now Playing] movies")
|
||||||
|
void shouldAbleToGetMovieList() throws Exception {
|
||||||
|
// given
|
||||||
|
assertNotNull(apiKey);
|
||||||
|
assertNotNull(readAccessToken);
|
||||||
|
|
||||||
|
ArrayList<Charset> acceptCharset = new ArrayList<>();
|
||||||
|
acceptCharset.add(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setAcceptCharset(acceptCharset);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.setBearerAuth(readAccessToken);
|
||||||
|
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("api_key", apiKey);
|
||||||
|
params.put("language", "ko");
|
||||||
|
|
||||||
|
HttpEntity<?> request = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
// when
|
||||||
|
ResponseEntity<?> response = restTemplate.exchange(
|
||||||
|
"https://api.themoviedb.org/3/movie/now_playing?" + mapToUrlParam(params),
|
||||||
|
HttpMethod.GET,
|
||||||
|
request,
|
||||||
|
String.class
|
||||||
|
);
|
||||||
|
|
||||||
|
// JSONParser parser = new JSONParser();
|
||||||
|
// Object obj = parser.parse(String.valueOf(response));
|
||||||
|
// Object results = ((JSONObject) obj).get("results");
|
||||||
|
//
|
||||||
|
// ArrayList<String> movieList = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// ArrayList<JSONObject> jsonMovieList = new ArrayList<>();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String mapToUrlParam(Map<String, String> params) {
|
||||||
|
StringBuffer paramData = new StringBuffer();
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> param : params.entrySet()) {
|
||||||
|
if (paramData.length() != 0) {
|
||||||
|
paramData.append('&');
|
||||||
|
}
|
||||||
|
|
||||||
|
paramData.append(param.getKey());
|
||||||
|
paramData.append('=');
|
||||||
|
paramData.append(param.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return paramData.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ class AuthControllerTest {
|
|||||||
|
|
||||||
private static final String LOGIN_URL = "/api/auth/token";
|
private static final String LOGIN_URL = "/api/auth/token";
|
||||||
private static final String REGISTER_URL = "/api/users";
|
private static final String REGISTER_URL = "/api/users";
|
||||||
|
private static final String USER_EMAIL = "ticketing@gmail.com";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WebApplicationContext context;
|
WebApplicationContext context;
|
||||||
@@ -53,7 +54,7 @@ class AuthControllerTest {
|
|||||||
@DisplayName("로그인 인증 성공")
|
@DisplayName("로그인 인증 성공")
|
||||||
void loginSuccess() throws Exception {
|
void loginSuccess() throws Exception {
|
||||||
// given
|
// given
|
||||||
LoginRequest request = new LoginRequest("ticketing@gmail.com", "qwe123");
|
LoginRequest request = new LoginRequest(USER_EMAIL, "qwe123");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
||||||
@@ -69,7 +70,7 @@ class AuthControllerTest {
|
|||||||
@DisplayName("로그인 패스워드 인증 실패")
|
@DisplayName("로그인 패스워드 인증 실패")
|
||||||
void loginPasswordFail() throws Exception {
|
void loginPasswordFail() throws Exception {
|
||||||
// given
|
// given
|
||||||
LoginRequest request = new LoginRequest("ticketing@gmail.com", "qwe1234");
|
LoginRequest request = new LoginRequest(USER_EMAIL, "qwe1234");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
ResultActions actions = mvc.perform(post(LOGIN_URL)
|
||||||
@@ -81,10 +82,6 @@ class AuthControllerTest {
|
|||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String asJsonString(Object object) throws JsonProcessingException {
|
|
||||||
return objectMapper.writeValueAsString(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() throws Exception {
|
void init() throws Exception {
|
||||||
mvc = MockMvcBuilders
|
mvc = MockMvcBuilders
|
||||||
@@ -92,7 +89,7 @@ class AuthControllerTest {
|
|||||||
.apply(springSecurity())
|
.apply(springSecurity())
|
||||||
.build();
|
.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)
|
mvc.perform(post(REGISTER_URL)
|
||||||
.content(asJsonString(signUpRequest))
|
.content(asJsonString(signUpRequest))
|
||||||
@@ -104,4 +101,8 @@ class AuthControllerTest {
|
|||||||
refreshRedisRepository.deleteAll();
|
refreshRedisRepository.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String asJsonString(Object object) throws JsonProcessingException {
|
||||||
|
return objectMapper.writeValueAsString(object);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ticketing.server.user.application;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class UserControllerTest {
|
||||||
|
|
||||||
|
}
|
||||||
37
server/src/intTest/resources/application.yml
Normal file
37
server/src/intTest/resources/application.yml
Normal 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
|
||||||
@@ -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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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:
|
jwt:
|
||||||
access-header: Authorization
|
access-header: Authorization
|
||||||
|
|||||||
Reference in New Issue
Block a user