add to AAI headers in request and metric log 45/97745/3
authorEinat Vinouze <einat.vinouze@intl.att.com>
Wed, 30 Oct 2019 07:43:24 +0000 (09:43 +0200)
committerEylon Malin <eylon.malin@intl.att.com>
Thu, 31 Oct 2019 05:28:34 +0000 (07:28 +0200)
Issue-ID: VID-253

Including API test + use VidMetricLogClientFilter

Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com>
Change-Id: I62980b3c88e941d1a47b03c75a1c837078e1988b

vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
vid-automation/src/test/java/org/onap/vid/api/AaiApiTest.java
vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java

index 4369c17..aadfd58 100644 (file)
@@ -22,8 +22,6 @@ package org.onap.vid.aai.util;
 
 
 import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
-import static org.onap.vid.logging.Headers.INVOCATION_ID;
-import static org.onap.vid.logging.Headers.PARTNER_NAME;
 
 import com.att.eelf.configuration.EELFLogger;
 import java.io.UnsupportedEncodingException;
@@ -43,7 +41,7 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.onap.vid.aai.ExceptionWithRequestInfo;
 import org.onap.vid.aai.ResponseWithRequestInfo;
 import org.onap.vid.aai.exceptions.InvalidPropertyException;
-import org.onap.vid.logging.RequestIdHeader;
+import org.onap.vid.logging.VidMetricLogClientFilter;
 import org.onap.vid.utils.Logging;
 import org.onap.vid.utils.Unchecked;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -127,6 +125,8 @@ public class AAIRestInterface {
         if (client == null) {
             try {
                 client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
+                VidMetricLogClientFilter metricLogClientFilter = new VidMetricLogClientFilter();
+                client.register(metricLogClientFilter);
             } catch (Exception e) {
                 logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString());
                 logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : " + e.toString());
@@ -193,18 +193,11 @@ public class AAIRestInterface {
 
             final Response response;
 
-            String requestId = extractOrGenerateRequestId();
-
             Invocation.Builder requestBuilder = client.target(url)
                 .request()
                 .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
-                .header(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue())
-                .header(TRANSACTION_ID_HEADER, transId)
                 .header(FROM_APP_ID_HEADER, fromAppId)
                 .header("Content-Type", MediaType.APPLICATION_JSON)
-                .header(RequestIdHeader.ONAP_ID.getHeaderName(), requestId)
-                .header(RequestIdHeader.ECOMP_ID.getHeaderName(), requestId)
-                .header(INVOCATION_ID.getHeaderName(), INVOCATION_ID.getHeaderValue())
                 ;
 
             requestBuilder = systemPropertyHelper.isClientCertEnabled() ?
index fd66dab..f03b897 100644 (file)
@@ -65,7 +65,6 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.vid.aai.util.AAIRestInterface;
 import org.onap.vid.aai.util.HttpsAuthClient;
 import org.onap.vid.aai.util.ServletRequestHelper;
 import org.onap.vid.aai.util.SystemPropertyHelper;
@@ -77,7 +76,6 @@ import org.onap.vid.mso.RestMsoImplementation;
 import org.onap.vid.testUtils.TestUtils;
 import org.onap.vid.utils.Logging;
 import org.onap.vid.utils.SystemPropertiesWrapper;
-import org.onap.vid.utils.Unchecked;
 import org.springframework.http.HttpMethod;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.web.context.request.RequestContextHolder;
@@ -115,9 +113,6 @@ public class OutgoingRequestHeadersTest {
     @Mock
     SyncRestClient syncRestClient;
 
-    @InjectMocks
-    private AAIRestInterface aaiRestInterface;
-
     @Captor
     private ArgumentCaptor<MultivaluedMap<String, Object>> multivaluedMapArgumentCaptor;
 
@@ -217,37 +212,6 @@ public class OutgoingRequestHeadersTest {
         return headersCapture;
     }
 
-    @DataProvider
-    public Object[][] aaiMethods() {
-        return Stream.<ThrowingConsumer<AAIRestInterface>>of(
-
-                client -> client.RestGet("from app id", "some transId", Unchecked.toURI("/any path"), false),
-                client -> client.RestPost("from app id", "/any path", "some payload", false),
-                client -> client.doRest("from app id", "some transId", Unchecked.toURI("/any path"), "somebody", HttpMethod.GET, false, true),
-                client -> client.RestPut("from app id", "/any path", "some payload", false, false)
-
-        ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
-    }
-
-    @Test(dataProvider = "aaiMethods")
-    public void aai(Consumer<AAIRestInterface> f) throws Exception {
-        //given
-        final TestUtils.JavaxRsClientMocks mocks = setAndGetMocksInsideRestImpl(aaiRestInterface);
-        //when
-        f.accept(aaiRestInterface);
-        //then
-        HeadersVerifier headersVerifier = new HeadersVerifier().verifyFirstCall(mocks.getFakeBuilder());
-
-        //verify requestId is same in next call but invocationId is different
-        //given
-        final TestUtils.JavaxRsClientMocks mocks2 = setAndGetMocksInsideRestImpl(aaiRestInterface);
-        //when
-        f.accept(aaiRestInterface);
-        //then
-        headersVerifier.verifySecondCall(mocks2.getFakeBuilder());
-
-    }
-
 //    @Test(dataProvider = "schedulerMethods")
 //    public void scheduler(Consumer<AAIRestInterface> f) throws Exception {
 //
index c128b86..39110c5 100644 (file)
@@ -15,6 +15,7 @@ import static org.testng.Assert.assertTrue;
 import static org.testng.AssertJUnit.assertEquals;
 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET;
+import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
 import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -767,6 +768,19 @@ public class AaiApiTest extends BaseApiAaiTest {
                 response.getBody());
     }
 
+    @Test
+    public void whenCallAaiThroughAAIRestInterface_thenRequestRecordedInMetricsLog() {
+        registerExpectationFromPresets(ImmutableList.of(
+            new PresetAAIGetVpnsByType(),
+            new PresetAAIGetSubscribersGet()
+        ),CLEAR_THEN_SET);
+
+        String url = uri + "/aai_get_vpn_list";
+        ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
+        final String requestId = response.getHeaders().getFirst("X-ECOMP-RequestID-echo");
+        LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId,"/network/vpn-bindings" , 1);
+    }
+
     @Test
     public void getVpnList() {
         SimulatorApi.registerExpectationFromPreset(new PresetAAIGetVpnsByType(), CLEAR_THEN_SET);
index 11a6932..5978510 100644 (file)
@@ -133,7 +133,7 @@ public class LoggerFormatTest extends BaseApiTest {
 
         List<RecordedRequests> requests = retrieveRecordedRequests();
         List<RecordedRequests> underTestRequests =
-            requests.stream().filter(x->x.path.startsWith(path)).collect(toList());
+            requests.stream().filter(x->x.path.contains(path)).collect(toList());
 
         assertThat(underTestRequests, hasSize(requestsSize));