From c183d2d73b46a51a028bd65c742ee46df5e7d547 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max" Date: Fri, 6 Nov 2020 18:04:49 -0500 Subject: added configurable read timeout value for A&AI added configurable read timeout value for A&AI Issue-ID: SO-3370 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I1216608a09f6a8649a57aa4b320fbea4982a7efe --- .../java/org/onap/so/client/RestClientTest.java | 61 ++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'common/src/test/java/org') diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java index cd00a9e4de..c6e282c14a 100644 --- a/common/src/test/java/org/onap/so/client/RestClientTest.java +++ b/common/src/test/java/org/onap/so/client/RestClientTest.java @@ -21,6 +21,8 @@ package org.onap.so.client; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -28,7 +30,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.net.MalformedURLException; import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Map; +import java.util.Optional; import javax.ws.rs.NotFoundException; +import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilderException; @@ -37,21 +45,24 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; -import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.logging.filter.base.ONAPComponents; +import org.onap.logging.filter.base.ONAPComponentsList; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import com.github.tomakehurst.wiremock.junit.WireMockRule; @RunWith(MockitoJUnitRunner.class) public class RestClientTest { private final HttpClientFactory httpClientFactory = new HttpClientFactory(); - @Mock - private RestProperties props; @Rule public ExpectedException thrown = ExpectedException.none(); + @Rule + public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.options().dynamicPort()); + @Test public void retries() throws Exception { RestClient spy = buildSpy(); @@ -80,6 +91,50 @@ public class RestClientTest { } + @Test + public void timeoutTest() throws URISyntaxException { + wireMockRule.stubFor(get("/chunked/delayed") + .willReturn(aResponse().withStatus(200).withBody("Hello world!").withChunkedDribbleDelay(2, 300))); + + + RestProperties props = new RestProperties() { + + @Override + public URL getEndpoint() throws MalformedURLException { + return new URL(String.format("http://localhost:%s", wireMockRule.port())); + } + + @Override + public String getSystemName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Long getReadTimeout() { + return Long.valueOf(100); + } + }; + RestClient client = new RestClient(props, Optional.of(new URI("/chunked/delayed"))) { + + @Override + protected void initializeHeaderMap(Map headerMap) { + // TODO Auto-generated method stub + + } + + @Override + protected ONAPComponentsList getTargetEntity() { + return ONAPComponents.EXTERNAL; + } + + }; + + thrown.expect(ProcessingException.class); + client.get(); + + } + private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException { RestClient client = httpClientFactory.newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), ONAPComponents.BPMN); -- cgit 1.2.3-korg