aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/test/java/org')
-rw-r--r--common/src/test/java/org/onap/so/client/RestClientTest.java70
-rw-r--r--common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java20
-rw-r--r--common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java22
-rw-r--r--common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java23
4 files changed, 104 insertions, 31 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..3bf4ccf127 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,30 +30,42 @@ 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.Optional;
import javax.ws.rs.NotFoundException;
+import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriBuilderException;
+import org.javatuples.Pair;
import org.junit.Rule;
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.extension.responsetemplating.ResponseTemplateTransformer;
+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().extensions(new ResponseTemplateTransformer(false)));
+
@Test
public void retries() throws Exception {
RestClient spy = buildSpy();
@@ -80,6 +94,56 @@ 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 Integer getRetries() {
+ return Integer.valueOf(0);
+ }
+
+ @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(MultivaluedMap<String, Pair<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);
diff --git a/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java b/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java
index 5075da3b7a..964707ab8f 100644
--- a/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java
@@ -21,32 +21,33 @@
package org.onap.so.client.adapter.rest;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
-import java.util.HashMap;
-import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.codec.binary.Base64;
+import org.javatuples.Pair;
import org.junit.Before;
import org.junit.Test;
+import org.onap.logging.filter.base.ONAPComponents;
import org.onap.so.client.policy.JettisonStyleMapperProvider;
import org.onap.so.utils.CryptoUtils;
-import org.onap.logging.filter.base.ONAPComponents;
public class AdapterRestClientTest {
private static final String CRYPTO_KEY = "546573746F736973546573746F736973";
private static final String INVALID_CRYPTO_KEY = "1234";
- private Map<String, String> headerMap;
+ private MultivaluedMap<String, Pair<String, String>> headerMap;
private AdapterRestProperties adapterRestPropertiesMock;
@Before
public void setup() {
- headerMap = new HashMap<>();
+ headerMap = new MultivaluedHashMap<>();
+
adapterRestPropertiesMock = mock(AdapterRestProperties.class);
}
@@ -60,7 +61,8 @@ public class AdapterRestClientTest {
// when
testedObject.initializeHeaderMap(headerMap);
// then
- assertThat(headerMap).containsOnly(entry("Authorization", getExpectedEncodedString(encyptedMessage)));
+ assertThat(headerMap.get("ALL"))
+ .containsOnly(Pair.with("Authorization", getExpectedEncodedString(encyptedMessage)));
}
@Test
@@ -70,7 +72,7 @@ public class AdapterRestClientTest {
// when
testedObject.initializeHeaderMap(headerMap);
// then
- assertThat(headerMap).containsOnly(entry("Authorization", null));
+ assertThat(headerMap.get("ALL")).containsOnly(Pair.with("Authorization", null));
}
@Test
@@ -84,7 +86,7 @@ public class AdapterRestClientTest {
// when
testedObject.initializeHeaderMap(headerMap);
// then
- assertThat(headerMap).containsOnly(entry("Authorization", null));
+ assertThat(headerMap.get("ALL")).containsOnly(Pair.with("Authorization", null));
}
@Test
diff --git a/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java b/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java
index ca5b5da2da..4f00b9db96 100644
--- a/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/dmaap/rest/DMaaPRestClientTest.java
@@ -24,8 +24,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
import org.junit.Test;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.slf4j.MDC;
@@ -48,11 +49,12 @@ public class DMaaPRestClientTest {
throw new RuntimeException(e);
}
DMaaPRestClient client = new DMaaPRestClient(url, contentType, auth, key);
- Map<String, String> map = new HashMap<>();
+ MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
client.initializeHeaderMap(map);
- map.put(ONAPLogConstants.MDCs.REQUEST_ID, "1234");
+ map.add("ALL", Pair.with(ONAPLogConstants.MDCs.REQUEST_ID, "1234"));
assertNotNull(map);
- assertEquals("Found expected RequesttId", "1234", map.get(ONAPLogConstants.MDCs.REQUEST_ID));
+ assertEquals("Found expected RequestId", true,
+ map.get("ALL").contains(Pair.with(ONAPLogConstants.MDCs.REQUEST_ID, "1234")));
}
@@ -67,11 +69,12 @@ public class DMaaPRestClientTest {
}
MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, "1234");
DMaaPRestClient client = new DMaaPRestClient(url, contentType, auth, key);
- Map<String, String> map = new HashMap<>();
+ MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
client.initializeHeaderMap(map);
assertNotNull(map);
- assertEquals("Found expected RequestId", "1234", map.get(ONAPLogConstants.Headers.INVOCATION_ID));
+ assertEquals("Found expected RequestId", true,
+ map.get("ALL").contains(Pair.with(ONAPLogConstants.Headers.INVOCATION_ID, "1234")));
}
@@ -87,11 +90,12 @@ public class DMaaPRestClientTest {
MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, null);
DMaaPRestClient client = new DMaaPRestClient(url, contentType, auth, key);
- Map<String, String> map = new HashMap<>();
+ MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
client.initializeHeaderMap(map);
assertNotNull(map);
- assertEquals("header not found as expected", null, map.get(ONAPLogConstants.Headers.INVOCATION_ID));
+ assertEquals("header not found as expected", false,
+ map.get("ALL").contains(Pair.with(ONAPLogConstants.Headers.INVOCATION_ID, "1234")));
}
}
diff --git a/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
index 3323fd8409..f9547cb3db 100644
--- a/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
+++ b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
@@ -23,21 +23,22 @@
package org.onap.so.client.policy;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import org.javatuples.Pair;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -56,10 +57,10 @@ import org.onap.so.client.policy.entities.PolicyConfig;
import org.onap.so.client.policy.entities.PolicyDecision;
import org.onap.so.client.policy.entities.PolicyDecisionRequest;
import org.onap.so.client.policy.entities.PolicyServiceType;
+import org.onap.so.client.policy.entities.Workstep;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
-import org.onap.so.client.policy.entities.Workstep;
public class PolicyClientImplTest {
@@ -79,11 +80,13 @@ public class PolicyClientImplTest {
@Test
public void successReadProperties() {
PolicyRestClient client = new PolicyRestClient(new PolicyRestPropertiesImpl(), PolicyServiceType.GET_DECISION);
- Map<String, String> map = new HashMap<>();
+ MultivaluedMap<String, Pair<String, String>> map = new MultivaluedHashMap<>();
client.initializeHeaderMap(map);
- assertEquals("Found expected Client Auth", "Basic bTAzNzQzOnBvbGljeVIwY2sk", map.get("ClientAuth"));
- assertEquals("Found expected Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==", map.get("Authorization"));
- assertEquals("Found expected Environment", "TEST", map.get("Environment"));
+ assertTrue("Found expected Client Auth",
+ map.get("ALL").contains(Pair.with("ClientAuth", "Basic bTAzNzQzOnBvbGljeVIwY2sk")));
+ assertTrue("Found expected Authorization",
+ map.get("ALL").contains(Pair.with("Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==")));
+ assertTrue("Found expected Environment", map.get("ALL").contains(Pair.with("Environment", "TEST")));
}
@Test