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

The following examples show how to use com.github.tomakehurst.wiremock.matching.StringValuePattern. 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: BasicMappingBuilder.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
@Override
public ScenarioMappingBuilder withQueryParams(
		Map<String, StringValuePattern> queryParams) {
	for (Map.Entry<String, StringValuePattern> entry : queryParams.entrySet()) {
		this.requestPatternBuilder.withQueryParam(entry.getKey(), entry.getValue());
	}
	return this;
}
 
Example #2
Source File: ConnectorDDMockClient.java    From pay-publicapi with MIT License 6 votes vote down vote up
public void respondOk_whenSearchMandatesRequest(Map<String, StringValuePattern> searchParams, MandateSearchConnectorResponse response, String gatewayAccountId) throws JsonProcessingException {
    String responseAsJson = new ObjectMapper().writeValueAsString(response);
    wireMockClassRule.stubFor(get(urlPathEqualTo(format(CONNECTOR_MOCK_MANDATES_PATH, gatewayAccountId)))
            .withHeader(ACCEPT, matching(APPLICATION_JSON))
            .withQueryParams(searchParams)
            .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader(CONTENT_TYPE, APPLICATION_JSON)
                    .withBody(responseAsJson)));
}
 
Example #3
Source File: AssemblyLine.java    From Architecting-Modern-Java-EE-Applications with MIT License 5 votes vote down vote up
private StringValuePattern processRequestBody() {
    // ...
    return null;
}
 
Example #4
Source File: BasicMappingBuilder.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Override
public BasicMappingBuilder withHeader(String key, StringValuePattern headerPattern) {
	this.requestPatternBuilder.withHeader(key, headerPattern);
	return this;
}
 
Example #5
Source File: BasicMappingBuilder.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Override
public BasicMappingBuilder withCookie(String name,
		StringValuePattern cookieValuePattern) {
	this.requestPatternBuilder.withCookie(name, cookieValuePattern);
	return this;
}
 
Example #6
Source File: BasicMappingBuilder.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Override
public BasicMappingBuilder withQueryParam(String key,
		StringValuePattern queryParamPattern) {
	this.requestPatternBuilder.withQueryParam(key, queryParamPattern);
	return this;
}
 
Example #7
Source File: MandateResourceSearchMandateIT.java    From pay-publicapi with MIT License 4 votes vote down vote up
@Test
public void shouldSuccessfullySearchMandate() throws JsonProcessingException {
    var searchNavigationLinksFromConnector = new SearchNavigationLinks()
            .withFirstLink(DD_CONNECTOR_BASE_SEARCH_URL + "&firstLink")
            .withLastLink(DD_CONNECTOR_BASE_SEARCH_URL + "&lastLink")
            .withNextLink(DD_CONNECTOR_BASE_SEARCH_URL + "&nextLink")
            .withSelfLink(DD_CONNECTOR_BASE_SEARCH_URL + "&selfLink");

    var selfLink = new PaymentConnectorResponseLink("self", "https://connector", "GET", null, null);

    MandateConnectorResponse mandate = aMandateConnectorResponse()
            .withMandateId(MANDATE_ID)
            .withMandateReference(MANDATE_REFERENCE)
            .withServiceReference(SERVICE_REFERENCE)
            .withReturnUrl(RETURN_URL)
            .withState(new MandateState("created", false, "mandate_state_details"))
            .withProviderId(PROVIDER_ID)
            .withCreatedDate(CREATED_DATE)
            .withPayer(new Payer(PAYER_NAME, PAYER_EMAIL))
            .withLinks(Collections.singletonList(selfLink))
            .build();

    MandateSearchConnectorResponse connectorResponse = aSearchMandateConnectorResponse()
            .withCount(1)
            .withPage(1)
            .withTotal(1)
            .withMandates(Collections.singletonList(mandate))
            .withLinks(searchNavigationLinksFromConnector)
            .build();

    String toDate = ISO_INSTANT_MILLISECOND_PRECISION.format(ZonedDateTime.now());
    String fromDate = ISO_INSTANT_MILLISECOND_PRECISION.format(ZonedDateTime.now().minusDays(1));

    Map<String, StringValuePattern>  searchParams = Map.of(
            "reference", equalTo(SERVICE_REFERENCE),
            "page", equalTo("1"),
            "display_size", equalTo("500"),
            "state", equalTo("created"),
            "to_date", equalTo(toDate),
            "from_date", equalTo(fromDate)
    );

    connectorDDMockClient.respondOk_whenSearchMandatesRequest(searchParams, connectorResponse, GATEWAY_ACCOUNT_ID);

    given().port(app.getLocalPort())
            .accept(JSON)
            .contentType(JSON)
            .header(AUTHORIZATION, "Bearer " + API_KEY)
            .queryParam("reference", SERVICE_REFERENCE)
            .queryParam("state", "created")
            .queryParam("to_date", toDate)
            .queryParam("from_date", fromDate)
            .get("/v1/directdebit/mandates/")
            .then()
            .statusCode(200)
            .contentType(JSON)
            .body("total", is(1))
            .body("count", is(1))
            .body("page", is(1))
            .body("results[0].mandate_id", is(MANDATE_ID))
            .body("results[0].provider_id", is(PROVIDER_ID))
            .body("results[0].reference", is(SERVICE_REFERENCE))
            .body("results[0].return_url", is(RETURN_URL))
            .body("results[0].state.status", is("created"))
            .body("results[0].state.details", is("mandate_state_details"))
            .body("results[0].created_date", is(CREATED_DATE))
            .body("results[0].payer.name", is(PAYER_NAME))
            .body("results[0].payer.email", is(PAYER_EMAIL))
            .body("results[0]._links.self.href", is(mandateLocationFor(MANDATE_ID)))
            .body("results[0]._links.self.method", is("GET"))
            .body("results[0]._links.payments.href", is("http://publicapi.url/v1/directdebit/payments?mandate_id=" + MANDATE_ID))
            .body("results[0]._links.payments.method", is("GET"))
            .body("_links.self.href", is("http://publicapi.url/v1/directdebit/mandates?page=1&display_size=500&selfLink"))
            .body("_links.first_page.href", is("http://publicapi.url/v1/directdebit/mandates?page=1&display_size=500&firstLink"))
            .body("_links.last_page.href", is("http://publicapi.url/v1/directdebit/mandates?page=1&display_size=500&lastLink"))
            .body("_links.next_page.href", is("http://publicapi.url/v1/directdebit/mandates?page=1&display_size=500&nextLink"));
}