Added examples for the @RestClientTest article, fixed mail port (#513)
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
3efa23b6b5
commit
cb8f58a9e7
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
spring.mail.host=localhost
|
||||
spring.mail.port=25
|
||||
spring.mail.port=8025
|
||||
spring.mail.properties.mail.smtp.auth=false
|
||||
Reference in New Issue
Block a user