aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/test/java/org/onap
diff options
context:
space:
mode:
authorBenjamin, Max <max.benjamin@att.com>2020-11-06 18:04:49 -0500
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-11-11 23:13:49 -0500
commitc183d2d73b46a51a028bd65c742ee46df5e7d547 (patch)
tree35f47caddf6107f7a4ee343503973d05be8dd361 /common/src/test/java/org/onap
parentea82d794ac51faa699b9b84ea003a9242b8d4ccc (diff)
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) <mb388a@att.com> Change-Id: I1216608a09f6a8649a57aa4b320fbea4982a7efe
Diffstat (limited to 'common/src/test/java/org/onap')
-rw-r--r--common/src/test/java/org/onap/so/client/RestClientTest.java61
1 files changed, 58 insertions, 3 deletions
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<String, String> 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);