au.com.dius.pact.model.RequestResponsePact Java Examples

The following examples show how to use au.com.dius.pact.model.RequestResponsePact. 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: UserServiceConsumerPactTest.java    From spring-microservice-sample with GNU General Public License v3.0 6 votes vote down vote up
@Pact(consumer = "auth-service")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json");

    //@formatter:off
    return builder
        .given("should return user if existed")
            .uponReceiving("Get a user by existing username: user")
            .path("/users/user")
            .method("GET")
        .willRespondWith()
            .headers(headers)
            .status(200)
            .body("{\"username\": \"user\", \"password\": \"password\", \"email\": \"[email protected]\" }")
        .given("should return error 404 if not existed")
            .uponReceiving("Get a user by none-existing username: noneExisting")
            .method("GET")
            .path("/users/noneExisting")
        .willRespondWith()
            .headers(headers)
            .status(404)
            .body("{\"entity\": \"USER\",\"id\": \"noneExisting\",\"code\": \"not_found\",\"message\": \"User:noneExisting was not found\"}")
        .toPact();
    //@formatter:on
}
 
Example #2
Source File: UserServiceConsumerTest.java    From code-examples with MIT License 6 votes vote down vote up
@Pact(state = "provider accepts a new person", provider = "userservice", consumer = "userclient")
RequestResponsePact createPersonPact(PactDslWithProvider builder) {

	// @formatter:off
	return builder
					.given("provider accepts a new person")
					.uponReceiving("a request to POST a person")
						.path("/user-service/users")
						.method("POST")
					.willRespondWith()
						.status(201)
						.matchHeader("Content-Type", "application/json")
						.body(new PactDslJsonBody()
										.integerType("id", 42))
					.toPact();
	// @formatter:on
}
 
Example #3
Source File: UserServiceConsumerTest.java    From code-examples with MIT License 6 votes vote down vote up
@Pact(state = "person 42 exists", provider = "userservice", consumer = "userclient")
RequestResponsePact updatePersonPact(PactDslWithProvider builder) {
	// @formatter:off
	return builder
					.given("person 42 exists")
					.uponReceiving("a request to PUT a person")
					  .path("/user-service/users/42")
					  .method("PUT")
					.willRespondWith()
					  .status(200)
					  .matchHeader("Content-Type", "application/json")
					  .body(new PactDslJsonBody()
										.stringType("firstName", "Zaphod")
										.stringType("lastName", "Beeblebrox"))
					.toPact();
	// @formatter:on
}
 
Example #4
Source File: BeerControllerTest.java    From spring-cloud-contract-samples with Apache License 2.0 6 votes vote down vote up
@Pact(consumer="beer-api-consumer-pact")
public RequestResponsePact beerNotOk(PactDslWithProvider builder) {
	return builder
			.given("")
				.uponReceiving("Represents a successful scenario of getting a beer")
				.path("/check")
				.method("POST")
				.headers("Content-Type", "application/json;charset=UTF-8")
				.body("{\"name\":\"marcin\",\"age\":25}")
				.willRespondWith()
				.status(200)
				.body("{\"status\":\"OK\"}")
				.headers(responseHeaders())
			.given("")
				.uponReceiving("Represents an unsuccessful scenario of getting a beer")
				.path("/check")
				.method("POST")
				.headers("Content-Type", "application/json;charset=UTF-8")
				.body("{\"name\":\"marcin\",\"age\":10}")
				.willRespondWith()
				.status(200)
				.body("{\"status\":\"NOT_OK\"}")
				.headers(responseHeaders())
			.toPact();
}
 
Example #5
Source File: ExternalBookingContractTest.java    From monolith with Apache License 2.0 5 votes vote down vote up
@Pact(provider="orders_service", consumer="test_synthetic_order")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
    RequestResponsePact pact = builder
            .given("available shows")
            .uponReceiving("booking request")
            .path("/rest/bookings")
            .matchHeader("Content-Type", "application/json")
            .method("POST")
            .body(bookingRequestBody())
            .willRespondWith()
            .body(syntheticBookingResponseBody())
            .status(200)
            .toPact();
    return pact;
}
 
Example #6
Source File: PactConsumerDrivenContractUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Pact(consumer = "test_consumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json");

    return builder.given("test GET").uponReceiving("GET REQUEST").path("/pact").method("GET").willRespondWith().status(200).headers(headers).body("{\"condition\": true, \"name\": \"tom\"}").given("test POST").uponReceiving("POST REQUEST").method("POST")
            .headers(headers).body("{\"name\": \"Michael\"}").path("/pact").willRespondWith().status(201).toPact();
}