2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.verificator;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertTrue;
28 import java.io.IOException;
29 import java.util.List;
32 import org.apache.commons.lang3.tuple.ImmutablePair;
33 import org.json.simple.JSONArray;
34 import org.json.simple.JSONObject;
35 import org.json.simple.JSONValue;
36 import org.openecomp.sdc.be.model.LifecycleStateEnum;
37 import org.openecomp.sdc.be.model.Resource;
38 import org.openecomp.sdc.be.model.User;
39 import org.openecomp.sdc.be.model.category.CategoryDefinition;
40 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
41 import org.openecomp.sdc.ci.tests.datatypes.LifeCycleStateEnum;
42 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
43 import org.openecomp.sdc.ci.tests.datatypes.enums.PropertyTypeEnum;
44 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
45 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
46 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
47 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
48 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
49 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
50 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
51 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
52 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
53 import org.openqa.selenium.By;
54 import org.openqa.selenium.WebElement;
55 import org.testng.Assert;
57 import com.aventstack.extentreports.Status;
59 public final class VfVerificator {
61 public static void verifyNumOfComponentInstances(ResourceReqDetails createResourceInUI, int numOfVFC, User user) {
62 ServiceVerificator.verifyNumOfComponentInstances(createResourceInUI, createResourceInUI.getVersion(), numOfVFC, user);
65 public static void verifyRILocationChanged(ResourceReqDetails createResourceInUI,
66 ImmutablePair<String, String> prevRIPos, User user) {
68 ImmutablePair<String, String> currRIPos = ResourceUIUtils.getFirstRIPos(createResourceInUI, user);
69 assertTrue(!prevRIPos.left.equals(currRIPos.left) || !prevRIPos.right.equals(currRIPos.right));
72 public static void verifyLinkCreated(ResourceReqDetails createResourceInUI, User user, int expectedRelationsSize) {
73 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifing that a link was created on canvas"));
74 String responseAfterDrag = RestCDUtils.getResource(createResourceInUI, user).getResponse();
75 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
76 assertTrue(((JSONArray) jsonResource.get("componentInstancesRelations")).size() == expectedRelationsSize);
77 ExtentTestActions.log(Status.INFO, "The link was verified.");
81 public static void verifyVFMetadataInUI(ResourceReqDetails vf) {
82 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifying fields on General screen through UI ..."));
83 assertTrue(vf.getName().equals(ResourceGeneralPage.getNameText()));
84 assertTrue(vf.getDescription().equals(ResourceGeneralPage.getDescriptionText()));
85 assertTrue(vf.getCategories().get(0).getSubcategories().get(0).getName().equals(GeneralUIUtils.getSelectedElementFromDropDown(ResourceGeneralPage.getCategoryDataTestsIdAttribute()).getText()));
86 assertTrue(vf.getVendorName().equals(ResourceGeneralPage.getVendorNameText()));
87 assertTrue(vf.getVendorRelease().equals(ResourceGeneralPage.getVendorReleaseText()));
88 assertTrue(vf.getContactId().equals(ResourceGeneralPage.getContactIdText()));
89 List<WebElement> tagsList = ResourceGeneralPage.getElementsFromTagsTable();
90 assertTrue(vf.getTags().size() == tagsList.size());
91 for (int i = 0 ; i < vf.getTags().size(); i ++ ){
92 assertTrue(vf.getTags().contains(tagsList.get(i).getText()));
94 assertTrue(vf.getContactId().equals(ResourceGeneralPage.getContactIdText()));
97 public static void verifyVFUpdated(ResourceReqDetails vf, User user) {
98 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifying fields on General screen through Backend ..."));
99 String response = RestCDUtils.getResource(vf, user).getResponse();
100 Resource resource = ResponseParser.convertResourceResponseToJavaObject(response);
101 assertTrue(vf.getName().equals(resource.getName()));
102 assertTrue(vf.getDescription().equals(resource.getDescription()));
103 assertTrue(vf.getVendorName().equals(resource.getVendorName()));
104 assertTrue(vf.getVendorRelease().equals(resource.getVendorRelease()));
105 assertTrue(vf.getContactId().equals(resource.getContactId()));
107 assertTrue(vf.getCategories().size() == (resource.getCategories().size()));
108 for (int i = 0 ; i < vf.getCategories().size() ; i ++)
110 CategoryDefinition expectedCategoryDefinition = vf.getCategories().get(i);
111 CategoryDefinition actualCategoryDefinition = resource.getCategories().get(i);
112 assertTrue(expectedCategoryDefinition.getName().equals(actualCategoryDefinition.getName()));
113 assertTrue(expectedCategoryDefinition.getSubcategories().get(i).getName().equals(actualCategoryDefinition.getSubcategories().get(i).getName()));
116 assertTrue(vf.getTags().size() == (resource.getTags().size()));
117 for (int i = 0 ; i < vf.getTags().size() ; i ++){
118 List<String> expectedTags = vf.getTags();
119 List<String> actualTags = resource.getTags();
121 assertTrue(actualTags.contains(expectedTags.get(i)));
126 public static void verifyVFLifecycle(ResourceReqDetails vf, User user, LifecycleStateEnum expectedLifecycleState) {
127 String responseAfterDrag = RestCDUtils.getResource(vf, user).getResponse();
128 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
129 String actualLifecycleState = jsonResource.get("lifecycleState").toString();
130 assertTrue(expectedLifecycleState.name().equals(actualLifecycleState), "actual: " + actualLifecycleState + "-- expected: " + expectedLifecycleState);
133 public static void verifyVfLifecycleInUI(LifeCycleStateEnum lifecycleState){
134 GeneralUIUtils.ultimateWait();
135 assertTrue(ResourceGeneralPage.getLifeCycleState().equals(lifecycleState.getValue()));
138 public static void verifyInstanceVersion(ResourceReqDetails vf, User user, String instanceName, String instanceVersion){
139 String responseAfterDrag = RestCDUtils.getResource(vf, user).getResponse();
140 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
141 JSONArray jsonArrayResource = (JSONArray) jsonResource.get("componentInstances");
142 for (int i = 0; i < jsonArrayResource.size(); i++){
143 Object object = jsonArrayResource.get(i);
145 JSONObject jRes = (JSONObject) JSONValue.parse(object.toString());
146 String componentName = jRes.get("componentName").toString();
147 if (componentName.equals(instanceName)){
148 String componentVersion = jRes.get("componentVersion").toString();
149 assertTrue(componentVersion.equals(instanceVersion));
153 System.out.println("Can't test object in componentInstances array");
154 Assert.fail("Can't test object in componentInstances array");
159 public static void verifyVfDeleted(ResourceReqDetails vf, User user){
160 RestResponse response = RestCDUtils.getResource(vf, user);
161 assertTrue(response.getErrorCode().intValue() == 404);
164 public static void verifyPropertiesInUI(List<PropertyTypeEnum> propertyList){
166 for (PropertyTypeEnum prop : propertyList){
167 String propName = prop.getName();
169 String actualName = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.PROPERTY_NAME.getValue() + propName).getText();
170 String actualType = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.PROPERTY_TYPE.getValue() + propName).getText();
171 String actualDesciprtion = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.PROPERTY_DESCRIPTION.getValue() + propName).getText();
173 assertTrue(propName.equals(actualName), String.format("Property name is not correct. expected:%s ; actual %s", propName, actualName));
174 assertTrue(prop.getType().equals(actualType), String.format("Property type is not correct. expected:%s ; actual %s", prop.getType(), actualType));
175 assertTrue(prop.getDescription().equals(actualDesciprtion), String.format("Property description is not correct. expected:%s ; actual %s", prop.getDescription(), actualDesciprtion));
177 if (prop.getSchemaDefinition() != null){
178 String actualSchema = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.ENTRY_SCHEMA.getValue() + propName).getText();
179 assertTrue(prop.getSchemaDefinition().equals(actualSchema), String.format("Property schema is not correct. expected:%s ; actual %s", prop.getSchemaDefinition(), actualSchema));
184 public static void verifyToscaArtifactsInfo(ResourceReqDetails vf, User user){
185 String responseAfterDrag = RestCDUtils.getResource(vf, user).getResponse();
186 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
187 JSONObject toscaArtifacts = (JSONObject) jsonResource.get("toscaArtifacts");
189 assertEquals(2, toscaArtifacts.size());
190 for (Object artifactObj : toscaArtifacts.keySet()){
191 JSONObject artifact = (JSONObject) JSONValue.parse(toscaArtifacts.get(artifactObj).toString());
192 assertFalse(artifact.get("artifactUUID").toString().isEmpty(), "artifactUUID field is empty");
193 assertFalse(artifact.get("artifactChecksum").toString().isEmpty(), "artifactChecksum filed is empty");
194 assertFalse(artifact.get("payloadUpdateDate").toString().isEmpty(), "payloadUpdateDate field is empty");
195 assertFalse(artifact.get("artifactVersion").toString().equals("0"), "artifactVersion field is 0");
199 public static void verifyVfInputs(String instanceName, Map<String, String> instancePropertiesMapFromJson,List<WebElement> propertyRowsFromTable) {
201 for (int i = 0 ; i < propertyRowsFromTable.size() ; i++){
202 WebElement row = propertyRowsFromTable.get(i);
203 String propertyNameFromTable = row.findElement(By.xpath(".//*[@data-tests-id='" + "propertyName']")).getText();
204 String propertyTypeFromTable = row.findElement(By.xpath(".//*[@data-tests-id='" + "propertyType']")).getText();
205 String instanceNameFromTable = row.findElement(By.xpath(".//*[@data-tests-id='" + "instanceName']")).getText();
206 String propertySchemaFromTable = row.findElement(By.xpath(".//*[@data-tests-id='" + "propertySchema']")).getText();
208 assertTrue(instancePropertiesMapFromJson.containsKey(propertyNameFromTable), "No property named : " + propertyNameFromTable + "for instance " + instanceName);
209 String expectedType = instancePropertiesMapFromJson.get(propertyNameFromTable);
210 assertTrue(expectedType.equals(propertyTypeFromTable.toLowerCase()), propertyNameFromTable + "type is incorrect");
211 assertTrue(instanceName.equals(instanceNameFromTable), "Instance name of property named " + propertyNameFromTable + "is incorrect");
215 public static void verifyOnboardedVnfMetadata(String vspName, Map<String, String> vspMetadata) {
216 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying metadata");
217 assertTrue(vspName.equals(ResourceGeneralPage.getNameText()), "VSP name is not valid.");
218 assertTrue(vspMetadata.get("description").equals(ResourceGeneralPage.getDescriptionText()), "VSP description is not valid.");
219 assertTrue(vspMetadata.get("subCategory").equals(GeneralUIUtils.getSelectedElementFromDropDown(ResourceGeneralPage.getCategoryDataTestsIdAttribute()).getText().toLowerCase().trim()), "VSP category is not valid.");
220 assertTrue(vspMetadata.get("vendorName").equals(ResourceGeneralPage.getVendorNameText()), "VSP vendor name is not valid.");
221 assertTrue("1.0".equals(ResourceGeneralPage.getVendorReleaseText()), "VSP version is not valid.");
222 List<WebElement> tagsList = ResourceGeneralPage.getElementsFromTagsTable();
223 assertTrue(tagsList.size() == 1, "VSP tags size is not equal to 1.");
224 assertTrue(vspName.equals(tagsList.get(0).getText()), "VSP tag is not its name.");
225 assertTrue(vspMetadata.get("attContact").equals(ResourceGeneralPage.getContactIdText()), "VSP attContact is not valid.");
228 public static void verifyIsElementDisabled(String elementLocator, String elementName){
229 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Checking if %s is disabled", elementName));
230 assertTrue(GeneralUIUtils.isElementReadOnly(elementLocator));
233 public static void verifyFilesChecksum(File actual, File expected){
235 String actualMd5OfFile = FileHandling.getMD5OfFile(actual);
236 String expectedMd5OfFile = FileHandling.getMD5OfFile(expected);
237 Assert.assertEquals(expectedMd5OfFile, actualMd5OfFile, "File does not exist");
238 } catch (IOException e) {
239 // TODO Auto-generated catch block