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 com.aventstack.extentreports.Status;
24 import org.json.simple.JSONArray;
25 import org.json.simple.JSONObject;
26 import org.json.simple.JSONValue;
27 import org.openecomp.sdc.be.model.GroupInstance;
28 import org.openecomp.sdc.be.model.GroupInstanceProperty;
29 import org.openecomp.sdc.be.model.LifecycleStateEnum;
30 import org.openecomp.sdc.be.model.Service;
31 import org.openecomp.sdc.be.model.User;
32 import org.openecomp.sdc.ci.tests.datatypes.ComponentReqDetails;
33 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.PropertiesPopupEnum;
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.ServiceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
39 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
40 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
41 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
42 import org.openecomp.sdc.ci.tests.pages.DeploymentPage;
43 import org.openecomp.sdc.ci.tests.pages.PropertyPopup;
44 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
45 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
46 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
47 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
48 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
49 import org.openqa.selenium.By;
50 import org.openqa.selenium.WebElement;
51 import org.openqa.selenium.support.ui.Select;
53 import java.util.ArrayList;
54 import java.util.Arrays;
55 import java.util.HashMap;
56 import java.util.List;
57 import java.util.Random;
58 import java.util.function.Predicate;
59 import java.util.stream.Collectors;
61 import static org.testng.Assert.assertTrue;
63 public class ServiceVerificator {
65 private static final int SLEEP_TIME = 1000;
66 private static final int ARTIFACT_SECTION_OFFSET = 700;
68 private ServiceVerificator() {
71 public static void verifyNumOfComponentInstances(ComponentReqDetails component, String version, int numOfVFC,
73 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifing the number of components on the canvas; should be %s", numOfVFC));
74 String responseAfterDrag = null;
75 component.setVersion(version);
76 if (component instanceof ServiceReqDetails) {
77 responseAfterDrag = RestCDUtils.getService((ServiceReqDetails) component, user).getResponse();
78 } else if (component instanceof ResourceReqDetails) {
79 responseAfterDrag = RestCDUtils.getResource((ResourceReqDetails) component, user).getResponse();
82 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
83 if(jsonResource.get("componentInstances")!= null){
84 size = ((JSONArray) jsonResource.get("componentInstances")).size();
85 assertTrue(size == numOfVFC, "Expected number of componenet instances is " + numOfVFC + ", but actual is " + size);
86 ExtentTestActions.log(Status.INFO, "The number of components on the canvas was verified.");
88 assertTrue(false, "Expected number of componenet instances is " + numOfVFC + ", but actual is " + size);
92 public static void verifyServiceUpdatedInUI(ServiceReqDetails service) {
93 assertTrue(service.getName().equals(ResourceGeneralPage.getNameText()));
94 assertTrue(service.getDescription().equals(ResourceGeneralPage.getDescriptionText()));
95 assertTrue(service.getCategory().equals(ServiceGeneralPage.getCategoryText()));
96 assertTrue(service.getServiceFunction().equals(ServiceGeneralPage.getServiceFunctionText()));
97 assertTrue(service.getNamingPolicy().equals(ServiceGeneralPage.getNamingPolicyText()));
98 for(String tag: ServiceGeneralPage.getTags()){
99 assertTrue(service.getTags().contains(tag));
101 assertTrue(service.getContactId().equals(ResourceGeneralPage.getContactIdText()));
104 public static void verifyServiceDeletedInUI(ServiceReqDetails service) throws InterruptedException {
106 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.DASHBOARD_CARD.getValue());
107 if (!(cardElements.isEmpty())){
108 for (WebElement cardElement: cardElements){
109 WebElement componentName = GeneralUIUtils.getElementfromElementByCSS(cardElement,
110 DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
111 WebElement componentType = GeneralUIUtils.getElementfromElementByCSS(cardElement,
112 DataTestIdEnum.DashboardCardEnum.ASSET_TYPE_CSS.getValue());
114 String componentNameStr = componentName.getAttribute("textContent").trim(),
115 componentTypeStr = componentType.getAttribute("class");
117 if (componentTypeStr.equals("S")) {
118 assertTrue(!(componentNameStr.equals(service.getName())), "Deleted service was found !!!");
124 public static void verifyServiceLifecycle(ServiceReqDetails service, User user, LifecycleStateEnum expectedLifecycleState) {
125 String responseAfterDrag = RestCDUtils.getService(service, user).getResponse();
126 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
127 String actualLifecycleState = jsonResource.get("lifecycleState").toString();
128 assertTrue(expectedLifecycleState.name().equals(actualLifecycleState), "actual: " + actualLifecycleState + "-- expected: " + expectedLifecycleState);
131 public static void verifyServiceLifecycleInUI(LifeCycleStateEnum lifecycleState) {
132 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verfiying that service state is %s", lifecycleState.getValue()));
133 GeneralUIUtils.ultimateWait();
134 assertTrue(ResourceGeneralPage.getLifeCycleState().equals(lifecycleState.getValue()));
137 public static void verifyLinkCreated(ServiceReqDetails createServiceInUI, User user, int expectedRelationsSize) {
138 String responseAfterDrag = RestCDUtils.getService(createServiceInUI, user).getResponse();
139 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
140 assertTrue(((JSONArray) jsonResource.get("componentInstancesRelations")).size() == expectedRelationsSize);
144 public static void verifyManagmentWorkflow(String expectedName, String expectedDescription) {
145 String actualName = GeneralUIUtils.getWebElementBy(By.cssSelector("div[class='text name']")).getText();
146 String actualDescription = GeneralUIUtils.getWebElementBy(By.cssSelector("div[class='text description']")).getText();
147 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifing name ( should be %s ) and description ( should be %s ) ", expectedName, expectedDescription));
148 assertTrue(actualName.equals(expectedName) && actualDescription.equals(expectedDescription));
151 public static void verifyVersionUI(String expected) {
152 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifying that version is %s", expected));
153 String actualVersion = GeneralUIUtils.getSelectedElementFromDropDown(DataTestIdEnum.
154 GeneralElementsEnum.VERSION_HEADER.getValue()).getText().replace("V", "");
155 assertTrue(actualVersion.equals(expected), String.format("Expected version: %s, Actual version: %s", expected, actualVersion));
158 public static void verifyResourceInstanceVersionUI(String expected) {
159 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifying that instance version is %s", expected));
160 List<WebElement> selectedVersion = GeneralUIUtils.
161 findElementsByXpath("//option[contains(@class,\"select-instance-version\") and contains (@selected, \"selected\")]");
162 String actual = selectedVersion.get(0).getText();
163 assertTrue(expected.equals(actual), String.format("Expected version: %s, Actual version: %s", expected, actual));
166 public static void verifyOpenTabTitle(DataTestIdEnum.CompositionScreenEnum currentTab) throws Exception {
167 List<String> expectedTitles = new ArrayList<String>();
168 for (String expectedTitle : currentTab.getTitle()) {
169 expectedTitles.add(expectedTitle.toLowerCase());
171 for (WebElement actualTitle : CompositionPage.getOpenTabTitle()) {
172 int indexOfTitle = expectedTitles.indexOf(actualTitle.getText().trim().toLowerCase());
173 assertTrue(indexOfTitle >= 0, "Wrong title");
174 expectedTitles.remove(indexOfTitle);
176 assertTrue(expectedTitles.size() == 0, "Missing titles in " + currentTab.getValue());
179 public static void verifyDeploymentPageSubElements(String moduleName, DeploymentViewVerificator verificatorObj) throws Exception {
181 HashMap<String, List<String>> moduleProperties = verificatorObj.getDeploymentViewData().get(moduleName);
183 ServiceVerificator.moveMetadataPropertiesArtifactSection(-ARTIFACT_SECTION_OFFSET);
185 List<WebElement> artifacts, properties;
186 artifacts = DeploymentPage.getArtifactNames();
187 properties = DeploymentPage.getPropertyNames();
188 assertTrue(moduleProperties.get("artifacts").size() == artifacts.size(), "Artifacts amount not as expected, expected " + moduleProperties.get("artifacts").size());
189 assertTrue(moduleProperties.get("artifacts").containsAll(artifacts.stream().
190 map(e -> e.getAttribute("textContent")).
191 collect(Collectors.toList())));
192 assertTrue(moduleProperties.get("properties").size() == properties.size(), "Properties amount not as expected, expected " + moduleProperties.get("properties").size());
193 assertTrue(moduleProperties.get("properties").containsAll(properties.stream().
194 map(e -> e.getAttribute("textContent")).
195 collect(Collectors.toList())));
197 DeploymentPage.clickOnProperties();
198 DeploymentPage.clickOnArtifacts();
199 ServiceVerificator.moveMetadataPropertiesArtifactSection(ARTIFACT_SECTION_OFFSET);
202 public static void verifyVFModuleCustomizationUUID(ServiceReqDetails service) throws Exception {
203 final int UUIDMinimalLength = 35;
204 Predicate<String> componentInstancePredicate = e -> e.length() > UUIDMinimalLength;
205 List<String> customizationUUIDList = getAllVFModuleCustomizationUUIDs(service);
206 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating vfModuleCustomizationUUID uniqness ... "));
207 assertTrue(customizationUUIDList.stream().allMatch(componentInstancePredicate), "vfModuleCustomizationUUID is less then 35 chars");
208 CustomizationUUIDVerificator.validateCustomizationUUIDuniqueness(customizationUUIDList);
211 public static List<String> getAllVFModuleCustomizationUUIDs(ServiceReqDetails service) throws Exception {
212 Service serviceObj = AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, service.getName(), service.getVersion());
213 List<String> customizationUUIDList = serviceObj.getComponentInstances().get(0).getGroupInstances().stream().
214 map(e -> e.getCustomizationUUID()).
215 collect(Collectors.toList());
217 return customizationUUIDList;
220 public static String getVFModulePropertyValue(ServiceReqDetails service, String propertyName, String moduleName) throws Exception {
221 Service serviceObj = AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, service.getName(), service.getVersion());
222 List<GroupInstance> groupInstances = serviceObj.getComponentInstances().get(0).getGroupInstances();
223 List<GroupInstanceProperty> groupInstancesProperties = groupInstances.stream().
224 filter(e -> e.getName().equals(moduleName)).
227 convertToGroupInstancesProperties();
228 String propertyValue = groupInstancesProperties.stream().
229 filter(e -> e.getName().equals(propertyName)).
233 return propertyValue;
236 public static boolean isEqualCustomizationUUIDsAfterChanges(List<String> listBefore, List<String> listAfter) {
237 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating if vfModuleCustomizationUUID changed after certification ... "));
238 return (listBefore.size() == listAfter.size()) && (listBefore.containsAll(listAfter));
241 public static void verifyDisabledServiceProperties() throws Exception {
242 List<String> propertiesForCheck = Arrays.asList("isBase", "vf_module_type", "vf_module_label", "vf_module_description");
243 List<PropertiesPopupEnum> popupElementsForCheck = Arrays.asList(PropertiesPopupEnum.PROPERTY_NAME,
244 PropertiesPopupEnum.PROPERTY_DESCRIPTION,
245 PropertiesPopupEnum.PROPERTY_TYPE,
246 PropertiesPopupEnum.PROPERTY_VALUE);
247 ServiceVerificator.moveMetadataPropertiesArtifactSection(-ARTIFACT_SECTION_OFFSET);
248 List<WebElement> properties = DeploymentPage.getPropertyNames();
250 for (WebElement property : properties) {
251 if (propertiesForCheck.contains(property.getAttribute("textContent"))) {
252 DeploymentPage.clickOnProperty(property);
253 Select propertTypeElement = new Select(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPopupEnum.PROPERTY_TYPE.getValue()));
254 boolean isTypeBoolean = propertTypeElement.getFirstSelectedOption().getText().contains("boolean");
255 for (PropertiesPopupEnum popupElement : popupElementsForCheck) {
256 if (isTypeBoolean && popupElement == PropertiesPopupEnum.PROPERTY_VALUE) {
257 assertTrue(GeneralUIUtils.checkForDisabledAttribute(DataTestIdEnum.PropertiesPopupEnum.PROPERTY_BOOLEAN_VALUE.getValue()), String.format("Element %s not disabled ", property.getText()));
259 assertTrue(GeneralUIUtils.checkForDisabledAttribute(popupElement.getValue()), String.format("Element %s not disabled ", property.getText()));
262 new PropertyPopup().clickCancel();
266 DeploymentPage.clickOnProperties();
267 ServiceVerificator.moveMetadataPropertiesArtifactSection(ARTIFACT_SECTION_OFFSET);
270 public static void verifyEnabledServiceProperties() throws Exception {
271 List<String> propertiesForCheck = Arrays.asList("initial_count", "max_vf_module_instances", "min_vf_module_instances");
273 ServiceVerificator.moveMetadataPropertiesArtifactSection(-ARTIFACT_SECTION_OFFSET);
274 List<WebElement> properties = DeploymentPage.getPropertyNames();
276 ServiceVerificator.positiveFlow(propertiesForCheck, properties);
277 ServiceVerificator.negativeFlow(propertiesForCheck, properties);
279 DeploymentPage.clickOnProperties();
280 ServiceVerificator.moveMetadataPropertiesArtifactSection(ARTIFACT_SECTION_OFFSET);
283 public static void positiveFlow(List<String> propertiesForCheck, List<WebElement> properties)
284 throws InterruptedException {
285 final int randomInteger = 100;
286 int baseNumber = new Random().nextInt(randomInteger) + 2;
287 for (WebElement property : properties) {
288 String propertyName = property.getAttribute("textContent");
289 if (propertiesForCheck.contains(propertyName)) {
290 DeploymentPage.clickOnProperty(property);
291 int actualNumber = 0;
292 if (propertyName.equals("initial_count")) {
293 actualNumber = baseNumber;
294 } else if (propertyName.equals("max_vf_module_instances")) {
295 actualNumber = baseNumber + 1;
296 } else if (propertyName.equals("min_vf_module_instances")) {
297 actualNumber = baseNumber - 1;
300 new PropertyPopup().insertPropertyDefaultValue(String.valueOf(actualNumber));
301 new PropertyPopup().clickSave();
302 assertTrue(DeploymentPage.getPropertyValueFromPropertiesList(propertyName).equals(String.valueOf(actualNumber)));
307 public static void negativeFlow(List<String> propertiesForCheck, List<WebElement> properties)
309 int currentMaxValue = Integer.valueOf(DeploymentPage.getPropertyValueFromPropertiesList("max_vf_module_instances"));
310 int currentMinValue = Integer.valueOf(DeploymentPage.getPropertyValueFromPropertiesList("min_vf_module_instances"));
311 int currentInitialValue = Integer.valueOf(DeploymentPage.getPropertyValueFromPropertiesList("initial_count"));
312 PropertyPopup propertyPopupObj = new PropertyPopup();
314 for (WebElement property : properties) {
315 String propertyName = property.getAttribute("textContent");
316 if (propertiesForCheck.contains(propertyName)) {
317 DeploymentPage.clickOnProperty(property);
318 if (propertyName.equals("initial_count")) {
320 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMaxValue + 1));
321 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
322 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMinValue - 1));
323 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
324 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(0));
325 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
327 } else if (propertyName.equals("max_vf_module_instances")) {
329 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentInitialValue - 1));
330 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
331 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMinValue - 1));
332 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
333 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(0));
334 verifyErrorPresentAndSaveDisabled();
336 } else if (propertyName.equals("min_vf_module_instances")) {
338 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentInitialValue + 1));
339 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
340 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMaxValue + 1));
341 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
344 new PropertyPopup().clickCancel();
349 public static void verifyErrorPresentAndSaveDisabled() throws Exception {
350 assertTrue(DeploymentPage.isPropertySaveButtonDisabled(), "Property Save button enabled, should be disabled");
351 assertTrue(DeploymentPage.getPropertyErrorValidationMessdge().size() == 1, "Error msg missing for input");
354 public static void moveMetadataPropertiesArtifactSection(int offset) throws InterruptedException {
355 WebElement dragLineElement = GeneralUIUtils.getElementByCSS("div.rg-top");
356 GeneralUIUtils.dragAndDropElementByY(dragLineElement, offset);