공부/Spring Boot
Spring REST Docs(99) - 오류와 해결이력 모음
오피스엑소더스
2020. 1. 9. 14:35
Spring REST Docs 사용 중 오류와 해결이력 모음
1. 200109 테스트오류
1.1. 오류 위치와 내용
java.lang.IllegalStateException: No LinkExtractor has been provided and one is not available for the content type null
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureRestDocs
@Import(RestDocsConfiguration.class)
public class MarketTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
@Test
public void createMarket() throws Exception{
String jsonData = FileUtils.readFileToString(new File("src/test/resources/market_1.json"));
mockMvc
.perform(
post("/market/create")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonData))
.andDo(print())
.andDo(document("create-market",
links(
linkWithRel("self").description("link to self")
),
requestHeaders(
headerWithName(HttpHeaders.ACCEPT).description("accept header"),
headerWithName(HttpHeaders.CONTENT_TYPE).description("header content type")
),
requestFields(
fieldWithPath("name").description("Name"),
fieldWithPath("description").description("desc")
),
responseHeaders(
headerWithName(HttpHeaders.LOCATION).description("resp header location")
)
,
responseFields(
fieldWithPath("respName").description("resp name"),
subsectionWithPath("respSub").description("sub section")
)
)
);
}
}
1.2. 해결방법
- 시도 : 컨트롤러를 확인해보았다. -> 링크를 설정해 주는 부분이 없었다.
- 해결 : 컨트롤러에 링크를 설정하는 부분을 만들어줬다.
- 2차문제 : 리퀘스트필드부분이 잘못됐다
- 해결 : requestFields()를 relaxedRequestFields()로 변경
- 해결완료