Skip to content

Commit

Permalink
Merge pull request #30 from Caramel1004/test/#23
Browse files Browse the repository at this point in the history
[#23][TEST]Controller test
  • Loading branch information
Caramel1004 authored May 24, 2024
2 parents 0cfc2c8 + bdc3be3 commit ff0ea67
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 72 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ dependencies {

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'

// Gson
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public HashMap<String, ExchangeRateInfoDTO> fetchExchangeRateInfoFromExternalAPI
.build()
)
.exchangeToMono(res -> {
return res.bodyToMono(new ParameterizedTypeReference<List<ExchangeRateInfoDTO>>() {
});
return res.bodyToMono(new ParameterizedTypeReference<List<ExchangeRateInfoDTO>>() {});
})
.block();// 배열 json 으로 넘어온 데이터를 List 로 변환

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.moin.remittance.domain.dto.requestbody.v2;

import lombok.Getter;
import lombok.Data;

import java.util.UUID;

@Getter
@Data
public class RemittanceAcceptRequestBodyV2DTO {
private UUID quoteId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum HttpResponseCode {

// 회원 관련 성공 상태 코드
/* 2xx */
SUCCESS_MEMBER_SIGNUP(HttpStatus.OK.value(), "회원 가입 성공", "SUCCESS_MEMBER_SIGNUP"),
SUCCESS_MEMBER_SIGNUP(HttpStatus.CREATED.value(), "회원 가입 성공", "SUCCESS_MEMBER_SIGNUP"),
SUCCESS_MEMBER_LOGIN(HttpStatus.OK.value(), "로그인 성공", "SUCCESS_MEMBER_LOGIN"),

// 송금 관련 성공 상태 코드
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.moin.remittance.presentation.v2;

import com.google.gson.Gson;
import com.moin.remittance.application.v2.user.impl.MemberServiceImplV2;
import com.moin.remittance.domain.dto.member.MemberDTO;
import com.moin.remittance.domain.dto.responsebody.HttpResponseBody;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.willDoNothing;
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;

import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
public class MemberControllerV2Test {

@Autowired
private MockMvc mockMvc;

@InjectMocks
private MemberControllerV2 memberControllerV2Mock;

@Mock
private MemberServiceImplV2 memberServiceMock;

@BeforeEach
@Test
@DisplayName("Mock 객체 생성")
void setMock() {
mockMvc = MockMvcBuilders.standaloneSetup(memberControllerV2Mock).build();
assertNotNull(mockMvc);
assertNotNull(memberControllerV2Mock);
assertNotNull(memberServiceMock);
}

@Test
@DisplayName("/api/v2/user/signup")
void signupTest() throws Exception {
MemberDTO member = MemberDTO.builder()
.userId("[email protected]")
.password("1234")
.name("카라멜프라프치노")
.idType("reg_no")
.idValue("111111-1111111")
.build();

willDoNothing().given(memberServiceMock).saveUser(any(MemberDTO.class));

mockMvc.perform(
MockMvcRequestBuilders
.post("/api/v2/user/signup")
.contentType(MediaType.APPLICATION_JSON)
.header("api-version", 2)
.content(new Gson().toJson(member))
)
.andExpect(status().isCreated())// 201
.andExpect(jsonPath("$.statusCode").value(201))
.andExpect(jsonPath("$.message").value("회원 가입 성공"))
.andExpect(jsonPath("$.codeName").value("SUCCESS_MEMBER_SIGNUP"))
.andDo(print());

verify(memberServiceMock).saveUser(any());
}
}
Loading

0 comments on commit ff0ea67

Please sign in to comment.