실패 테스트 모두 수정

This commit is contained in:
shinmj
2021-11-15 14:58:16 +09:00
parent 952c5e248e
commit e298bc9c20
22 changed files with 149 additions and 46 deletions

View File

@@ -2,7 +2,9 @@ package org.egovframe.cloud.apigateway;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@ActiveProfiles(profiles = "test")
@SpringBootTest
class ApigatewayApplicationTests {

View File

@@ -4,10 +4,12 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@ActiveProfiles(profiles = "test")
@SpringBootTest(webEnvironment = RANDOM_PORT)
class MessageSourceConfigTest {
@@ -17,7 +19,7 @@ class MessageSourceConfigTest {
@Test
public void 메세지를_외부위치에서_읽어온다() throws Exception {
// when
String message = restTemplate.getForObject("http://localhost:8000/api/v1/messages/common.login/ko", String.class);
String message = restTemplate.getForObject("/api/v1/messages/common.login/ko", String.class);
// then
assertThat(message).isEqualTo("로그인");

View File

@@ -1,27 +1,33 @@
package org.egovframe.cloud.apigateway.config;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
@SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class ReactiveAuthorizationTest {
@Value("${server.port}")
private String PORT;
@Autowired
private WebTestClient webTestClient;
@Test
public void API요청시_토큰인증_만료된다() throws Exception {
// given
String baseUrl = "http://localhost:" + PORT;
String notValidToken = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI2NWEwMGY2NS04NDYwLTQ5YWYtOThlYy0wNDI5NzdlNTZmNGIiLCJhdXRob3JpdGllcyI6IlJPTEVfVVNFUiIsImV4cCI6MTYyNjc4MjQ0N30.qiScvtr1m88SHPLpHqcJiklXFyIQ7WBJdiFcdcb2B8YSWC59QcdRRgMtXDGSZnjBgF194W-GRBpHUta6VCkrfQ";
// when, then
WebTestClient.bindToServer().baseUrl(baseUrl).defaultHeader(HttpHeaders.AUTHORIZATION, notValidToken).build()
webTestClient
.get()
.uri("/user-service/api/v1/users")
.header(HttpHeaders.AUTHORIZATION, notValidToken)
.exchange().expectStatus().isUnauthorized()
;
}

View File

@@ -0,0 +1,25 @@
server:
port: 8000
spring:
application:
name: apigateway
file:
directory: ${user.home}/msa-attach-volume
messages:
directory: ${file.directory}/messages
# jwt token
token:
secret: egovframe_user_token
# ftp server
ftp:
enabled: false # ftp 사용 여부, FTP 서버에 최상위 디렉토리 자동 생성 및 구현체를 결정하게 된다.
# eureka 가 포함되면 eureka server 도 등록되므로 해제한다.
eureka:
client:
register-with-eureka: false
fetch-registry: false

View File

@@ -2,8 +2,10 @@ package org.egovframe.cloud.portalservice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest
@ActiveProfiles(profiles = "test")
class PortalServiceApplicationTests {
@Test

View File

@@ -7,6 +7,7 @@ import org.egovframe.cloud.portalservice.api.code.dto.CodeResponseDto;
import org.egovframe.cloud.portalservice.api.code.dto.CodeSaveRequestDto;
import org.egovframe.cloud.portalservice.api.code.dto.CodeUpdateRequestDto;
import org.json.JSONObject;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -69,6 +70,7 @@ class CodeApiControllerTest {
@Test
@Order(Integer.MIN_VALUE)
@Disabled
public void setup() throws Exception {
// 사용자 등록
HttpHeaders headers = new HttpHeaders();

View File

@@ -9,6 +9,7 @@ import org.egovframe.cloud.portalservice.api.code.dto.CodeDetailResponseDto;
import org.egovframe.cloud.portalservice.api.code.dto.CodeDetailSaveRequestDto;
import org.egovframe.cloud.portalservice.api.code.dto.CodeUpdateRequestDto;
import org.json.JSONObject;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -74,6 +75,7 @@ class CodeDetailApiControllerTest {
@Test
@Order(Integer.MIN_VALUE)
@Disabled
public void setup() throws Exception {
// 사용자 등록
HttpHeaders headers = new HttpHeaders();

View File

@@ -3,11 +3,14 @@ package org.egovframe.cloud.portalservice.config;
import org.egovframe.cloud.common.exception.dto.ErrorResponse;
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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@@ -29,7 +32,10 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* 2021/07/16 jaeyeolkim 최초 생성
* </pre>
*/
@SpringBootTest(webEnvironment = RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
public class ExceptionResponseTest {
@Autowired

View File

@@ -1,17 +1,19 @@
package org.egovframe.cloud.portalservice.config;
import static org.assertj.core.api.Assertions.assertThat;
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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.MessageSource;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import java.util.Locale;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@SpringBootTest(webEnvironment = RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class MessageSourceConfigTest {
@Autowired
@@ -20,7 +22,7 @@ class MessageSourceConfigTest {
@Test
public void 메세지를_외부위치에서_읽어온다() throws Exception {
// when
String message = restTemplate.getForObject("http://localhost:8000/portal-service/api/v1/messages/common.login/ko", String.class);
String message = restTemplate.getForObject("/api/v1/messages/common.login/ko", String.class);
// then
assertThat(message).isEqualTo("로그인");

View File

@@ -3,9 +3,12 @@ package org.egovframe.cloud.portalservice.config;
import org.assertj.core.api.Assertions;
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.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
/**
* org.egovframe.cloud.portalservice.config.MessageSourceTest
@@ -24,7 +27,10 @@ import org.springframework.context.i18n.LocaleContextHolder;
* 2021/07/16 jaeyeolkim 최초 생성
* </pre>
*/
@SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
public class MessageSourceTest {
@Autowired
@@ -34,7 +40,7 @@ public class MessageSourceTest {
public void 메세지_읽어온다() throws Exception {
// given
String messageCode = "err.invalid.input.value";
String messageName = "입력값이 올바르지 않습니다.";
String messageName = "입력값이 올바르지 않습니다";
// then
String message = messageSource.getMessage(messageCode, new Object[]{}, "default", LocaleContextHolder.getLocale());

View File

@@ -1,25 +1,23 @@
package org.egovframe.cloud.portalservice.domain.attachment;
import org.egovframe.cloud.portalservice.api.attachment.dto.AttachmentResponseDto;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.assertThat;
import javax.persistence.EntityManager;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.AfterEach;
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 static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class AttachmentRepositoryTest {
@Autowired
EntityManager em;
@@ -40,7 +38,7 @@ class AttachmentRepositoryTest {
public void 첨부파일_등록() throws Exception {
//given
AttachmentId attachmentId = AttachmentId.builder()
.code(UUID.randomUUID().toString())
.code("testAttachmentCode")
.seq(1L).build();
Attachment attachment = Attachment.builder()
@@ -63,7 +61,7 @@ class AttachmentRepositoryTest {
@Test
public void 여러건_등록() throws Exception {
//given
String code = UUID.randomUUID().toString();
String code = "testAttachmentCode";
AttachmentId attachmentId1 = AttachmentId.builder()
.code(code)
.seq(1L).build();
@@ -100,7 +98,7 @@ class AttachmentRepositoryTest {
@Test
public void code로다건조회() throws Exception {
//given
String code = UUID.randomUUID().toString();
String code = "testAttachmentCode";
for (Long i = 1L; i <= 5L; i++) {
AttachmentId attachmentId = AttachmentId.builder()
.code(code)
@@ -127,7 +125,7 @@ class AttachmentRepositoryTest {
@Test
public void 대체키로한건조회() throws Exception {
//given
String code = UUID.randomUUID().toString();
String code = "testAttachmentCode";
String id = "";
for (Long i = 1L; i <= 5L; i++) {
AttachmentId attachmentId = AttachmentId.builder()

View File

@@ -7,9 +7,12 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
@@ -35,7 +38,10 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* </pre>
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@SpringBootTest(webEnvironment = RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class CodeRepositoryTest {
@Autowired

View File

@@ -3,7 +3,10 @@ package org.egovframe.cloud.portalservice.domain.menu;
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.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
@@ -13,8 +16,10 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
//@Import(TestConfig.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class MenuRepositoryTest {
@Autowired

View File

@@ -6,7 +6,10 @@ 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.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
@@ -16,7 +19,10 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class MenuRoleRepositoryTest {
@Autowired
private EntityManager em;

View File

@@ -5,7 +5,10 @@ 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.transaction.annotation.Transactional;
import java.util.List;
@@ -14,7 +17,10 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@SpringBootTest(webEnvironment = RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class MessageRepositoryTest {
@Autowired

View File

@@ -6,9 +6,13 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
@@ -19,7 +23,10 @@ import java.util.Optional;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class PolicyRepositoryTest {
@Autowired

View File

@@ -3,14 +3,20 @@ package org.egovframe.cloud.portalservice.domain.statistics;
import org.junit.jupiter.api.AfterEach;
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 javax.persistence.EntityManager;
import java.util.UUID;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class StatisticsRepositoryTest {
@Autowired
EntityManager em;

View File

@@ -2,8 +2,10 @@ package org.egovframe.cloud.reservechecksevice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest
@ActiveProfiles(profiles = "test")
class ReserveCheckSeviceApplicationTests {
@Test

View File

@@ -2,8 +2,10 @@ package org.egovframe.cloud.reserveitemservice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest
@ActiveProfiles(profiles = "test")
class ReserveItemServiceApplicationTests {
@Test

View File

@@ -2,8 +2,10 @@ package org.egovframe.cloud.reserverequestservice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest
@ActiveProfiles(profiles = "test")
class ReserveRequestServiceApplicationTests {
@Test

View File

@@ -2,8 +2,10 @@ package org.egovframe.cloud.userservice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest
@ActiveProfiles(profiles = "test")
class UserServiceApplicationTests {
@Test

View File

@@ -2,16 +2,22 @@ package org.egovframe.cloud.userservice.config;
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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.MessageSource;
import java.util.Locale;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@SpringBootTest(webEnvironment = RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableConfigurationProperties
@TestPropertySource(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles(profiles = "test")
class MessageSourceConfigTest {
@Autowired
@@ -20,7 +26,7 @@ class MessageSourceConfigTest {
@Test
public void 메세지를_외부위치에서_읽어온다() throws Exception {
// when
String message = restTemplate.getForObject("http://localhost:8000/user-service/api/v1/messages/common.login/ko", String.class);
String message = restTemplate.getForObject("/api/v1/messages/common.login/ko", String.class);
// then
assertThat(message).isEqualTo("로그인");