org.springframework.restdocs.operation.OperationRequestPart Java Examples

The following examples show how to use org.springframework.restdocs.operation.OperationRequestPart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultipartContentOperationPreprocessorTest.java    From spring-auto-restdocs with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotReplaceWhenNotMultipart() throws URISyntaxException {
    OperationRequest request = createRequestWithContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);

    OperationRequest processedRequest = preprocessor.preprocess(request);
    assertArrayEquals(request.getContent(), processedRequest.getContent());
    assertEquals(request.getHeaders(), processedRequest.getHeaders());
    assertEquals(request.getMethod(), processedRequest.getMethod());
    assertEquals(request.getUri(), processedRequest.getUri());
    assertEquals(request.getParameters(), processedRequest.getParameters());

    OperationRequestPart[] expectedParts = request.getParts().toArray(new OperationRequestPart[0]);
    OperationRequestPart[] operationRequestParts = processedRequest.getParts().toArray(new OperationRequestPart[0]);
    for (int i = 0; i < operationRequestParts.length; i++) {
        assertEquals(expectedParts[i], operationRequestParts[i]);
    }
}
 
Example #2
Source File: OperationBuilder.java    From restdocs-raml with MIT License 5 votes vote down vote up
private OperationRequest buildRequest() {
	List<OperationRequestPart> parts = new ArrayList<>();
	for (OperationRequestPartBuilder builder : this.partBuilders) {
		parts.add(builder.buildPart());
	}
	return new OperationRequestFactory().create(this.requestUri, this.method,
			this.content, this.headers, this.parameters, parts);
}
 
Example #3
Source File: OperationBuilder.java    From restdocs-wiremock with Apache License 2.0 5 votes vote down vote up
private OperationRequest buildRequest() {
	List<OperationRequestPart> parts = new ArrayList<>();
	for (OperationRequestPartBuilder builder : this.partBuilders) {
		parts.add(builder.buildPart());
	}
	return new OperationRequestFactory().create(this.requestUri, this.method,
			this.content, this.headers, this.parameters, parts);
}
 
Example #4
Source File: MultipartContentOperationPreprocessor.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
@Override
public OperationRequest preprocess(OperationRequest request) {
    if (isMultipart(request)) {
        List<OperationRequestPart> parts = request.getParts().stream()
                .map(this::replaceBinary)
                .collect(toList());
        return requestFactory.create(request.getUri(),
                request.getMethod(), request.getContent(), request.getHeaders(), request.getParameters()
                , parts);
    }
    return request;
}
 
Example #5
Source File: MultipartContentOperationPreprocessorTest.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceContent() throws URISyntaxException {
    OperationRequest request = createRequestWithContentType(MediaType.MULTIPART_FORM_DATA_VALUE);

    OperationRequest processedRequest = preprocessor.preprocess(request);
    assertArrayEquals(request.getContent(), processedRequest.getContent());
    assertEquals(request.getHeaders(), processedRequest.getHeaders());
    assertEquals(request.getMethod(), processedRequest.getMethod());
    assertEquals(request.getUri(), processedRequest.getUri());
    assertEquals(request.getParameters(), processedRequest.getParameters());
    for (OperationRequestPart part : processedRequest.getParts()) {
        assertArrayEquals(EXPECTED_CONTENT, part.getContent());
    }
}
 
Example #6
Source File: MultipartContentOperationPreprocessorTest.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
private OperationRequest createRequestWithContentType(String contentType) throws URISyntaxException {
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_TYPE, contentType);
    Parameters parameters = new Parameters();
    parameters.add("parameter", "value");
    List<OperationRequestPart> requestParts = new ArrayList<>();
    requestParts.add(partFactory.create("first", "file1", BINARY_CONTENT, new HttpHeaders()));
    return requestFactory.create(new URI("http://localhost"), HttpMethod.POST, BINARY_CONTENT, headers, parameters, requestParts);
}
 
Example #7
Source File: OperationBuilder.java    From restdocs-raml with MIT License 4 votes vote down vote up
private OperationRequestPart buildPart() {
	return new OperationRequestPartFactory().create(this.name,
			this.submittedFileName, this.content, this.headers);
}
 
Example #8
Source File: WireMockSnippetTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private OperationRequest request() {
	return new OperationRequest() {

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

		@Override
		public String getContentAsString() {
			return null;
		}

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

		@Override
		public HttpMethod getMethod() {
			return HttpMethod.GET;
		}

		@Override
		public Parameters getParameters() {
			return null;
		}

		@Override
		public Collection<OperationRequestPart> getParts() {
			return null;
		}

		@Override
		public URI getUri() {
			return URI.create("https://foo/bar");
		}

		@Override
		public Collection<RequestCookie> getCookies() {
			return Collections.emptySet();
		}
	};
}
 
