com.github.tomakehurst.wiremock.matching.ContentPattern Java Examples

The following examples show how to use com.github.tomakehurst.wiremock.matching.ContentPattern. 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: WireMockRestServiceServer.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
private void bodyPatterns(ResponseActions expect, RequestPattern request) {
	if (request.getBodyPatterns() == null) {
		return;
	}
	for (final ContentPattern<?> pattern : request.getBodyPatterns()) {
		if (pattern instanceof MatchesJsonPathPattern) {
			expect.andExpect(MockRestRequestMatchers
					.jsonPath(((MatchesJsonPathPattern) pattern).getMatchesJsonPath())
					.exists());
		}
		else if (pattern instanceof MatchesXPathPattern) {
			expect.andExpect(xpath((MatchesXPathPattern) pattern));
		}
		expect.andExpect(matchContents(pattern));
	}
}
 
Example #2
Source File: CredHubStubFixture.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
public void stubWriteCredential(String credentialName, ContentPattern<?>... appMetadataPatterns) {
	MappingBuilder mappingBuilder = put(urlPathEqualTo("/api/v1/data"))
		.withRequestBody(matchingJsonPath("$.[?(@.name == '" + credentialName + "')]"))
		.withRequestBody(matchingJsonPath("$.[?(@.type == 'json')]"));
	for (ContentPattern<?> appMetadataPattern : appMetadataPatterns) {
		mappingBuilder.withRequestBody(appMetadataPattern);
	}
	stubFor(mappingBuilder
		.willReturn(ok()
			.withHeader("Content-type", "application/json")
			.withBody(credhub("put-data-json"))));
}
 
Example #3
Source File: CloudControllerStubFixture.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private void stubCreateAppMetadata(String appName, ContentPattern<?>... appMetadataPatterns) {
	MappingBuilder mappingBuilder = post(urlPathEqualTo("/v2/apps"))
		.withRequestBody(matchingJsonPath("$.[?(@.name == '" + appName + "')]"));
	for (ContentPattern<?> appMetadataPattern : appMetadataPatterns) {
		mappingBuilder.withRequestBody(appMetadataPattern);
	}
	stubFor(mappingBuilder
		.willReturn(ok()
			.withBody(cc("get-app-STOPPED",
				replace("@name", appName),
				replace("@guid", appGuid(appName))))));
}
 
Example #4
Source File: WireMockRestServiceServer.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
private RequestMatcher matchContents(
		@SuppressWarnings("rawtypes") final ContentPattern pattern) {
	return new RequestMatcher() {
		@Override
		public void match(ClientHttpRequest request)
				throws IOException, AssertionError {
			MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
			@SuppressWarnings("unchecked")
			MatchResult result = pattern.match(mockRequest.getBodyAsString());
			MatcherAssert.assertThat(
					"Request as string [" + mockRequest.getBodyAsString() + "]",
					result.isExactMatch());
		}
	};
}
 
Example #5
Source File: BaristaSystem.java    From coffee-testing with Apache License 2.0 4 votes vote down vote up
private ContentPattern<?> requestJson(String orderId) {
    return equalToJson("{\"order\":\"" + orderId + "\"}", true, true);
}
 
Example #6
Source File: BaristaSystem.java    From coffee-testing with Apache License 2.0 4 votes vote down vote up
private ContentPattern<?> requestJson(String orderId, String status) {
    return equalToJson("{\"order\":\"" + orderId + "\",\"status\":\"" + status + "\"}", true, true);
}
 
Example #7
Source File: CloudControllerStubFixture.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
public void stubPushApp(final String appName, ContentPattern<?>... appMetadataPatterns) {
	stubCreateAppMetadata(appName, appMetadataPatterns);
	stubAppAfterCreation(appName, appName);
}
 
Example #8
Source File: CloudControllerStubFixture.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
public void stubPushAppWithHost(final String appName, final String host, ContentPattern<?>... appMetadataPatterns) {
	stubCreateAppMetadata(appName, appMetadataPatterns);
	stubAppAfterCreation(appName, host);
}
 
Example #9
Source File: BasicMappingBuilder.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Override
public ScenarioMappingBuilder withRequestBody(ContentPattern<?> bodyPattern) {
	this.requestPatternBuilder.withRequestBody(bodyPattern);
	return this;
}