re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / PNF.java
1 package org.openecomp.sdc.ci.tests.execute.sanity;
2
3 import com.aventstack.extentreports.Status;
4 import org.openecomp.sdc.be.dao.api.ActionStatus;
5 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
6 import org.openecomp.sdc.be.model.LifecycleStateEnum;
7 import org.openecomp.sdc.ci.tests.datatypes.*;
8 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.LeftPanelCanvasItems;
9 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
10 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
11 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
12 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
13 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
14 import org.openecomp.sdc.ci.tests.pages.*;
15 import org.openecomp.sdc.ci.tests.utilities.*;
16 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
17 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
18 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
19 import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
20 import org.openqa.selenium.By;
21 import org.openqa.selenium.WebElement;
22 import org.testng.AssertJUnit;
23 import org.testng.annotations.BeforeClass;
24 import org.testng.annotations.BeforeMethod;
25 import org.testng.annotations.Test;
26
27 import java.util.List;
28
29 import static org.testng.Assert.assertTrue;
30
31 public class PNF extends SetupCDTest {
32         
33         private String filePath;
34         @BeforeClass
35         public void beforeClass(){
36                 filePath = FileHandling.getFilePath("");
37         }
38         
39         @BeforeMethod
40         public void beforeTest(){
41                 System.out.println("File repository is : " + filePath);
42                 getExtendTest().log(Status.INFO, "File repository is : " + filePath);
43         }
44                 
45         @Test
46         public void updatePNF() throws Exception {
47
48                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
49
50                 // update Resource
51                 ResourceReqDetails updatedResource = new ResourceReqDetails();
52                 updatedResource.setName(ElementFactory.getResourcePrefix() + "UpdatedName" + pnfMetaData.getName());
53                 updatedResource.setDescription("kuku");
54                 updatedResource.setVendorName("updatedVendor");
55                 updatedResource.setVendorRelease("updatedRelease");
56                 updatedResource.setContactId("ab0001");
57                 updatedResource.setCategories(pnfMetaData.getCategories());
58                 updatedResource.setVersion("0.1");
59                 updatedResource.setResourceType(ResourceTypeEnum.VF.getValue());
60                 List<String> newTags = pnfMetaData.getTags();
61                 newTags.remove(pnfMetaData.getName());
62                 newTags.add(updatedResource.getName());
63                 updatedResource.setTags(newTags);
64                 ResourceUIUtils.updateResource(updatedResource, getUser());
65
66                 VfVerificator.verifyVFMetadataInUI(updatedResource);
67                 VfVerificator.verifyVFUpdated(updatedResource, getUser());
68         }
69         
70         @Test
71         public void addUpdateDeleteInformationalArtifactPNFTest() throws Exception {
72                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
73
74                 ResourceGeneralPage.getLeftMenu().moveToInformationalArtifactScreen();
75                 
76                 ArtifactInfo informationalArtifact = new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "OTHER");
77                 InformationalArtifactPage.clickAddNewArtifact();
78                 ArtifactUIUtils.fillAndAddNewArtifactParameters(informationalArtifact);
79                 
80                 AssertJUnit.assertTrue("artifact table does not contain artifacts uploaded", InformationalArtifactPage.checkElementsCountInTable(1));
81                 
82                 String newDescription = "new description";
83                 InformationalArtifactPage.clickEditArtifact(informationalArtifact.getArtifactLabel());
84                 InformationalArtifactPage.artifactPopup().insertDescription(newDescription);
85                 InformationalArtifactPage.artifactPopup().clickDoneButton();
86                 String actualArtifactDescription = InformationalArtifactPage.getArtifactDescription(informationalArtifact.getArtifactLabel());
87                 AssertJUnit.assertTrue("artifact description is not updated", newDescription.equals(actualArtifactDescription));
88                 
89                 InformationalArtifactPage.clickDeleteArtifact(informationalArtifact.getArtifactLabel());
90                 InformationalArtifactPage.clickOK();
91                 AssertJUnit.assertTrue("artifact "+ informationalArtifact.getArtifactLabel() + "is not deleted", InformationalArtifactPage.checkElementsCountInTable(0));
92         }
93         
94         @Test
95         public void addPropertiesToVfcInstanceInPNFTest() throws Exception {
96                 
97                 if(true){
98 //                      throw new SkipException("Open bug 373762, can't update properties on CP or VFC instance  on Composition screen");
99                         SetupCDTest.getExtendTest().log(Status.INFO, "Open bug 373762, can't update properties on CP or VFC instance  on Composition screen");
100                 }
101                 
102                 String fileName = "CP02.yml";
103                 ResourceReqDetails atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.CP, NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
104                 
105                 try{
106                         ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
107                         ResourceGeneralPage.clickCheckinButton(atomicResourceMetaData.getName());
108         
109                         ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
110         
111                         ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
112                         CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
113                         CompositionPage.searchForElement(atomicResourceMetaData.getName());
114                         CanvasElement cpElement = vfCanvasManager.createElementOnCanvas(atomicResourceMetaData.getName());
115         
116                         vfCanvasManager.clickOnCanvaElement(cpElement);
117                         CompositionPage.showPropertiesAndAttributesTab();
118                         List<WebElement> properties = CompositionPage.getProperties();
119                         String propertyValue = "abc123";
120                         for (int i = 0; i < 2; i++) {
121                                 WebElement findElement = properties.get(i).findElement(By.className("i-sdc-designer-sidebar-section-content-item-property-and-attribute-label"));
122                                 findElement.click();
123                                 PropertiesPage.getPropertyPopup().insertPropertyDefaultValue(propertyValue);
124                                 PropertiesPage.getPropertyPopup().clickSave();                          
125                                 
126                                 findElement = properties.get(i).findElement(By.className("i-sdc-designer-sidebar-section-content-item-property-value"));
127                                 SetupCDTest.getExtendTest().log(Status.INFO, "Validating properties");
128                                 AssertJUnit.assertTrue(findElement.getText().equals(propertyValue));
129                         }
130                 }
131                 finally{
132                         ResourceRestUtils.deleteResourceByNameAndVersion(atomicResourceMetaData.getName(), "0.1");
133                 }
134         }
135         
136         @Test
137         public void changeInstanceVersionPNFTest() throws Exception{
138                 
139                 ResourceReqDetails atomicResourceMetaData = null;
140                 ResourceReqDetails pnfMetaData = null;
141                 CanvasManager vfCanvasManager;
142                 CanvasElement cpElement = null;
143                 String fileName = "CP03.yml";
144                 try{
145                         atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.CP, NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
146                         ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
147                         //TODO Andrey should click on certify button
148                         ResourceGeneralPage.clickCertifyButton(atomicResourceMetaData.getName());
149                         
150                         pnfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.PNF, getUser());
151                         ResourceUIUtils.createPNF(pnfMetaData, getUser());
152                         ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
153                         vfCanvasManager = CanvasManager.getCanvasManager();
154                         CompositionPage.searchForElement(atomicResourceMetaData.getName());
155                         cpElement = vfCanvasManager.createElementOnCanvas(atomicResourceMetaData.getName());
156
157                         //TODO Andrey should click on certify button
158                         CompositionPage.clickCertifyButton(pnfMetaData.getName());
159                         assert(false);
160                 }
161                 catch(Exception e){ 
162                         String errorMessage = GeneralUIUtils.getWebElementByClassName("w-sdc-modal-caption").getText();
163                         String checkUIResponseOnError = ErrorValidationUtils.checkUIResponseOnError(ActionStatus.VALIDATED_RESOURCE_NOT_FOUND.name());
164                         AssertJUnit.assertTrue(errorMessage.contains(checkUIResponseOnError));
165
166                         /*reloginWithNewRole(UserRoleEnum.TESTER);
167                         GeneralUIUtils.findComponentAndClick(atomicResourceMetaData.getName());
168                         TesterOperationPage.certifyComponent(atomicResourceMetaData.getName());
169                         
170                         reloginWithNewRole(UserRoleEnum.DESIGNER);*/
171                         GeneralUIUtils.findComponentAndClick(pnfMetaData.getName());
172                         ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
173                         vfCanvasManager = CanvasManager.getCanvasManager();
174                         CompositionPage.changeComponentVersion(vfCanvasManager, cpElement, "1.0");
175                         
176                         //verfication
177                         VfVerificator.verifyInstanceVersion(pnfMetaData, getUser(), atomicResourceMetaData.getName(), "1.0");
178                 }
179                         
180                 finally{
181                         ResourceRestUtils.deleteResourceByNameAndVersion(atomicResourceMetaData.getName(), "1.0");
182                 }
183                 
184         }
185         
186         @Test
187         public void verifyToscaArtifactsExistPNFTest() throws Exception{
188                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
189                 
190                 final int numOfToscaArtifacts = 2;
191                 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
192                 AssertJUnit.assertTrue(ToscaArtifactsPage.checkElementsCountInTable(numOfToscaArtifacts));
193                 
194                 for(int i = 0; i < numOfToscaArtifacts; i++){
195                         String typeFromScreen = ToscaArtifactsPage.getArtifactType(i);
196                         AssertJUnit.assertTrue(typeFromScreen.equals(ArtifactTypeEnum.TOSCA_CSAR.getType()) || typeFromScreen.equals(ArtifactTypeEnum.TOSCA_TEMPLATE.getType()));
197                 }
198                 //TODO Andrey should click on certify button
199                 ToscaArtifactsPage.clickCertifyButton(pnfMetaData.getName());
200                 pnfMetaData.setVersion("1.0");
201                 VfVerificator.verifyToscaArtifactsInfo(pnfMetaData, getUser());
202         }       
203         
204         @Test
205         public void pnfCertificationTest() throws Exception{
206                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
207                 
208                 String vfName = pnfMetaData.getName();
209                 
210                 ResourceGeneralPage.clickCheckinButton(vfName);
211                 GeneralUIUtils.findComponentAndClick(vfName);
212                 //TODO Andrey should click on certify button
213                 ResourceGeneralPage.clickCertifyButton(vfName);
214                 
215                 /*reloginWithNewRole(UserRoleEnum.TESTER);
216                 GeneralUIUtils.findComponentAndClick(vfName);
217                 TesterOperationPage.certifyComponent(vfName);*/
218                 
219                 pnfMetaData.setVersion("1.0");
220                 VfVerificator.verifyVFLifecycle(pnfMetaData, getUser(), LifecycleStateEnum.CERTIFIED);
221                 
222                 /*reloginWithNewRole(UserRoleEnum.DESIGNER);*/
223                 GeneralUIUtils.findComponentAndClick(vfName);
224                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CERTIFIED);
225         }
226         
227         @Test
228         public void deletePNFTest() throws Exception{
229                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
230                 
231                 GeneralPageElements.clickTrashButtonAndConfirm();
232                 
233                 pnfMetaData.setVersion("0.1");
234                 VfVerificator.verifyVfDeleted(pnfMetaData, getUser());
235         }
236         
237         @Test
238         public void revertPNFMetadataTest() throws Exception{
239                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
240                 
241                 ResourceReqDetails pvfRevertDetails = new ResourceReqDetails();
242                 pvfRevertDetails.setName("ciUpdatedName");
243                 pvfRevertDetails.setDescription("kuku");
244                 pvfRevertDetails.setCategories(pnfMetaData.getCategories());
245                 pvfRevertDetails.setVendorName("updatedVendor");
246                 pvfRevertDetails.setVendorRelease("updatedRelease");
247                 ResourceUIUtils.fillResourceGeneralInformationPage(pvfRevertDetails, getUser(), false);
248                 
249                 GeneralPageElements.clickRevertButton();
250                 
251                 VfVerificator.verifyVFMetadataInUI(pnfMetaData);                
252         }
253
254         @Test
255         public void checkoutPnfTest() throws Exception{
256                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
257                 
258                 ResourceGeneralPage.clickCheckinButton(pnfMetaData.getName());
259                 GeneralUIUtils.findComponentAndClick(pnfMetaData.getName());
260                 GeneralPageElements.clickCheckoutButton();
261                 
262                 pnfMetaData.setVersion("0.2");
263                 VfVerificator.verifyVFLifecycle(pnfMetaData, getUser(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
264                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CHECKOUT);
265                 //TODO Andrey should click on certify button
266                 ResourceGeneralPage.clickCertifyButton(pnfMetaData.getName());
267                 
268                 /*reloginWithNewRole(UserRoleEnum.TESTER);
269                 GeneralUIUtils.findComponentAndClick(pnfMetaData.getName());
270                 TesterOperationPage.certifyComponent(pnfMetaData.getName());
271                 
272                 reloginWithNewRole(UserRoleEnum.DESIGNER);*/
273                 GeneralUIUtils.findComponentAndClick(pnfMetaData.getName());
274                 ResourceGeneralPage.clickCheckoutButton();
275                 
276                 pnfMetaData.setVersion("1.1");
277                 pnfMetaData.setUniqueId(null);
278                 VfVerificator.verifyVFLifecycle(pnfMetaData, getUser(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
279                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CHECKOUT);
280         }
281         
282         public ResourceReqDetails createPNFWithGenerateName() throws Exception {
283                 ResourceReqDetails pnfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.PNF, getUser());
284                 ResourceUIUtils.createPNF(pnfMetaData, getUser());
285                 return pnfMetaData;
286         }
287
288         @Test
289         public void verifyPNF_UI_Limitations() throws Exception {
290                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
291
292                 SetupCDTest.getExtendTest().log(Status.INFO, "Validating Deployment Artifact Left Side Menu not exist");
293                 assertTrue(GeneralUIUtils.isElementInvisibleByTestId("Deployment ArtifactLeftSideMenu"));
294                 SetupCDTest.getExtendTest().log(Status.INFO, "Validating Deployment Left Side Menu not exist");
295                 assertTrue(GeneralUIUtils.isElementInvisibleByTestId("DeploymentLeftSideMenu"));
296         }
297
298         @Test
299         public void filteringCatalogByPNF() throws Exception {
300                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
301
302                 String pnfName = pnfMetaData.getName();
303                 //TODO Andrey should click on certify button
304                 ResourceGeneralPage.clickCertifyButton(pnfName);
305                 /*reloginWithNewRole(UserRoleEnum.TESTER);
306                 GeneralUIUtils.findComponentAndClick(pnfName);
307                 TesterOperationPage.certifyComponent(pnfName);*/
308
309                 pnfMetaData.setVersion("1.0");
310                 VfVerificator.verifyVFLifecycle(pnfMetaData, getUser(), LifecycleStateEnum.CERTIFIED);
311
312                 /*reloginWithNewRole(UserRoleEnum.DESIGNER);*/
313                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
314                 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf("PNF"));
315                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating resource %s found", pnfName));
316                 GeneralUIUtils.clickOnElementByTestId(pnfName);
317         }
318
319         @Test
320         public void addPNFtoServiceAndDistribute() throws Exception {
321                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
322
323                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
324                 CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
325                 CompositionPage.searchForElement("ContrailPort");
326                 vfCanvasManager.createElementOnCanvas("ContrailPort");
327
328                 String pnfName = pnfMetaData.getName();
329                 //TODO Andrey should click on certify button
330                 ResourceGeneralPage.clickCertifyButton(pnfName);
331
332                 /*reloginWithNewRole(UserRoleEnum.TESTER);
333                 GeneralUIUtils.findComponentAndClick(pnfName);
334                 TesterOperationPage.certifyComponent(pnfName);*/
335
336                 pnfMetaData.setVersion("1.0");
337                 VfVerificator.verifyVFLifecycle(pnfMetaData, getUser(), LifecycleStateEnum.CERTIFIED);
338
339                 /*reloginWithNewRole(UserRoleEnum.DESIGNER);*/
340                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
341                 ServiceUIUtils.createService(serviceMetadata, getUser());
342                 DeploymentArtifactPage.getLeftMenu().moveToCompositionScreen();
343                 CanvasManager canvasManager = CanvasManager.getCanvasManager();
344                 CompositionPage.searchForElement(pnfName);
345                 CanvasElement pnfElement = canvasManager.createElementOnCanvas(pnfName);
346                 CanvasElement networkElement = canvasManager.createElementOnCanvas(LeftPanelCanvasItems.CONTRAIL_VIRTUAL_NETWORK);
347
348                 canvasManager.linkElements(pnfElement, networkElement);
349                 String serviceName = serviceMetadata.getName();
350                 ServiceGeneralPage.clickSubmitForTestingButton(serviceName);
351                 reloginWithNewRole(UserRoleEnum.TESTER);
352                 GeneralUIUtils.findComponentAndClick(serviceName);
353                 TesterOperationPage.certifyComponent(serviceName);
354
355                 reloginWithNewRole(UserRoleEnum.GOVERNOR);
356                 GeneralUIUtils.findComponentAndClick(serviceName);
357                 GovernorOperationPage.approveSerivce(serviceName);
358
359                 reloginWithNewRole(UserRoleEnum.OPS);
360                 GeneralUIUtils.findComponentAndClick(serviceName);
361                 OpsOperationPage.distributeService();
362         }
363
364         @Test
365         public void checkInfomationArtifactUploadLimitation() throws Exception {
366                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
367                 ResourceGeneralPage.getLeftMenu().moveToInformationalArtifactScreen();
368                 List<WebElement> webElements = GeneralUIUtils.getWebElementsListBy(By.xpath(DataTestIdEnum.ArtifactPageEnum.ADD_OTHER_ARTIFACT_BUTTON.getValue()));
369                 int numberOfElements = webElements.size();
370                 String buttonText = webElements.get(0).getText();
371                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying only one button exist: Add Other Artifact");
372                 assertTrue(buttonText.equalsIgnoreCase(("Add Other Artifact")));
373                 assertTrue(1==numberOfElements, "There should be only one option for uploading artifact in PNF");
374         }
375
376         @Test
377         public void checkNonCPVLObjectsNotExistInComosition() throws Exception {
378                 ResourceReqDetails pnfMetaData = createPNFWithGenerateName();
379                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
380                 String pnfName = pnfMetaData.getName();
381                 // Searching for VFC element and make sure it not exist in PNF composition (Only VL/CP are allowed).
382                 CompositionPage.searchForElement("BlockStorage");
383                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying Element found");
384                 assertTrue(GeneralUIUtils.isElementInvisibleByTestId("BlockStorage"));
385         }
386
387         @Override
388         protected UserRoleEnum getRole() {
389                 return UserRoleEnum.DESIGNER;
390         }
391
392 }