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.execute.AmdocsComplexService;
23 import com.aventstack.extentreports.Status;
24 import com.clearspring.analytics.util.Pair;
25 import com.google.gson.Gson;
26 import org.openecomp.sdc.be.model.Service;
27 import org.openecomp.sdc.be.model.User;
28 import org.openecomp.sdc.ci.tests.config.Config;
29 import org.openecomp.sdc.ci.tests.datatypes.*;
30 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
33 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
34 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
35 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
36 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
37 import org.openecomp.sdc.ci.tests.pages.HomePage;
38 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
39 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
40 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
41 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
42 import org.openecomp.sdc.ci.tests.utils.Utils;
43 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
44 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
45 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
46 import org.openecomp.sdc.ci.tests.verificator.VfVerificator;
47 import org.openqa.selenium.WebElement;
48 import org.testng.Assert;
50 import java.util.ArrayList;
51 import java.util.HashMap;
52 import java.util.List;
55 import static org.testng.AssertJUnit.assertEquals;
58 public class PathUtilities {
60 public static void openPathList() throws Exception {
61 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue());
62 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
65 public static ServiceReqDetails createService(User user) throws Exception {
66 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
67 ServiceUIUtils.createService(serviceMetadata, user);
68 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
69 GeneralUIUtils.ultimateWait();
70 return serviceMetadata;
73 public static List <CanvasElement> linkVFs(String vspName, int linksNum)throws Exception {
74 CompositionPage.searchForElement(vspName);
75 GeneralUIUtils.ultimateWait();
76 CanvasManager canvasManager = CanvasManager.getCanvasManager();
77 GeneralUIUtils.ultimateWait();
78 List <CanvasElement> VFs = new ArrayList<CanvasElement>();
79 VFs.add(canvasManager.createElementOnCanvas(vspName));
80 for (int i = 1; i<linksNum; i++) {
81 VFs.add(canvasManager.createElementOnCanvas(vspName));
82 GeneralUIUtils.ultimateWait();
83 // for(int a=0; a<3; a++)
85 // canvasManager.linkElements(VFs.get(i), CircleSize.VF, VFs.get(i - 1), CircleSize.VF);
87 // } catch (Exception ignore) {}
88 SetupCDTest.getExtendTest().log(Status.INFO, "link VFs");
89 GeneralUIUtils.ultimateWait();
94 public static List <CanvasElement> linkServices(String Service1, String Service2, int linksNum)throws Exception {
95 CanvasManager canvasManager = CanvasManager.getCanvasManager();
96 List <CanvasElement> VFs = new ArrayList<CanvasElement>();
99 CompositionPage.searchForElement(Service1);
100 VFs.add(canvasManager.createElementOnCanvas(Service1));
102 String service = Service2;
103 for (int i = 1; i<linksNum; i++)
105 CompositionPage.searchForElement(service);
106 VFs.add(canvasManager.createElementOnCanvas(service));
107 GeneralUIUtils.ultimateWait();
108 // for(int a=0; a<3; a++)
110 // canvasManager.linkElements(VFs.get(i), CircleSize.SERVICE, VFs.get(i-1), CircleSize.SERVICE);
112 // } catch (Exception ignore) {}
113 SetupCDTest.getExtendTest().log(Status.INFO, "link services");
114 GeneralUIUtils.ultimateWait();
116 // change service to link
117 if (service.equals(Service2)) service = Service1;
118 else service = Service2;
123 public static void openCreatePath() throws Exception{
124 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue());
125 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_PATH_MENU_BUTTON.getValue());
128 public static void sendValue(String DataTestId, String value) throws Exception {
129 GeneralUIUtils.getWebElementByTestID(DataTestId).sendKeys(value);
130 GeneralUIUtils.ultimateWait();
133 public static void insertValues(String pathName, String pathProtocol, String pathPortNumbers) throws Exception {
134 sendValue(DataTestIdEnum.ComplexServiceAmdocs.PATH_NAME.getValue(),pathName);
135 sendValue(DataTestIdEnum.ComplexServiceAmdocs.PATH_PROTOCOL.getValue(),pathProtocol);
136 sendValue(DataTestIdEnum.ComplexServiceAmdocs.PATH_PORT_NUMBER.getValue(),pathPortNumbers);
137 GeneralUIUtils.ultimateWait();
140 public static void selectFirstLineParam() throws Exception{
141 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.LINK_SOURCE.getValue()+ "']//option").get(0).click();
142 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+ DataTestIdEnum.ComplexServiceAmdocs.LINK_SOURCE_CP.getValue()+"']//option").get(0).click();
143 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET.getValue()+"']//option").get(0).click();
144 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET_CP.getValue()+"']//option").get(0).click();
147 public static void editPathName(String pathName, String newName) throws Exception{
148 GeneralUIUtils.findElementsByXpath("//*[text()='"+pathName+"']/parent::*//span").get(0).click();
149 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ComplexServiceAmdocs.PATH_NAME.getValue()).clear();
150 sendValue(DataTestIdEnum.ComplexServiceAmdocs.PATH_NAME.getValue(), newName);
151 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.SAVE.getValue());
154 public static void editPathProtocol(String pathName, String newProtocol) throws Exception{
155 GeneralUIUtils.findElementsByXpath("//*[text()='"+pathName+"']/parent::*//span").get(0).click();
156 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ComplexServiceAmdocs.PATH_PROTOCOL.getValue()).clear();
157 sendValue(DataTestIdEnum.ComplexServiceAmdocs.PATH_PROTOCOL.getValue(), newProtocol);
158 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.SAVE.getValue());
161 public static int deleteLines(int numOfLinesToDelete, int numOfLines)throws Exception{
162 for (int i=0; i<numOfLinesToDelete; i++){
163 GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.REMOVE_LINK.getValue()+"']//span").get(0).click();
166 if (GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='"+DataTestIdEnum.ComplexServiceAmdocs.LINK_TARGET_CP+"']//option").size()>(numOfLines+1))
167 throw new Exception("Path element was not deleted");
168 GeneralUIUtils.ultimateWait();
172 public static String createPath(String pathName, String vspName) throws Exception {
175 insertValues(pathName, "pathProtocol1", "pathPortNumbers1");
176 selectFirstLineParam();
177 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
178 SetupCDTest.getExtendTest().log(Status.INFO, "path" +pathName+" has been created");
182 public static void deleteComponents(List<CanvasElement> elements)throws Exception {
183 for(CanvasElement element: elements)
185 CanvasManager.getCanvasManager().clickOnCanvaElement(element);
186 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.DELETE_COMPONENT.getValue());
187 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
191 public static void updateVF(String vspName, VendorSoftwareProductObject vendorSoftwareProduct) throws Exception {
192 boolean vspFound = HomePage.searchForVSP(vspName);
194 List<WebElement> elementsFromTable = HomePage.getElemenetsFromTable();
195 elementsFromTable.get(1).click();
196 GeneralUIUtils.waitForLoader();
197 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.UPDATE_VSP.getValue());
199 OnboardingUiUtils.doCheckOut();
201 //Metadata verification
202 VfVerificator.verifyOnboardedVnfMetadata(vspName, vendorSoftwareProduct);
204 ExtentTestActions.log(Status.INFO, "Clicking create/update VNF");
205 String duration = GeneralUIUtils.getActionDuration(() -> waitUntilVnfCreated());
206 ExtentTestActions.log(Status.INFO, "Succeeded in importing/updating " + vspName, duration);
208 else Assert.fail("Did not find VSP named " + vspName);
211 public static void waitUntilVnfCreated() {
212 GeneralUIUtils.clickOnElementByTestIdWithoutWait(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
213 GeneralUIUtils.waitForLoader(60*10);
214 GeneralUIUtils.waitForAngular();
215 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
218 public static void deleteComponent(CanvasElement element)throws Exception {
219 CanvasManager.getCanvasManager().clickOnCanvaElement(element);
220 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.DELETE_COMPONENT.getValue());
221 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
224 public static void submitForTesting(){
225 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.SUBMIT_FOR_TESTING.getValue());
226 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ComplexServiceAmdocs.CHANGE_LIFE_CYCLE_MESSAGE.getValue()).sendKeys("new service to certify");
227 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.OK.getValue());
230 public static String createPathWithoutLink(String pathName, String vspName) throws Exception {
232 insertValues(pathName, "pathProtocol1", "pathPortNumbers1");
233 selectFirstLineParam();
234 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
235 SetupCDTest.getExtendTest().log(Status.INFO, "path" +pathName+" has been created");
240 private static String getServiceUUIDfromCompositionURL() throws Exception {
241 String url = SetupCDTest.getDriver().getCurrentUrl();
242 String[] result = url.split("/");
243 for(int i = 0; i < result.length; i++) if (result[i].equals("workspace")) return result[i + 1];
244 throw new Exception("service uuid not found in the url");
247 private static Map<String, String> prepareHeadersMap(String userId) {
248 Map<String, String> headersMap = new HashMap<String, String>();
249 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
250 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
251 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
255 public static Pair<RestResponse, ServiceReqDetails> getServiceIDByNameAndVersion(String serviceName, String version) throws Exception {
256 User sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
258 RestResponse restResponse = ServiceRestUtils.getServiceByNameAndVersion(sdncUserDetails, serviceName, version);
259 ServiceReqDetails service = new ServiceReqDetails();
260 service.setName(serviceName);
261 service.setUniqueId(ResponseParser.getUniqueIdFromResponse(restResponse));
262 service.setVersion(version);
264 return new Pair<>(restResponse, service);
267 public static RestResponse createServiceAPI(User sdncUserDetails, ServiceReqDetails serviceDetails) throws Exception {
268 String serviceBaseVersion = "0.1";
269 RestResponse restResponse = ServiceRestUtils.createService(serviceDetails, sdncUserDetails);
270 assertEquals("Check API response code for CreateServiceAPI call", 201, restResponse.getErrorCode().intValue());
274 public static RestResponse getServiceAPI(User sdncUserDetails, ServiceReqDetails serviceDetails) throws Exception {
275 String serviceBaseVersion = "0.1";
277 // User sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
279 // create serviceDetails
280 // ServiceReqDetails serviceDetails = ElementFactory.getDefaultService();
283 RestResponse restResponse = ServiceRestUtils.getServiceByNameAndVersion(sdncUserDetails, serviceDetails.getName(),
285 assertEquals("Check API response code for GetServiceAPI call", 200, restResponse.getErrorCode().intValue());
287 Service service = ResponseParser.convertServiceResponseToJavaObject(restResponse.getResponse());
288 String uniqueId = service.getUniqueId();
289 serviceDetails.setUniqueId(uniqueId);
290 // ServiceValidationUtils.validateServiceResponseMetaData(serviceDetails, service, sdncUserDetails, (LifecycleStateEnum) null);
294 public static RestResponse getServiceForwardingPathsAPI(String serviceName) throws Exception {
295 User sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
298 Pair<RestResponse, ServiceReqDetails> servicePaths = getServiceIDByNameAndVersion(serviceName, "0.1");
301 Config config = Utils.getConfig();
302 String url = String.format(
303 PathUrls.SERVICE_FORWARDING_PATHS,
304 config.getCatalogBeHost(),
305 config.getCatalogBePort(),
306 servicePaths.right.getUniqueId()
308 String userId = sdncUserDetails.getUserId();
310 Map<String, String> headersMap = prepareHeadersMap(userId);
312 HttpRequest http = new HttpRequest();
313 RestResponse restResponse = http.httpSendGet(url, headersMap);
314 assertEquals("Check API response code for GetServiceForwardingPathsAPI call", 200, restResponse.getErrorCode().intValue());
318 public static RestResponse getServicePathLinkMapAPI(String serviceName) throws Exception {
319 User sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
322 Pair<RestResponse, ServiceReqDetails> servicePaths = getServiceIDByNameAndVersion(serviceName, "0.1");
325 Config config = Utils.getConfig();
326 String url = String.format(
327 PathUrls.SERVICE_PATH_LINK_MAP,
328 config.getCatalogBeHost(),
329 config.getCatalogBePort(),
330 servicePaths.right.getUniqueId()
333 String userId = sdncUserDetails.getUserId();
335 Map<String, String> headersMap = prepareHeadersMap(userId);
337 HttpRequest http = new HttpRequest();
338 RestResponse restResponse = http.httpSendGet(url, headersMap);
339 assertEquals("Check API response code for GetServiceForwardingPathsAPI call", 200, restResponse.getErrorCode().intValue());
343 public static Pair<RestResponse, ServiceReqDetails> getServicePathsAPI(String serviceName) throws Exception {
344 User sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
346 Pair<RestResponse, ServiceReqDetails> servicePaths = getServiceIDByNameAndVersion(serviceName, "0.1");
349 Config config = Utils.getConfig();
350 String url = String.format(
351 PathUrls.GET_SERVICE_PATHS,
352 config.getCatalogFeHost(),
353 config.getCatalogFePort(),
354 servicePaths.right.getUniqueId());
356 String userId = sdncUserDetails.getUserId();
358 Map<String, String> headersMap = prepareHeadersMap(userId);
360 HttpRequest http = new HttpRequest();
361 RestResponse restResponse = http.httpSendGet(url, headersMap);
362 assertEquals("Check API response code for GetServiceForwardingPathsAPI call", 200, restResponse.getErrorCode().intValue());
363 return new Pair<>(restResponse, servicePaths.right);
366 public static Pair<RestResponse, OnboardItemObject> createNewItemVersion(String itemId, String itemVersion, String description, User user) throws Exception {
367 Config config = Utils.getConfig();
368 String url = String.format(
369 PathUrls.CREATE_NEW_ITEM_VERSION,
370 config.getCatalogBeHost(),
371 config.getCatalogBePort(),
372 itemId, itemVersion);
373 String userId = user.getUserId();
374 OnboardItemObject onboardItemObject = new OnboardItemObject();
376 onboardItemObject.setCreationMethod("major");
377 onboardItemObject.setDescription(description);
379 Map<String, String> headersMap = prepareHeadersMap(userId);
380 HttpRequest http = new HttpRequest();
381 Gson gson = new Gson();
382 String body = gson.toJson(onboardItemObject);
384 RestResponse response = http.httpSendPost(url, body, headersMap);
386 onboardItemObject.setItemId(ResponseParser.getValueFromJsonResponse(response.getResponse(), "id"));
387 onboardItemObject.setName(ResponseParser.getValueFromJsonResponse(response.getResponse(), "name"));
388 onboardItemObject.setBaseId(ResponseParser.getValueFromJsonResponse(response.getResponse(), "baseId"));
389 onboardItemObject.setStatus(ResponseParser.getValueFromJsonResponse(response.getResponse(), "status"));
391 return new Pair<>(response, onboardItemObject);
394 public static RestResponse updateVendorSoftwareProduct(VendorSoftwareProductObject vendorSoftwareProductObject, User user) throws Exception {
395 Config config = Utils.getConfig();
396 String url = String.format(
397 PathUrls.UPDATE_VENDOR_SOFTWARE_PRODUCT,
398 config.getCatalogBeHost(),
399 config.getCatalogBePort(),
400 vendorSoftwareProductObject.getVspId(),
401 vendorSoftwareProductObject.getComponentId());
402 String userId = user.getUserId();
403 VendorSoftwareProductObject updateVendorSoftwareProductObject = new VendorSoftwareProductObject();
405 updateVendorSoftwareProductObject.setName(vendorSoftwareProductObject.getName());
406 updateVendorSoftwareProductObject.setDescription(vendorSoftwareProductObject.getDescription());
407 updateVendorSoftwareProductObject.setCategory(vendorSoftwareProductObject.getCategory());
408 updateVendorSoftwareProductObject.setSubCategory(vendorSoftwareProductObject.getSubCategory());
409 updateVendorSoftwareProductObject.setVendorName(vendorSoftwareProductObject.getVendorName());
410 updateVendorSoftwareProductObject.setVendorId(vendorSoftwareProductObject.getVendorId());
411 updateVendorSoftwareProductObject.setIcon(vendorSoftwareProductObject.getIcon());
412 updateVendorSoftwareProductObject.setLicensingData(vendorSoftwareProductObject.getLicensingData());
413 updateVendorSoftwareProductObject.setLicensingVersion(vendorSoftwareProductObject.getLicensingVersion());
415 Map<String, String> headersMap = prepareHeadersMap(userId);
416 HttpRequest http = new HttpRequest();
417 Gson gson = new Gson();
418 String body = gson.toJson(updateVendorSoftwareProductObject);
420 return http.httpSendPut(url, body, headersMap);