From: Kai Moritz Date: Sat, 13 Mar 2021 15:13:42 +0000 (+0100) Subject: WIP X-Git-Tag: wip-consumer~4 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=2819247c41afad8ca474e3af84e1216353c2bb38;p=demos%2Fpact WIP --- diff --git a/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumer.java b/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumer.java index fd09ddc..d47283c 100644 --- a/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumer.java +++ b/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumer.java @@ -1,7 +1,7 @@ package de.juplo.demos.consumer.adapter; import de.juplo.demos.consumer.domain.User; -import de.juplo.demos.consumer.domain.UserService; +import de.juplo.demos.consumer.domain.UsersService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -12,7 +12,7 @@ import java.util.UUID; @RequiredArgsConstructor -public class RemoteUsersServiceConsumer implements UserService +public class RemoteUsersServiceConsumer implements UsersService { private String uriTemplate; private RestTemplate restTemplate; diff --git a/consumer/src/main/java/de/juplo/demos/consumer/domain/UsersService.java b/consumer/src/main/java/de/juplo/demos/consumer/domain/UsersService.java index b65f4eb..dc82975 100644 --- a/consumer/src/main/java/de/juplo/demos/consumer/domain/UsersService.java +++ b/consumer/src/main/java/de/juplo/demos/consumer/domain/UsersService.java @@ -4,7 +4,7 @@ import java.util.Optional; import java.util.UUID; -public interface UserService +public interface UsersService { Optional getUser(UUID id); } diff --git a/consumer/src/test/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumerIT.java b/consumer/src/test/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumerIT.java index 12ce6c9..ee8bd61 100644 --- a/consumer/src/test/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumerIT.java +++ b/consumer/src/test/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumerIT.java @@ -1,7 +1,9 @@ package de.juplo.demos.consumer.adapter; +import au.com.dius.pact.consumer.dsl.PactDslWithProvider; import au.com.dius.pact.consumer.junit5.PactConsumerTestExt; import au.com.dius.pact.consumer.junit5.PactTestFor; +import au.com.dius.pact.core.model.RequestResponsePact; import org.junit.jupiter.api.extension.ExtendWith; @@ -9,5 +11,22 @@ import org.junit.jupiter.api.extension.ExtendWith; @PactTestFor(providerName = "UsersProvider") public class RemoteUsersServiceConsumerIT { - + @Pact(provider="UsersProvider", consumer="EmailServicesConsumer") + public RequestResponsePact createPact(PactDslWithProvider builder) { + return builder + .given("User with email pact@juplo.de exists") + .uponReceiving("Request for user with email pact@juplo.de") + .path("/get") + .matchQuery( + "email", + // See: https://stackoverflow.com/a/201378/247276 + "(?:[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])+)\\])", + "pact@juplo.de") + .method("GET") + .matchHeader("", "", "") + .willRespondWith() + .status(200) + .body("{\"responsetest\": true}") + .toPact(); + } } diff --git a/pom.xml b/pom.xml index b365df0..cefbc41 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ Pact-Demo based on Spring Boot 11 - 4.1.0 + 4.2.2 consumer