1 package org.onap.vid.api;
3 import com.fasterxml.jackson.core.type.TypeReference;
4 import com.google.common.collect.ImmutableList;
5 import com.google.common.collect.ImmutableMap;
6 import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset;
7 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
8 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
9 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
10 import org.onap.simulator.presetGenerator.presets.mso.*;
11 import org.onap.vid.model.asyncInstantiation.JobAuditStatus;
12 import org.onap.vid.model.asyncInstantiation.JobAuditStatus.SourceStatus;
13 import org.onap.vid.model.asyncInstantiation.ServiceInfo;
14 import org.testng.annotations.AfterMethod;
15 import org.testng.annotations.DataProvider;
16 import org.testng.annotations.Test;
17 import vid.automation.test.infra.FeatureTogglingTest;
18 import vid.automation.test.infra.Features;
19 import vid.automation.test.model.JobStatus;
20 import vid.automation.test.model.ServiceAction;
21 import vid.automation.test.services.AsyncJobsService;
22 import vid.automation.test.services.SimulatorApi;
23 import vid.automation.test.services.SimulatorApi.RegistrationStrategy;
25 import java.io.IOException;
26 import java.util.List;
28 import java.util.UUID;
30 import static org.hamcrest.CoreMatchers.is;
31 import static org.hamcrest.MatcherAssert.assertThat;
32 import static org.hamcrest.Matchers.allOf;
33 import static org.hamcrest.Matchers.equalTo;
34 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
35 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateInstancePost.DEFAULT_REQUEST_ID;
36 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys.SERVICE_NAME;
37 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset;
38 import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
40 @FeatureTogglingTest({Features.FLAG_ASYNC_ALACARTE_VNF})
41 public class AsyncInstantiationALaCarteApiTest2 extends AsyncInstantiationBase {
43 private static final String CREATE_BULK_OF_ALACARTE_MULTIPLE_VNF_NETWORK_REQUEST_CYPRESS = "a-la-carte/redux-multiple-vnf-network.json";
44 private static final String DELETE_BULK_OF_ALACARTE_REQUEST = "VnfGroup/ServiceWithVnfGroupsDeleteRequest.json";
45 private static final String SERVICE_INSTANCE_ID = BaseMSOPreset.DEFAULT_INSTANCE_ID;
49 public static Object[][] scenarios() {
50 return new Object[][]{
53 // {Scenario.NAME_TAKEN}, Not relevant because the name uniqueness is supported only for bulk in Macro
54 // {Scenario.DUPLICATE_NAME}, Not relevant because name duplication is not handled in A La Carte
55 {Scenario.IN_PROGRESS},
61 protected void dropAllFromNameCounter() {
62 AsyncJobsService asyncJobsService = new AsyncJobsService();
63 asyncJobsService.dropAllFromNameCounter();
67 public void deleteService_withBadResponseFromMso_verifyStatus() {
68 List<PresetMSOBaseDelete> deletePresets = ImmutableList.of(new PresetMSODeleteALaCarteService( DEFAULT_REQUEST_ID, SERVICE_INSTANCE_ID, 500));
69 List<PresetMSOOrchestrationRequestGet> inProgressPresets = ImmutableList.of(new PresetMSOOrchestrationRequestGet());
70 List<BasePreset> presets = getDeletePresets(deletePresets, inProgressPresets);
72 registerExpectationFromPresets(presets, RegistrationStrategy.CLEAR_THEN_SET);
73 final List<String> uuids = createBulkOfInstances(false, 1, ImmutableMap.of(), DELETE_BULK_OF_ALACARTE_REQUEST);
75 assertThat(uuids, hasSize(1));
76 final String jobId = uuids.get(0);
78 assertServiceInfoSpecificDeletion(jobId, JobStatus.FAILED, "wowServiceWithVnfGroping", "TYLER SILVIA");
79 assertThat(SimulatorApi.retrieveRecordedRequestsPathCounter(), allOf(
80 TestUtils.hasOrLacksOfEntry(deletePresets.get(0).getReqPath(), 1L),
81 TestUtils.hasOrLacksOfEntry(inProgressPresets.get(0).getReqPath(), 0L)
87 public void instantiationFailedForService(){
88 CreateInstanceWithFailedService createInstanceWithFailedService = new CreateInstanceWithFailedService(this);
89 createInstanceWithFailedService.deployServiceFailedInstance();
93 void getBulkForRetry_notFoundException(){
94 CreateServiceWithFailedVnf createServiceWithFailedVnf = new CreateServiceWithFailedVnf(this);
95 createServiceWithFailedVnf.getBulkForRetryNotFound();
100 public void deploy1Service1FailedVnf_EditJobSendingSameDataAndRetry_verifyNewJobWithSameData() {
101 CreateServiceWithFailedVnf createServiceWithFailedVnf = new CreateServiceWithFailedVnf(this);
102 String bulkRetryPayload = createServiceWithFailedVnf.deployService1FailedVnf();
103 createServiceWithFailedVnf.assertResourceAuditStatus(bulkRetryPayload);
104 createServiceWithFailedVnf.secondRegistration();
105 createServiceWithFailedVnf.retryJobWithOtherDataAndAssert(bulkRetryPayload);
109 public void deploy1Service1FailedVnf_EditSomeDetailsAndRetry_verifyNewJobWithEditedData() {
110 CreateServiceWithFailedVnf createServiceWithFailedVnf = new CreateServiceWithFailedVnf(this);
111 String originalBulkForRetry = createServiceWithFailedVnf.deployService1FailedVnf();
112 createServiceWithFailedVnf.assertResourceAuditStatus(originalBulkForRetry);
113 String changedData = createServiceWithFailedVnf.changeSomeDataAndRegisterToSimulator(originalBulkForRetry);
114 createServiceWithFailedVnf.retryJobWithOtherDataAndAssert(changedData);
117 private List<JobAuditStatus> getExpectedAuditFromFile(String fileName) throws IOException {
118 String content = TestUtils.convertRequest(objectMapper, fileName);
119 List<JobAuditStatus> auditStatusList = ImmutableList.copyOf(objectMapper.readValue(content, JobAuditStatus[].class));
120 return auditStatusList;
126 public void getAuditInfoForALaCarteByServiceInstanceId() throws IOException {
127 final String expectedMsoAuditInfo = "a-la-carte/auditInfoMSOALaCarte.json";
128 registerExpectationFromPreset(
129 new PresetMSOOrchestrationRequestsGetByServiceInstanceId(),
130 RegistrationStrategy.CLEAR_THEN_SET);
131 List<JobAuditStatus> actualMsoAudits = getJobMsoAuditStatusForAlaCarte(UUID.randomUUID().toString(), "aa1234d1-5a33-55df-13ab-12abad84e333", "bc305d54-75b4-431b-adb2-eb6b9e546014");
132 List<JobAuditStatus> expectedMsoAudits = getExpectedAuditFromFile(expectedMsoAuditInfo);
133 assertThat(actualMsoAudits, is(expectedMsoAudits));
138 public void getAuditInfoForALaCarteByRequestId() {
139 registerExpectationFromPreset(
140 new PresetMSOOrchestrationRequestsGetByRequestId(),
141 RegistrationStrategy.CLEAR_THEN_SET);
142 final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names = ImmutableMap.of(SERVICE_NAME, "serviceInstanceName");
143 String uuid = createBulkOfInstances(false, 1, names, CREATE_BULK_OF_ALACARTE_MULTIPLE_VNF_NETWORK_REQUEST_CYPRESS).get(0);
144 List<JobAuditStatus> actualMsoAudits = getJobMsoAuditStatusForAlaCarte( uuid, "405652f4-ceb3-4a75-9474-8aea71480a77", null);
145 List<JobAuditStatus> expectedMsoAudits = ImmutableList.of(
146 new JobAuditStatus("serviceInstanceName", "FAILED", UUID.fromString("405652f4-ceb3-4a75-9474-8aea71480a77"),"Service Instance was failed.",false, "service"));
147 assertThat(actualMsoAudits, is(expectedMsoAudits));
152 public void getAuditInfoForALaCarteByJobId() throws IOException {
153 SimulatorApi.registerExpectationFromPresets(ImmutableList.of(
154 new PresetMSOCreateServiceInstanceGen2ErrorResponse(),
155 new PresetGetSessionSlotCheckIntervalGet(),
156 new PresetAAIGetSubscribersGet()
158 RegistrationStrategy.CLEAR_THEN_SET);
159 final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names = ImmutableMap.of(SERVICE_NAME, "serviceInstanceName");
160 String uuid = createBulkOfInstances(false, 1, names, CREATE_BULK_OF_ALACARTE_MULTIPLE_VNF_NETWORK_REQUEST_CYPRESS).get(0);
162 assertAndRetryIfNeeded(() -> {
163 final List<JobAuditStatus> actualMsoAudits = getJobMsoAuditStatusForAlaCarte( uuid, null, null);
164 List<JobAuditStatus> expectedMsoAudits = ImmutableList.of(
165 new JobAuditStatus(UUID.fromString(uuid), "FAILED", SourceStatus.MSO, null,
166 "Http Code:500, \"messageId\":\"SVC0002\",\"text\":\"JSON Object Mapping Request\"", false, "serviceInstanceName"));
167 assertThat(actualMsoAudits, is(expectedMsoAudits));
170 //assert error audit status
171 Map<String, Object> bulkForRetry = objectMapper.readValue(getRetryBulk(uuid).getBody(), new TypeReference<Map<String, Object>>(){});
172 String serviceTrackById = bulkForRetry.get("trackById").toString();
173 Map<String, Object> resourceAuditInfo = (Map) getResourceAuditInfo(serviceTrackById);
174 assertThat(resourceAuditInfo.get("jobStatus"), equalTo("FAILED"));
175 assertThat(resourceAuditInfo.get("additionalInfo"), equalTo("Http Code:500, \"messageId\":\"SVC0002\",\"text\":\"JSON Object Mapping Request\""));
178 @Test(expectedExceptions = RuntimeException.class)
179 public void getAuditInfoForALaCarte_badResponseFromMso_throwsException() {
180 registerExpectationFromPreset(
181 new PresetMSOOrchestrationRequestGetErrorResponse(500),
182 RegistrationStrategy.CLEAR_THEN_SET);
183 getJobMsoAuditStatusForAlaCarte( UUID.randomUUID().toString(), "405652f4-ceb3-4a75-9474-8aea71480a77", null);
186 private void assertServiceInfoSpecificDeletion(String jobId, JobStatus jobStatus, String serviceInstanceName, String serviceType) {
187 assertExpectedStatusAndServiceInfo(jobStatus, jobId, PATIENCE_LEVEL.FAIL_SLOW, new ServiceInfo(
188 "us16807000", jobStatus, false,
194 null, serviceInstanceName,
195 "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc", "Grouping Service for Test", "1.0",
196 jobId, null, ServiceAction.DELETE, false)
202 PARALLEL, COMPLETED, NAME_TAKEN, DUPLICATE_NAME, IN_PROGRESS, MSO_FAIL