-
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.
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/test/java/slvtwn/khu/toyouserver/response/PageableDto.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,9 @@ | ||
package slvtwn.khu.toyouserver.response; | ||
|
||
import slvtwn.khu.toyouserver.common.PageInfoResponse; | ||
|
||
public record PageableDto( | ||
Long id, | ||
String name, | ||
PageInfoResponse pageInfo) { | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/java/slvtwn/khu/toyouserver/response/ResponseController.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 slvtwn.khu.toyouserver.response; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequestMapping("/test") | ||
@RestController | ||
public class ResponseController { | ||
|
||
private final ResponseService responseService; | ||
|
||
public ResponseController(ResponseService responseService) {this.responseService = responseService;} | ||
|
||
@GetMapping | ||
public PageableDto health() { | ||
return responseService.health(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/slvtwn/khu/toyouserver/response/ResponseControllerTest.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,39 @@ | ||
package slvtwn.khu.toyouserver.response; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
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.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import slvtwn.khu.toyouserver.common.PageInfoResponse; | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest | ||
public class ResponseControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private ResponseService responseService; | ||
|
||
@DisplayName("서버 응답 테스트를 실행한다.") | ||
@Test | ||
public void 응답_테스트() throws Exception { | ||
PageableDto expect = new PageableDto(1L, "test", PageInfoResponse.of(1, 1, 1)); | ||
given(responseService.health()) | ||
.willReturn(expect); | ||
mockMvc.perform(get("/test")) | ||
.andExpect(status().isOk()) | ||
.andExpect(result -> { | ||
String contentAsString = result.getResponse().getContentAsString(); | ||
System.out.println(contentAsString); | ||
}); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/java/slvtwn/khu/toyouserver/response/ResponseService.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,13 @@ | ||
package slvtwn.khu.toyouserver.response; | ||
|
||
import org.springframework.stereotype.Service; | ||
import slvtwn.khu.toyouserver.common.PageInfoResponse; | ||
|
||
@Service | ||
public class ResponseService { | ||
|
||
public PageableDto health() { | ||
PageInfoResponse pageInfo = PageInfoResponse.of(1, 1, 1); | ||
return new PageableDto(1L, "health", pageInfo); | ||
} | ||
} |