aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java10
-rw-r--r--vid-automation/pom.xml4
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/AaiApiTest.java3
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/AsyncInfraApiTest.java14
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java3
-rw-r--r--vid-automation/src/test/java/org/onap/vid/more/AuditLoggerTest.java65
-rw-r--r--vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java50
-rw-r--r--vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java43
8 files changed, 144 insertions, 48 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java
index 6936d0a71..6c5595ca3 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java
@@ -29,6 +29,7 @@ import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.ServletContext;
+import org.onap.logging.filter.spring.LoggingInterceptor;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.AaiClient;
import org.onap.vid.aai.AaiClientInterface;
@@ -68,6 +69,8 @@ import org.onap.vid.utils.Logging;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.togglz.core.manager.FeatureManager;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -77,7 +80,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@Configuration
-public class WebConfig {
+public class WebConfig implements WebMvcConfigurer {
/**
* Gets the object mapper.
@@ -216,4 +219,9 @@ public class WebConfig {
int threadsCount = defaultIfNull(Integer.parseInt(SystemProperties.getProperty(VidProperties.VID_THREAD_COUNT)), 1);
return Executors.newFixedThreadPool(threadsCount);
}
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new LoggingInterceptor());
+ }
}
diff --git a/vid-automation/pom.xml b/vid-automation/pom.xml
index 6f2ae22c2..e2ef865f4 100644
--- a/vid-automation/pom.xml
+++ b/vid-automation/pom.xml
@@ -191,8 +191,8 @@
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>1.3</version>
+ <artifactId>java-hamcrest</artifactId>
+ <version>2.0.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
diff --git a/vid-automation/src/test/java/org/onap/vid/api/AaiApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/AaiApiTest.java
index 4ca01dc63..c128b864b 100644
--- a/vid-automation/src/test/java/org/onap/vid/api/AaiApiTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/api/AaiApiTest.java
@@ -58,6 +58,7 @@ import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaMo
import org.onap.vid.model.aai.AaiResponse;
import org.onap.vid.model.mso.OperationalEnvironmentList;
import org.onap.vid.more.LoggerFormatTest;
+import org.onap.vid.more.LoggerFormatTest.LogName;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@@ -353,7 +354,7 @@ public class AaiApiTest extends BaseApiAaiTest {
SimulatorApi.registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), APPEND);
restTemplateErrorAgnostic.getForEntity(uri + "/aai_get_services", String.class);
- String logLines = LoggerFormatTest.getLogLines("error", 15, 0, restTemplate, uri);
+ String logLines = LoggerFormatTest.getLogLines(LogName.error, 15, 0, restTemplate, uri);
assertThat("not found in error log", logLines, containsString("Failed to parse aai response"));
assertThat("not found in error log", logLines, containsString(notAJson));
diff --git a/vid-automation/src/test/java/org/onap/vid/api/AsyncInfraApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/AsyncInfraApiTest.java
index 058cb2f5b..b3c605ced 100644
--- a/vid-automation/src/test/java/org/onap/vid/api/AsyncInfraApiTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/api/AsyncInfraApiTest.java
@@ -1,21 +1,21 @@
package org.onap.vid.api;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.testng.AssertJUnit.assertEquals;
+
import com.google.common.collect.ImmutableList;
+import java.util.UUID;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
import org.onap.vid.more.LoggerFormatTest;
+import org.onap.vid.more.LoggerFormatTest.LogName;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import vid.automation.test.services.SimulatorApi;
-import java.util.UUID;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.testng.AssertJUnit.assertEquals;
-
public class AsyncInfraApiTest extends BaseApiTest {
public static final String API_URL = "asyncForTests";
@@ -51,7 +51,7 @@ public class AsyncInfraApiTest extends BaseApiTest {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, jobResult.getStatusCode());
assertThat(jobResult.getBody(), containsString("GenericUncheckedException"));
assertThat(jobResult.getBody(), containsString("dummy error"));
- String logLines = LoggerFormatTest.getLogLines("error", 15, 0, restTemplate, uri);
+ String logLines = LoggerFormatTest.getLogLines(LogName.error, 15, 0, restTemplate, uri);
assertThat(logLines, containsString("GenericUncheckedException"));
assertThat(logLines, containsString("dummy error"));
}
diff --git a/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java
index 95fb68a10..c6ee5fd62 100644
--- a/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java
@@ -48,6 +48,7 @@ import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet
import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
import org.onap.vid.more.LoggerFormatTest;
+import org.onap.vid.more.LoggerFormatTest.LogName;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeClass;
@@ -238,7 +239,7 @@ public class SdcApiTest extends BaseApiTest {
ResponseEntity<String> response = restTemplate.getForEntity(
buildUri(SDC_GET_SERVICE_MODEL + modelInfo.modelVersionId), String.class);
- String logLines = LoggerFormatTest.getLogLines("metrics2019", 15, 0, restTemplate, uri);
+ String logLines = LoggerFormatTest.getLogLines(LogName.metrics2019, 15, 0, restTemplate, uri);
final String requestId = response.getHeaders().getFirst("X-ECOMP-RequestID-echo");
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);
+ }
+
+}
diff --git a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
index e01ffe8b4..fd05b9dde 100644
--- a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java
@@ -1,12 +1,16 @@
package org.onap.vid.more;
+import static java.util.Collections.reverse;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import com.fasterxml.jackson.databind.JsonNode;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
@@ -24,6 +28,10 @@ public class LoggerFormatTest extends BaseApiTest {
private final static String logChecker = System.getProperty("EELF_LOG_CHECKER", "http://my-logchecker:8888/validate");
private final Logger logger = LogManager.getLogger(LoggerFormatTest.class);
+ public enum LogName {
+ audit, error, audit2019, metrics2019, metrics
+ }
+
@BeforeClass
public void login() {
super.login();
@@ -37,34 +45,34 @@ public class LoggerFormatTest extends BaseApiTest {
@SkipTestUntil("2019-09-24")
@Test
public void validateAuditLogsFormat() {
- validateLogsFormat("audit");
+ validateLogsFormat(LogName.audit);
}
@Test
public void validateAudit2019LogsFormat() {
- validateLogsFormat("audit2019", "audit-ELS-2019.11", 0);
+ validateLogsFormat(LogName.audit2019, "audit-ELS-2019.11", 0);
}
@Test(enabled = false) // no total-score is returned for error-log
public void validateErrorLogsFormat() {
- validateLogsFormat("error");
+ validateLogsFormat(LogName.error);
}
@SkipTestUntil("2019-09-24")
@Test
public void validateMetricsLogsFormat() {
- validateLogsFormat("metrics", "metric");
+ validateLogsFormat(LogName.metrics, "metric");
}
- private void validateLogsFormat(String logName) {
- validateLogsFormat(logName, logName);
+ private void validateLogsFormat(LogName logName) {
+ validateLogsFormat(logName, logName.name());
}
- private void validateLogsFormat(String logName, String logType) {
+ private void validateLogsFormat(LogName logName, String logType) {
validateLogsFormat(logName, logType, 0.95);
}
- private void validateLogsFormat(String logName, String logType, double score) {
+ private void validateLogsFormat(LogName logName, String logType, double score) {
String logLines = getLogLines(logName);
logger.info("logLines are: "+logLines);
@@ -78,18 +86,36 @@ public class LoggerFormatTest extends BaseApiTest {
}
- private String getLogLines(String logname) {
+ private String getLogLines(LogName logname) {
return getLogLines(logname, 5000, 30, restTemplate, uri);
}
- public static String getLogLines(String logname, int maxRows, int minRows, RestTemplate restTemplate, URI uri) {
- String logLines = restTemplate.getForObject(uri + "/logger/" + logname + "?limit={maxRows}", String.class, maxRows);
- assertThat("expecting at least " + minRows + " rows in " + logname,
+ public static String getLogLines(LogName logname, int maxRows, int minRows, RestTemplate restTemplate, URI uri) {
+ String logLines = restTemplate.getForObject(uri + "/logger/" + logname.name() + "?limit={maxRows}", String.class, maxRows);
+ assertThat("expecting at least " + minRows + " rows in " + logname.name(),
StringUtils.countMatches(logLines, '\n') + 1,
is(greaterThanOrEqualTo(minRows)));
return logLines;
}
+ /**
+ * @return Chronological-ordered list of recent log-lines of a given requestId
+ */
+ public static List<String> getRequestLogLines(String requestId, LogName logname, RestTemplate restTemplate, URI uri) {
+ String logLines = LoggerFormatTest.getLogLines(LogName.audit2019, 30, 1, restTemplate, uri);
+
+ // Split
+ List<String> lines = new ArrayList<>(Arrays.asList(logLines.split("(\\r?\\n)")));
+
+ // Filter
+ lines.removeIf(line -> !StringUtils.containsIgnoreCase(line, requestId));
+
+ // Reverse
+ reverse(lines);
+
+ return lines;
+ }
+
private JsonNode getCheckerResults(String logtype, String logLines) {
Map<String, String> params = new HashMap<>();
params.put("format", "raw");
diff --git a/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java b/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java
index fb710b324..07bd3b0dc 100644
--- a/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java
+++ b/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java
@@ -9,7 +9,6 @@ import static org.onap.vid.api.pProbeMsoApiTest.MSO_CREATE_CONFIGURATION;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.UUID;
@@ -21,6 +20,7 @@ import org.onap.simulator.presetGenerator.presets.aaf.AAFGetUrlServicePreset;
import org.onap.vid.api.BaseApiTest;
import org.onap.vid.api.OperationalEnvironmentControllerApiTest;
import org.onap.vid.api.ServiceInstanceMsoApiTest;
+import org.onap.vid.more.LoggerFormatTest.LogName;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -53,7 +53,7 @@ public class RequestIdFilterInstalled extends BaseApiTest {
}
@Test
- public void frontendApi_doGET_RequestIdReceived() throws InterruptedException {
+ public void frontendApi_doGET_RequestIdReceived() {
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.GET,
@@ -61,12 +61,12 @@ public class RequestIdFilterInstalled extends BaseApiTest {
null,
OperationalEnvironmentControllerApiTest.GET_CLOUD_RESOURCES_REQUEST_STATUS
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid);
}
@Test
- public void frontendApi_doPOST_RequestIdReceived() throws InterruptedException {
+ public void frontendApi_doPOST_RequestIdReceived() {
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.POST,
@@ -74,7 +74,7 @@ public class RequestIdFilterInstalled extends BaseApiTest {
"{}",
ServiceInstanceMsoApiTest.DEACTIVATE_OK_JSON
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid);
}
@Test
@@ -85,20 +85,20 @@ public class RequestIdFilterInstalled extends BaseApiTest {
"/" + MSO_CREATE_CONFIGURATION,
"i'm not a json"
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.error, responseAndUuid);
}
@Test(groups = { "worksOnlyWithLocalhostVID" })
- public void mopOwningEntityApi_doGET_RequestIdReceived() throws InterruptedException {
+ public void mopOwningEntityApi_doGET_RequestIdReceived() {
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.GET,
"/" + MAINTENANCE_CATEGORY_PARAMETER + "?familyName=PARAMETER_STANDARDIZATION",
null
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid);
/*
test should be for:
@@ -113,7 +113,7 @@ public class RequestIdFilterInstalled extends BaseApiTest {
}
@Test
- public void schedulerApi_doPOST_RequestIdReceived() throws InterruptedException {
+ public void schedulerApi_doPOST_RequestIdReceived() {
final String anyInstanceId = "any instance id";
SimulatorApi.registerExpectation(
@@ -130,7 +130,7 @@ public class RequestIdFilterInstalled extends BaseApiTest {
"/change-management/workflow/" + anyInstanceId,
"{}"
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid);
}
@@ -139,12 +139,12 @@ public class RequestIdFilterInstalled extends BaseApiTest {
final Pair<HttpEntity, String> responseAndUuid = makeRequest(
HttpMethod.GET, "/healthCheck", null
);
- assertThatUuidInResponseAndUuidIsInARecentLog(responseAndUuid);
+ assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit, responseAndUuid);
}
- private void assertThatUuidInResponseAndUuidIsInARecentLog(Pair<HttpEntity, String> responseAndUuid) {
+ private void assertThatUuidInResponseAndUuidIsInARecentLog(LogName logName, Pair<HttpEntity, String> responseAndUuid) {
assertThatResponseHasUuid(responseAndUuid.getLeft(), responseAndUuid.getRight());
- assertThatTermIsInARecentLog(responseAndUuid.getRight());
+ assertThatTermIsInARecentLog(logName, responseAndUuid.getRight());
}
private void assertThatResponseHasUuid(HttpEntity response, String uuid) {
@@ -153,17 +153,13 @@ public class RequestIdFilterInstalled extends BaseApiTest {
// id" filter, which is great!
Assert.assertNotNull(response);
List<String> ecompRequestIdHeaderValues = response.getHeaders().get(ECOMP_REQUEST_ID_ECHO);
- Assert.assertThat(ecompRequestIdHeaderValues, hasItem(equalToIgnoringCase(uuid)));
+ assertThat(ecompRequestIdHeaderValues, hasItem(equalToIgnoringCase(uuid)));
}
- private void assertThatTermIsInARecentLog(String uuid) {
- final ImmutableList<String> logLines = ImmutableList.of(
- LoggerFormatTest.getLogLines("audit", 20, 0, restTemplate, uri),
- LoggerFormatTest.getLogLines("error", 20, 0, restTemplate, uri)
- );
+ private void assertThatTermIsInARecentLog(LogName logName, String uuid) {
+ final String logLines = LoggerFormatTest.getLogLines(logName, 20, 0, restTemplate, uri);
- // Assert that audit *OR* error has the uuid
- assertThat("uuid not found in any log", logLines, hasItem(containsString(uuid)));
+ assertThat("uuid not found in any log", logLines, containsString(uuid));
}
private Pair<HttpEntity, String> makeRequest(HttpMethod httpMethod, String url, String body) {
@@ -184,9 +180,8 @@ public class RequestIdFilterInstalled extends BaseApiTest {
SimulatorApi.registerExpectation("ecompportal_getSessionSlotCheckInterval.json", APPEND);
HttpEntity entity = new HttpEntity<>(body, headers);
- ResponseEntity<String> response = null;
- response = restTemplateErrorAgnostic.exchange(uri + url,
- httpMethod, entity, String.class);
+ ResponseEntity<String> response =
+ restTemplateErrorAgnostic.exchange(uri + url, httpMethod, entity, String.class);
return Pair.of(response, uuid);
}