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