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);
}
-
}
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
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;
import static org.assertj.core.api.Assertions.fail;
-@ExtendWith({ SpringExtension.class, PactConsumerTestExt.class })
+@SpringBootTest
+@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "UsersProvider")
public class RemoteUsersServiceConsumerIT
{