register scheduler to work with MetricLogClient Filter 86/97786/3
authorSara Weiss <sara.weiss@intl.att.com>
Thu, 31 Oct 2019 12:41:26 +0000 (14:41 +0200)
committerIttay Stern <ittay.stern@att.com>
Thu, 31 Oct 2019 13:27:48 +0000 (13:27 +0000)
Issue-ID: VID-253
Signed-off-by: Sara Weiss <sara.weiss@intl.att.com>
Change-Id: Ic624e1c2a4b04d31177c737a5d249e734a4cfb48

vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
vid-automation/src/test/java/org/onap/vid/api/ChangeManagementMsoApiLoggingTest.java [deleted file]
vid-automation/src/test/java/org/onap/vid/api/ChangeManagementUserApiLoggingTest.java [new file with mode: 0644]

index 8d45bee..a956dc4 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -76,7 +76,7 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
         commonHeaders = Maps.newHashMap();
         commonHeaders.put("Authorization", "Basic " + authStringEnc);
 
-        syncRestClient = new SyncRestClient(loggingService);
+        syncRestClient = new SyncRestClient(loggingService, true);
 
         logger.info("\t<== Client Initialized \n");
     }
@@ -94,7 +94,6 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
             loggingService.logRequest(outgoingRequestsLogger, HttpMethod.GET, url);
             Map<String, String> requestHeaders = ImmutableMap.<String, String>builder()
                     .putAll(commonHeaders)
-                    .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId())
                     .build();
             final HttpResponse<String> response = syncRestClient.get(url, requestHeaders,
                     Collections.emptyMap(), String.class);
@@ -128,7 +127,7 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
         loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
         Map<String, String> requestHeaders = ImmutableMap.<String, String>builder()
                 .putAll(commonHeaders)
-                .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()).build();
+                .build();
         final HttpResponse<T> response = (HttpResponse<T>) syncRestClient.delete(url, requestHeaders, t.getClass());
 
         loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url, response);
