aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'vid-automation/src/test/java/org/onap')
-rw-r--r--vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java b/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java
new file mode 100644
index 000000000..b27d6a8af
--- /dev/null
+++ b/vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java
@@ -0,0 +1,65 @@
+package org.onap.vid.more;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.equalToIgnoringCase;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.collection.IsMapContaining.hasKey;
+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.registerExpectationFromPreset;
+
+import java.util.List;
+import java.util.function.Supplier;
+import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetVpnsByType;
+import org.onap.vid.api.BaseApiTest;
+import org.onap.vid.more.LoggerFormatTest.LogName;
+import org.springframework.http.ResponseEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import vid.automation.test.services.SimulatorApi;
+
+public class AuditLoggerTest extends BaseApiTest {
+
+ private final String ECOMP_REQUEST_ID_ECHO = "x-ecomp-requestid-echo";
+
+ @BeforeClass
+ public void login() {
+ super.login();
+ }
+
+ @BeforeMethod
+ public void resetPreset() {
+ SimulatorApi.registerExpectation("create_new_instance/aai_get_full_subscribers.json", CLEAR_THEN_SET);
+ }
+
+ @Test
+ public void aaiController2$GetVpnList_requestIdIsAuditedInEntryAndInExit() {
+ registerExpectationFromPreset(new PresetAAIGetVpnsByType(), APPEND);
+ String requestId = getRequestId(() -> restTemplate.getForEntity(buildUri("aai_get_vpn_list"), String.class));
+
+ assertThat("request id must be found in exactly two rows", getRequestLogLines(requestId),
+ contains(
+ allOf(containsString(requestId), containsString("Entering")),
+ allOf(containsString(requestId), containsString("Exiting"))
+ ));
+ }
+
+ private List<String> getRequestLogLines(String requestId) {
+ return LoggerFormatTest.getRequestLogLines(requestId, LogName.audit2019, restTemplate, uri);
+ }
+
+ private String getRequestId(Supplier<ResponseEntity<?>> request) {
+ ResponseEntity<?> response = request.get();
+
+ assertThat(response.getHeaders(), hasKey(equalToIgnoringCase(ECOMP_REQUEST_ID_ECHO)));
+ List<String> requestIds = response.getHeaders().get(ECOMP_REQUEST_ID_ECHO);
+
+ assertThat(requestIds, hasSize(1));
+ return requestIds.get(0);
+ }
+
+}