diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 3bf77ba..2523496 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -10,7 +10,7 @@ spring: jdbc: time_zone: Asia/Seoul hibernate: - ddl-auto: update + ddl-auto: none h2: console: diff --git a/src/test/java/com/potatocake/everymoment/EverymomentApplicationTests.java b/src/test/java/com/potatocake/everymoment/EverymomentApplicationTests.java index a277c76..e1c7736 100644 --- a/src/test/java/com/potatocake/everymoment/EverymomentApplicationTests.java +++ b/src/test/java/com/potatocake/everymoment/EverymomentApplicationTests.java @@ -2,12 +2,14 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +@ActiveProfiles("dev") @SpringBootTest class EverymomentApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } } diff --git a/src/test/java/com/potatocake/everymoment/controller/MemberControllerTest.java b/src/test/java/com/potatocake/everymoment/controller/MemberControllerTest.java index c5ac5df..d24b883 100644 --- a/src/test/java/com/potatocake/everymoment/controller/MemberControllerTest.java +++ b/src/test/java/com/potatocake/everymoment/controller/MemberControllerTest.java @@ -7,9 +7,11 @@ import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willDoNothing; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -22,8 +24,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.mock.web.MockMultipartFile; import org.springframework.security.test.context.support.WithMockUser; @@ -32,8 +33,7 @@ import org.springframework.web.multipart.MultipartFile; @WithMockUser -@AutoConfigureMockMvc -@SpringBootTest +@WebMvcTest(MemberController.class) class MemberControllerTest { @Autowired @@ -146,13 +146,15 @@ void should_UpdateMemberInfo_When_ValidInput() throws Exception { @DisplayName("프로필 이미지와 닉네임이 모두 누락되면 예외가 발생한다.") void should_ThrowException_When_ProfileImageAndNicknameAreMissing() throws Exception { // when - ResultActions result = mockMvc.perform(multipart("/api/members")); + ResultActions result = mockMvc.perform(multipart("/api/members") + .with(csrf())); // then result .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.code").value(INFO_REQUIRED.getStatus().value())) - .andExpect(jsonPath("$.message").value(INFO_REQUIRED.getMessage())); + .andExpect(jsonPath("$.message").value(INFO_REQUIRED.getMessage())) + .andDo(print()); then(memberService).shouldHaveNoInteractions(); } @@ -180,7 +182,8 @@ private ResultActions performMultipart(String url, MockMultipartFile file, Strin return mockMvc.perform(multipart(url) .file(file) .param("nickname", nickname) - .with(user(memberDetails))); + .with(user(memberDetails)) + .with(csrf())); } } diff --git a/src/test/java/com/potatocake/everymoment/repository/MemberRepositoryTest.java b/src/test/java/com/potatocake/everymoment/repository/MemberRepositoryTest.java index 2e72d9e..b20c713 100644 --- a/src/test/java/com/potatocake/everymoment/repository/MemberRepositoryTest.java +++ b/src/test/java/com/potatocake/everymoment/repository/MemberRepositoryTest.java @@ -11,7 +11,9 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.ScrollPosition; import org.springframework.data.domain.Window; +import org.springframework.test.context.ActiveProfiles; +@ActiveProfiles("dev") @DataJpaTest class MemberRepositoryTest { diff --git a/src/test/java/com/potatocake/everymoment/service/MemberServiceTest.java b/src/test/java/com/potatocake/everymoment/service/MemberServiceTest.java index df574a6..25da818 100644 --- a/src/test/java/com/potatocake/everymoment/service/MemberServiceTest.java +++ b/src/test/java/com/potatocake/everymoment/service/MemberServiceTest.java @@ -30,8 +30,10 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.ScrollPosition; import org.springframework.data.domain.Window; +import org.springframework.test.context.ActiveProfiles; import org.springframework.web.multipart.MultipartFile; +@ActiveProfiles("dev") @ExtendWith(MockitoExtension.class) class MemberServiceTest { diff --git a/src/test/java/com/potatocake/everymoment/util/PagingUtilTest.java b/src/test/java/com/potatocake/everymoment/util/PagingUtilTest.java index 4808d11..bd37717 100644 --- a/src/test/java/com/potatocake/everymoment/util/PagingUtilTest.java +++ b/src/test/java/com/potatocake/everymoment/util/PagingUtilTest.java @@ -12,7 +12,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.ScrollPosition; import org.springframework.data.domain.Window; +import org.springframework.test.context.ActiveProfiles; +@ActiveProfiles("dev") class PagingUtilTest { private PagingUtil pagingUtil;