au.com.dius.pact.core.model.annotations.Pact Java Examples

The following examples show how to use au.com.dius.pact.core.model.annotations.Pact. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: MemberSignedUpEventPactContracts.java    From microservices-testing-examples with MIT License 5 votes vote down vote up
@Pact(consumer = WELCOME_MEMBER_EMAIL_SERVICE, provider = SPECIAL_MEMBERSHIP_SERVICE)
public MessagePact newMemberTonyStark(MessagePactBuilder builder) {
  PactDslJsonBody body = new PactDslJsonBody()
      .stringValue("@type", "memberSignedUpEvent")
      .stringMatcher("email", ".+@.+\\..+", "[email protected]");

  Map<String, String> metadata = new HashMap<>();

  return builder.given("Tony Stark became a new member")
      .expectsToReceive("An event notifying Tony Stark's new membership")
      .withMetadata(metadata)
      .withContent(body)
      .toPact();
}
 
Example #10
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();
}