-
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.
#34 - Test: 회원 로그인 POST 요청(JSON 방식) 컨트롤러 테스트 추가
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...tbooks/src/test/java/com/example/mutbooks/app/api/controller/MemberApiControllerTest.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,50 @@ | ||
package com.example.mutbooks.app.api.controller; | ||
|
||
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.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@Transactional | ||
@ActiveProfiles("test") | ||
class MemberApiControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mvc; | ||
|
||
@Test | ||
@DisplayName("POST /api/v1/member/login 은 로그인 처리 URL 이다.") | ||
void t1() throws Exception { | ||
// When | ||
ResultActions resultActions = mvc | ||
.perform( | ||
post("/api/v1/member/login") | ||
.content(""" | ||
{ | ||
"username": "user1", | ||
"password": "1234" | ||
} | ||
""".stripIndent()) | ||
.contentType(new MediaType(MediaType.APPLICATION_JSON, StandardCharsets.UTF_8)) | ||
) | ||
.andDo(print()); | ||
|
||
// Then | ||
resultActions | ||
.andExpect(status().is2xxSuccessful()); | ||
} | ||
} |