-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: TestContainers 라이브러리 적용하여 MySQL 컨테이너 설정 * test: ControllerTest와 ServiceTest에 MySql Container 사용한도록 하는 스프링 컨텍스트 구현 * test: ControllerTest와 ServiceTest에 MySql Container 사용한도록 하는 스프링 컨텍스트 적용 * chore: DEV 브랜치 CI/CD 워크플로우 수정
- Loading branch information
1 parent
1a45f38
commit eb385e5
Showing
26 changed files
with
129 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
backend/src/test/java/com/now/naaga/common/MySqlContainerControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.now.naaga.common; | ||
|
||
import com.now.naaga.auth.domain.AuthToken; | ||
import com.now.naaga.auth.infrastructure.AuthType; | ||
import com.now.naaga.auth.infrastructure.jwt.AuthTokenGenerator; | ||
import com.now.naaga.auth.infrastructure.jwt.JwtProvider; | ||
import com.now.naaga.member.domain.Member; | ||
import com.now.naaga.player.domain.Player; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.ExtractableResponse; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
public abstract class MySqlContainerControllerTest extends MySqlContainerTest { | ||
|
||
@Autowired | ||
protected AuthTokenGenerator authTokenGenerator; | ||
|
||
@Autowired | ||
protected JwtProvider jwtProvider; | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
RestAssured.port = port; | ||
} | ||
|
||
protected String authorizationForBearer(final Player player) { | ||
final Member member = player.getMember(); | ||
final AuthToken generate = authTokenGenerator.generate(member, member.getId(), AuthType.KAKAO); | ||
final String accessToken = generate.getAccessToken(); | ||
return "Bearer " + accessToken; | ||
} | ||
|
||
protected String authorizationForBearer(final Member member) { | ||
final AuthToken generate = authTokenGenerator.generate(member, member.getId(), AuthType.KAKAO); | ||
final String accessToken = generate.getAccessToken(); | ||
return "Bearer " + accessToken; | ||
} | ||
|
||
protected Long getIdFromLocationHeader(ExtractableResponse<Response> extractableResponse) { | ||
String[] split = extractableResponse.header("Location").split("/"); | ||
return Long.parseLong(split[split.length - 1]); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/test/java/com/now/naaga/common/MySqlContainerServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.now.naaga.common; | ||
|
||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
public abstract class MySqlContainerServiceTest extends MySqlContainerTest { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/test/java/com/now/naaga/common/MySqlContainerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.now.naaga.common; | ||
|
||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.MySQLContainer; | ||
|
||
public abstract class MySqlContainerTest extends AbstractTest { | ||
|
||
static final MySQLContainer<?> mySqlContainer = new MySQLContainer<>("mysql:8.0.35"); | ||
|
||
@DynamicPropertySource | ||
static void mySqlProperties(final DynamicPropertyRegistry registry) { | ||
mySqlContainer.start(); | ||
registry.add("spring.datasource.url", mySqlContainer::getJdbcUrl); | ||
registry.add("spring.datasource.username", mySqlContainer::getUsername); | ||
registry.add("spring.datasource.password", mySqlContainer::getPassword); | ||
registry.add("spring.datasource.driver-class-name", mySqlContainer::getDriverClassName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.