diff options
author | Ittay Stern <ittay.stern@att.com> | 2019-10-22 21:17:31 +0300 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-10-23 14:18:56 +0300 |
commit | d90cc53c8a66b50038576df2e74e8fe383969f22 (patch) | |
tree | 8395e81455700f0a9b1ba70f4be8ea842373bf33 | |
parent | e8d29ab5e3775472f59a4997fa3a5df9319de306 (diff) |
Introduce LOG-NAME enumerator
Issue-ID: VID-253
Change-Id: Ib24e6ce12fd89bdddaf1b15b7c0d47b3d6f8af9a
Signed-off-by: Ittay Stern <ittay.stern@att.com>
5 files changed, 68 insertions, 45 deletions
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/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); } |