Example #9
Source File: WireMockSnippetTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private OperationRequest requestPostWithJsonContentType() {
	return new OperationRequest() {

		@Override
		public byte[] getContent() {
			String content = "{\"name\": \"12\"}";
			return content.getBytes(Charset.forName("UTF-8"));
		}

		@Override
		public String getContentAsString() {
			return "{\"name\": \"12\"}";
		}

		@Override
		public HttpHeaders getHeaders() {
			HttpHeaders httpHeaders = new HttpHeaders();
			httpHeaders.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
			return httpHeaders;
		}

		@Override
		public HttpMethod getMethod() {
			return HttpMethod.POST;
		}

		@Override
		public Parameters getParameters() {
			return null;
		}

		@Override
		public Collection<OperationRequestPart> getParts() {
			return null;
		}

		@Override
		public URI getUri() {
			return URI.create("https://foo/bar");
		}

		@Override
		public Collection<RequestCookie> getCookies() {
			return Collections.emptySet();
		}
	};
}
 
Example #10
Source File: WireMockSnippetTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private OperationRequest requestPostWithXmlContentType() {
	return new OperationRequest() {

		@Override
		public byte[] getContent() {
			String content = "<name>foo</name>";
			return content.getBytes(Charset.forName("UTF-8"));
		}

		@Override
		public String getContentAsString() {
			return "<name>foo</name>";
		}

		@Override
		public HttpHeaders getHeaders() {
			HttpHeaders httpHeaders = new HttpHeaders();
			httpHeaders.add("Content-Type", MediaType.APPLICATION_XML_VALUE);
			return httpHeaders;
		}

		@Override
		public HttpMethod getMethod() {
			return HttpMethod.POST;
		}

		@Override
		public Parameters getParameters() {
			return null;
		}

		@Override
		public Collection<OperationRequestPart> getParts() {
			return null;
		}

		@Override
		public URI getUri() {
			return URI.create("https://foo/bar");
		}

		@Override
		public Collection<RequestCookie> getCookies() {
			return Collections.emptySet();
		}
	};
}
 
Example #11
Source File: WireMockSnippetTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private OperationRequest requestPostWithEmptyBody() {
	return new OperationRequest() {
		@Override
		public byte[] getContent() {
			return new byte[0];
		}

		@Override
		public String getContentAsString() {
			return "";
		}

		@Override
		public HttpHeaders getHeaders() {
			HttpHeaders httpHeaders = new HttpHeaders();
			httpHeaders.add(HttpHeaders.CONTENT_TYPE,
					MediaType.APPLICATION_JSON_VALUE);
			return httpHeaders;
		}

		@Override
		public HttpMethod getMethod() {
			return HttpMethod.POST;
		}

		@Override
		public Parameters getParameters() {
			return null;
		}

		@Override
		public Collection<OperationRequestPart> getParts() {
			return null;
		}

		@Override
		public URI getUri() {
			return URI.create("https://foo/bar");
		}

		@Override
		public Collection<RequestCookie> getCookies() {
			return Collections.emptySet();
		}
	};
}
 
Example #12
Source File: WireMockSnippetTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private OperationRequest requestPostWithEmptyQueryParamValue() {
	return new OperationRequest() {
		@Override
		public byte[] getContent() {
			return new byte[0];
		}

		@Override
		public String getContentAsString() {
			return "";
		}

		@Override
		public HttpHeaders getHeaders() {
			HttpHeaders httpHeaders = new HttpHeaders();
			httpHeaders.add(HttpHeaders.CONTENT_TYPE,
					MediaType.APPLICATION_JSON_VALUE);
			return httpHeaders;
		}

		@Override
		public HttpMethod getMethod() {
			return HttpMethod.POST;
		}

		@Override
		public Parameters getParameters() {
			Parameters parameters = new Parameters();
			parameters.put("myParam", Collections.singletonList(""));
			return parameters;
		}

		@Override
		public Collection<OperationRequestPart> getParts() {
			return null;
		}

		@Override
		public URI getUri() {
			return URI.create("https://foo/bar?myParam=");
		}

		@Override
		public Collection<RequestCookie> getCookies() {
			return Collections.emptySet();
		}
	};
}
 
Example #13
Source File: WireMockSnippetTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
private OperationRequest requestGetWithQueryParam() {
	return new OperationRequest() {
		@Override
		public byte[] getContent() {
			return new byte[0];
		}

		@Override
		public String getContentAsString() {
			return "";
		}

		@Override
		public HttpHeaders getHeaders() {
			HttpHeaders httpHeaders = new HttpHeaders();
			httpHeaders.add(HttpHeaders.CONTENT_TYPE,
					MediaType.APPLICATION_JSON_VALUE);
			return httpHeaders;
		}

		@Override
		public HttpMethod getMethod() {
			return HttpMethod.GET;
		}

		@Override
		public Parameters getParameters() {
			return null;
		}

		@Override
		public Collection<OperationRequestPart> getParts() {
			return null;
		}

		@Override
		public URI getUri() {
			return URI.create("https://foo/bar?myParam=myValue");
		}

		@Override
		public Collection<RequestCookie> getCookies() {
			return Collections.emptySet();
		}
	};
}
 
Example #14
Source File: OperationBuilder.java    From restdocs-wiremock with Apache License 2.0 4 votes vote down vote up
private OperationRequestPart buildPart() {
	return new OperationRequestPartFactory().create(this.name,
			this.submittedFileName, this.content, this.headers);
}
 
Example #15
Source File: MultipartContentOperationPreprocessor.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
private OperationRequestPart replaceBinary(OperationRequestPart part) {
    return partFactory.create(part.getName(), part.getSubmittedFileName()
            , BINARY_REPLACEMENT, part.getHeaders());
}