From: Kai Moritz Date: Sat, 13 Mar 2021 15:13:41 +0000 (+0100) Subject: WIP X-Git-Tag: wip-consumer~5 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=0bed04371871dbcd898d0b64ba57b4a304d7c525;p=demos%2Fpact WIP --- diff --git a/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUserServiceConsumer.java b/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUserServiceConsumer.java deleted file mode 100644 index 104339c..0000000 --- a/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUserServiceConsumer.java +++ /dev/null @@ -1,41 +0,0 @@ -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 getUser(UUID id) { - ResponseEntity 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()); - } - } -} diff --git a/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUserServiceConsumerIT.java b/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUserServiceConsumerIT.java deleted file mode 100644 index 2a33f89..0000000 --- a/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUserServiceConsumerIT.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.juplo.demos.consumer.adapter; - -import org.junit.jupiter.api.extension.ExtendWith; - - -@ExtendWith(PactConsumerTestExt.class) -@PactTestFor(providerName = "UsersProvider") -public class RemoteUserServiceConsumerIT -{ - -} 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 new file mode 100644 index 0000000..fd09ddc --- /dev/null +++ b/consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumer.java @@ -0,0 +1,41 @@ +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 RemoteUsersServiceConsumer implements UserService +{ + private String uriTemplate; + private RestTemplate restTemplate; + + + @Override + public Optional getUser(UUID id) { + ResponseEntity 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()); + } + } +} diff --git a/consumer/src/main/java/de/juplo/demos/consumer/domain/UserService.java b/consumer/src/main/java/de/juplo/demos/consumer/domain/UserService.java deleted file mode 100644 index b65f4eb..0000000 --- a/consumer/src/main/java/de/juplo/demos/consumer/domain/UserService.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.juplo.demos.consumer.domain; - -import java.util.Optional; -import java.util.UUID; - - -public interface UserService -{ - Optional getUser(UUID id); -} 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 new file mode 100644 index 0000000..b65f4eb --- /dev/null +++ b/consumer/src/main/java/de/juplo/demos/consumer/domain/UsersService.java @@ -0,0 +1,10 @@ +package de.juplo.demos.consumer.domain; + +import java.util.Optional; +import java.util.UUID; + + +public interface UserService +{ + 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 new file mode 100644 index 0000000..12ce6c9 --- /dev/null +++ b/consumer/src/test/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumerIT.java @@ -0,0 +1,13 @@ +package de.juplo.demos.consumer.adapter; + +import au.com.dius.pact.consumer.junit5.PactConsumerTestExt; +import au.com.dius.pact.consumer.junit5.PactTestFor; +import org.junit.jupiter.api.extension.ExtendWith; + + +@ExtendWith(PactConsumerTestExt.class) +@PactTestFor(providerName = "UsersProvider") +public class RemoteUsersServiceConsumerIT +{ + +}