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;
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;
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})
}
}
+
+ @Test
+ public void deployServiceAfterDragAndDropVFModule__verifyOrderMsoCalls() {
+ final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names = ImmutableMap
+ .of(SERVICE_NAME, "serviceInstanceName");
+ String vnfRequestId = UUID.randomUUID().toString();
+ registerPresetsForRetryTest("none", names, vnfRequestId, false);
+
+ final List<String> uuids = createBulkOfInstances(false, 1, names,
+ CREATE_BULK_OF_ALACARTE_NO_TESTAPI_REQUEST_CYPRESS);
+
+ final String jobId = uuids.get(0);
+
+ assertServiceInfoSpecific2(jobId, JobStatus.COMPLETED, names.get(SERVICE_NAME));
+ assertMSOcalledWithOrder();
+ }
+
+ @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> underTestRequests = retrieveRecordedRequests();
+
+ 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> allMsoRequestsIds = 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);
+ if (request.path.contains(msoURL)) {
+ allMsoRequestsIds.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",
+ allMsoRequestsIds, containsInAnyOrder(new HashSet<>(allMsoRequestsIds).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();
));
}
+
+ private void assertMSOcalledWithOrder() {
+
+ List<RecordedRequests> requests = retrieveRecordedRequests();
+
+ String path = "/mso/serviceInstantiation/v7/serviceInstances/.*/vnfs/.*/vfModules";
+ List<String> msoVFModulesRequests =
+ requests.stream().filter(x -> x.path.matches(path)).map(x -> x.body).collect(toList());
+
+ assertThat("request for vfNodule send with position order",
+ msoVFModulesRequests,
+ contains(
+ containsString("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0"),
+ containsString("2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2"),
+ containsString("2017488PasqualeVpe..PASQUALE_vRE_BV..module-1")
+ ));
+ }
+
private ImmutableList<JobAuditStatus> vidAuditStatusesCompleted(String jobId) {
return ImmutableList.of(
vidAuditStatus(jobId, "PENDING", false),