summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-09-05 23:57:37 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-09-08 15:24:31 +0300
commite25b88b5a7a0f3bf63ca7160a441b53145484bcc (patch)
tree484d6b437d159fea57f15fc7b31802010e3af98f /vid-app-common/src/test
parenta855f8d76f3fbedcf7696eb91d34a4912d55114a (diff)
send different request id on each mso call
Don't use static headers for ECOMP_REQUEST_ID and ONAP_REQUEST_ID but getting them from request / generate them each time Issue-ID: VID-378 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: I1be4e8e86195901975d613694acf0082cd555886 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java63
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java47
2 files changed, 85 insertions, 25 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
index c91e88be7..78982ef24 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
@@ -25,18 +25,32 @@ import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasEntry;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.refEq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
+import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
+import static org.onap.vid.utils.Logging.ONAP_REQUEST_ID_HEADER_KEY;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.AssertJUnit.assertEquals;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.joshworks.restclient.http.HttpResponse;
import io.joshworks.restclient.http.JsonMapper;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.HttpResponseWithRequestInfo;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
@@ -54,17 +68,11 @@ import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import static org.mockito.ArgumentMatchers.refEq;
-import static org.mockito.hamcrest.MockitoHamcrest.argThat;
-import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
-
@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
@WebAppConfiguration
@@ -139,6 +147,45 @@ public class MsoRestClientTest {
}
@Test
+ public void whenCreateInstanceTwice_thenRequestIdHeaderIsDifferentEachTime() {
+
+ RequestAttributes prevRequestAttributes = RequestContextHolder.getRequestAttributes();
+
+ try {
+ //given
+ Mockito.reset(client);
+
+ //mocking syncRestClient
+ RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
+ HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
+ when( client.post( anyString() ,anyMap(), any(RequestDetails.class), eq(String.class) ) ).thenReturn(httpResponse);
+
+ //when
+ //create different ECOMP_REQUEST_ID header in Spring HttpServlet each time
+ OutgoingRequestHeadersTest.putRequestInSpringContext();
+ restClient.createInstance(requestDetails, "someEndPoint");
+
+ OutgoingRequestHeadersTest.putRequestInSpringContext();
+ restClient.createInstance(requestDetails, "someEndPoint");
+
+ //then
+ ArgumentCaptor<Map<String, String>> requestCaptor = ArgumentCaptor.forClass(Map.class);
+ verify(client, times(2)).post(anyString(), requestCaptor.capture(), any(RequestDetails.class), eq(String.class));
+ assertEquals(2, requestCaptor.getAllValues().size());
+ assertNotEquals(requestCaptor.getAllValues().get(0).get(SystemProperties.ECOMP_REQUEST_ID),
+ requestCaptor.getAllValues().get(1).get(SystemProperties.ECOMP_REQUEST_ID),
+ SystemProperties.ECOMP_REQUEST_ID + " headers are the same");
+ assertNotEquals(requestCaptor.getAllValues().get(0).get(ONAP_REQUEST_ID_HEADER_KEY),
+ requestCaptor.getAllValues().get(1).get(ONAP_REQUEST_ID_HEADER_KEY),
+ ONAP_REQUEST_ID_HEADER_KEY + " headers are the same");
+ }
+ finally {
+ //make sure other test keep go smooth
+ RequestContextHolder.setRequestAttributes(prevRequestAttributes);
+ }
+ }
+
+ @Test
public void shouldProperlyCreateVnf() {
// given
RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest();
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
index 316f200de..b70ba063f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
@@ -20,9 +20,33 @@
package org.onap.vid.mso.rest;
+import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasToString;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.matchesPattern;
+import static org.mockito.Mockito.when;
+
import com.google.common.collect.ImmutableList;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.lang3.reflect.FieldUtils;
-import org.mockito.*;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.onap.vid.aai.util.AAIRestInterface;
import org.onap.vid.aai.util.ServletRequestHelper;
import org.onap.vid.aai.util.SystemPropertyHelper;
@@ -37,21 +61,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.MultivaluedMap;
-import java.util.Set;
-import java.util.UUID;
-import java.util.function.Consumer;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-import static org.mockito.Mockito.when;
-
public class OutgoingRequestHeadersTest {
@@ -78,7 +87,11 @@ public class OutgoingRequestHeadersTest {
}
@BeforeMethod
- private void putRequestInSpringContext() {
+ private void setup() {
+ putRequestInSpringContext();
+ }
+
+ public static void putRequestInSpringContext() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes((HttpServletRequest) PromiseEcompRequestIdFilter.wrapIfNeeded(new MockHttpServletRequest())));
}