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.assertTrue;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Random;
31 import java.util.function.Predicate;
32 import java.util.stream.Collector;
33 import java.util.stream.Collectors;
34 import java.util.stream.Stream;
36 import org.json.simple.JSONArray;
37 import org.json.simple.JSONObject;
38 import org.json.simple.JSONValue;
39 import org.openecomp.sdc.be.model.GroupInstance;
40 import org.openecomp.sdc.be.model.GroupInstanceProperty;
41 import org.openecomp.sdc.be.model.LifecycleStateEnum;
42 import org.openecomp.sdc.be.model.Service;
43 import org.openecomp.sdc.be.model.User;
44 import org.openecomp.sdc.ci.tests.datatypes.ComponentReqDetails;
45 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
46 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.PropertiesPopupEnum;
47 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
48 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
49 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
50 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
51 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
52 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
53 import org.openecomp.sdc.ci.tests.pages.DeploymentPage;
54 import org.openecomp.sdc.ci.tests.pages.PropertyPopup;
55 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
56 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
57 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
58 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
59 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
60 import org.openqa.selenium.By;
61 import org.openqa.selenium.WebElement;
62 import org.openqa.selenium.support.ui.Select;
64 import com.aventstack.extentreports.Status;
66 public class ServiceVerificator {
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();
81 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
82 int size = ((JSONArray) jsonResource.get("componentInstances")).size();
83 assertTrue(size == numOfVFC);
84 ExtentTestActions.log(Status.INFO, "The number of components on the canvas was verified.");
87 public static void verifyServiceUpdatedInUI(ServiceReqDetails service) {
88 assertTrue(service.getName().equals(ResourceGeneralPage.getNameText()));
89 assertTrue(service.getDescription().equals(ResourceGeneralPage.getDescriptionText()));
90 assertTrue(service.getCategory().equals(ServiceGeneralPage.getCategoryText()));
91 assertTrue(service.getProjectCode().equals(ServiceGeneralPage.getProjectCodeText()));
92 for(String tag: ServiceGeneralPage.getTags()){
93 assertTrue(service.getTags().contains(tag));
95 assertTrue(service.getContactId().equals(ResourceGeneralPage.getContactIdText()));
98 public static void verifyServiceDeletedInUI(ServiceReqDetails service) throws InterruptedException {
100 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.DASHBOARD_CARD.getValue());
101 if (!(cardElements.isEmpty())){
102 for (WebElement cardElement: cardElements){
103 WebElement componentName = GeneralUIUtils.getElementfromElementByCSS(cardElement,
104 DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
105 WebElement componentType = GeneralUIUtils.getElementfromElementByCSS(cardElement,
106 DataTestIdEnum.DashboardCardEnum.ASSET_TYPE_CSS.getValue());
108 String componentNameStr = componentName.getAttribute("textContent").trim(),
109 componentTypeStr = componentType.getAttribute("class");
111 if(componentTypeStr.equals("S")){
112 assertTrue( !(componentNameStr.equals(service.getName())), "Deleted service was found !!!");
118 public static void verifyServiceLifecycle(ServiceReqDetails service, User user, LifecycleStateEnum expectedLifecycleState) {
119 String responseAfterDrag = RestCDUtils.getService(service, user).getResponse();
120 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
121 String actualLifecycleState = jsonResource.get("lifecycleState").toString();
122 assertTrue(expectedLifecycleState.name().equals(actualLifecycleState), "actual: " + actualLifecycleState + "-- expected: " + expectedLifecycleState);
125 public static void verifyLinkCreated(ServiceReqDetails createServiceInUI, User user, int expectedRelationsSize) {
126 String responseAfterDrag = RestCDUtils.getService(createServiceInUI, user).getResponse();
127 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
128 assertTrue(((JSONArray) jsonResource.get("componentInstancesRelations")).size() == expectedRelationsSize);
132 public static void verifyManagmentWorkflow(String expectedName, String expectedDescription){
133 String actualName = GeneralUIUtils.getWebElementBy(By.cssSelector("div[class='text name']")).getText();
134 String actualDescription = GeneralUIUtils.getWebElementBy(By.cssSelector("div[class='text description']")).getText();
135 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Verifing name ( should be %s ) and description ( should be %s ) ", expectedName, expectedDescription));
136 assertTrue(actualName.equals(expectedName) && actualDescription.equals(expectedDescription));
139 public static void verifyVersionUI(String expected){
140 String actualVersion = GeneralUIUtils.getSelectedElementFromDropDown(DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue()).getText().replace("V", "");
141 assertTrue(actualVersion.equals(expected), String.format( "Expected version: %s, Actual version: %s", expected, actualVersion));
144 public static void verifyOpenTabTitle(DataTestIdEnum.CompositionScreenEnum currentTab) throws Exception{
145 List<String> expectedTitles = new ArrayList<String>();
146 for(String expectedTitle: currentTab.getTitle()){
147 expectedTitles.add(expectedTitle);
149 for (WebElement actualTitle: CompositionPage.getOpenTabTitle()){
150 int indexOfTitle = expectedTitles.indexOf(actualTitle.getText());
151 assertTrue(indexOfTitle >= 0, "Wrong title");
152 expectedTitles.remove(indexOfTitle);
154 assertTrue(expectedTitles.size() == 0, "Missing titles in " + currentTab.getValue());
157 public static void verifyDeploymentPageSubElements(String moduleName, DeploymentViewVerificator verificatorObj) throws Exception{
158 HashMap<String, List<String>> moduleProperties = verificatorObj.getDeploymentViewData().get(moduleName);
160 ServiceVerificator.moveMetadataPropertiesArtifactSection(-700);
162 List<WebElement> artifacts, properties;
163 artifacts = DeploymentPage.getArtifactNames();
164 properties = DeploymentPage.getPropertyNames();
165 assertTrue(moduleProperties.get("artifacts").size() == artifacts.size(), "Artifacts amount not as expected, expected " + moduleProperties.get("artifacts").size());
166 assertTrue(moduleProperties.get("artifacts").containsAll(artifacts.stream().
167 map(e -> e.getAttribute("textContent")).
168 collect(Collectors.toList())));
169 assertTrue(moduleProperties.get("properties").size() == properties.size(), "Properties amount not as expected, expected " + moduleProperties.get("properties").size());
170 assertTrue(moduleProperties.get("properties").containsAll(properties.stream().
171 map(e -> e.getAttribute("textContent")).
172 collect(Collectors.toList())));
174 DeploymentPage.clickOnProperties();
175 DeploymentPage.clickOnArtifacts();
176 ServiceVerificator.moveMetadataPropertiesArtifactSection(700);
179 public static void verifyVFModuleCustomizationUUID(ServiceReqDetails service) throws Exception {
180 Predicate<String> componentInstancePredicate = e -> e.length() > 35;
181 List<String> customizationUUIDList = getAllVFModuleCustomizationUUIDs(service);
182 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating vfModuleCustomizationUUID uniqness ... "));
183 assertTrue(customizationUUIDList.stream().allMatch(componentInstancePredicate), "vfModuleCustomizationUUID is less then 35 chars");
184 CustomizationUUIDVerificator.validateCustomizationUUIDuniqueness(customizationUUIDList);
187 public static List<String> getAllVFModuleCustomizationUUIDs(ServiceReqDetails service) throws Exception {
188 Service serviceObj = AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, service.getName(), service.getVersion());
189 List<String> customizationUUIDList = serviceObj.getComponentInstances().get(0).getGroupInstances().stream().
190 map(e -> e.getCustomizationUUID()).
191 collect(Collectors.toList());
193 return customizationUUIDList;
196 public static String getVFModulePropertieValue(ServiceReqDetails service, String propertyName, String moduleName) throws Exception {
197 Service serviceObj = AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, service.getName(), service.getVersion());
198 List<GroupInstance> groupInstances = serviceObj.getComponentInstances().get(0).getGroupInstances();
199 List<GroupInstanceProperty> groupInstancesProperties = groupInstances.stream().
200 filter(e -> e.getName().equals(moduleName)).
203 convertToGroupInstancesProperties();
204 String propertieValue = groupInstancesProperties.stream().
205 filter(e -> e.getName().equals(propertyName)).
209 return propertieValue;
212 public static boolean isEqualCustomizationUUIDsAfterChanges(List<String> listBefore, List<String> listAfter){
213 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating if vfModuleCustomizationUUID changed after certification ... "));
214 return (listBefore.size() == listAfter.size()) && (listBefore.containsAll(listAfter));
217 public static void verifyDisabledServiceProperties() throws Exception{
218 List<String> propertiesForCheck = Arrays.asList("isBase", "vf_module_type", "vf_module_label", "vf_module_description");
219 List<PropertiesPopupEnum> popupElementsForCheck = Arrays.asList(PropertiesPopupEnum.PROPERTY_NAME,
220 PropertiesPopupEnum.PROPERTY_DESCRIPTION,
221 PropertiesPopupEnum.PROPERTY_TYPE,
222 PropertiesPopupEnum.PROPERTY_VALUE);
223 ServiceVerificator.moveMetadataPropertiesArtifactSection(-700);
224 List<WebElement> properties = DeploymentPage.getPropertyNames();
226 for(WebElement property : properties){
227 if (propertiesForCheck.contains(property.getAttribute("textContent"))){
228 DeploymentPage.clickOnProperty(property);
229 Select propertTypeElement = new Select(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPopupEnum.PROPERTY_TYPE.getValue()));
230 boolean isTypeBoolean = propertTypeElement.getFirstSelectedOption().getText().contains("boolean");
231 for (PropertiesPopupEnum popupElement: popupElementsForCheck){
232 if (isTypeBoolean && popupElement == PropertiesPopupEnum.PROPERTY_VALUE){
233 assertTrue(GeneralUIUtils.checkForDisabledAttribute(DataTestIdEnum.PropertiesPopupEnum.PROPERTY_BOOLEAN_VALUE.getValue()), String.format("Element %s not disabled ", property.getText()));
235 assertTrue(GeneralUIUtils.checkForDisabledAttribute(popupElement.getValue()), String.format("Element %s not disabled ", property.getText()));
238 new PropertyPopup().clickCancel();
242 DeploymentPage.clickOnProperties();
243 ServiceVerificator.moveMetadataPropertiesArtifactSection(700);
246 public static void verifyEnabledServiceProperties() throws Exception{
247 List<String> propertiesForCheck = Arrays.asList("initial_count", "max_vf_module_instances", "min_vf_module_instances");
249 ServiceVerificator.moveMetadataPropertiesArtifactSection(-700);
250 List<WebElement> properties = DeploymentPage.getPropertyNames();
252 ServiceVerificator.positiveFlow(propertiesForCheck, properties);
253 ServiceVerificator.negativeFlow(propertiesForCheck, properties);
255 DeploymentPage.clickOnProperties();
256 ServiceVerificator.moveMetadataPropertiesArtifactSection(700);
259 public static void positiveFlow(List<String> propertiesForCheck, List<WebElement> properties)
260 throws InterruptedException {
261 int baseNumber = new Random().nextInt(100) + 2;
262 for(WebElement property : properties){
263 String propertyName = property.getAttribute("textContent");
264 if (propertiesForCheck.contains(propertyName)){
265 DeploymentPage.clickOnProperty(property);
266 int actualNumber = 0;
267 if (propertyName.equals("initial_count")){
268 actualNumber = baseNumber;
269 } else if (propertyName.equals("max_vf_module_instances")) {
270 actualNumber = baseNumber + 1;
271 } else if (propertyName.equals("min_vf_module_instances")){
272 actualNumber = baseNumber - 1;
275 new PropertyPopup().insertPropertyDefaultValue(String.valueOf(actualNumber));
276 new PropertyPopup().clickSave();
277 assertTrue(DeploymentPage.getPropertyValueFromPropertiesList(propertyName).equals(String.valueOf(actualNumber)));
282 public static void negativeFlow(List<String> propertiesForCheck, List<WebElement> properties)
284 int currentMaxValue = Integer.valueOf(DeploymentPage.getPropertyValueFromPropertiesList("max_vf_module_instances"));
285 int currentMinValue = Integer.valueOf(DeploymentPage.getPropertyValueFromPropertiesList("min_vf_module_instances"));
286 int currentInitialValue = Integer.valueOf(DeploymentPage.getPropertyValueFromPropertiesList("initial_count"));
287 PropertyPopup propertyPopupObj = new PropertyPopup();
289 for(WebElement property : properties){
290 String propertyName = property.getAttribute("textContent");
291 if (propertiesForCheck.contains(propertyName)){
292 DeploymentPage.clickOnProperty(property);
293 if (propertyName.equals("initial_count")){
295 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMaxValue + 1));
296 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
297 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMinValue - 1));
298 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
299 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(0));
300 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
302 } else if (propertyName.equals("max_vf_module_instances")) {
304 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentInitialValue - 1));
305 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
306 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMinValue - 1));
307 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
308 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(0));
309 verifyErrorPresentAndSaveDisabled();
311 } else if (propertyName.equals("min_vf_module_instances")){
313 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentInitialValue + 1));
314 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
315 propertyPopupObj.insertPropertyDefaultValue(String.valueOf(currentMaxValue + 1));
316 ServiceVerificator.verifyErrorPresentAndSaveDisabled();
319 new PropertyPopup().clickCancel();
324 public static void verifyErrorPresentAndSaveDisabled() throws Exception{
325 assertTrue(DeploymentPage.isPropertySaveButtonDisabled());
326 assertTrue(DeploymentPage.getPropertyErrorValidationMessdge().size() == 1);
329 public static void moveMetadataPropertiesArtifactSection(int offset) throws InterruptedException {
330 WebElement dragLineElement = GeneralUIUtils.getElementByCSS("div.rg-top");
331 GeneralUIUtils.dragAndDropElementByY(dragLineElement, offset);