2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.onap.sdc.frontend.ci.tests.utilities;
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.onap.sdc.backend.ci.tests.datatypes.enums.ResourceCategoryEnum;
26 import org.onap.sdc.backend.ci.tests.datatypes.http.RestResponse;
27 import org.onap.sdc.frontend.ci.tests.pages.CompositionPage;
28 import org.onap.sdc.frontend.ci.tests.pages.ServiceGeneralPage;
29 import org.onap.sdc.backend.ci.tests.utils.general.FileHandling;
30 import org.onap.sdc.backend.ci.tests.utils.rest.PropertyRestUtils;
31 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
32 import org.openecomp.sdc.be.model.Component;
33 import org.openecomp.sdc.be.model.ComponentInstance;
34 import org.openecomp.sdc.be.model.InputDefinition;
35 import org.openecomp.sdc.be.model.Resource;
36 import org.openecomp.sdc.be.model.Service;
37 import org.openecomp.sdc.be.model.User;
38 import org.onap.sdc.frontend.ci.tests.datatypes.CanvasElement;
39 import org.onap.sdc.frontend.ci.tests.datatypes.CanvasManager;
40 import org.onap.sdc.frontend.ci.tests.datatypes.ConnectionWizardPopUpObject;
41 import org.onap.sdc.frontend.ci.tests.datatypes.PortMirrioringConfigurationObject;
42 import org.onap.sdc.frontend.ci.tests.datatypes.PortMirroringEnum;
43 import org.onap.sdc.backend.ci.tests.datatypes.PropertyObject;
44 import org.onap.sdc.backend.ci.tests.datatypes.ResourceReqDetails;
45 import org.onap.sdc.frontend.ci.tests.datatypes.ServiceContainer;
46 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
47 import org.onap.sdc.frontend.ci.tests.datatypes.TopMenuButtonsEnum;
48 import org.onap.sdc.backend.ci.tests.datatypes.VendorLicenseModel;
49 import org.onap.sdc.backend.ci.tests.datatypes.VendorSoftwareProductObject;
50 import org.onap.sdc.backend.ci.tests.datatypes.enums.LifeCycleStatesEnum;
51 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
52 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
53 import org.onap.sdc.backend.ci.tests.utils.general.AtomicOperationUtils;
54 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
55 import org.onap.sdc.backend.ci.tests.utils.general.OnboardingUtillViaApis;
56 import org.onap.sdc.backend.ci.tests.utils.general.VendorLicenseModelRestUtils;
57 import org.onap.sdc.backend.ci.tests.utils.general.VendorSoftwareProductRestUtils;
59 import java.util.List;
62 public class PortMirroringUtils {
65 private static final int WAITING_FOR_LOADER_TIME_OUT = 2000;
67 private PortMirroringUtils() {
71 public static ServiceContainer createServiceFromHeatFile(String filePath, String vnfFile) throws Throwable {
73 User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
74 VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(sdncDesignerDetails1);
75 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Vendor Software License (VLM): %s v1.0", vendorLicenseModel
76 .getVendorLicenseName()));
77 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
78 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Vendor Software Product (VSP): %s v1.0 from heat file: %s ", resourceReqDetails.getName(), vnfFile));
79 VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails1,
81 // VendorSoftwareProductObject vendorSoftwareProductObject = OnboardViaApis.fillVendorSoftwareProductObjectWithMetaData(vnfFile, createVendorSoftwareProduct);
82 //2. Create VF, certify - v1.0 is created
83 resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
84 Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
85 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
86 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Virtual Function (VF): %s v1.0", resourceReqDetails.getName()));
87 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Certify the VF"));
88 //3. Create Service add to it the certified VF and certify the Service v1.0
89 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
90 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
91 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Service: %s v1.0", serviceReqDetails.getName()));
92 Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
93 ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();
94 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Adding VF instance to Service"));
95 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
96 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Certify the Service"));
98 return new ServiceContainer(service, resource, vendorSoftwareProductObject, vendorLicenseModel);
101 public static Resource generatePNFAndUpdateInput(String resourceName, String vendorModelNumber, User user) throws Exception {
102 Resource resource = getresourcebytype(ResourceTypeEnum.PNF, resourceName, vendorModelNumber);
103 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating pnf %s and certify it", resource.getName()));
104 Component componentObject = AtomicOperationUtils.getComponentObject(resource, UserRoleEnum.DESIGNER);
105 updateResourceInputViaAPI(user, componentObject, "physicalProbe", "nf_role");
106 resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
110 private static void updateResourceInputViaAPI(User user, Component componentObject, String defaultValue, String inputName) throws Exception {
111 List<InputDefinition> componentInputs = componentObject.getInputs();
112 PropertyObject propertyObject = new PropertyObject(defaultValue, inputName, componentInputs.get(1).getParentUniqueId(), componentInputs.get(1).getUniqueId());
113 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Update input %s to %s", "nf_role", "physicalProbe"));
114 PropertyRestUtils.updateInput(componentObject, propertyObject, user);
117 public static Resource getresourcebytype(ResourceTypeEnum resourceTypeEnum, String resourceName, String vendorModelNumber) {
118 ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(resourceTypeEnum, resourceName, ResourceCategoryEnum.NETWORK_L2_3_INFRASTRUCTURE, resourceName, vendorModelNumber);
119 return AtomicOperationUtils.createResourceByResourceDetails(resourceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
122 public static String createproxyinstanceservicename(String serviceName, String instanceId) {
123 String serviceProxyInstanceName = String.format("%s_proxy %s", serviceName, instanceId);
124 return serviceProxyInstanceName;
127 public static PortMirrioringConfigurationObject createPortMirriongConfigurationStructure(boolean isCapPropAssign) throws Throwable {
129 //Using API onboard and certify 2 zip files Source: vmmme and Collector: Vprobe
130 String filePath = FileHandling.getPortMirroringRepositoryPath();
131 ServiceContainer serviceContainerVmme_Source = PortMirroringUtils.createServiceFromHeatFile(filePath, PortMirroringEnum.VMME_ZIP.getValue());
132 ServiceContainer serviceContainerVprobe_Collector = PortMirroringUtils.createServiceFromHeatFile(filePath, PortMirroringEnum.VPROBE_ZIP.getValue());
135 ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
136 //ServiceUIUtils.createService(serviceMetadata, getUser());
138 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating container %s: ", serviceReqDetails.getName()));
139 Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
141 String vmmeSourceName = serviceContainerVmme_Source.getService().getName();
142 String vprobeSourceName = serviceContainerVprobe_Collector.getService().getName();
144 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
145 GeneralUIUtils.findComponentAndClick(service.getName());
147 ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
148 CanvasManager canvasManager = CanvasManager.getCanvasManager();
150 CanvasElement serviceElementVmmeSourceName = canvasManager.createElementOnCanvas(vmmeSourceName);
152 CanvasElement serviceElementVprobeCollector = canvasManager.createElementOnCanvas(vprobeSourceName);
154 CompositionPage.searchForElement(PortMirroringEnum.PMC_ELEMENT_IN_PALLETE.getValue());
155 CanvasElement portMirroringConfigurationElement = canvasManager.createElementOnCanvas(PortMirroringEnum.PMC_ELEMENT_IN_PALLETE.getValue());
157 ConnectionWizardPopUpObject connectionWizardPopUpObjectVMME = new ConnectionWizardPopUpObject("", "",
158 PortMirroringEnum.PM_REQ_TYPE.getValue(), PortMirroringEnum.PMC_SOURCE_CAP.getValue());
159 ConnectionWizardPopUpObject connectionWizardPopUpObjectVProbe = new ConnectionWizardPopUpObject("", "",
160 PortMirroringEnum.PM_REQ_TYPE.getValue(), PortMirroringEnum.PMC_COLLECTOR_CAP.getValue());
161 Map<String, String> capPropValues1 = null;
163 if (isCapPropAssign) {
164 capPropValues1 = canvasManager.linkElementsWithCapPropAssignment(serviceElementVmmeSourceName, portMirroringConfigurationElement, connectionWizardPopUpObjectVMME);
165 GeneralUIUtils.waitForLoader(WAITING_FOR_LOADER_TIME_OUT);
166 canvasManager.linkElementsWithCapPropAssignment(serviceElementVprobeCollector, portMirroringConfigurationElement, connectionWizardPopUpObjectVProbe);
168 canvasManager.linkElementsAndSelectCapReqTypeAndCapReqName(serviceElementVmmeSourceName, portMirroringConfigurationElement, connectionWizardPopUpObjectVMME);
169 canvasManager.linkElementsAndSelectCapReqTypeAndCapReqName(serviceElementVprobeCollector, portMirroringConfigurationElement, connectionWizardPopUpObjectVProbe);
173 PortMirrioringConfigurationObject portMirrioringConfigurationObject = new PortMirrioringConfigurationObject(serviceReqDetails, vmmeSourceName,
174 vprobeSourceName, canvasManager, serviceElementVmmeSourceName, serviceElementVprobeCollector, service,
175 portMirroringConfigurationElement, serviceContainerVmme_Source.getService(), serviceContainerVprobe_Collector.getService());
177 if (capPropValues1 != null) {
178 portMirrioringConfigurationObject.setCapPropValues(capPropValues1);
181 return portMirrioringConfigurationObject;