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