Java Code Examples for com.github.tomakehurst.wiremock.stubbing.StubMapping#buildFrom()

The following examples show how to use com.github.tomakehurst.wiremock.stubbing.StubMapping#buildFrom() . 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: WiremockServerRestDocsApplicationTests.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Test
public void queryParamsAreFetchedFromStubs() throws Exception {
	this.mockMvc.perform(MockMvcRequestBuilders.get(
			"/project_metadata/spring-framework?callback=a_function_name&foo=foo&bar=bar"))
			.andExpect(status().isOk())
			.andExpect(content().string("spring-framework a_function_name foo bar"))
			.andDo(document("query"));

	File file = new File("target/snippets/stubs", "query.json");
	BDDAssertions.then(file).exists();
	StubMapping stubMapping = StubMapping
			.buildFrom(new String(Files.readAllBytes(file.toPath())));
	Map<String, MultiValuePattern> queryParameters = stubMapping.getRequest()
			.getQueryParameters();
	BDDAssertions.then(queryParameters.get("callback").getValuePattern())
			.isEqualTo(WireMock.equalTo("a_function_name"));
	BDDAssertions.then(queryParameters.get("foo").getValuePattern())
			.isEqualTo(WireMock.equalTo("foo"));
	BDDAssertions.then(queryParameters.get("bar").getValuePattern())
			.isEqualTo(WireMock.equalTo("bar"));
}
 
Example 2
Source File: WiremockServerRestDocsApplicationTests.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Test
public void stubsRenderLinksWithPlaceholder() throws Exception {
	this.mockMvc.perform(MockMvcRequestBuilders.get("/link"))
			.andExpect(status().isOk())
			.andExpect(content().string(containsString("link:")))
			.andDo(document("link"));

	File file = new File("target/snippets/stubs", "link.json");
	BDDAssertions.then(file).exists();
	StubMapping stubMapping = StubMapping
			.buildFrom(new String(Files.readAllBytes(file.toPath())));
	String body = stubMapping.getResponse().getBody();
	BDDAssertions.then(body)
			.contains("http://localhost:{{request.requestLine.port}}/link");
	BDDAssertions.then(stubMapping.getResponse().getTransformers())
			.contains("response-template");
}
 
Example 3
Source File: WiremockServerRestDocsHypermediaApplicationTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void stubsRenderLinksWithoutPlaceholder() throws Exception {
	this.mockMvc.perform(MockMvcRequestBuilders.get("/link"))
			.andExpect(status().isOk())
			.andExpect(content().string(containsString("link:")))
			.andDo(document("link"));

	File file = new File("target/snippets/stubs", "link.json");
	BDDAssertions.then(file).exists();
	StubMapping stubMapping = StubMapping
			.buildFrom(new String(Files.readAllBytes(file.toPath())));
	String body = stubMapping.getResponse().getBody();
	BDDAssertions.then(body).contains("http://localhost:8080/link");
}
 
Example 4
Source File: WiremockServerWebTestClientApplicationTests.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Test
public void stubsRenderLinksWithPlaceholder() throws Exception {
	this.client.get().uri("/link").exchange().expectBody(String.class)
			.value(containsString("link:")).consumeWith(document("link"));

	File file = new File("target/snippets/webtestclient/stubs", "link.json");
	BDDAssertions.then(file).exists();
	StubMapping stubMapping = StubMapping
			.buildFrom(new String(Files.readAllBytes(file.toPath())));
	String body = stubMapping.getResponse().getBody();
	BDDAssertions.then(body)
			.contains("http://localhost:{{request.requestLine.port}}/link");
	BDDAssertions.then(stubMapping.getResponse().getTransformers())
			.contains("response-template");
}
 
Example 5
Source File: WireMockHttpServerStub.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
StubMapping getMapping(File file) {
	try (InputStream stream = Files.newInputStream(file.toPath())) {
		return StubMapping.buildFrom(
				StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
	}
	catch (IOException e) {
		throw new IllegalStateException("Cannot read file", e);
	}
}
 
Example 6
Source File: IronTestUtils.java    From irontest with Apache License 2.0 5 votes vote down vote up
/**
 * Create (clone) a new instance out of the stub spec, with UUID generated for the instance.
 * The instance also has the ironTestId as metadata.
 * The spec is not changed.
 * @param spec
 * @return
 */
public static StubMapping createStubInstance(long ironTestId, short ironTestNumber, StubMapping spec) {
    StubMapping stubInstance = StubMapping.buildFrom(StubMapping.buildJsonStringFor(spec));
    stubInstance.setMetadata(metadata()
            .attr(WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID, ironTestId)
            .attr(WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER, ironTestNumber)
            .build());
    stubInstance.setDirty(false);
    return stubInstance;
}
 
Example 7
Source File: HTTPStubMappingMapper.java    From irontest with Apache License 2.0 5 votes vote down vote up
@Override
public HTTPStubMapping map(ResultSet rs, StatementContext ctx) throws SQLException {
    String specJSON = rs.getString("spec_json");
    StubMapping spec = StubMapping.buildFrom(specJSON);
    HTTPStubMapping httpStubMapping = new HTTPStubMapping(
            rs.getLong("id"), rs.getLong("testcase_id"),
            rs.getShort("number"), spec, rs.getString("request_body_main_pattern_value"),
            rs.getShort("expected_hit_count"));

    return httpStubMapping;
}
 
Example 8
Source File: WireMockStubMapping.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
public static StubMapping buildFrom(String mappingDefinition) {
	return StubMapping.buildFrom(mappingDefinition);
}
 
Example 9
Source File: WireMockStubMapping.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
public static StubMapping buildFrom(String mappingDefinition) {
	return StubMapping.buildFrom(mappingDefinition);
}