au.com.dius.pact.consumer.dsl.PactDslWithProvider Java Examples

The following examples show how to use au.com.dius.pact.consumer.dsl.PactDslWithProvider. 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: PollingTest.java    From microservice-istio with Apache License 2.0 6 votes vote down vote up
@Pact(consumer = "Shipping")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
	Map<String, String> headers = new HashMap<String, String>();
	headers.put("Content-Type", "application/json");
	Date now = new Date();
	return builder	.uponReceiving("Request for order feed")
					.method("GET")
					.path("/feed")
					.willRespondWith()
					.status(200)
					.headers(headers)
					.body(feedBody(now))
					.uponReceiving("Request for an order")
					.method("GET")
					.path("/order/1")
					.willRespondWith()
					.status(200)
					.headers(headers)
					.body(order(now))
					.toPact();
}
 
Example #2
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 #3
Source File: PactJunitRuleTest.java    From Pact-JVM-Example with MIT License 6 votes vote down vote up
@Pact(consumer = "JunitRuleConsumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json;charset=UTF-8");

    return builder
            .given("")
            .uponReceiving("Pact JVM example Pact interaction")
            .path("/information")
            .query("name=Miku")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body("{\n" +
                    "    \"salary\": 45000,\n" +
                    "    \"name\": \"Hatsune Miku\",\n" +
                    "    \"nationality\": \"Japan\",\n" +
                    "    \"contact\": {\n" +
                    "        \"Email\": \"[email protected]\",\n" +
                    "        \"Phone Number\": \"9090950\"\n" +
                    "    }\n" +
                    "}")
            .toPact();
}
 
Example #4
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 #5
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 #6
Source File: ClientPactTest.java    From pact-workshop-jvm with Apache License 2.0 6 votes vote down vote up
@Pact(provider = "Our Provider", consumer = "Our Little Consumer")
public RequestResponsePact pact(PactDslWithProvider builder) {
  dateTime = LocalDateTime.now();
  dateResult = OffsetDateTime.now().truncatedTo(ChronoUnit.SECONDS);
  return builder
    .given("data count > 0")
    .uponReceiving("a request for json data")
    .path("/provider.json")
    .method("GET")
    .query("validDate=" + dateTime.toString())
    .willRespondWith()
    .status(200)
    .body(
        new PactDslJsonBody()
            .stringValue("test", "NO")
            .datetime("validDate", "yyyy-MM-dd'T'HH:mm:ssXX", dateResult.toInstant())
            .integerType("count", 100)
    )
    .toPact();
}
 
Example #7
Source File: AuthenticationServiceHappyTest.java    From ServiceComb-Company-WorkShop with Apache License 2.0 6 votes vote down vote up
@Pact(consumer = "Manager")
public PactFragment createFragment(PactDslWithProvider pactDslWithProvider) throws JsonProcessingException {
  Map<String, String> headers = new HashMap<>();
  headers.put("Content-Type", MediaType.TEXT_PLAIN_VALUE);

  return pactDslWithProvider
      .given("User Sean is authorized")
      .uponReceiving("a request to access from Sean")
      .path("/rest/validate")
      .body(objectMapper.writeValueAsString(new Token(token)), APPLICATION_JSON)
      .method("POST")
      .willRespondWith()
      .headers(headers)
      .status(HttpStatus.OK.value())
      .body(username)
      .toFragment();
}
 
Example #8
Source File: AuthenticationServiceFailedTest.java    From ServiceComb-Company-WorkShop with Apache License 2.0 6 votes vote down vote up
@Pact(consumer = "Manager")
public PactFragment createFragment(PactDslWithProvider pactDslWithProvider) throws JsonProcessingException {
  Map<String, String> headers = new HashMap<>();
  headers.put("Content-Type", MediaType.TEXT_PLAIN_VALUE);

  return pactDslWithProvider
      .given("User Jack is unauthorized")
      .uponReceiving("a request to access from Jack")
      .path("/rest/validate")
      .body(objectMapper.writeValueAsString(new Token(token)), APPLICATION_JSON)
      .method("POST")
      .willRespondWith()
      .headers(headers)
      .status(HttpStatus.FORBIDDEN.value())
      .toFragment();
}
 
Example #9
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 #10
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 6 votes vote down vote up
@Pact(consumer = "Invoice")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
	Map<String, String> headers = new HashMap<String, String>();
	headers.put("Content-Type", "application/json");
	Date now = new Date();
	return builder	.uponReceiving("Request for order feed")
					.method("GET")
					.path("/feed")
					.willRespondWith()
					.status(200)
					.headers(headers)
					.body(feedBody(now))
					.uponReceiving("Request for an order")
					.method("GET")
					.path("/order/1")
					.willRespondWith()
					.status(200)
					.headers(headers)
					.body(order(now))
					.toPact();
}
 
Example #11
Source File: PollingTest.java    From microservice-istio with Apache License 2.0 6 votes vote down vote up
@Pact(consumer = "Bonus")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
	Map<String, String> headers = new HashMap<String, String>();
	headers.put("Content-Type", "application/json");
	Date now = new Date();
	return builder	.uponReceiving("Request for order feed")
					.method("GET")
					.path("/feed")
					.willRespondWith()
					.status(200)
					.headers(headers)
					.body(feedBody(now))
					.uponReceiving("Request for an order")
					.method("GET")
					.path("/order/1")
					.willRespondWith()
					.status(200)
					.headers(headers)
					.body(order(now))
					.toPact();
}
 
