TA 역할 Spring 경계 smoke (role-ta-live-1522-001)
Some checks failed
ci / test (pull_request) Failing after 4s
Some checks failed
ci / test (pull_request) Failing after 4s
This commit is contained in:
parent
19a4d610b5
commit
5e9d29c817
1 changed files with 62 additions and 0 deletions
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.runtimematrix.controller;
|
||||||
|
|
||||||
|
import com.runtimematrix.config.GlobalExceptionHandler;
|
||||||
|
import com.runtimematrix.domain.exception.BusinessException;
|
||||||
|
import com.runtimematrix.service.RoleService;
|
||||||
|
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.WebMvcTest;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
|
/** ADR-001 RFC 7807 오류 응답 계약 테스트 */
|
||||||
|
@WebMvcTest(RoleController.class)
|
||||||
|
@Import(GlobalExceptionHandler.class)
|
||||||
|
@DisplayName("오류 응답 계약 테스트")
|
||||||
|
class ErrorResponseContractTest {
|
||||||
|
|
||||||
|
@Autowired private MockMvc mockMvc;
|
||||||
|
@MockBean private RoleService roleService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("역할 미존재 시 404와 RFC 7807 형식 응답 반환")
|
||||||
|
void role_not_found_returns_404_with_problem_details() throws Exception {
|
||||||
|
String roleId = "non-existent";
|
||||||
|
when(roleService.getRole(roleId)).thenThrow(new BusinessException.RoleNotFoundException(roleId));
|
||||||
|
|
||||||
|
mockMvc.perform(get("/api/v1/roles/{roleId}", roleId))
|
||||||
|
.andExpect(status().isNotFound())
|
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON))
|
||||||
|
.andExpect(jsonPath("$.type", startsWith("https://api.runtimematrix.com/errors/")))
|
||||||
|
.andExpect(jsonPath("$.title", is("역할을 찾을 수 없습니다")))
|
||||||
|
.andExpect(jsonPath("$.status", is(404)))
|
||||||
|
.andExpect(jsonPath("$.detail", containsString(roleId)))
|
||||||
|
.andExpect(jsonPath("$.instance", containsString("/api/v1/roles/")))
|
||||||
|
.andExpect(jsonPath("$.timestamp", notNullValue()))
|
||||||
|
.andExpect(jsonPath("$.traceId", notNullValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("오류 응답에 모든 필수 필드 포함")
|
||||||
|
void error_response_contains_all_required_fields() throws Exception {
|
||||||
|
when(roleService.getRole("test")).thenThrow(new BusinessException.RoleNotFoundException("test"));
|
||||||
|
|
||||||
|
mockMvc.perform(get("/api/v1/roles/{roleId}", "test"))
|
||||||
|
.andExpect(status().isNotFound())
|
||||||
|
.andExpect(jsonPath("$", hasKey("type")))
|
||||||
|
.andExpect(jsonPath("$", hasKey("title")))
|
||||||
|
.andExpect(jsonPath("$", hasKey("status")))
|
||||||
|
.andExpect(jsonPath("$", hasKey("detail")))
|
||||||
|
.andExpect(jsonPath("$", hasKey("instance")))
|
||||||
|
.andExpect(jsonPath("$", hasKey("timestamp")))
|
||||||
|
.andExpect(jsonPath("$", hasKey("traceId")));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue