ee8bd61e55a6331ae8a37d95a1883dce296e187f
[demos/pact] / consumer / src / test / java / de / juplo / demos / consumer / adapter / RemoteUsersServiceConsumerIT.java
1 package de.juplo.demos.consumer.adapter;
2
3 import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
4 import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
5 import au.com.dius.pact.consumer.junit5.PactTestFor;
6 import au.com.dius.pact.core.model.RequestResponsePact;
7 import org.junit.jupiter.api.extension.ExtendWith;
8
9
10 @ExtendWith(PactConsumerTestExt.class)
11 @PactTestFor(providerName = "UsersProvider")
12 public class RemoteUsersServiceConsumerIT
13 {
14   @Pact(provider="UsersProvider", consumer="EmailServicesConsumer")
15   public RequestResponsePact createPact(PactDslWithProvider builder) {
16     return builder
17         .given("User with email pact@juplo.de exists")
18           .uponReceiving("Request for user with email pact@juplo.de")
19             .path("/get")
20             .matchQuery(
21                 "email",
22                 // See: https://stackoverflow.com/a/201378/247276
23                 "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])",
24                 "pact@juplo.de")
25             .method("GET")
26             .matchHeader("", "", "")
27           .willRespondWith()
28             .status(200)
29             .body("{\"responsetest\": true}")
30         .toPact();
31   }
32 }