WIP
authorKai Moritz <kai@juplo.de>
Sat, 13 Mar 2021 16:02:39 +0000 (17:02 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 13 Mar 2021 16:02:39 +0000 (17:02 +0100)
consumer/src/main/java/de/juplo/demos/consumer/ConsumerApplication.java
consumer/src/main/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumer.java
consumer/src/test/java/de/juplo/demos/consumer/adapter/RemoteUsersServiceConsumerIT.java

index e697bf5..fee7c45 100644 (file)
@@ -1,13 +1,25 @@
 package de.juplo.demos.consumer;
 
+import de.juplo.demos.consumer.adapter.RemoteUsersServiceConsumer;
+import de.juplo.demos.consumer.domain.UsersService;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
 
 @SpringBootApplication
 public class ConsumerApplication {
 
+       @Bean
+       public UsersService usersService(RestTemplateBuilder builder) {
+               RestTemplate restTemplate = builder.rootUri("http://localhost:8080/").build();
+               return new RemoteUsersServiceConsumer("/get?email={email}", restTemplate);
+       }
+
+
        public static void main(String[] args) {
                SpringApplication.run(ConsumerApplication.class, args);
        }
-
 }
index b69ef81..8cbc3eb 100644 (file)
@@ -5,18 +5,16 @@ import de.juplo.demos.consumer.domain.UsersService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
 import java.util.Optional;
 
 
-@Service
 @RequiredArgsConstructor
 public class RemoteUsersServiceConsumer implements UsersService
 {
-  private String uriTemplate;
-  private RestTemplate restTemplate;
+  private final String uriTemplate;
+  private final RestTemplate restTemplate;
 
 
   @Override
index 6c65008..9c0e9e4 100644 (file)
@@ -7,6 +7,7 @@ import au.com.dius.pact.consumer.junit5.PactTestFor;
 import au.com.dius.pact.core.model.RequestResponsePact;
 import au.com.dius.pact.core.model.annotations.Pact;
 import de.juplo.demos.consumer.domain.User;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +22,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
 
 
-@ExtendWith({ SpringExtension.class, PactConsumerTestExt.class })
+@SpringBootTest
+@ExtendWith(PactConsumerTestExt.class)
 @PactTestFor(providerName = "UsersProvider")
 public class RemoteUsersServiceConsumerIT
 {