<description>Demo of a Pact Provider</description>
<properties>
<java.version>11</java.version>
+ <pact.version>4.1.0</pact.version>
</properties>
<dependencies>
<dependency>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>au.com.dius.pact.consumer</groupId>
+ <artifactId>junit5</artifactId>
+ <version>${pact.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
</excludes>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
</plugins>
</build>
--- /dev/null
+package de.juplo.demos.consumer.adapter;
+
+import de.juplo.demos.consumer.domain.User;
+import de.juplo.demos.consumer.domain.UserService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Optional;
+import java.util.UUID;
+
+
+@RequiredArgsConstructor
+public class RemoteUserServiceConsumer implements UserService
+{
+ private String uriTemplate;
+ private RestTemplate restTemplate;
+
+
+ @Override
+ public Optional<User> getUser(UUID id) {
+ ResponseEntity<UserDTO> response =
+ restTemplate.getForEntity(uriTemplate, UserDTO.class, id);
+ HttpStatus status = response.getStatusCode();
+ UserDTO dto = response.getBody();
+ switch (response.getStatusCode()) {
+ case OK:
+ return
+ Optional.of(
+ User.builder()
+ .id(dto.id)
+ .email(dto.email)
+ .build());
+ case NOT_FOUND:
+ return Optional.empty();
+ default:
+ throw new RuntimeException(status.toString());
+ }
+ }
+}
--- /dev/null
+package de.juplo.demos.consumer.adapter;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+
+@ExtendWith(PactConsumerTestExt.class)
+@PactTestFor(providerName = "UsersProvider")
+public class RemoteUserServiceConsumerIT
+{
+
+}
--- /dev/null
+package de.juplo.demos.consumer.domain;
+
+import java.util.Optional;
+import java.util.UUID;
+
+
+public interface UserService
+{
+ Optional<User> getUser(UUID id);
+}