Catalog alignment
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / OnboardingFlowsThroughAPI.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.sanity;
22
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.openecomp.sdc.be.model.ArtifactDefinition;
26 import org.openecomp.sdc.be.model.ComponentInstance;
27 import org.openecomp.sdc.be.model.Resource;
28 import org.openecomp.sdc.be.model.Service;
29 import org.openecomp.sdc.be.model.User;
30 import org.openecomp.sdc.ci.tests.data.providers.OnboardingDataProviders;
31 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
32 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
33 import org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.VendorLicenseModel;
35 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
36 import org.openecomp.sdc.ci.tests.datatypes.enums.CvfcTypeEnum;
37 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
39 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
40 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
41 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
42 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
43 import org.openecomp.sdc.ci.tests.utilities.CatalogUIUtilitis;
44 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
45 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
46 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
47 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
48 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
49 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtillViaApis;
50 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtils;
51 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
52 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
53 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
54 import org.openecomp.sdc.ci.tests.verificator.CatalogVerificator;
55 import org.testng.Assert;
56 import org.testng.annotations.Test;
57
58 import java.io.File;
59 import java.util.HashMap;
60 import java.util.List;
61 import java.util.Map;
62 import java.util.Map.Entry;
63
64 import static org.testng.AssertJUnit.assertTrue;
65
66 public class OnboardingFlowsThroughAPI extends SetupCDTest {
67
68     protected boolean skipReport = false;
69     private User sdncDesignerDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
70
71
72 //      https://sdp.web.att.com/fa3qm1/web/console/Application_Development_Tools_QM_20.20.01#action=com.ibm.rqm.planning.home.actionDispatcher&subAction=viewTestPlan&id=6184
73
74     @Test
75     public void addVesFileToVsp() throws Exception {
76         String vnfFile = "vMME_Ericsson_small_v2.zip";
77         String vesArtifactFile = "VES.zip";
78         String filePath = FileHandling.getFilePath("VFCArtifacts");
79         String vesArtifactFileLocation = filePath + File.separator + vesArtifactFile;
80         List<String> vesArtifacts = FileHandling.getFileNamesFromZip(vesArtifactFileLocation);
81         List<String> tempVesArtifacts = FileHandling.getFileNamesFromZip(vesArtifactFileLocation);
82         Map<CvfcTypeEnum, String> cvfcArtifacts = new HashMap<>();
83         cvfcArtifacts.put(CvfcTypeEnum.VES_EVENTS, vesArtifactFileLocation);
84         getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
85
86         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
87         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
88         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
89             vendorLicenseModel, cvfcArtifacts);
90         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
91         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
92         List<ComponentInstance> componentInstances = resource.getComponentInstances();
93         for (ComponentInstance componentInstance : componentInstances) {
94             if (componentInstance.getDeploymentArtifacts() != null && !componentInstance.getDeploymentArtifacts().isEmpty()) {
95                 Map<String, ArtifactDefinition> deploymentArtifacts = componentInstance.getDeploymentArtifacts();
96                 for (Entry<String, ArtifactDefinition> entry : deploymentArtifacts.entrySet()) {
97                     if (entry.getValue().getArtifactType().equals(CvfcTypeEnum.VES_EVENTS.getValue())) {
98                         for (String vesArtifact : vesArtifacts) {
99                             if (entry.getValue().getArtifactName().equals(vesArtifact)) {
100                                 tempVesArtifacts.remove(vesArtifact);
101                             }
102                         }
103                     }
104                 }
105             }
106         }
107         assertTrue("Not all VES_EVENTS artifact files are on the resource instance", tempVesArtifacts.isEmpty());
108     }
109
110 //      741433: Update Old VSP
111 //      2.      Updated VSP "JSA AUG 2017" with the attached zip from v3 to v4. Follow normal steps to update the VF
112 //      3.     Update the VSP "vHSS-EPC-RDM3-Lab-0830" using the attached zip. Follow the normal steps to update the VF
113 //      @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "randomVNF_List")
114 //      public void create2(String filePath, String vnfFile) throws Exception{
115 //              setLog(vnfFile);
116 //      }
117
118
119     //  741509: E2E flow using old VLM
120     @Test
121     public void VlmReuse() throws Exception {
122         List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
123         List<String> newRandomFileNamesFromFolder = OnboardingDataProviders.getRandomElements(2, fileNamesFromFolder);
124         String filePath = FileHandling.getVnfRepositoryPath();
125         String vnfFile = newRandomFileNamesFromFolder.get(0);
126         getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
127 //              setLog(vnfFile);
128         getExtendTest().log(Status.INFO, "Create Vendor License");
129         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
130         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
131         getExtendTest().log(Status.INFO, "Create Vendor Software Product: " + resourceReqDetails.getName());
132         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
133             vendorLicenseModel, null);
134         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
135         getExtendTest().log(Status.INFO, "Create Resource: " + resourceReqDetails.getName());
136         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
137         getExtendTest().log(Status.INFO, "Certify the Resource: " + resourceReqDetails.getName());
138         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
139
140         ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails);
141         getExtendTest().log(Status.INFO, "Create Service: " + serviceReqDetails.getName());
142         org.openecomp.sdc.be.model.Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
143
144         getExtendTest().log(Status.INFO, "Add VF to service");
145         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
146         addComponentInstanceToComponentContainer.left().value();
147         getExtendTest().log(Status.INFO, "Certify the service");
148         service = (org.openecomp.sdc.be.model.Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
149         getExtendTest().log(Status.INFO, "Start distributing the service");
150         Boolean distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
151         getExtendTest().log(Status.INFO, "Service distributed");
152         assertTrue("Distribution of service " + service.getName() + " failed", distributeAndValidateService);
153
154 //              update
155         vnfFile = newRandomFileNamesFromFolder.get(1);
156         getExtendTest().log(Status.INFO, "Going to update VLM with new file " + vnfFile);
157         VendorLicenseModelRestUtils.updateVendorLicense(vendorLicenseModel, sdncDesignerDetails, false);
158         vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
159             vendorLicenseModel, null);
160         getExtendTest().log(Status.INFO, "Create new VSP: " + vendorSoftwareProductObject.getName());
161         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
162         getExtendTest().log(Status.INFO, "Create new resource: " + resourceReqDetails.getName());
163         resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
164         getExtendTest().log(Status.INFO, "Certify the resource");
165         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
166
167         serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails);
168         getExtendTest().log(Status.INFO, "Create new service: " + serviceReqDetails.getName());
169         service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
170
171         getExtendTest().log(Status.INFO, "Add VF to service");
172         addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
173         addComponentInstanceToComponentContainer.left().value();
174         getExtendTest().log(Status.INFO, "Certify the service");
175         service = (org.openecomp.sdc.be.model.Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
176         getExtendTest().log(Status.INFO, "Start distributing the service");
177         distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
178         getExtendTest().log(Status.INFO, "Service distributed");
179         assertTrue("Distribution of service " + service.getName() + " failed", distributeAndValidateService);
180     }
181
182
183     //  741607: E2E flow using old VSP
184     @Test
185     public void updateVfiVersionOnServiceLevel() throws Throwable {
186         List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
187         List<String> newRandomFileNamesFromFolder = OnboardingDataProviders.getRandomElements(2, fileNamesFromFolder);
188         String filePath = FileHandling.getVnfRepositoryPath();
189         String vnfFile = newRandomFileNamesFromFolder.get(0);
190         getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
191         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
192         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
193         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
194             vendorLicenseModel, null);
195         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
196         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
197         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
198
199         ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails);
200         org.openecomp.sdc.be.model.Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
201
202         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
203         ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();
204         service = (org.openecomp.sdc.be.model.Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
205         Boolean distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
206         assertTrue("Distribution of service " + service.getName() + " failed", distributeAndValidateService);
207
208 //              update resource to v2.0
209         String updateVnfFile = newRandomFileNamesFromFolder.get(1);
210         getExtendTest().log(Status.INFO, "Going to update VNF with file " + vnfFile);
211         VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vendorSoftwareProductObject, sdncDesignerDetails, filePath, updateVnfFile);
212         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
213         resourceReqDetails.setUniqueId(resource.getUniqueId());
214         resourceReqDetails.setVersion(resource.getVersion());
215         resource = AtomicOperationUtils.updateResource(resourceReqDetails, sdncDesignerDetails, true).left().value();
216         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
217
218         service = (org.openecomp.sdc.be.model.Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
219         AtomicOperationUtils.changeComponentInstanceVersion(service, componentInstance, resource, UserRoleEnum.DESIGNER, true);
220
221         service = (org.openecomp.sdc.be.model.Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
222         distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
223         assertTrue("Distribution of service " + service.getName() + " failed", distributeAndValidateService);
224     }
225
226
227 //      741608: E2E flow using old Service
228 //      @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "randomVNF_List")
229 //      public void create5(String filePath, String vnfFile) throws Exception{
230 //              setLog(vnfFile);
231 //              // 1. Create Service with old resource -> Certify this Service - > Distribute
232 //              // 2. Service is distributed
233 //              // 3. Update old Service: fetch few new resources and few old resources -> Certify this Service - > Distribute
234 //              // 4. Service is distributed
235 //      }
236
237     //  741633: Update HEAT parameter value
238     @Test()
239     public void updateHeatParametersValue() throws Throwable {
240         String msg = "VfArtifacts-->checkDefaultCreatedEnvArtifactsAfterVspUpdate tests with data provider index 4(last one) check it fully";
241         getExtendTest().log(Status.INFO, msg);
242     }
243
244     // temporaly disabled, until fixed
245     @Test()
246     public void updateVSPNameTest() throws Throwable {
247         // External Defect: 430425
248 //              Import VSP v1.0
249         List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
250         List<String> newRandomFileNamesFromFolder = OnboardingDataProviders.getRandomElements(1, fileNamesFromFolder);
251         String filePath = FileHandling.getVnfRepositoryPath();
252         String vnfFile = newRandomFileNamesFromFolder.get(0);
253         getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
254         User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
255         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(sdncDesignerDetails1);
256         getExtendTest().log(Status.INFO, "Create Vendor License Model " + vendorLicenseModel.getVendorLicenseName());
257         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
258         getExtendTest().log(Status.INFO, "Create Vendor Software Product " + resourceReqDetails.getName());
259         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
260             vendorLicenseModel, null);
261
262 //              Create VF, certify - v1.0 is created
263         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
264         getExtendTest().log(Status.INFO, "Create VF " + resourceReqDetails.getName());
265         Resource resource_v1 = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
266         getExtendTest().log(Status.INFO, "Certify VF " + resourceReqDetails.getName());
267         AtomicOperationUtils.changeComponentState(resource_v1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
268
269 //              Update VSP to v2.0 wih the zip from v1.0, update VSP name
270         getExtendTest().log(Status.INFO, "Update VSP to version 2.0");
271         String origVspName = vendorSoftwareProductObject.getName();
272         vendorSoftwareProductObject.setName("Upd" + ElementFactory.generateUUIDforSufix());
273         vendorSoftwareProductObject = VendorSoftwareProductRestUtils.updateVSPWithNewVLMParameters(vendorSoftwareProductObject,
274             vendorLicenseModel, sdncDesignerDetails1);
275         VendorSoftwareProductRestUtils.validateVspExist(vendorSoftwareProductObject, sdncDesignerDetails1);
276
277         //Validate that VF cannot be found by the updated VSP name
278         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
279         CatalogUIUtilitis.catalogSearchBox(vendorSoftwareProductObject.getName());
280         int numOfElementsInFilteredCatalog = CatalogVerificator.getNumberOfElementsFromCatalogHeader();
281         assertTrue(String.format("Wrong number fo elements, Expected : %s , Actual: %s", 0, numOfElementsInFilteredCatalog), numOfElementsInFilteredCatalog == 0);
282
283         //Update VF with the new VSP version
284         GeneralUIUtils.findComponentAndClick(origVspName);
285         GeneralPageElements.clickCheckoutButton();
286         GeneralPageElements.clickBrowseButton();
287         OnboardingUiUtils.updateVSP(vendorSoftwareProductObject);
288
289
290         //Validate that VF name in v1.1 is not changed to new VSP name (it is required to keep the name if at least one certification was done)
291         Assert.assertTrue(origVspName.equals(ResourceGeneralPage.getNameText()));
292
293         //Validate that VF name in v1.0 is the old VF name
294         GeneralPageElements.selectVersion("V1.0");
295         Assert.assertTrue(origVspName.equals(ResourceGeneralPage.getNameText()));
296     }
297
298     @Test()
299     public void UpdateVSPRevertToEarlierVersion() throws Throwable {
300         // Test Case: 745821
301 //              1. Import VSP v1.0
302         List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
303         List<String> newRandomFileNamesFromFolder = OnboardingDataProviders.getRandomElements(1, fileNamesFromFolder);
304         String filePath = FileHandling.getVnfRepositoryPath();
305         String vnfFile = newRandomFileNamesFromFolder.get(0);
306         getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
307         User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
308         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(sdncDesignerDetails1);
309         getExtendTest().log(Status.INFO, "Create Vendor License Model " + vendorLicenseModel.getVendorLicenseName());
310         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
311         getExtendTest().log(Status.INFO, "Create Vendor Software Product " + resourceReqDetails.getName());
312         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
313             vendorLicenseModel, null);
314 //              2. Create VF, certify - v1.0 is created
315         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
316         getExtendTest().log(Status.INFO, "Create VF " + resourceReqDetails.getName());
317         Resource resource_v1 = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
318         getExtendTest().log(Status.INFO, "Certify VF " + resourceReqDetails.getName());
319         resource_v1 = (Resource) AtomicOperationUtils.changeComponentState(resource_v1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
320 //              3. Update VSP to v2.0
321         getExtendTest().log(Status.INFO, "Update VSP to version 2.0");
322         VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vendorSoftwareProductObject, sdncDesignerDetails1, filePath, vnfFile);
323         VendorSoftwareProductRestUtils.validateVspExist(vendorSoftwareProductObject, sdncDesignerDetails1);
324 //              4. Update the VF with v2.0 of the VSP
325         getExtendTest().log(Status.INFO, "Checkout VF v1.1");
326         resource_v1 = (Resource) AtomicOperationUtils.changeComponentState(resource_v1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
327         resourceReqDetails.setUniqueId(resource_v1.getUniqueId());
328         resourceReqDetails.setVersion("1.1");
329         resourceReqDetails.setCsarVersion("2.0");
330         getExtendTest().log(Status.INFO, "Update VF to v2.0");
331         resource_v1 = AtomicOperationUtils.updateResource(resourceReqDetails, sdncDesignerDetails, true).left().value();
332         getExtendTest().log(Status.INFO, "Certify VF");
333         Resource resource_v2 = (Resource) AtomicOperationUtils.changeComponentState(resource_v1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
334 //              5. Update VSP to v3.0 wih the zip from v1.0
335         getExtendTest().log(Status.INFO, "Update VSP to version 3.0");
336         VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vendorSoftwareProductObject, sdncDesignerDetails1, false);
337         VendorSoftwareProductRestUtils.validateVspExist(vendorSoftwareProductObject, sdncDesignerDetails1);
338         getExtendTest().log(Status.INFO, "Checkout VF v2.1");
339         resource_v1 = (Resource) AtomicOperationUtils.changeComponentState(resource_v1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
340         resourceReqDetails.setUniqueId(resource_v1.getUniqueId());
341         resourceReqDetails.setVersion("2.1");
342         resourceReqDetails.setCsarVersion("3.0");
343         getExtendTest().log(Status.INFO, "Update VF to v3.0");
344         ResourceRestUtils.updateResource(resourceReqDetails, sdncDesignerDetails1, resource_v1.getUniqueId());
345 //              6. Update VF to v3.0
346         getExtendTest().log(Status.INFO, "Certify VF");
347         Resource resource_v3 = (Resource) AtomicOperationUtils.changeComponentState(resource_v1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
348 //              7. Compare versions v1.0 and v3.0 - should be the same
349 //      TODO: Shay add resource comparison.
350 //              8. Add each of the versions to service, certify - OK
351         ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails1);
352         getExtendTest().log(Status.INFO, "Create Service " + serviceReqDetails.getName());
353         org.openecomp.sdc.be.model.Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
354         getExtendTest().log(Status.INFO, "Add vf's v1 & v2 to service");
355         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource_v1, service, UserRoleEnum.DESIGNER, true);
356         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer1 = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource_v3, service, UserRoleEnum.DESIGNER, true);
357         getExtendTest().log(Status.INFO, "Certify Service");
358         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
359         System.out.println("");
360     }
361
362     @Test(dataProviderClass = org.openecomp.sdc.ci.tests.dataProvider.OnbordingDataProviders.class, dataProvider = "updateList")
363     public void updateVSPFlowFromOnboardToDistribution(String vnfFile1, String vnfFile2) throws Throwable {
364         setLog(String.format("Create VSP from %s , update VSP with %s ", vnfFile1, vnfFile2));
365 //              1. Import VSP v1.0
366         String filePath = org.openecomp.sdc.ci.tests.utilities.FileHandling.getUpdateVSPVnfRepositoryPath();
367         User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
368         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(sdncDesignerDetails1);
369         getExtendTest().log(Status.INFO, String.format("Creating Vendor Software License (VLM): %s v1.0", vendorLicenseModel
370             .getVendorLicenseName()));
371         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
372         getExtendTest().log(Status.INFO, String.format("Creating Vendor Software Product (VSP): %s v1.0 from heat file: %s ", resourceReqDetails.getName(), vnfFile1));
373         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile1, filePath, sdncDesignerDetails,
374             vendorLicenseModel, null);
375 //              2. Create VF, certify - v1.0 is created
376         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
377         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
378         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
379         getExtendTest().log(Status.INFO, String.format("Creating Virtual Function (VF): %s v1.0", resourceReqDetails.getName()));
380         getExtendTest().log(Status.INFO, String.format("Certify the VF"));
381 //              3. Create Service add to it the certified VF and certify the Service v1.0
382         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
383         Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
384         getExtendTest().log(Status.INFO, String.format("Creating Service: %s v1.0", serviceReqDetails.getName()));
385         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
386         ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();
387         getExtendTest().log(Status.INFO, String.format("Adding VF instance to Service"));
388         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
389         getExtendTest().log(Status.INFO, String.format("Certify the Service"));
390 //              4. Distribute the Service v1.0
391         Boolean distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
392         getExtendTest().log(Status.INFO, String.format("Distribute and validate the Service"));
393         assertTrue("Distribution status is " + distributeAndValidateService, distributeAndValidateService);
394 //              5. Update VSP to v2.0
395         getExtendTest().log(Status.INFO, "Upgrading the VSP with new file: " + vnfFile2);
396         VendorSoftwareProductRestUtils.updateVendorSoftwareProductToNextVersion(vendorSoftwareProductObject, sdncDesignerDetails1, filePath, vnfFile2);
397         getExtendTest().log(Status.INFO, String.format("Validating VSP %s upgrade to version 2.0: ", vnfFile2));
398         VendorSoftwareProductRestUtils.validateVspExist(vendorSoftwareProductObject, sdncDesignerDetails1);
399 //              6. Update the VF with v2.0 of the VSP and certify the VF
400         getExtendTest().log(Status.INFO, String.format("Checkout the VF %s v1.1 ", resourceReqDetails.getName()));
401         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
402         resourceReqDetails.setUniqueId(resource.getUniqueId());
403         resourceReqDetails.setVersion("1.1");
404         resourceReqDetails.setCsarVersion("2.0");
405         getExtendTest().log(Status.INFO, String.format("Upgrade the VF %s v1.1 with the new VSP %s v2.0 ", resourceReqDetails.getName(), vendorSoftwareProductObject.getName()));
406         resource = AtomicOperationUtils.updateResource(resourceReqDetails, sdncDesignerDetails, true).left().value();
407         getExtendTest().log(Status.INFO, String.format("Certify the VF to v2.0"));
408         Resource resource_v2 = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
409 //              7. Update the Service with the VFi version 2.0
410         getExtendTest().log(Status.INFO, String.format("Checkout the Service v1.1"));
411         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
412         getExtendTest().log(Status.INFO, String.format("Change the instance of the VF in the service to VFi v2.0"));
413         AtomicOperationUtils.changeComponentInstanceVersion(service, componentInstance, resource, UserRoleEnum.DESIGNER, true);
414         getExtendTest().log(Status.INFO, String.format("Certify the Service to v2.0"));
415         service = (org.openecomp.sdc.be.model.Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
416 //              8. Distribute the service v2.0
417         distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
418         getExtendTest().log(Status.INFO, String.format("Distribute and validate the Service"));
419         assertTrue("Distribution status is " + distributeAndValidateService, distributeAndValidateService);
420     }
421
422     @Test(dataProviderClass = org.openecomp.sdc.ci.tests.dataProvider.OnbordingDataProviders.class, dataProvider = "VNF_List")
423     public void fromOnboardToDistribution(String filePath, String vnfFile) throws Throwable {
424 //              String vnfFile1 = "1-2016-20-visbc3vf-(VOIP)_v2.1.zip";
425 //              String vnfFile2 = "2-2016-20-visbc3vf-(VOIP)_v2.0.zip";
426         setLog(String.format("%s", vnfFile));
427 //              1. Import VSP v1.0
428         //String filePath = FileHandling.getVnfRepositoryPath();
429         User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
430         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(sdncDesignerDetails1);
431         getExtendTest().log(Status.INFO, String.format("Creating Vendor Software License (VLM): %s v1.0", vendorLicenseModel
432             .getVendorLicenseName()));
433         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
434         getExtendTest().log(Status.INFO, String.format("Creating Vendor Software Product (VSP): %s v1.0 from heat file: %s ", resourceReqDetails.getName(), vnfFile));
435         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails1,
436             vendorLicenseModel);
437 //              VendorSoftwareProductObject vendorSoftwareProductObject = OnboardViaApis.fillVendorSoftwareProductObjectWithMetaData(vnfFile, createVendorSoftwareProduct);
438 //              2. Create VF, certify - v1.0 is created
439         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
440         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
441         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
442         getExtendTest().log(Status.INFO, String.format("Creating Virtual Function (VF): %s v1.0", resourceReqDetails.getName()));
443         getExtendTest().log(Status.INFO, String.format("Certify the VF"));
444 //              3. Create Service add to it the certified VF and certify the Service v1.0
445         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
446         Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
447         getExtendTest().log(Status.INFO, String.format("Creating Service: %s v1.0", serviceReqDetails.getName()));
448         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
449         ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();
450         getExtendTest().log(Status.INFO, String.format("Adding VF instance to Service"));
451         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
452         getExtendTest().log(Status.INFO, String.format("Certify the Service"));
453 //              4. Distribute the Service v1.0
454         Boolean distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
455         getExtendTest().log(Status.INFO, String.format("Distribute and validate the Service"));
456         assertTrue("Distribution status is " + distributeAndValidateService, distributeAndValidateService);
457     }
458
459     @Test()
460     public void onboardE2EviaAPI() throws Throwable {
461 //                      1. Import VSP v1.0
462         String filePath = FileHandling.getVnfRepositoryPath();
463         String vnfFile1 = "1-VF-vCSCF-StateDB-new-update_v3.0.zip";
464         User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
465         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(sdncDesignerDetails1);
466         getExtendTest().log(Status.INFO, String.format("Creating Vendor Software License (VLM): %s v1.0", vendorLicenseModel
467             .getVendorLicenseName()));
468         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
469         getExtendTest().log(Status.INFO, String.format("Creating Vendor Software Product (VSP): %s v1.0 from heat file: %s ", resourceReqDetails.getName(), vnfFile1));
470         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile1, filePath, sdncDesignerDetails1,
471             vendorLicenseModel);
472 //                      VendorSoftwareProductObject vendorSoftwareProductObject = OnboardViaApis.fillVendorSoftwareProductObjectWithMetaData(vnfFile1, createVendorSoftwareProduct);
473 //                      2. Create VF, certify - v1.0 is created
474         resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
475         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
476         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
477         getExtendTest().log(Status.INFO, String.format("Creating Virtual Function (VF): %s v1.0", resourceReqDetails.getName()));
478         getExtendTest().log(Status.INFO, String.format("Certify the VF"));
479 //                      3. Create Service add to it the certified VF and certify the Service v1.0
480         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
481         Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
482         getExtendTest().log(Status.INFO, String.format("Creating Service: %s v1.0", serviceReqDetails.getName()));
483         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
484         ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();
485         getExtendTest().log(Status.INFO, String.format("Adding VF instance to Service"));
486         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
487         getExtendTest().log(Status.INFO, String.format("Certify the Service"));
488 //                      4. Distribute the Service v1.0
489         Boolean distributeAndValidateService = AtomicOperationUtils.distributeAndValidateService(service);
490         getExtendTest().log(Status.INFO, String.format("Distribute and validate the Service"));
491         assertTrue("Distribution status is " + distributeAndValidateService, distributeAndValidateService);
492     }
493
494     @Override
495     protected UserRoleEnum getRole() {
496         return UserRoleEnum.DESIGNER;
497     }
498
499 }