aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
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/java/org/onap/vid/mso/rest/MsoRestClientTest.java
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/java/org/onap/vid/mso/rest/MsoRestClientTest.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java63
1 files changed, 55 insertions, 8 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();