diff options
author | Eylon Malin <eylon.malin@intl.att.com> | 2019-11-03 15:29:12 +0200 |
---|---|---|
committer | Eylon Malin <eylon.malin@intl.att.com> | 2019-11-03 22:05:32 +0200 |
commit | 3a6149664092cacfdf76c0ab985a250ec9131439 (patch) | |
tree | dabb1b295900b26efc33529702e9f717e9b7093e /vid-automation/src/test | |
parent | 87e8d266de1ddc2495e229a076363542609a005a (diff) |
send unqiue request ids to MSO in async instantiation
Issue-ID: VID-253
Change-Id: I73e7829a2e7e980540e0c253823d030e77b9976b
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-automation/src/test')
-rw-r--r-- | vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java | 66 | ||||
-rw-r--r-- | vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java | 57 |
2 files changed, 103 insertions, 20 deletions
diff --git a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java index b6fa0fb9b..9b1dc6506 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java @@ -1,18 +1,27 @@ package org.onap.vid.api; import static java.util.Collections.emptyMap; +import static java.util.stream.Collectors.toList; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset.DEFAULT_INSTANCE_ID; import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateInstancePost.DEFAULT_REQUEST_ID; import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE; import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME; import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets; +import static vid.automation.test.services.SimulatorApi.retrieveRecordedRequests; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.UUID; @@ -39,6 +48,8 @@ import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaMo import org.onap.vid.model.asyncInstantiation.JobAuditStatus; import org.onap.vid.model.asyncInstantiation.JobAuditStatus.SourceStatus; import org.onap.vid.model.asyncInstantiation.ServiceInfo; +import org.onap.vid.more.LoggerFormatTest; +import org.onap.vid.more.LoggerFormatTest.LogName; import org.testng.annotations.AfterMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -49,6 +60,7 @@ import vid.automation.test.model.JobStatus; import vid.automation.test.model.ServiceAction; import vid.automation.test.services.AsyncJobsService; import vid.automation.test.services.SimulatorApi; +import vid.automation.test.services.SimulatorApi.RecordedRequests; import vid.automation.test.services.SimulatorApi.RegistrationStrategy; @FeatureTogglingTest({Features.FLAG_ASYNC_ALACARTE_VNF}) @@ -397,6 +409,60 @@ public class AsyncInstantiationALaCarteApiTest extends AsyncInstantiationBase { } } + @Test + public void verifyMetricsLogInAsyncInstantiation() { + + final String UUID_REGEX = "[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}"; + + final String msoURL = "/mso/serviceInstantiation/v"; + + deploy1ServiceFromCypress__verifyStatusAndMsoCalls_andRetry("none", emptyMap(), emptyMap(), true); + List<String> logLines = LoggerFormatTest.getLogLinesAsList(LogName.metrics2019, 200, 1, restTemplate, uri); + List<RecordedRequests> requests = retrieveRecordedRequests(); + List<RecordedRequests> underTestRequests = + requests.stream().filter(x->x.path.contains(msoURL)).collect(toList()); + + underTestRequests.forEach(request-> { + assertThat("X-ONAP-RequestID", request.headers.get("X-ONAP-RequestID"), contains(matchesPattern(UUID_REGEX))); + assertThat("X-ECOMP-RequestID", request.headers.get("X-ECOMP-RequestID"), contains(matchesPattern(UUID_REGEX))); + assertThat("X-ECOMP-RequestID", request.headers.get("X-InvocationID"), contains(matchesPattern(UUID_REGEX))); + assertThat("X-ONAP-PartnerName", request.headers.get("X-ONAP-PartnerName"), contains("VID.VID")); + }); + + List<String> allInvocationIds = new LinkedList<>(); + List<String> allRequestsIds = new LinkedList<>(); + + underTestRequests.forEach(request->{ + String invocationId = request.headers.get("X-InvocationID").get(0); + allInvocationIds.add(invocationId); + + String requestId = request.headers.get("X-ONAP-RequestID").get(0); + allRequestsIds.add(requestId); + + assertThat("request id and invocation id must be found in two rows", + logLines, + hasItems( + allOf( + containsString("RequestID="+requestId), + containsString("InvocationID="+ invocationId), + containsString("Invoke")), + allOf( + containsString("RequestID="+requestId), + containsString("InvocationID="+ invocationId), + containsString("InvokeReturn")) + )); + }); + + //make sure no InvocationId is repeated twice + assertThat("expect all InvocationIds to be unique", + allInvocationIds, containsInAnyOrder(new HashSet<>(allInvocationIds).toArray())); + + //make sure no RequestId is repeated twice + assertThat("expect all RequestIds to be unique", + allRequestsIds, containsInAnyOrder(new HashSet<>(allRequestsIds).toArray())); + + } + private void registerPresetsForRetryTest(String whatToFail, ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names, String vnfRequestId, boolean withTestApi ) { String networkRequestId = UUID.randomUUID().toString(); String vfModule0RequestId = UUID.randomUUID().toString(); 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 81d255391..2f8215a97 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 @@ -97,29 +97,41 @@ public class LoggerFormatTest extends BaseApiTest { 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))); + StringUtils.countMatches(logLines, '\n') + 1, + is(greaterThanOrEqualTo(minRows))); return logLines; } /** - * @return Chronological-ordered list of recent log-lines of a given requestId + * @return Chronological-ordered list of recent log-lines */ - public static List<String> getRequestLogLines(String requestId, LogName logname, RestTemplate restTemplate, URI uri) { - String logLines = LoggerFormatTest.getLogLines(logname, 30, 1, restTemplate, uri); + public static List<String> getLogLinesAsList(LogName logname, int maxRows, int minRows, RestTemplate restTemplate, URI uri) { + String logLines = LoggerFormatTest.getLogLines(logname, maxRows, minRows, 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; } + + /** + * @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) { + + List<String> lines = getLogLinesAsList(logname, 30, 1, restTemplate, uri); + + //Filter + lines.removeIf(line -> !StringUtils.containsIgnoreCase(line, requestId)); + + return lines; + } + + public static void assertHeadersAndMetricLogs(RestTemplate restTemplate, URI uri, String requestId, String path, int requestsSize) { List<String> logLines = getRequestLogLines(requestId, LogName.metrics2019, restTemplate, uri); @@ -146,24 +158,29 @@ public class LoggerFormatTest extends BaseApiTest { String invocationId = invocationIds.get(0); allInvocationIds.add(invocationId); - assertThat("request id and invocation id must be found in exactly two rows", - logLines, - containsInRelativeOrder( - allOf( - containsString("RequestID="+requestId), - containsString("InvocationID="+ invocationId), - containsString("Invoke")), - allOf( - containsString("RequestID="+requestId), - containsString("InvocationID="+ invocationId), - containsString("InvokeReturn")) - )); + assertIdsInMetricsLog(logLines, requestId, invocationId); }); + //make sure no InvocationId is repeated twice assertThat("expect all InvocationIds to be unique", allInvocationIds, containsInAnyOrder(new HashSet<>(allInvocationIds).toArray())); } + public static void assertIdsInMetricsLog(List<String> logLines, String requestId, String invocationId) { + assertThat("request id and invocation id must be found in exactly two rows", + logLines, + containsInRelativeOrder( + allOf( + containsString("RequestID="+requestId), + containsString("InvocationID="+ invocationId), + containsString("Invoke")), + allOf( + containsString("RequestID="+requestId), + containsString("InvocationID="+ invocationId), + containsString("InvokeReturn")) + )); + } + private JsonNode getCheckerResults(String logtype, String logLines) { Map<String, String> params = new HashMap<>(); params.put("format", "raw"); |