Example #12
Source File: ClientPactTest.java    From pact-workshop-jvm with Apache License 2.0 5 votes vote down vote up
@Pact(provider = "Our Provider", consumer = "Our Little Consumer")
public RequestResponsePact pactForMissingDateParameter(PactDslWithProvider builder) {
  return builder
          .given("data count > 0")
          .uponReceiving("a request with a missing date parameter")
          .path("/provider.json")
          .method("GET")
          .willRespondWith()
          .status(400)
          .body(
              new PactDslJsonBody().stringValue("error", "validDate is required")
          )
          .toPact();
}
 
Example #13
Source File: ClientPactTest.java    From pact-workshop-jvm with Apache License 2.0 5 votes vote down vote up
@Pact(provider = "Our Provider", consumer = "Our Little Consumer")
public RequestResponsePact pactForInvalidDateParameter(PactDslWithProvider builder) {
  return builder
          .given("data count > 0")
          .uponReceiving("a request with an invalid date parameter")
          .path("/provider.json")
          .method("GET")
          .query("validDate=This is not a date")
          .willRespondWith()
          .status(400)
          .body(
               new PactDslJsonBody().stringValue("error", "'This is not a date' is not a date")
          )
          .toPact();
}
 
Example #14
Source File: ClientPactTest.java    From pact-workshop-jvm with Apache License 2.0 5 votes vote down vote up
@Pact(provider = "Our Provider", consumer = "Our Little Consumer")
public RequestResponsePact pactForWhenThereIsNoData(PactDslWithProvider builder) {
  dateTime = LocalDateTime.now();
  return builder
          .given("data count == 0")
          .uponReceiving("a request for json data")
          .path("/provider.json")
          .method("GET")
          .query("validDate=" + dateTime.toString())
          .willRespondWith()
          .status(404)
          .toPact();
}
 
Example #15
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 #16
Source File: PactBaseConsumerTest.java    From Pact-JVM-Example with MIT License 5 votes vote down vote up
@Override
@Pact(provider="ExampleProvider", consumer="BaseConsumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json;charset=UTF-8");

    return builder
            .given("")
            .uponReceiving("Pact JVM example Pact interaction")
            .path("/information")
            .query("name=Miku")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body("{\n" +
                    "    \"salary\": 45000,\n" +
                    "    \"name\": \"Hatsune Miku\",\n" +
                    "    \"nationality\": \"Japan\",\n" +
                    "    \"contact\": {\n" +
                    "        \"Email\": \"[email protected]\",\n" +
                    "        \"Phone Number\": \"9090950\"\n" +
                    "    }\n" +
                    "}")

            .toPact();
}
 
Example #17
Source File: CreditScoreServicePactContracts.java    From microservices-testing-examples with MIT License 5 votes vote down vote up
@Pact(provider = CREDIT_SCORE_SERVICE, consumer = SPECIAL_MEMBERSHIP_SERVICE)
public RequestResponsePact tonyStarkCreditScore(PactDslWithProvider pact) {
  return pact.given("There is a [email protected]")
      .uponReceiving("A credit score request for [email protected]")
      .path("/credit-scores/[email protected]").method("GET")
      .willRespondWith()
      .status(200)
      .headers(singletonMap(CONTENT_TYPE, APPLICATION_JSON))
      .body(new PactDslJsonBody().integerType("creditScore", 850))
      .toPact();
}
 
Example #18
Source File: CreditScoreServicePactContracts.java    From microservices-testing-examples with MIT License 5 votes vote down vote up
@Pact(provider = CREDIT_SCORE_SERVICE, consumer = SPECIAL_MEMBERSHIP_SERVICE)
public RequestResponsePact hawleyGriffinCreditScore(PactDslWithProvider pact) {
  return pact.given("There is not a [email protected]")
      .uponReceiving("A credit score request for [email protected]")
      .path("/credit-scores/[email protected]").method("GET")
      .willRespondWith()
      .status(404)
      .toPact();
}
 
Example #19
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();
}
 
Example #20
Source File: PactJunitRuleMultipleInteractionsTest.java    From Pact-JVM-Example with MIT License 4 votes vote down vote up
@Pact(consumer="JunitRuleMultipleInteractionsConsumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json;charset=UTF-8");

    return builder
            .given("")
            .uponReceiving("Miku")
            .path("/information")
            .query("name=Miku")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body("{\n" +
                    "    \"salary\": 45000,\n" +
                    "    \"name\": \"Hatsune Miku\",\n" +
                    "    \"nationality\": \"Japan\",\n" +
                    "    \"contact\": {\n" +
                    "        \"Email\": \"[email protected]\",\n" +
                    "        \"Phone Number\": \"9090950\"\n" +
                    "    }\n" +
                    "}")
            .given("")
            .uponReceiving("Nanoha")
            .path("/information")
            .query("name=Nanoha")
            .method("GET")
            .willRespondWith()
            .headers(headers)
            .status(200)
            .body("{\n" +
                    "    \"salary\": 80000,\n" +
                    "    \"name\": \"Takamachi Nanoha\",\n" +
                    "    \"nationality\": \"Japan\",\n" +
                    "    \"contact\": {\n" +
                    "        \"Email\": \"[email protected]\",\n" +
                    "        \"Phone Number\": \"9090940\"\n" +
                    "    }\n" +
                    "}")
            .toPact();
}