Example usage for org.springframework.restdocs.operation Operation getResponse

List of usage examples for org.springframework.restdocs.operation Operation getResponse

Introduction

In this page you can find the example usage for org.springframework.restdocs.operation Operation getResponse.

Prototype

OperationResponse getResponse();

Source Link

Document

Returns the response that was received.

Usage

From source file:io.spring.initializr.web.test.ResponseFieldSnippet.java

@Override
protected Map<String, Object> createModel(Operation operation) {
    try {/*from ww  w . jav  a 2s . com*/
        Object object = objectMapper.readValue(operation.getResponse().getContentAsString(), Object.class);
        Object field = fieldProcessor.extract(JsonFieldPath.compile(path), object);
        if (field instanceof List && index != null) {
            field = ((List<?>) field).get(index);
        }
        return Collections.singletonMap("value", objectMapper.writeValueAsString(field));
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}