-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/test' into dev-check
- Loading branch information
Showing
36 changed files
with
595 additions
and
55 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
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,47 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: local | ||
|
||
kakao: | ||
api-url: ${KAKAO_API_URL} | ||
token-info-url: ${KAKAO_TOKEN_INFO_URL} | ||
client-id: ${KAKAO_CLIENT_ID} | ||
redirect-uri: ${KAKAO_REDIRECT_URL} | ||
token-api-url: ${KAKAO_TOKEN_API_URL} | ||
user-api-url: ${KAKAO_USER_API_URL} | ||
map-api-url: ${KAKAO_MAP_API_URL} | ||
|
||
naver: | ||
client-id: ${NAVER_CLIENT_ID} | ||
client-secret: ${NAVER_CLIENT_SECRET} | ||
state: ${NAVER_STATE} | ||
token-api-url: ${NAVER_TOKEN_API_URL} | ||
user-api-url: ${NAVER_USER_API_URL} | ||
|
||
storage-path: | ||
shelter-database-init-path: ${SHELTER_DATABASE_INIT_PATH} | ||
|
||
--- | ||
|
||
spring: | ||
config: | ||
activate: | ||
on-profile: dev | ||
|
||
kakao: | ||
client-id: ${KAKAO_CLIENT_ID} | ||
redirect-uri: ${KAKAO_REDIRECT_URL} | ||
token-api-url: ${KAKAO_TOKEN_API_URL} | ||
user-api-url: ${KAKAO_USER_API_URL} | ||
map-api-url: ${KAKAO_MAP_API_URL} | ||
|
||
naver: | ||
client-id: ${NAVER_CLIENT_ID} | ||
client-secret: ${NAVER_CLIENT_SECRET} | ||
state: ${NAVER_STATE} | ||
token-api-url: ${NAVER_TOKEN_API_URL} | ||
user-api-url: ${NAVER_USER_API_URL} | ||
|
||
storage-path: | ||
shelter-database-init-path: ${SHELTER_DATABASE_INIT_PATH} |
78 changes: 78 additions & 0 deletions
78
daepiro-api/src/test/java/com/numberone/backend/ServiceIntegrationTestBase.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,78 @@ | ||
package com.numberone.backend; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
|
||
|
||
@Slf4j | ||
@SpringBootTest(classes = ServiceIntegrationTestConfiguration.class) | ||
@Import({CoreTestConfiguration.class}) | ||
public abstract class ServiceIntegrationTestBase { | ||
|
||
private static final String REDIS_DOCKER_IMAGE = "redis:5.0.3-alpine"; | ||
private static final String MYSQL_DOCKER_IMAGE = "mysql:8.0"; | ||
private static final String MYSQL_ROOT = "root"; | ||
private static final String MYSQL_PASSWORD = "1234"; | ||
|
||
private static final int REDIS_PORT = 6379; | ||
|
||
@Container | ||
protected static MySQLContainer mySQLContainer; | ||
|
||
@Container | ||
protected static GenericContainer redisContainer; | ||
|
||
@DynamicPropertySource | ||
static void configureProperties(final DynamicPropertyRegistry registry) { | ||
// mysql env init | ||
log.info(""" | ||
\n | ||
✅ mysql property 를 주입합니다. | ||
"""); | ||
registry.add("spring.datasource.url", mySQLContainer::getJdbcUrl); | ||
registry.add("spring.datasource.username", () -> MYSQL_ROOT); | ||
registry.add("spring.datasource.password", () -> MYSQL_PASSWORD); | ||
|
||
// redis env init | ||
log.info(""" | ||
\n | ||
✅ redis property 를 주입합니다. | ||
"""); | ||
registry.add("spring.redis.host", redisContainer::getHost); | ||
registry.add("spring.redis.port", () -> "" + redisContainer.getMappedPort(REDIS_PORT)); | ||
} | ||
|
||
static { | ||
// mysql test container init | ||
mySQLContainer = (MySQLContainer) new MySQLContainer(MYSQL_DOCKER_IMAGE) | ||
.withUsername(MYSQL_ROOT) | ||
.withPassword(MYSQL_PASSWORD) | ||
.withDatabaseName("test") | ||
.withEnv("MYSQL_ROOT_PASSWORD", MYSQL_PASSWORD); | ||
|
||
log.info(""" | ||
\n | ||
🐳 MYSQL 테스트 컨테이너를 시작합니다. | ||
- base image: {} | ||
""", MYSQL_DOCKER_IMAGE); | ||
mySQLContainer.start(); | ||
|
||
// redis test container init | ||
redisContainer = new GenericContainer<>(REDIS_DOCKER_IMAGE) | ||
.withExposedPorts(REDIS_PORT) | ||
.withReuse(true); | ||
log.info(""" | ||
\n | ||
🐳 Redis 테스트 컨테이너를 시작합니다. | ||
- base image: {} | ||
""", REDIS_DOCKER_IMAGE); | ||
redisContainer.start(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
daepiro-api/src/test/java/com/numberone/backend/ServiceIntegrationTestConfiguration.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,25 @@ | ||
package com.numberone.backend; | ||
|
||
import com.numberone.backend.config.FirebaseConfig; | ||
import com.numberone.backend.config.S3Config; | ||
import com.numberone.backend.provider.s3.S3Provider; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@ActiveProfiles("test") | ||
@TestConfiguration | ||
@SpringBootApplication | ||
public class ServiceIntegrationTestConfiguration { | ||
|
||
@MockBean | ||
private S3Config s3Config; | ||
|
||
@MockBean | ||
private S3Provider s3Provider; | ||
|
||
@MockBean | ||
private FirebaseConfig firebaseConfig; | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
daepiro-api/src/test/java/com/numberone/backend/domain/shelter/ServiceServiceTest.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,36 @@ | ||
package com.numberone.backend.domain.shelter; | ||
|
||
import com.numberone.backend.ServiceIntegrationTestBase; | ||
import com.numberone.backend.domain.shelter.dto.request.NearbyShelterRequest; | ||
import com.numberone.backend.domain.shelter.dto.response.NearbyShelterListResponse; | ||
import com.numberone.backend.domain.shelter.entity.Shelter; | ||
import com.numberone.backend.domain.shelter.repository.ShelterRepository; | ||
import com.numberone.backend.domain.shelter.service.ShelterService; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class ServiceServiceTest extends ServiceIntegrationTestBase { | ||
|
||
@Autowired | ||
private ShelterService shelterService; | ||
|
||
@Autowired | ||
private ShelterRepository shelterRepository; | ||
|
||
@DisplayName("1000 m 이내에 위치한 주변 대피소 리스트를 조회할 수 있습니다.") | ||
@Test | ||
void getNearestShelterTest() { | ||
// given | ||
shelterRepository.save(Shelter.of(ShelterType.CIVIL_DEFENCE, "1000m 이내의 대피소 민방위대피소", 35.504, 35.5)); | ||
shelterRepository.save(Shelter.of(ShelterType.CIVIL_DEFENCE, "1000m 보다 먼 대피소", 36.504, 36.5)); | ||
|
||
// when | ||
NearbyShelterListResponse response = shelterService.getNearbyShelterList(NearbyShelterRequest.of(35.5, 35.5, "민방위")); | ||
|
||
// then | ||
Assertions.assertThat(response.getCount()).isEqualTo(1); | ||
} | ||
|
||
} |
Oops, something went wrong.