Example usage for org.springframework.restdocs.operation OperationRequest getParts

List of usage examples for org.springframework.restdocs.operation OperationRequest getParts

Introduction

In this page you can find the example usage for org.springframework.restdocs.operation OperationRequest getParts.

Prototype

Collection<OperationRequestPart> getParts();

Source Link

Document

Returns the request's parts, provided that it is a multipart request.

Usage

From source file:io.github.restdocsext.jersey.operation.preprocess.BinaryPartPlaceholderOperationPreprocessor.java

@Override
public OperationRequest preprocess(OperationRequest request) {
    final Collection<OperationRequestPart> parts = request.getParts();
    if (parts.isEmpty()) {
        return request;
    }/*from   www . j  a  v  a2 s .co m*/
    final Collection<OperationRequestPart> modifiedParts = modifyParts(parts);
    return this.requestFactory.create(request.getUri(), request.getMethod(), request.getContent(),
            request.getHeaders(), request.getParameters(), modifiedParts);
}

From source file:io.github.restdocsext.jersey.operation.preprocess.BinaryPartPlaceholderOperationPreprocessorTest.java

@Test
public void replace_binary_multipart_content_with_placeholder() {
    OperationRequestPart part1 = this.partFactory.create("field1", "file1.png", "BinaryContent".getBytes(),
            new HttpHeaders());
    OperationRequestPart part2 = this.partFactory.create("field2", null, "TextContent".getBytes(),
            new HttpHeaders());
    final OperationRequest request = this.requestFactory.create(URI.create("http://localhost"), HttpMethod.POST,
            null, new HttpHeaders(), new Parameters(), Arrays.asList(part1, part2));

    this.preprocessor.field("field1", "<<placeholder>>");
    final OperationRequest preprocessed = this.preprocessor.preprocess(request);
    final Collection<OperationRequestPart> parts = preprocessed.getParts();
    assertThat(hasPart(parts, "field1", "<<placeholder>>"), is(true));
    assertThat(hasPart(parts, "field2", "TextContent"), is(true));
}

From source file:io.github.restdocsext.jersey.operation.preprocess.BinaryPartPlaceholderOperationPreprocessorTest.java

@Test
public void replace_binary_multipart_content_with_default_placeholder() {
    OperationRequestPart part1 = this.partFactory.create("field1", "file1.png", "BinaryContent".getBytes(),
            new HttpHeaders());
    OperationRequestPart part2 = this.partFactory.create("field2", null, "TextContent".getBytes(),
            new HttpHeaders());
    final OperationRequest request = this.requestFactory.create(URI.create("http://localhost"), HttpMethod.POST,
            null, new HttpHeaders(), new Parameters(), Arrays.asList(part1, part2));

    this.preprocessor.field("field1");
    final OperationRequest preprocessed = this.preprocessor.preprocess(request);
    final Collection<OperationRequestPart> parts = preprocessed.getParts();
    assertThat(hasPart(parts, "field1", "<<binary data>>"), is(true));
    assertThat(hasPart(parts, "field2", "TextContent"), is(true));
}