Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/test/java/com/ject/studytrip/BaseIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest(classes = {StudytripApplication.class})
Expand All @@ -20,4 +21,16 @@ public abstract class BaseIntegrationTest {

@Autowired protected MockMvc mockMvc;
@Autowired protected ObjectMapper objectMapper;

/**
* 응답 본문(JSON)을 지정한 클래스 타입으로 변환하는 메서드, 테스트 응답 결과를 객체로 파싱해 내용 검증에 활용할 수 있음
*
* @param result MockMvc 응답 결과
* @param clazz 변환할 클래스 타입
* @return 파싱된 응답 객체
*/
protected <T> T parseResponse(ResultActions result, Class<T> clazz) throws Exception {
String content = result.andReturn().getResponse().getContentAsString();
return objectMapper.readValue(content, clazz);
}
}