objectMapper); ObjectMapperConfig jackson2ObjectMapperConfig = new ObjectMapperConfig(jackson2Mapper); RestAssured.config = RestAssuredConfig.config() .objectMapperConfig(jackson2ObjectMapperCon"> objectMapper); ObjectMapperConfig jackson2ObjectMapperConfig = new ObjectMapperConfig(jackson2Mapper); RestAssured.config = RestAssuredConfig.config() .objectMapperConfig(jackson2ObjectMapperCon"> objectMapper); ObjectMapperConfig jackson2ObjectMapperConfig = new ObjectMapperConfig(jackson2Mapper); RestAssured.config = RestAssuredConfig.config() .objectMapperConfig(jackson2ObjectMapperCon">
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AcceptanceTestBase {
protected static final String BASE_URL = "<http://localhost>";
@LocalServerPort
protected int port;
@Autowired
protected ObjectMapper objectMapper;
protected String[] ignoringFieldsForResponseWithId = new String[]{"createdDateTime", "modifiedDateTime", "id"};
protected String[] ignoringFieldsForResponse = new String[]{"createdDateTime", "modifiedDateTime"};
protected String[] ignoringFieldsForErrorResponse = new String[]{"timestamp"};
{
setUpRestAssured();
}
private void setUpRestAssured() {
Jackson2Mapper jackson2Mapper = new Jackson2Mapper((type, charset) -> objectMapper);
ObjectMapperConfig jackson2ObjectMapperConfig = new ObjectMapperConfig(jackson2Mapper);
RestAssured.config = RestAssuredConfig.config()
.objectMapperConfig(jackson2ObjectMapperConfig);
}
}
기본 설정은 AcceptanceTestBase 클래스를 상속하는 것으로 한다.
@ParameterizedTest
@MethodSource("readAllProvider")
@DisplayName("")
void readAll(String desc, GroupRequest givenGroupRequest,GroupResponses expectedGroupResponses) {
String path = "/api/groups";
RequestSpecification givenRequest = RestAssured.given()
.baseUri(BASE_URL)
.port(port)
.basePath(path);
Response actualResponse = givenRequest.when()
.log().all()
.get()
.andReturn();
then(actualResponse)
.as("사용자가 가입한 전체 그룹 조회 : %s", desc)
.hasFieldOrPropertyWithValue("statusCode", HttpStatus.OK.value())
.extracting(response -> response.as(GroupResponses.class))
.usingRecursiveComparison()
.isEqualTo(expectedGroupResponses);
}
MethodSource
클래스 네이밍은 *Provider로 한다.https://happy-coding-day.tistory.com/177