Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi authored May 9, 2024
1 parent d362d33 commit 1ab2dea
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions spring-code-for-deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,106 @@ public class MemberServiceTest {
## Controller Test
- Service를 Mocking하고 Test

```Java
@WebMvcTest(controllers = MemberController.class)
public class MemberControllerTest extends ControllerTestManager {

@MockBean
private MemberService memberService;
@Test
@DisplayName("신규 회원을 등록한다.")
void createMember() throws Exception {

// given
when(memberService.create(any(MemberCreateRequest.class)))
.thenReturn("/api/member/1");

MemberCreateRequest request = new MemberCreateRequest(
"오해영",
"5hae0",
28,
SOPT.builder()
.part(Part.DESIGN)
.build()
);

// when, then
mockMvc.perform(MockMvcRequestBuilders.post("/api/member")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isCreated())
.andExpect(MockMvcResultMatchers.header().string("Location", "/api/member/1"))
;
}

@Test
@DisplayName("특정 회원 정보를 조회한다.")
void test() throws Exception {
// given
Member member = Member.builder()
.age(28)
.name("오해영")
.nickname("5hae0")
.sopt(
SOPT.builder()
.part(Part.DESIGN)
.build()
).build();

BDDMockito.given(memberService.getMemberById(1L))
.willReturn(MemberGetResponse.of(member));

// when
mockMvc.perform(MockMvcRequestBuilders.get("/api/member/1"))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("name").value("오해영"))
.andExpect(MockMvcResultMatchers.jsonPath("age").value(28))
.andExpect(MockMvcResultMatchers.jsonPath("nickname").value("5hae0"))
.andExpect(MockMvcResultMatchers.jsonPath("soptInfo.part").value("DESIGN"))
.andExpect(MockMvcResultMatchers.jsonPath("soptInfo.generation").value(34));

// then

}

@Test
@DisplayName("회원 정보 목록을 조회한다.")

void getMembersProfile() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/api/member"))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
@DisplayName("회원 정보를 수정한다.")
void updateMemberSoptInfo() throws Exception {

MemberProfileUpdateRequest request = new MemberProfileUpdateRequest((short) 6, Part.SERVER);

mockMvc.perform(MockMvcRequestBuilders.patch("/api/member/1")
.content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isNoContent());
}

@Test
@DisplayName("회원 정보를 삭제한다.")
void deleteMember() throws Exception {
// given // when // then
mockMvc.perform(MockMvcRequestBuilders.delete("/api/member/1"))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isNoContent());

}


}
```



## 통합 테스트
Expand Down

0 comments on commit 1ab2dea

Please sign in to comment.