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