Java源码示例:org.springframework.restdocs.operation.OperationResponse

示例1
public Map<String, Object> generateModel(Operation operation, RamlResourceSnippetParameters parameters) {
    final OperationResponse response = operation.getResponse();
    if (!StringUtils.isEmpty(response.getContentAsString())) {
        Map<String, Object> model = new HashMap<>();
        model.put("responseBodyFileName", getResponseFileName(operation.getName()));
        model.put("responseBodyPresent", true);
        model.put("contentTypeResponse", getContentTypeOrDefault(response));
        if (!parameters.getResponseFields().isEmpty()) {
            validateResponseFieldsAndInferTypeInformation(operation, parameters);
            model.put("responseFieldsPresent", true);
            if (shouldGenerateResponseSchemaFile(operation, parameters)) {
                model.put("responseSchemaFileName", getResponseSchemaFileName(operation.getName()));
            }
        }
        return model;
    }
    return emptyMap();
}
 
示例2
private OperationResponse response() {
	return new OperationResponse() {

		@Override
		public HttpStatus getStatus() {
			return HttpStatus.ACCEPTED;
		}

		@Override
		public HttpHeaders getHeaders() {
			return new HttpHeaders();
		}

		@Override
		public byte[] getContent() {
			return new byte[0];
		}

		@Override
		public String getContentAsString() {
			return null;
		}
	};
}
 
示例3
private String getContentTypeOrDefault(OperationResponse response) {
    if (response.getHeaders().getContentType() != null) {
        return response.getHeaders().getContentType().getType() + "/" + response.getHeaders().getContentType().getSubtype();
    } else {
        return APPLICATION_JSON_VALUE;
    }
}
 
示例4
@Override
public OperationResponse preprocess(OperationResponse response) {
	String content = response.getContentAsString();
	if (content.contains("localhost:8080")) {
		content = content.replace("localhost:8080",
				"localhost:{{request.requestLine.port}}");
		response = this.responseFactory.createFrom(response, content.getBytes());
	}
	return response;
}
 
示例5
private void insertResponseModel(Operation operation, Map<String, Object> model) {
	OperationResponse response = operation.getResponse();
	model.put("response_status", response.getStatus().value());
	model.put("response_body_present", response.getContent().length > 0);
	model.put("response_body", response.getContentAsString());
	Map<String, String> headers = new HashMap<>(
			response.getHeaders().toSingleValueMap());
	filterHeaders(headers);
	model.put("response_headers_present", !headers.isEmpty());
	model.put("response_headers", headers.entrySet());
}
 
示例6
private Operation operation(String name, OperationRequest request,
		OperationResponse response, RestDocumentationContext context) {
	return new Operation() {

		Map<String, Object> map = new HashMap<>();

		@Override
		public Map<String, Object> getAttributes() {
			this.map.put(RestDocumentationContext.class.getName(), context);
			return this.map;
		}

		@Override
		public String getName() {
			return name;
		}

		@Override
		public OperationRequest getRequest() {
			return request;
		}

		@Override
		public OperationResponse getResponse() {
			return response;
		}
	};
}
 
示例7
private void preprocessorTest(TestData testData) {
    // given
    OperationResponse unprocessedResponse =
            new OperationResponseFake(testData.getContent(), testData.getContentType());
    // when
    OperationResponse processedResponse =
            testData.getPreprocessor().preprocess(unprocessedResponse);
    // then
    assertThat(processedResponse.getContentAsString(), is(testData.getExpectedResult()));
}
 
示例8
private OperationResponse buildResponse() {
	return new OperationResponseFactory().create(this.status, this.headers,
			this.content);
}
 
示例9
private Operation operation(OperationRequest request, OperationResponse response,
		RestDocumentationContext context) {
	return operation("foo", request, response, context);
}
 
示例10
private OperationResponse buildResponse() {
	return new OperationResponseFactory().create(this.status, this.headers,
			this.content);
}