Я раздвоенный этот проект:тест RestTemplate терпит неудачу с ResourceAccessException
https://github.com/soudmaijer/drools
здесь:
https://github.com/fastnsilver/drools
Я обновил некоторые зависимости POM быть больше тока, и я добавил тест клиента с помощью RestTemplate
, который должен для осуществления FraudController
.
Когда я выполняю тест под названием FraudControllerClientTest
, я получаю ResourceAccessException
.
Смотрите этот след
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 4.486 sec <<< FAILURE! - in com.oudmaijer.drools.fraud.FraudControllerClientTest
thatOrderSucceeds(com.oudmaijer.drools.fraud.FraudControllerClientTest) Time elapsed: 0.251 sec <<< ERROR!
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8080/fraud/check/order":Connection reset; nested exception is java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:152)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:270)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:91)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:568)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:537)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:365)
at com.oudmaijer.drools.fraud.FraudControllerClientTest.thatOrderSucceeds(FraudControllerClientTest.java:41)
тест ...
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = FraudApplication.class)
@WebAppConfiguration
@IntegrationTest
public class FraudControllerClientTest {
@Value("${env.baseUrl}")
private String baseUrl;
@Test
public void thatOrderSucceeds() {
String uri = String.format("%s%s%s", baseUrl, Routes.BASE, Routes.ORDER);
RestTemplate rest = new TestRestTemplate();
ResponseEntity<Errors> response =
rest.postForEntity(uri, TestFixture.standardOrder(), Errors.class, Collections.EMPTY_MAP);
assertEquals(HttpStatus.OK, response.getStatusCode());
Errors errors = response.getBody();
assertFalse(errors.hasErrors());
}
@Test
public void thatOrderFails() {
String uri = String.format("%s%s%s", baseUrl, Routes.BASE, Routes.ORDER);
RestTemplate rest = new TestRestTemplate();
ResponseEntity<Errors> response =
rest.postForEntity(uri, TestFixture.suspiciousOrder(), Errors.class, Collections.EMPTY_MAP);
assertEquals(HttpStatus.OK, response.getStatusCode());
Errors errors = response.getBody();
assertTrue(errors.hasErrors());
}
private static class TestFixture {
static Order standardOrder() {
return new Order("1", new Seller(5), new Address("456XYZ", 66));
}
static Order suspiciousOrder() {
return new Order("1", new Seller(3), new Address("3452RK", 53));
}
}
}
Есть ли что-то я не хватает? Не могу ли я проверить реальное приложение Spring Boot с RestTemplate
?