diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index 4ac008cfc8..ada02a9965 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -12,7 +12,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.6.RELEASE + 1.4.0.RC1 @@ -116,4 +116,41 @@ + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + diff --git a/spring-boot/src/main/java/org/baeldung/client/Details.java b/spring-boot/src/main/java/org/baeldung/client/Details.java new file mode 100644 index 0000000000..2ae3adc38f --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/client/Details.java @@ -0,0 +1,32 @@ +package org.baeldung.client; + +public class Details { + + private String name; + + private String login; + + public Details() { + } + + public Details(String name, String login) { + this.name = name; + this.login = login; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } +} diff --git a/spring-boot/src/main/java/org/baeldung/client/DetailsServiceClient.java b/spring-boot/src/main/java/org/baeldung/client/DetailsServiceClient.java new file mode 100644 index 0000000000..51fa7c6181 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/client/DetailsServiceClient.java @@ -0,0 +1,20 @@ +package org.baeldung.client; + +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class DetailsServiceClient { + + private final RestTemplate restTemplate; + + public DetailsServiceClient(RestTemplateBuilder restTemplateBuilder) { + restTemplate = restTemplateBuilder.build(); + } + + public Details getUserDetails(String name) { + return restTemplate.getForObject("/{name}/details", Details.class, name); + } + +} \ No newline at end of file diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootMailTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootMailTest.java index 2e436ece2e..d36a7906a3 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootMailTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootMailTest.java @@ -37,7 +37,7 @@ public class SpringBootMailTest { @Before public void setUp() throws Exception { - final int TEST_PORT = 25; + final int TEST_PORT = 8025; wiser = new Wiser(TEST_PORT); wiser.start(); } diff --git a/spring-boot/src/test/java/org/baeldung/client/DetailsServiceClientTest.java b/spring-boot/src/test/java/org/baeldung/client/DetailsServiceClientTest.java new file mode 100644 index 0000000000..c594610be2 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/client/DetailsServiceClientTest.java @@ -0,0 +1,47 @@ +package org.baeldung.client; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.client.MockRestServiceServer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; + +@RunWith(SpringRunner.class) +@RestClientTest(DetailsServiceClient.class) +public class DetailsServiceClientTest { + + @Autowired + private DetailsServiceClient client; + + @Autowired + private MockRestServiceServer server; + + @Autowired + private ObjectMapper objectMapper; + + @Before + public void setUp() throws Exception { + String detailsString = objectMapper.writeValueAsString(new Details("John Smith", "john")); + this.server.expect(requestTo("/john/details")) + .andRespond(withSuccess(detailsString, MediaType.APPLICATION_JSON)); + } + + @Test + public void whenCallingGetUserDetails_thenClientExecutesCorrectCall() throws Exception { + + Details details = this.client.getUserDetails("john"); + + assertThat(details.getLogin()).isEqualTo("john"); + assertThat(details.getName()).isEqualTo("John Smith"); + + } + +} diff --git a/spring-boot/src/test/resources/application.properties b/spring-boot/src/test/resources/application.properties index bcfcf4b2fb..14b190629e 100644 --- a/spring-boot/src/test/resources/application.properties +++ b/spring-boot/src/test/resources/application.properties @@ -1,3 +1,3 @@ spring.mail.host=localhost -spring.mail.port=25 +spring.mail.port=8025 spring.mail.properties.mail.smtp.auth=false \ No newline at end of file