Java Code Examples for com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder#withBody()

The following examples show how to use com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder#withBody() . 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: UnmarshallingTestRunner.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private ResponseDefinitionBuilder toResponseBuilder(GivenResponse givenResponse) {

        ResponseDefinitionBuilder responseBuilder = aResponse().withStatus(200);
        if (givenResponse.getHeaders() != null) {
            givenResponse.getHeaders().forEach(responseBuilder::withHeader);
        }
        if (givenResponse.getStatusCode() != null) {
            responseBuilder.withStatus(givenResponse.getStatusCode());
        }
        if (givenResponse.getBody() != null) {
            responseBuilder.withBody(givenResponse.getBody());
        } else if (metadata.isXmlProtocol()) {
            // XML Unmarshallers expect at least one level in the XML document. If no body is explicitly
            // set by the test add a fake one here.
            responseBuilder.withBody("<foo></foo>");
        }
        return responseBuilder;
    }
 
Example 2
Source File: WireMockTestUtils.java    From junit-servers with MIT License 6 votes vote down vote up
private static void stubRequest(String method, String endpoint, int status, Collection<Pair> headers, String body) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	MappingBuilder request = request(method, urlPattern);

	ResponseDefinitionBuilder response = aResponse().withStatus(status);

	HttpHeaders httpHeaders = new HttpHeaders();

	for (Pair header : headers) {
		String name = header.getO1();
		List<String> values = header.getO2();
		HttpHeader h = new HttpHeader(name, values);
		httpHeaders = httpHeaders.plus(h);
	}

	response.withHeaders(httpHeaders);

	if (body != null) {
		response.withBody(body);
	}

	stubFor(request.willReturn(response));
}
 
Example 3
Source File: MarshallingTestRunner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Reset wire mock and re-configure stubbing.
 */
private void resetWireMock() {
    WireMock.reset();
    // Stub to return 200 for all requests
    ResponseDefinitionBuilder responseDefBuilder = aResponse().withStatus(200);
    // XML Unmarshallers expect at least one level in the XML document.
    if (model.getMetadata().isXmlProtocol()) {
        responseDefBuilder.withBody("<foo></foo>");
    }
    stubFor(any(urlMatching(".*")).willReturn(responseDefBuilder));
}