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