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