@Override protected Map<String, Object> createModel(Operation operation) { Map<String, Object> model = new HashMap<>(); model.put("method", operation.getRequest().getMethod()); model.put("path", getPath(operation.getRequest())); model.put("headers", getHeaders(operation.getRequest())); model.put("requestBody", getRequestBody(operation.getRequest())); return model; }
@Override protected byte[] getContent(Operation operation) throws IOException { return operation.getRequest().getContent(); }
@Override protected byte[] getContent(Operation operation) throws IOException { return operation.getRequest().getContent(); }
private Set<String> extractActualRequestParts(Operation operation) { Set<String> actualRequestParts = new HashSet<>(); for (OperationRequestPart requestPart : operation.getRequest().getParts()) { actualRequestParts.add(requestPart.getName()); } return actualRequestParts; }
@Override protected MediaType getContentType(Operation operation) { return operation.getRequest().getHeaders().getContentType(); }
@Override protected Map<String, Object> createModel(Operation operation) { Map<String, Object> model = new HashMap<>(); CliOperationRequest request = new CliOperationRequest(operation.getRequest()); model.put("echoContent", getContentStandardIn(request)); model.put("options", getOptions(request)); model.put("url", getUrl(request)); model.put("requestItems", getRequestItems(request)); return model; }
@Override protected Set<String> extractActualParameters(Operation operation) { return operation.getRequest().getParameters().keySet(); }
@Override protected MediaType getContentType(Operation operation) { return operation.getRequest().getHeaders().getContentType(); }
@Override protected Set<String> extractActualHeaders(Operation operation) { return operation.getRequest().getHeaders().keySet(); }
private OperationRequestPart findPart(Operation operation) { for (OperationRequestPart candidate : operation.getRequest().getParts()) { if (candidate.getName().equals(this.partName)) { return candidate; } } throw new SnippetException("A request part named '" + this.partName + "' was not found in the request"); }
private OperationRequestPart findPart(Operation operation) { for (OperationRequestPart candidate : operation.getRequest().getParts()) { if (candidate.getName().equals(this.partName)) { return candidate; } } throw new SnippetException("A request part named '" + this.partName + "' was not found in the request"); }
private String getUrl(Operation operation) { OperationRequest request = operation.getRequest(); Parameters uniqueParameters = request.getParameters() .getUniqueParameters(operation.getRequest().getUri()); if (!uniqueParameters.isEmpty() && includeParametersInUri(request)) { return String.format("'%s%s%s'", request.getUri(), StringUtils.hasText(request.getUri().getRawQuery()) ? "&" : "?", uniqueParameters.toQueryString()); } return String.format("'%s'", request.getUri()); }
private void verifySnippetInvocation(Snippet snippet, OperationRequest operationRequest, OperationResponse operationResponse, Map<String, Object> attributes, int times) throws IOException { ArgumentCaptor<Operation> operation = ArgumentCaptor.forClass(Operation.class); verify(snippet, Mockito.times(times)).document(operation.capture()); assertThat(operationRequest).isEqualTo(operation.getValue().getRequest()); assertThat(operationResponse).isEqualTo(operation.getValue().getResponse()); }
private void verifySnippetInvocation(Snippet snippet, Map<String, Object> attributes) throws IOException { ArgumentCaptor<Operation> operation = ArgumentCaptor.forClass(Operation.class); verify(snippet).document(operation.capture()); assertThat(this.operationRequest).isEqualTo(operation.getValue().getRequest()); assertThat(this.operationResponse).isEqualTo(operation.getValue().getResponse()); assertThat(attributes).isEqualTo(operation.getValue().getAttributes()); }
private void verifySnippetInvocation(InOrder inOrder, Snippet snippet, Map<String, Object> attributes) throws IOException { ArgumentCaptor<Operation> operation = ArgumentCaptor.forClass(Operation.class); inOrder.verify(snippet).document(operation.capture()); assertThat(this.operationRequest).isEqualTo(operation.getValue().getRequest()); assertThat(this.operationResponse).isEqualTo(operation.getValue().getResponse()); assertThat(attributes).isEqualTo(operation.getValue().getAttributes()); }
private String getOptions(Operation operation) { StringBuilder builder = new StringBuilder(); writeIncludeHeadersInOutputOption(builder); CliOperationRequest request = new CliOperationRequest(operation.getRequest()); writeUserOptionIfNecessary(request, builder); writeHttpMethod(request, builder); List<String> additionalLines = new ArrayList<>(); writeHeaders(request, additionalLines); writeCookies(request, additionalLines); writePartsIfNecessary(request, additionalLines); writeContent(request, additionalLines); builder.append(this.commandFormatter.format(additionalLines)); return builder.toString(); }