diff options
Diffstat (limited to 'vid-automation/src')
6 files changed, 114 insertions, 30 deletions
diff --git a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseAAIPreset.java b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseAAIPreset.java index c3c89c5d6..3870c8369 100644 --- a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseAAIPreset.java +++ b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseAAIPreset.java @@ -13,8 +13,8 @@ public abstract class BaseAAIPreset extends BasePreset { public Map<String, String> getRequestHeaders() { Map<String, String> map = super.getRequestHeaders(); map.put("X-ONAP-PartnerName", "VID.VID"); - map.put("X-InvocationID", "[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}"); - map.put("X-ONAP-RequestID", "[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}"); + map.put("X-InvocationID", UUID_REGEX); + map.put("X-ONAP-RequestID", UUID_REGEX); return map; } } diff --git a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseMSOPreset.java b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseMSOPreset.java index f17efffb3..7c4ce0376 100644 --- a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseMSOPreset.java +++ b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseMSOPreset.java @@ -48,9 +48,9 @@ public abstract class BaseMSOPreset extends BasePreset { public Map<String, String> getRequestHeaders() { Map<String, String> map = super.getRequestHeaders(); map.put("X-ONAP-PartnerName", "VID.VID"); - map.put("X-ECOMP-RequestID", "[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}"); - map.put("X-InvocationID", "[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}"); - map.put("X-ONAP-RequestID", "[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}"); + map.put("X-ECOMP-RequestID", UUID_REGEX); + map.put("X-InvocationID", UUID_REGEX); + map.put("X-ONAP-RequestID", UUID_REGEX); return map; } } diff --git a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BasePreset.java b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BasePreset.java index aded77ccf..d90af3fe2 100644 --- a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BasePreset.java +++ b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BasePreset.java @@ -1,17 +1,18 @@ package org.onap.simulator.presetGenerator.presets.BasePresets; -import org.onap.simulator.presetGenerator.presets.model.RegistrationRequest; -import org.springframework.http.HttpMethod; - import java.util.HashMap; import java.util.List; import java.util.Map; +import org.onap.simulator.presetGenerator.presets.model.RegistrationRequest; +import org.springframework.http.HttpMethod; /** * Created by itzikliderman on 13/12/2017. */ public abstract class BasePreset { + public static 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}"; + public RegistrationRequest generateScenario() { Map<String, String> responseHeaders = new HashMap<>(); responseHeaders.put("Content-Type", getContentType()); diff --git a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java index 4a1da9e27..1179bf46c 100644 --- a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java +++ b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/BasePresets/BaseSDCPreset.java @@ -15,8 +15,8 @@ public abstract class BaseSDCPreset extends BasePreset { public Map<String, String> getRequestHeaders() { Map<String, String> map = super.getRequestHeaders(); map.put("X-ONAP-PartnerName", "VID.VID"); - map.put("X-InvocationID", "[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}"); - map.put("X-ONAP-RequestID", "[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}"); + map.put("X-InvocationID", UUID_REGEX); + map.put("X-ONAP-RequestID", UUID_REGEX); return map; } 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"); |