+ @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);
+ }
+ }
+