re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / ImportVFCAsset.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 static org.assertj.core.api.Assertions.assertThat;
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.ArtifactInfo;
28 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.InformationalArtifactsPlaceholders;
30 import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
32 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.enums.PropertyTypeEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
35 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
36 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
37 import org.openecomp.sdc.ci.tests.pages.*;
38 import org.openecomp.sdc.ci.tests.utilities.*;
39 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
40 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
41 import org.openecomp.sdc.ci.tests.verificator.PropertyVerificator;
42 import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
43 import org.testng.Assert;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.DataProvider;
46 import org.testng.annotations.Test;
47
48 import java.util.ArrayList;
49 import java.util.Arrays;
50 import java.util.List;
51
52 import static org.testng.AssertJUnit.assertTrue;
53
54 @Test(singleThreaded=true)
55 public class ImportVFCAsset extends SetupCDTest {
56         
57         private ResourceReqDetails atomicResourceMetaData;
58         private String filePath;
59
60         @BeforeClass
61         public void beforeClass(){
62                 filePath = FileHandling.getFilePath("");
63         }
64         
65         @DataProvider(name = "assetFiles", parallel = false)
66     public Object[][] createDataX() {
67              return new Object[][] { { "importVFC_VFC9.yml" }, { "CP.yml" }, {"VL.yml"} };
68     }
69         
70         @Test
71         public void importVFCTest() throws Exception {
72                 String fileName = "importVFC_VFC1.yml";
73                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
74                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
75                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
76         }
77         
78         @Test
79         public void importDuplicateVFCTest() throws Exception {
80                 String fileName = "importVFC_VFC2.yml";
81                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
82                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
83                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
84                 ResourceGeneralPage.clickCheckinButton(atomicResourceMetaData.getName()); 
85                 
86                 ResourceReqDetails atomicResourceMetaDataDup = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
87                                 ResourceCategoryEnum.NETWORK_L2_3_INFRASTRUCTURE, getUser());
88                 try{
89                         ResourceUIUtils.importVfc(atomicResourceMetaDataDup, filePath, fileName, getUser());
90                         assert(false);
91                 }
92                 catch(Exception e){
93                         String errorMessage = GeneralUIUtils.getWebElementByClassName("w-sdc-modal-caption").getText();
94                         String checkUIResponseOnError = ErrorValidationUtils.checkUIResponseOnError(ActionStatus.RESOURCE_ALREADY_EXISTS.name());
95                         Assert.assertTrue(errorMessage.contains(checkUIResponseOnError));       
96                 } 
97         }
98         
99         @Test
100         public void badFileVFCTest() throws Exception {
101                 String fileName = "importVFC_VFC3.yml";
102                 String customFileName = "Heat-File 1.yaml";
103
104                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
105                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());          
106                 try{
107                         ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, customFileName, getUser());
108                         assert(false);
109                 }
110                 catch(Exception e){
111                         String errorMessage = GeneralUIUtils.getWebElementByClassName("w-sdc-modal-caption").getText();
112                         String checkUIResponseOnError = ErrorValidationUtils.checkUIResponseOnError(ActionStatus.INVALID_TOSCA_TEMPLATE.name());
113                         Assert.assertTrue(errorMessage.contains(checkUIResponseOnError));       
114                 }
115         }
116         
117         @Test
118         public void validContactAfterCreateVFCTest() throws Exception{
119                 String fileName = "importVFC_VFC4.yml";
120                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
121                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
122                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
123                 
124                 assertTrue("wrong userId", atomicResourceMetaData.getContactId().equals(ResourceGeneralPage.getContactIdText()));
125         }
126         
127         @Test
128         public void validContactAfterUpdateVFCTest() throws Exception{
129                 String fileName = "importVFC_VFC5.yml";
130                 String userIdUpdated = "up1234";
131
132                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
133                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
134                 
135                 ResourceUIUtils.defineUserId(userIdUpdated);
136                 assertTrue("userId is not updated",userIdUpdated.equals(ResourceGeneralPage.getContactIdText()));
137         }
138         
139         @Test
140         public void addUpdateDeleteDeploymentArtifactToVFCTest() throws Exception {
141                 String fileName = "importVFC_VFC6.yml";
142                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
143                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
144                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
145
146                 ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
147
148                 List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
149                 deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "OTHER"));
150                 deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "YANG_XML"));          
151                 for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
152                         DeploymentArtifactPage.clickAddNewArtifact();
153                         ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true) );
154                 }
155                 assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));
156                 
157                 String newDescription = "new description";
158                 DeploymentArtifactPage.updateDescription(newDescription, deploymentArtifactList.get(0));
159                 String actualArtifactDescription = DeploymentArtifactPage.getArtifactDescription(deploymentArtifactList.get(0).getArtifactLabel());
160                 assertTrue("artifact description is not updated", newDescription.equals(actualArtifactDescription));
161                 
162                 DeploymentArtifactPage.clickDeleteArtifact(deploymentArtifactList.get(0).getArtifactLabel());
163                 DeploymentArtifactPage.clickOK();
164                 assertTrue("artifact "+ deploymentArtifactList.get(0).getArtifactLabel() + "is not deleted", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size() - 1));
165                 
166                 assertTrue("artifact "+ deploymentArtifactList.get(1).getArtifactLabel() + "is not displayed", DeploymentArtifactPage.clickOnArtifactDescription(deploymentArtifactList.get(1).getArtifactLabel()).isDisplayed());
167         }
168         
169         @Test
170         public void addUpdateDeletePlaceholdersInformationalArtifactVFCTest() throws Exception{
171                 String fileName = "importVFC_VFC7.yml";
172                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
173                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
174                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
175                 
176         ResourceGeneralPage.getLeftMenu().moveToInformationalArtifactScreen();
177         
178                 // create artifacts
179         List<ArtifactInfo> informationalArtifactList = new ArrayList<ArtifactInfo>();
180         informationalArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "OTHER"));
181         informationalArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuuuuku", "artifact3", "HEAT"));
182         for (ArtifactInfo informationalArtifact : informationalArtifactList) {
183                 InformationalArtifactPage.clickAddNewArtifact();
184                         ArtifactUIUtils.fillAndAddNewArtifactParameters(informationalArtifact);
185                 }               
186                 assertThat(InformationalArtifactPage.checkElementsCountInTable(informationalArtifactList.size())).
187                 as("Check that artifact table contains artifacts uploaded").isTrue();
188                 
189                 // update artifact description
190                 String newDescription = "new description";
191                 InformationalArtifactPage.clickEditArtifact(informationalArtifactList.get(0).getArtifactLabel());
192                 InformationalArtifactPage.artifactPopup().insertDescription(newDescription);
193                 InformationalArtifactPage.artifactPopup().clickDoneButton();
194                 String actualArtifactDescription = InformationalArtifactPage.getArtifactDescription(informationalArtifactList.get(0).getArtifactLabel());
195                 assertThat(actualArtifactDescription).as("Check artifact description update").isEqualTo(newDescription);
196                 
197                 // delete artifacts 
198                 for (ArtifactInfo informationalArtifact : informationalArtifactList) {
199                         InformationalArtifactPage.clickDeleteArtifact(informationalArtifact.getArtifactLabel());
200                         InformationalArtifactPage.clickOK();
201                 }
202                 
203                 assertThat(InformationalArtifactPage.checkElementsCountInTable(0)).
204                 as("Check that all artifacts were deleted").isTrue();
205
206                 // fill placeholders
207         int fileNameCounter = 0;
208                 for(InformationalArtifactsPlaceholders informArtifact : InformationalArtifactsPlaceholders.values()){
209             fileName = HEAT_FILE_YAML_NAME_PREFIX + fileNameCounter + HEAT_FILE_YAML_NAME_SUFFIX;
210             ArtifactUIUtils.fillPlaceHolderInformationalArtifact(informArtifact, FileHandling.getFilePath("uniqueFileNames"),
211                     fileName, informArtifact.getValue());
212             fileNameCounter++;
213                 }               
214                 assertThat(InformationalArtifactPage.checkElementsCountInTable(InformationalArtifactsPlaceholders.values().length)).isTrue();
215         }
216         
217         @Test
218         public void addSimplePropertiesToVFCTest() throws Exception{
219                 String fileName = "importVFC_VFC8.yml";
220                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
221                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
222                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
223                         
224                 ResourceGeneralPage.getLeftMenu().moveToPropertiesScreen();
225                 List<PropertyTypeEnum> propertyList = Arrays.asList(PropertyTypeEnum.STRING, PropertyTypeEnum.INTEGER, PropertyTypeEnum.FLOAT);
226                 int propertiesCount = PropertiesPage.getElemenetsFromTable().size();    
227                 for (PropertyTypeEnum prop : propertyList){
228                         PropertiesUIUtils.addNewProperty(prop);
229                 }
230                 assertTrue(GeneralUIUtils.checkElementsCountInTable(propertiesCount + propertyList.size(), () -> PropertiesPage.getElemenetsFromTable()));
231                 
232         }
233         
234         @Test
235         public void updateAfterCheckoutNewSimplePropertiesVFCTest() throws Exception{
236                 String fileName = "importVFC_VFC16.yml";
237                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
238                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
239                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
240                         
241                 ResourceGeneralPage.getLeftMenu().moveToPropertiesScreen();
242                 List<PropertyTypeEnum> propertyList = Arrays.asList(PropertyTypeEnum.STRING, PropertyTypeEnum.INTEGER, PropertyTypeEnum.FLOAT);
243                 int propertiesCount = PropertiesPage.getElemenetsFromTable().size();    
244                 for (PropertyTypeEnum prop : propertyList){
245                         PropertiesUIUtils.addNewProperty(prop);
246                 }
247                 ResourceGeneralPage.clickCheckinButton(atomicResourceMetaData.getName());
248                 GeneralUIUtils.findComponentAndClick(atomicResourceMetaData.getName());
249                 GeneralPageElements.clickCheckoutButton();
250                 ResourceGeneralPage.getLeftMenu().moveToPropertiesScreen();
251                 
252                 for (PropertyTypeEnum prop : propertyList){
253                         PropertiesUIUtils.updateProperty(prop);
254                 }
255                 assertTrue(GeneralUIUtils.checkElementsCountInTable(propertiesCount + propertyList.size(), () -> PropertiesPage.getElemenetsFromTable()));
256                 
257                 for (PropertyTypeEnum prop : propertyList){
258                                 PropertiesPage.clickOnProperty(prop.getName());
259                                 PropertyVerificator.validateEditVFCPropertiesPopoverFields(prop);
260                                 PropertiesPage.getPropertyPopup().clickCancel();        
261                 }
262                 
263         }
264         
265                 
266         @Test(dataProvider = "assetFiles")
267         public void checkinCheckoutChangeDeleteVersionVFCTest(String customfileName) throws Exception{
268                 setLog(customfileName);         
269 //              getExtendTest().setDescription(customfileName);
270                 
271                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
272                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
273                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, customfileName, getUser());
274                 
275                 ResourceGeneralPage.clickCheckinButton(atomicResourceMetaData.getName());
276                 GeneralUIUtils.findComponentAndClick(atomicResourceMetaData.getName());
277                 GeneralPageElements.clickCheckoutButton();              
278                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CHECKOUT);
279                 
280                 GeneralPageElements.selectVersion("V0.1");
281                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CHECKIN);
282                 GeneralUIUtils.clickJSOnElementByText("latest version");
283                 
284                 GeneralPageElements.clickTrashButtonAndConfirm();
285                 GeneralUIUtils.findComponentAndClick(atomicResourceMetaData.getName());
286                 String actualVersion = GeneralUIUtils.getSelectedElementFromDropDown(DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue()).getText();
287                 assertTrue("Expected version: V0.1, Actual version: " + actualVersion, actualVersion.equals("V0.1"));
288         }
289         
290         @Test
291         public void certificationVFCTest() throws Exception{
292                 String fileName = "importVFC_VFC10.yml";
293                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
294                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
295                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
296                 
297                 String vfName = atomicResourceMetaData.getName();
298                 
299                 ResourceGeneralPage.clickCheckinButton(vfName);
300                 GeneralUIUtils.findComponentAndClick(vfName);
301                 //TODO Andrey should click on certify button
302                 ResourceGeneralPage.clickCertifyButton(vfName);
303                 
304                 /*reloginWithNewRole(UserRoleEnum.TESTER);
305                 GeneralUIUtils.findComponentAndClick(vfName);
306                 TesterOperationPage.certifyComponent(vfName);*/
307                 
308                 atomicResourceMetaData.setVersion("1.0");
309                 VfVerificator.verifyVFLifecycle(atomicResourceMetaData, getUser(), LifecycleStateEnum.CERTIFIED);
310                 
311                 /*reloginWithNewRole(UserRoleEnum.DESIGNER);*/
312                 GeneralUIUtils.findComponentAndClick(vfName);
313                 VfVerificator.verifyVfLifecycleInUI(LifeCycleStateEnum.CERTIFIED);
314         }
315         
316         @Test
317         public void activityLogVFCTest() throws Exception{              
318                 String fileName = "importVFC_VFC11.yml";
319                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
320                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
321                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
322                 
323         ResourceGeneralPage.getLeftMenu().moveToInformationalArtifactScreen();
324                 
325                 ArtifactInfo informationalArtifact = new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "OTHER");
326                 InformationalArtifactPage.clickAddNewArtifact();
327                 ArtifactUIUtils.fillAndAddNewArtifactParameters(informationalArtifact);
328                 
329                 ResourceGeneralPage.getLeftMenu().moveToActivityLogScreen();
330                 
331                 int numberOfRows = GeneralUIUtils.getElementsByCSS("div[class^='flex-container']").size();
332                 assertTrue("Wrong rows number, should be 2", numberOfRows == 2);
333         }
334         
335         @Test
336         public void removeFileFromGeneralPageVFCTest() throws Exception{
337                 String fileName = "importVFC_VFC12.yml";
338
339                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
340                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
341                 ResourceUIUtils.importVfcNoCreate(atomicResourceMetaData, filePath, fileName, getUser());
342                 
343                 GeneralPageElements.clickDeleteFile();
344                 
345                 try{
346                         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue(), 30);
347                         assert(false);
348                 }
349                 catch(Exception e){
350                         assert(true);   
351                 }
352         }
353         
354         @Test
355         public void maxLengthGeneralInformationVFCTest() throws Exception{
356                 String fileName = "importVFC_VFC13.yml";
357                 atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT, 
358                                 ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
359                 ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());               
360                 ResourceUIUtils.fillMaxValueResourceGeneralInformationPage(atomicResourceMetaData);
361 //              GeneralPageElements.clickUpdateButton();
362 //              VFCverificator.verifyVFCUpdatedInUI(atomicResourceMetaData);
363 //              GeneralPageElements.clickDeleteVersionButton();
364                 // Validate that button disabled 
365                 assertTrue(GeneralUIUtils.checkForDisabledAttribute(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue()));
366         }       
367         
368         
369
370         @Override
371         protected UserRoleEnum getRole() {
372                 return UserRoleEnum.DESIGNER;
373         }
374
375 }