re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / VfAPI.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.datatypes.enums.ResourceTypeEnum;
25 import org.openecomp.sdc.be.model.Resource;
26 import org.openecomp.sdc.ci.tests.datatypes.*;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.InformationalArtifactsPlaceholders;
28 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.LeftPanelCanvasItems;
29 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.ResourceMetadataEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.ToscaArtifactsScreenEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.enums.*;
32 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
33 import org.openecomp.sdc.ci.tests.execute.setup.AttFtpClient;
34 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
35 import org.openecomp.sdc.ci.tests.pages.*;
36 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
37 import org.openecomp.sdc.ci.tests.utilities.*;
38 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
39 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
40 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
41 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
42 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
43 import org.openecomp.sdc.ci.tests.verificator.ServiceVerificator;
44 import org.openecomp.sdc.ci.tests.verificator.VfModuleVerificator;
45 import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
46 import org.openqa.selenium.By;
47 import org.openqa.selenium.WebElement;
48 import org.testng.AssertJUnit;
49 import org.testng.annotations.BeforeClass;
50 import org.testng.annotations.BeforeMethod;
51 import org.testng.annotations.Test;
52
53 import java.io.File;
54 import java.util.*;
55 import static org.assertj.core.api.Assertions.assertThat;
56
57
58 public class VfAPI extends SetupCDTest {
59
60         private String filePath;
61
62         @BeforeClass
63         public void beforeClass(){
64                 filePath = FileHandling.getFilePath("");
65         }
66         
67         @BeforeMethod
68         public void beforeTest(){
69                 System.out.println("File repository is : " + filePath);
70                 getExtendTest().log(Status.INFO, "File repository is : " + filePath);
71         }
72         
73         private ResourceReqDetails createVFviaAPI() {
74                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
75                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating VF %s", vfMetaData.getName()));
76                 AtomicOperationUtils.createResourceByResourceDetails(vfMetaData, UserRoleEnum.DESIGNER, true).left().value();
77                 return vfMetaData;
78         }
79         
80
81         @Test
82         public void updateVF() throws Exception {
83
84                 // create Resource
85                 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
86                 ResourceUIUtils.createVF(resourceMetaData, getUser());
87
88                 // update Resource
89                 ResourceReqDetails updatedResource = new ResourceReqDetails();
90                 updatedResource.setName(ElementFactory.getResourcePrefix() + "UpdatedName" + resourceMetaData.getName());
91                 updatedResource.setDescription("kuku");
92                 updatedResource.setVendorName("updatedVendor");
93                 updatedResource.setVendorRelease("updatedRelease");
94                 updatedResource.setContactId("ab0001");
95                 updatedResource.setCategories(resourceMetaData.getCategories());
96                 updatedResource.setVersion("0.1");
97                 updatedResource.setResourceType(ResourceTypeEnum.VF.getValue());
98                 List<String> newTags = resourceMetaData.getTags();
99                 newTags.remove(resourceMetaData.getName());
100                 newTags.add(updatedResource.getName());
101                 updatedResource.setTags(newTags);
102                 ResourceUIUtils.updateResource(updatedResource, getUser());
103
104                 VfVerificator.verifyVFMetadataInUI(updatedResource);
105                 VfVerificator.verifyVFUpdated(updatedResource, getUser());
106         }
107
108
109         
110         @Test
111         public void vfcLinkedToComputeInVfFlowApi() throws Exception {
112                 String fileName = "vFW_VFC2.yml";
113                 ResourceReqDetails atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
114                 
115                 try{
116                         //Create VFC via API
117                         Resource vfc = AtomicOperationUtils.importResource(filePath, fileName).left().value();
118                         atomicResourceMetaData.setName(vfc.getName());
119
120                         //Certify VFC via API
121                         vfc = (Resource) AtomicOperationUtils.changeComponentState(vfc, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
122
123                         //Create VF via API
124                         ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
125                         AtomicOperationUtils.createResourceByResourceDetails(vfMetaData, UserRoleEnum.DESIGNER, true).left().value();
126
127                         //Go to Catalog and find the created VF
128                         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
129                         GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
130                         
131                 //Composition - drag the created VFC and another element, link between them
132                         DeploymentArtifactPage.getLeftMenu().moveToCompositionScreen();
133                         CanvasManager canvasManager = CanvasManager.getCanvasManager();
134                         CompositionPage.searchForElement(String.format("%s %s", LeftPanelCanvasItems.COMPUTE.getValue() , "1.0"));
135                         CanvasElement computeElement = canvasManager.createElementOnCanvas(LeftPanelCanvasItems.COMPUTE);
136                         CompositionPage.searchForElement(atomicResourceMetaData.getName());
137                         CanvasElement cpElement = canvasManager.createElementOnCanvas(atomicResourceMetaData.getName());
138                         AssertJUnit.assertNotNull(cpElement);
139                         ServiceVerificator.verifyNumOfComponentInstances(vfMetaData, "0.1", 2, getUser());
140                         canvasManager.linkElements(cpElement, computeElement);
141         
142                         vfMetaData.setVersion("0.1");
143                         VfVerificator.verifyLinkCreated(vfMetaData, getUser(), 1);
144                 }
145                 finally{
146                         ResourceRestUtils.deleteResourceByNameAndVersion(atomicResourceMetaData.getName(), "1.0");
147                 }
148
149         }
150
151         
152         @Test
153         public void addUpdateDeleteDeploymentArtifactToVfTestApi() throws Exception {
154                 //Create VF via API             
155                 ResourceReqDetails vfMetaData = createVFviaAPI();
156                 
157                 //Go to Catalog and find the created VF
158                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
159                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
160
161                 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
162
163                 List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
164                 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "OTHER"));
165                 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "YANG_XML"));
166                 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
167                         DeploymentArtifactPage.clickAddNewArtifact();
168                         ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact);
169                 }
170                 AssertJUnit.assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));
171                 
172                 String newDescription = "new description";
173                 DeploymentArtifactPage.clickEditArtifact(deploymentArtifactList.get(0).getArtifactLabel());
174                 DeploymentArtifactPage.artifactPopup().insertDescription(newDescription);
175                 DeploymentArtifactPage.artifactPopup().clickDoneButton();
176                 String actualArtifactDescription = DeploymentArtifactPage.getArtifactDescription(deploymentArtifactList.get(0).getArtifactLabel());
177                 AssertJUnit.assertTrue("artifact description is not updated", newDescription.equals(actualArtifactDescription));
178                 
179                 DeploymentArtifactPage.clickDeleteArtifact(deploymentArtifactList.get(0).getArtifactLabel());
180                 DeploymentArtifactPage.clickOK();
181                 AssertJUnit.assertTrue("artifact "+ deploymentArtifactList.get(0).getArtifactLabel() + "is not deleted", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size() - 1));
182                 
183                 AssertJUnit.assertTrue("artifact "+ deploymentArtifactList.get(1).getArtifactLabel() + "is not displayed", DeploymentArtifactPage.clickOnArtifactDescription(deploymentArtifactList.get(1).getArtifactLabel()).isDisplayed());
184         }
185         
186
187         @Test
188         public void addUpdateDeleteInformationalArtifactApi() throws Exception {
189                 //Create VF via API
190                 ResourceReqDetails vfMetaData = createVFviaAPI();
191                                 
192                 //Go to Catalog and find the created VF
193                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
194                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
195
196                 ResourceGeneralPage.getLeftMenu().moveToInformationalArtifactScreen();
197                 
198                 ArtifactInfo informationalArtifact = new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "OTHER");
199                 InformationalArtifactPage.clickAddNewArtifact();
200                 ArtifactUIUtils.fillAndAddNewArtifactParameters(informationalArtifact);
201                 
202                 AssertJUnit.assertTrue("artifact table does not contain artifacts uploaded", InformationalArtifactPage.checkElementsCountInTable(1));
203                 
204                 String newDescription = "new description";
205                 InformationalArtifactPage.clickEditArtifact(informationalArtifact.getArtifactLabel());
206                 InformationalArtifactPage.artifactPopup().insertDescription(newDescription);
207                 InformationalArtifactPage.artifactPopup().clickDoneButton();
208                 String actualArtifactDescription = InformationalArtifactPage.getArtifactDescription(informationalArtifact.getArtifactLabel());
209                 AssertJUnit.assertTrue("artifact description is not updated", newDescription.equals(actualArtifactDescription));
210                 
211                 InformationalArtifactPage.clickDeleteArtifact(informationalArtifact.getArtifactLabel());
212                 InformationalArtifactPage.clickOK();
213                 AssertJUnit.assertTrue("artifact "+ informationalArtifact.getArtifactLabel() + "is not deleted", InformationalArtifactPage.checkElementsCountInTable(0));
214         }
215
216
217         @Test
218         public void addPropertiesToVfcInstanceInVfTestApi() throws Exception {
219                 
220                 String fileName = "vFW_VFC.yml";
221                 ResourceReqDetails atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
222                 
223                 try{            
224                         //Create VFC via API
225                         Resource vfc = AtomicOperationUtils.importResource(filePath, fileName).left().value();
226                         atomicResourceMetaData.setName(vfc.getName());
227
228                         //Certify VFC via API
229                         vfc = (Resource) AtomicOperationUtils.changeComponentState(vfc, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
230
231                         //Create VF via API
232                         ResourceReqDetails vfMetaData = createVFviaAPI();
233
234                         //Go to Catalog and find the created VF
235                         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
236                         GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
237                         
238                         ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
239                         CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
240                         CompositionPage.searchForElement(atomicResourceMetaData.getName());
241                         CanvasElement vfcElement = vfCanvasManager.createElementOnCanvas(atomicResourceMetaData.getName());
242         
243                         vfCanvasManager.clickOnCanvaElement(vfcElement);
244                         CompositionPage.showPropertiesAndAttributesTab();
245                         List<WebElement> properties = CompositionPage.getProperties();
246                         String propertyValue = "abc123";
247                         for (int i = 0; i < 2; i++) {
248                                 WebElement findElement = properties.get(i).findElement(By.className("i-sdc-designer-sidebar-section-content-item-property-and-attribute-label"));
249                                 findElement.click();
250                                 PropertiesPage.getPropertyPopup().insertPropertyDefaultValue(propertyValue);
251                                 PropertiesPage.getPropertyPopup().clickSave();
252                                 
253                                 
254                                 findElement = properties.get(i).findElement(By.className("i-sdc-designer-sidebar-section-content-item-property-value"));
255                                 AssertJUnit.assertTrue(findElement.getText().equals(propertyValue));
256                         }
257                 }
258                 finally{
259                         ResourceRestUtils.deleteResourceByNameAndVersion(atomicResourceMetaData.getName(), "0.1");
260                 }
261         }
262         
263 /*      @Test
264         public void changeInstanceVersionTest() throws Exception{
265                 
266                 ResourceReqDetails atomicResourceMetaData = null;
267                 ResourceReqDetails vfMetaData = null;
268                 CanvasManager vfCanvasManager;
269                 CanvasElement vfcElement = null;
270                 String fileName = "vFW_VFC3.yml";
271                 try{
272                         atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
273                         ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
274                         ResourceGeneralPage.clickSubmitForTestingButton(atomicResourceMetaData.getName());
275                         
276                         vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
277                         ResourceUIUtils.createVF(vfMetaData, getUser());
278                         ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
279                         vfCanvasManager = CanvasManager.getCanvasManager();
280                         CompositionPage.searchForElement(atomicResourceMetaData.getName());
281                         vfcElement = vfCanvasManager.createElementOnCanvas(atomicResourceMetaData.getName());
282                         
283                 
284                         CompositionPage.clickSubmitForTestingButton(vfMetaData.getName());
285                         assert(false);
286                 }
287                 catch(Exception e){ 
288                         String errorMessage = GeneralUIUtils.getWebElementByClassName("w-sdc-modal-caption").getText();
289                         String checkUIResponseOnError = ErrorValidationUtils.checkUIResponseOnError(ActionStatus.VALIDATED_RESOURCE_NOT_FOUND.name());
290                         AssertJUnit.assertTrue(errorMessage.contains(checkUIResponseOnError));
291                         
292                         
293                         reloginWithNewRole(UserRoleEnum.TESTER);
294                         GeneralUIUtils.findComponentAndClick(atomicResourceMetaData.getName());
295                         TesterOperationPage.certifyComponent(atomicResourceMetaData.getName());
296                         
297                         reloginWithNewRole(UserRoleEnum.DESIGNER);
298                         GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
299                         ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
300                         vfCanvasManager = CanvasManager.getCanvasManager();
301                         CompositionPage.changeComponentVersion(vfCanvasManager, vfcElement, "1.0");
302                         
303                         //verification
304                         VfVerificator.verifyInstanceVersion(vfMetaData, getUser(), atomicResourceMetaData.getName(), "1.0");
305                 }
306                         
307                 finally{
308                         ResourceRestUtils.deleteResourceByNameAndVersion(atomicResourceMetaData.getName(), "1.0");
309                 }
310                 
311         }*/
312
313     // future removed from ui
314         @Test(enabled = false)
315         public void addUpdateDeleteSimplePropertiesToVfTest() throws Exception{
316                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
317                 ResourceUIUtils.createVF(vfMetaData, getUser());
318                         
319                 ResourceGeneralPage.getLeftMenu().moveToPropertiesScreen();
320                 List<PropertyTypeEnum> propertyList = Arrays.asList(PropertyTypeEnum.STRING, PropertyTypeEnum.INTEGER);
321                 int propertiesCount = PropertiesPage.getElemenetsFromTable().size();    
322                 for (PropertyTypeEnum prop : propertyList){
323                         PropertiesUIUtils.addNewProperty(prop);
324                 }
325                 AssertJUnit.assertTrue(GeneralUIUtils.checkElementsCountInTable(propertiesCount + propertyList.size(), () -> PropertiesPage.getElemenetsFromTable()));
326                 VfVerificator.verifyPropertiesInUI(propertyList);
327                 PropertiesPage.verifyTotalProperitesField(propertiesCount + propertyList.size());
328
329
330                 PropertyTypeEnum prop = propertyList.get(0);
331                 prop.setDescription("updatedDescription");
332                 prop.setValue("value");
333                 PropertiesUIUtils.updateProperty(prop);
334                 
335                 PropertiesPage.clickDeletePropertyArtifact(prop.getName());
336                 AssertJUnit.assertTrue(GeneralUIUtils.checkElementsCountInTable(propertiesCount + propertyList.size() - 1, () -> PropertiesPage.getElemenetsFromTable()));
337         }
338         
339         // future removed from ui
340         @Test(enabled = false)
341         public void vfcInstancesInputScreenTest() throws Exception{
342                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
343                 ResourceUIUtils.createVF(vfMetaData, getUser());
344                 
345                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
346                 CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
347                 
348                 Map<String, String> elementsIntancesMap = new HashMap<String, String>();
349                 for (LeftPanelCanvasItems element : Arrays.asList(LeftPanelCanvasItems.DATABASE, LeftPanelCanvasItems.BLOCK_STORAGE)){
350                         CanvasElement elementOnCanvas = vfCanvasManager.createElementOnCanvas(element);
351                         vfCanvasManager.clickOnCanvaElement(elementOnCanvas);
352                         String selectedInstanceName = CompositionPage.getSelectedInstanceName();
353                         elementsIntancesMap.put(selectedInstanceName, element.getValue());
354                 }
355
356                 CompositionPage.moveToInputsScreen();
357                 int canvasElementsSize = vfCanvasManager.getCanvasElements().size();
358                 AssertJUnit.assertTrue("Instances count is not as expected: " + canvasElementsSize, InputsPage.checkElementsCountInTable(canvasElementsSize));
359                 
360                 for (String element : elementsIntancesMap.keySet()){
361                         String resourceName = elementsIntancesMap.get(element);
362                         ResourceReqDetails resource = new ResourceReqDetails();
363                         resource.setName(resourceName);
364                         resource.setVersion("1.0");
365                         resource.setResourceType(ResourceTypeEnum.VFC.toString());
366                         RestResponse restResponse = RestCDUtils.getResource(resource, getUser());
367                         Map<String, String> propertiesNameTypeJson = ResponseParser.getPropertiesNameType(restResponse);
368                         
369                         List<WebElement> propertyRowsFromTable = InputsPage.getInstancePropertiesList(element);
370                         AssertJUnit.assertTrue("Some properties are missing in table. Instance name is : " + element, propertyRowsFromTable.size() == propertiesNameTypeJson.size());
371                         VfVerificator.verifyVfInputs(element, propertiesNameTypeJson, propertyRowsFromTable);
372                         
373                         GeneralUIUtils.clickOnElementByText(element);
374                 }
375                 
376         }
377
378
379         @Test
380         public void addAllInformationalArtifactPlaceholdersInVfTestApi() throws Exception{
381                 //Create VF via API
382                 ResourceReqDetails vfMetaData = createVFviaAPI();
383                 //Go to Catalog and find the created VF
384                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
385                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
386
387                 ResourceGeneralPage.getLeftMenu().moveToInformationalArtifactScreen();
388                 int fileNameCounter = 0;
389                 String fileName;
390                 for(InformationalArtifactsPlaceholders informArtifact : InformationalArtifactsPlaceholders.values()){
391                         fileName = HEAT_FILE_YAML_NAME_PREFIX + fileNameCounter + HEAT_FILE_YAML_NAME_SUFFIX;
392                         ArtifactUIUtils.fillPlaceHolderInformationalArtifact(informArtifact,
393                                         FileHandling.getFilePath("uniqueFileNames"),fileName,
394                                         informArtifact.getValue());
395                         fileNameCounter++;
396                 }
397                 assertThat(InformationalArtifactPage.checkElementsCountInTable(InformationalArtifactsPlaceholders.values().length)).isTrue();
398         }
399         
400         @Test
401         public void verifyToscaArtifactsExistApi() throws Exception{
402                 //Create VF via API
403                 ResourceReqDetails vfMetaData = createVFviaAPI();
404
405                 //Go to Catalog and find the created VF
406                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
407                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
408                 
409                 final int numOfToscaArtifacts = 2;
410                 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
411                 AssertJUnit.assertTrue(ToscaArtifactsPage.checkElementsCountInTable(numOfToscaArtifacts));
412                 
413                 for(int i = 0; i < numOfToscaArtifacts; i++){
414                         String typeFromScreen = ToscaArtifactsPage.getArtifactType(i);
415                         AssertJUnit.assertTrue(typeFromScreen.equals(ArtifactTypeEnum.TOSCA_CSAR.getType()) || typeFromScreen.equals(ArtifactTypeEnum.TOSCA_TEMPLATE.getType()));
416                 }
417
418                 //TODO Andrey should click on certify button
419                 ToscaArtifactsPage.clickCertifyButton(vfMetaData.getName());
420                 vfMetaData.setVersion("1.0");
421                 VfVerificator.verifyToscaArtifactsInfo(vfMetaData, getUser());
422         }
423         
424         @Test(enabled=false)
425         public void testDownload() throws Exception{
426 //              ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
427 //              ResourceUIUtils.createResource(vfMetaData, getUser());
428 //              
429 //              final int numOfToscaArtifacts = 2;
430 //              ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
431 //              assertTrue(ToscaArtifactsPage.checkElementsCountInTable(numOfToscaArtifacts));
432 //              GeneralUIUtils.clickOnElementByTestId("download-Tosca Model");
433 //              System.out.println("download me");
434                 
435                 AttFtpClient attFtpClient = AttFtpClient.getInstance();
436                 
437                 File retrieveLastModifiedFileFromFTP = attFtpClient.retrieveLastModifiedFileFromFTP();
438                 attFtpClient.deleteFilesFromFTPserver();
439         }
440         
441         @Test
442         public void vfCertificationTestApi() throws Exception{
443                 //Create VF via API
444                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
445                 Resource vf = AtomicOperationUtils.createResourceByResourceDetails(vfMetaData, UserRoleEnum.DESIGNER, true).left().value();
446                                 
447                 //Certify  VF via API
448                 vf = (Resource) AtomicOperationUtils.changeComponentState(vf, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
449                 
450                 //Go to Catalog and find the created VF
451                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
452                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
453                 
454                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CERTIFIED);
455         }
456         
457         @Test
458         public void deleteVfCheckedoutTestApi() throws Exception{
459                 //Create VF via API
460                 ResourceReqDetails vfMetaData = createVFviaAPI();
461
462                 //Go to Catalog and find the created VF
463                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
464                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
465                 
466                 GeneralPageElements.clickTrashButtonAndConfirm();
467                 
468                 vfMetaData.setVersion("0.1");
469                 VfVerificator.verifyVfDeleted(vfMetaData, getUser());
470         }
471         
472         @Test
473         public void revertVfMetadataTestApi() throws Exception{
474                 //Create VF via API
475                 ResourceReqDetails vfMetaData = createVFviaAPI();
476
477                 //Go to Catalog and find the created VF
478                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
479                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
480                 
481                 ResourceReqDetails vfRevertDetails = new ResourceReqDetails();
482                 vfRevertDetails.setName("ciUpdatedName");
483                 vfRevertDetails.setDescription("kuku");
484                 vfRevertDetails.setCategories(vfMetaData.getCategories());
485                 vfRevertDetails.setVendorName("updatedVendor");
486                 vfRevertDetails.setVendorRelease("updatedRelease");
487                 ResourceUIUtils.fillResourceGeneralInformationPage(vfRevertDetails, getUser(), false);
488                 
489                 GeneralPageElements.clickRevertButton();
490                 
491                 VfVerificator.verifyVFMetadataInUI(vfMetaData);
492                 
493         }
494         
495         @Test
496         public void addDeploymentArtifactInCompositionScreenTestApi() throws Exception{
497                 //Create VF via API
498                 ResourceReqDetails vfMetaData = createVFviaAPI();
499
500                 //Go to Catalog and find the created VF
501                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
502                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
503                 
504                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
505                 
506                 ArtifactInfo artifact = new ArtifactInfo(filePath, "Heat-File.yaml", "kuku", "artifact3","OTHER");
507                 CompositionPage.showDeploymentArtifactTab();
508                 CompositionPage.clickAddArtifactButton();
509                 ArtifactUIUtils.fillAndAddNewArtifactParameters(artifact, CompositionPage.artifactPopup());
510                 
511                 List<WebElement> actualArtifactList = GeneralUIUtils.getWebElementsListBy(By.className("i-sdc-designer-sidebar-section-content-item-artifact"));
512                 AssertJUnit.assertEquals(1, actualArtifactList.size());
513         }
514         
515         // future removed from ui
516         @Test(enabled = false)
517         public void addPropertyInCompositionScreenTest() throws Exception{
518                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
519                 ResourceUIUtils.createVF(vfMetaData, getUser());
520                 
521                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
522                 
523                 CompositionPage.showPropertiesAndAttributesTab();
524                 List<PropertyTypeEnum> propertyList = Arrays.asList(PropertyTypeEnum.STRING, PropertyTypeEnum.INTEGER);
525                 int propertiesCount = CompositionPage.getProperties().size();
526                 for (PropertyTypeEnum prop : propertyList){
527                         PropertiesUIUtils.addNewProperty(prop);
528                 }
529                 AssertJUnit.assertTrue(GeneralUIUtils.checkElementsCountInTable(propertiesCount + propertyList.size(), () -> CompositionPage.getProperties()));
530         }
531         
532         @Test
533         public void addDeploymentArtifactAndVerifyInCompositionScreenApi() throws Exception{            
534                 //Create VF via API
535                 ResourceReqDetails vfMetaData = createVFviaAPI();
536
537                 //Go to Catalog and find the created VF
538                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
539                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());     
540                 
541                 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
542
543                 ArtifactInfo deploymentArtifact = new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "OTHER");
544                 DeploymentArtifactPage.clickAddNewArtifact();
545                 ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact);
546                 AssertJUnit.assertTrue(DeploymentArtifactPage.checkElementsCountInTable(1));
547                 
548                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
549                 
550                 CompositionPage.showDeploymentArtifactTab();
551                 List<WebElement> deploymentArtifactsFromScreen = CompositionPage.getDeploymentArtifacts();
552                 AssertJUnit.assertTrue(1 == deploymentArtifactsFromScreen.size());
553                 
554                 String actualArtifactFileName = deploymentArtifactsFromScreen.get(0).getText();
555                 AssertJUnit.assertTrue("asc_heat-0-2.yaml".equals(actualArtifactFileName));
556         }
557         
558         /*@Test
559         public void checkoutVfTest() throws Exception{
560                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
561                 ResourceUIUtils.createVF(vfMetaData, getUser());
562                 
563                 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
564                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
565                 GeneralPageElements.clickCheckoutButton();
566                 
567                 vfMetaData.setVersion("0.2");
568                 VfVerificator.verifyVFLifecycle(vfMetaData, getUser(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
569                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CHECKOUT);
570                 
571                 ResourceGeneralPage.clickSubmitForTestingButton(vfMetaData.getName());
572                 
573                 reloginWithNewRole(UserRoleEnum.TESTER);
574                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
575                 TesterOperationPage.certifyComponent(vfMetaData.getName());
576                 
577                 reloginWithNewRole(UserRoleEnum.DESIGNER);
578                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
579                 ResourceGeneralPage.clickCheckoutButton();
580                 
581                 vfMetaData.setVersion("1.1");
582                 vfMetaData.setUniqueId(null);
583                 VfVerificator.verifyVFLifecycle(vfMetaData, getUser(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
584                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CHECKOUT);
585         }*/
586         
587         @Test
588         public void deleteInstanceFromVfCanvasApi() throws Exception{
589                 //Create VF via API
590                 ResourceReqDetails vfMetaData = createVFviaAPI();
591
592                 //Go to Catalog and find the created VF
593                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
594                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
595                 
596                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
597                 CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
598                 CanvasElement computeElement = vfCanvasManager.createElementOnCanvas(LeftPanelCanvasItems.COMPUTE);
599                 vfCanvasManager.createElementOnCanvas(LeftPanelCanvasItems.PORT);
600                 
601                 vfCanvasManager.clickOnCanvaElement(computeElement);
602                 vfCanvasManager.deleteElementFromCanvas(computeElement);
603                 
604                 VfVerificator.verifyNumOfComponentInstances(vfMetaData, 1, getUser());
605         }
606         
607         @Test
608         public void changeInstanceNameInVfTestApi() throws Exception{
609                 //Create VF via API
610                 ResourceReqDetails vfMetaData = createVFviaAPI();
611
612                 //Go to Catalog and find the created VF
613                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
614                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
615                 
616                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
617                 CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
618                 CanvasElement computeElement = vfCanvasManager.createElementOnCanvas(LeftPanelCanvasItems.COMPUTE);
619                 
620                 String updatedInstanceName = "updatedName";
621                 vfCanvasManager.updateElementNameInCanvas(computeElement, updatedInstanceName);
622                 
623                 String actualSelectedInstanceName = CompositionPage.getSelectedInstanceName();
624                 AssertJUnit.assertTrue(updatedInstanceName.equals(actualSelectedInstanceName));
625         }
626         
627         
628         /*@Test
629         public void submitVfForTestingWithNonCertifiedAssetApi() throws Exception{
630                 String fileName = "vFW_VFC4.yml";
631                 ResourceReqDetails atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
632                 
633                 //Create VFC via API
634                 Resource vfc = AtomicOperationUtils.importResource(filePath, fileName).left().value();
635                 atomicResourceMetaData.setName(vfc.getName());
636                 
637                 //Submit VFC for testing via API
638                 vfc = (Resource) AtomicOperationUtils.changeComponentState(vfc, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFICATIONREQUEST, true).getLeft();
639
640                 //Create VF via API
641                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
642                 AtomicOperationUtils.createResourceByResourceDetails(vfMetaData, UserRoleEnum.DESIGNER, true).left().value();
643                 
644                 //Go to Catalog and find the created VF
645                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
646                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
647                 
648                 DeploymentArtifactPage.getLeftMenu().moveToCompositionScreen();
649                 CanvasManager canvasManager = CanvasManager.getCanvasManager();
650                 CompositionPage.searchForElement(atomicResourceMetaData.getName());
651                 canvasManager.createElementOnCanvas(atomicResourceMetaData.getName());
652                 
653                 try{
654                         //TODO Andrey should click on certify button
655                         CompositionPage.clickCertifyButton(vfMetaData.getName());
656                         assert(false);
657                 }
658                 catch(Exception e){ 
659                         String errorMessage = GeneralUIUtils.getWebElementByClassName("w-sdc-modal-caption").getText();
660                         String checkUIResponseOnError = ErrorValidationUtils.checkUIResponseOnError(ActionStatus.VALIDATED_RESOURCE_NOT_FOUND.name());
661                         AssertJUnit.assertTrue(errorMessage.contains(checkUIResponseOnError));  
662                 }
663                 finally{
664                         ResourceRestUtils.deleteResourceByNameAndVersion(atomicResourceMetaData.getName(), "0.1");
665                 }
666         }*/
667         
668         @Test
669         public void isDisabledAndReadOnlyInCheckinApi() throws Exception{               
670                 //Create VF via API
671                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
672                 Resource vf = AtomicOperationUtils.createResourceByResourceDetails(vfMetaData, UserRoleEnum.DESIGNER, true).left().value();
673                 
674                 //Check in  VF via API
675                 vf = (Resource) AtomicOperationUtils.changeComponentState(vf, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
676                 
677                 //Go to Catalog and find the created VF
678                 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
679                 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
680                 
681                 ResourceMetadataEnum[] fieldsForCheck = {ResourceMetadataEnum.RESOURCE_NAME,
682                                 ResourceMetadataEnum.DESCRIPTION, ResourceMetadataEnum.VENDOR_NAME, ResourceMetadataEnum.VENDOR_RELEASE,
683                                 ResourceMetadataEnum.CONTACT_ID};
684
685                 for (ResourceMetadataEnum field: fieldsForCheck){
686                         AssertJUnit.assertTrue(GeneralUIUtils.isElementReadOnly(field.getValue()));
687                 }
688                 
689                 AssertJUnit.assertTrue(GeneralUIUtils.isElementDisabled(ResourceMetadataEnum.CATEGORY.getValue()));
690                 AssertJUnit.assertTrue(GeneralUIUtils.isElementDisabled(DataTestIdEnum.LifeCyleChangeButtons.CREATE.getValue()));
691         }
692
693     @Test
694     public void displayHomeAfterNavigationToOnboardingTest() throws Exception{
695         //Production bug scenario: "Home" - Click on any VF/ Service - Copy the URL - Go to “ONBOARD” - Paste the URL - Review the breadcrumbs
696         // Expected: "Home"       Actual: "Onboarding"
697
698         //Create VF via API
699         ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
700         Resource vf = AtomicOperationUtils.createResourceByResourceDetails(vfMetaData, UserRoleEnum.DESIGNER, true).left().value();
701
702         //Check in  VF via API
703         vf = (Resource) AtomicOperationUtils.changeComponentState(vf, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
704
705         //Find the created VF on Home page
706         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
707         HomePage.navigateToHomePage();
708         GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
709
710         //Copy current URL, navigate to OB screen and paste URL
711         String url = GeneralUIUtils.copyCurrentURL();
712         CompositionPage.moveToOnboardScreen();
713         GeneralUIUtils.navigateToURL(url);
714         GeneralUIUtils.ultimateWait();
715
716         //Validate that main menu button is Home and not Onboarding
717                 String id = DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue();
718         WebElement button = GeneralUIUtils.getWebElementByTestID(id);
719         AssertJUnit.assertTrue(button.getAttribute("text").trim().equals("HOME"));
720     }
721         
722         @Test
723         public void exportToscaWithModulePropertiesVFTest() throws Exception {
724                 String vnfFile = "1-Vf-zrdm5bpxmc02-092017-(MOBILITY)_v2.0.zip";
725                 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
726                 VendorSoftwareProductObject vsp= OnboardingUiUtils.onboardAndValidate(resourceReqDetails, FileHandling.getVnfRepositoryPath(), vnfFile, getUser());
727                 String vspName = vsp.getName();
728                 ResourceGeneralPage.clickCertifyButton(vspName);
729                 Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, vspName, "1.0");
730                 VfModuleVerificator.validateSpecificModulePropertiesFromRequest(resource);
731         }
732         
733         @Test
734         public void exportToscaWithModulePropertiesTemplateCheckVFTest() throws Exception {
735                 String vnfFile = "1-Vf-zrdm5bpxmc02-092017-(MOBILITY)_v2.0.zip";
736                 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();//getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
737                 OnboardingUiUtils.onboardAndValidate(resourceReqDetails, FileHandling.getVnfRepositoryPath(), vnfFile, getUser());
738                 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
739                 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_MODEL.getValue());
740                 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
741                 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(latestFilefromDir);
742                 VfModuleVerificator.validateSpecificModulePropertiesFromFile(toscaDefinition);
743         }
744         
745
746
747         @Override
748         protected UserRoleEnum getRole() {
749                 return UserRoleEnum.DESIGNER;
750         }
751
752 }