diff --git a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementMsoApiLoggingTest.java b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementMsoApiLoggingTest.java
deleted file mode 100644 (file)
index 6e29a97..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.onap.vid.api;
-
-import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
-import org.onap.vid.more.LoggerFormatTest;
-import org.springframework.http.ResponseEntity;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-import vid.automation.test.services.SimulatorApi;
-import vid.automation.test.services.SimulatorApi.RegistrationStrategy;
-
-public class ChangeManagementMsoApiLoggingTest extends BaseApiTest {
-
-  public static final String MSO = "/mso";
-  public static final String CHANGE_MANAGEMENT = "change-management";
-  public static final String  MSO_GET_CHANGE_MANAGEMENTS_SCALEOUT ="changeManagement/mso_get_change_managements_scaleout.json";
-  public static final String  MSO_GET_CHANGE_MANAGEMENTS = "changeManagement/mso_get_change_managements.json";
-
-
-  @BeforeClass
-  public void login() {
-    super.login();
-  }
-
-  @Test
-  public void testGetOrchestrationRequestsLoggedInMetricsLog () {
-    SimulatorApi.registerExpectation(MSO_GET_CHANGE_MANAGEMENTS_SCALEOUT, RegistrationStrategy.CLEAR_THEN_SET);
-    SimulatorApi.registerExpectation(MSO_GET_CHANGE_MANAGEMENTS, RegistrationStrategy.APPEND);
-    SimulatorApi.registerExpectationFromPreset( new PresetAAIGetSubscribersGet(), RegistrationStrategy.APPEND);
-
-    ResponseEntity<String> responseEntity = restTemplate.getForEntity(buildUri(CHANGE_MANAGEMENT + MSO ), String.class);
-    String requestId = responseEntity.getHeaders().getFirst("X-ECOMP-RequestID-echo");
-
-    LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, "/mso/orchestrationRequests/", 2);
-  }
-
-}
diff --git a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementUserApiLoggingTest.java b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementUserApiLoggingTest.java
new file mode 100644 (file)
index 0000000..dd58e81
--- /dev/null
@@ -0,0 +1,84 @@
+package org.onap.vid.api;
+
+import com.google.common.collect.ImmutableList;
+import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
+import org.onap.simulator.presetGenerator.presets.scheduler.PresetDeleteSchedulerChangeManagement;
+import org.onap.simulator.presetGenerator.presets.scheduler.PresetGetSchedulerChangeManagements;
+import org.onap.vid.more.LoggerFormatTest;
+import org.springframework.http.ResponseEntity;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import vid.automation.test.services.SimulatorApi;
+import vid.automation.test.services.SimulatorApi.RegistrationStrategy;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
+
+public class ChangeManagementUserApiLoggingTest extends BaseApiTest {
+
+  public static final String MSO = "/mso";
+  public static final String CHANGE_MANAGEMENT = "change-management";
+  public static final String  MSO_GET_CHANGE_MANAGEMENTS_SCALEOUT ="changeManagement/mso_get_change_managements_scaleout.json";
+  public static final String  MSO_GET_CHANGE_MANAGEMENTS = "changeManagement/mso_get_change_managements.json";
+
+
+  @BeforeClass
+  public void login() {
+    super.login();
+  }
+
+  @Test
+  public void testGetOrchestrationRequestsLoggedInMetricsLog () {
+    SimulatorApi.registerExpectation(MSO_GET_CHANGE_MANAGEMENTS_SCALEOUT, RegistrationStrategy.CLEAR_THEN_SET);
+    SimulatorApi.registerExpectation(MSO_GET_CHANGE_MANAGEMENTS, RegistrationStrategy.APPEND);
+    SimulatorApi.registerExpectationFromPreset( new PresetAAIGetSubscribersGet(), RegistrationStrategy.APPEND);
+
+    ResponseEntity<String> responseEntity = restTemplate.getForEntity(buildUri(CHANGE_MANAGEMENT + MSO ), String.class);
+    String requestId = responseEntity.getHeaders().getFirst("X-ECOMP-RequestID-echo");
+
+    LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, "/mso/orchestrationRequests/", 2);
+  }
+
+  @Test
+  public void whenCallSchedulerGet_thenRequestRecordedInMetricsLog() {
+
+    String SCHEDULER_PATH = "change-management/scheduler";
+
+    String VID_TO_SCHEDULER_PATH = "/scheduler/v1/ChangeManagement/schedules" ;
+
+    registerExpectationFromPresets(ImmutableList.of(
+            new PresetGetSchedulerChangeManagements(),
+            new PresetAAIGetSubscribersGet()),
+            RegistrationStrategy.CLEAR_THEN_SET);
+
+    ResponseEntity<String> responseEntity = restTemplate.getForEntity(buildUri(SCHEDULER_PATH), String.class);
+
+    String requestId = responseEntity.getHeaders().getFirst("X-ECOMP-RequestID-echo");
+    LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, VID_TO_SCHEDULER_PATH, 1);
+  }
+
+
+  @Test
+  public void whenCallSchedulerDelete_thenRequestRecordedInMetricsLog() {
+
+    String SCHEDULER_PATH = "change-management/scheduler/schedules/83aec7bf-602f-49eb-9788-bbc33ac550d9";
+
+    String VID_TO_SCHEDULER_PATH = "/scheduler/v1/ChangeManagement/schedules/83aec7bf-602f-49eb-9788-bbc33ac550d9" ;
+
+    registerExpectationFromPresets(ImmutableList.of(
+            new PresetDeleteSchedulerChangeManagement(),
+            new PresetAAIGetSubscribersGet()),
+            RegistrationStrategy.CLEAR_THEN_SET);
+
+    WebTarget webTarget = client.target(uri).path(SCHEDULER_PATH);
+    Response response = webTarget.request(MediaType.APPLICATION_JSON_TYPE).delete();
+
+
+    String requestId = response.getHeaders().getFirst("X-ECOMP-RequestID-echo").toString();
+    LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, VID_TO_SCHEDULER_PATH, 1);
+  }
+}