From: Kai Moritz Date: Sat, 13 Mar 2021 16:02:39 +0000 (+0100) Subject: WIP X-Git-Tag: wip-consumer~2 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=03f0d97c64e951be02d48fb2e3442535dc1d193e;p=demos%2Fpact WIP --- diff --git a/consumer/src/main/java/de/juplo/demos/consumer/ConsumerApplication.java b/consumer/src/main/java/de/juplo/demos/consumer/ConsumerApplication.java index e697bf5..fee7c45 100644 --- a/consumer/src/main/java/de/juplo/demos/consumer/ConsumerApplication.java +++ b/consumer/src/main/java/de/juplo/demos/consumer/ConsumerApplication.java @@ -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); } - } 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 b69ef81..8cbc3eb 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 @@ -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 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 6c65008..9c0e9e4 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 @@ -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 {