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