Added oparent to sdc main
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / PortMirroringUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.utilities;
22
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
26 import org.openecomp.sdc.be.model.*;
27 import org.openecomp.sdc.ci.tests.datatypes.*;
28 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
32 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
33 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
34 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
35 import org.openecomp.sdc.ci.tests.utils.general.*;
36 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
37 import org.openecomp.sdc.ci.tests.utils.rest.PropertyRestUtils;
38
39 import java.util.List;
40 import java.util.Map;
41
42 public class PortMirroringUtils {
43
44
45     public static ServiceContainer createServiceFromHeatFile(String filePath, String vnfFile) throws Throwable {
46 //              1. Import VSP v1.0
47         User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
48         AmdocsLicenseMembers amdocsLicenseMembers = VendorLicenseModelRestUtils.createVendorLicense(sdncDesignerDetails1);
49         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Vendor Software License (VLM): %s v1.0", amdocsLicenseMembers.getVendorLicenseName()));
50         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
51         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Vendor Software Product (VSP): %s v1.0 from heat file: %s ", resourceReqDetails.getName(), vnfFile));
52         VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails1, amdocsLicenseMembers);
53 //        VendorSoftwareProductObject vendorSoftwareProductObject = OnboardViaApis.fillVendorSoftwareProductObjectWithMetaData(vnfFile, createVendorSoftwareProduct);
54 //              2. Create VF, certify - v1.0 is created
55         resourceReqDetails = org.openecomp.sdc.ci.tests.utils.general.OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
56         Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);
57         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
58         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Virtual Function (VF): %s v1.0", resourceReqDetails.getName()));
59         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Certify the VF"));
60 //              3. Create Service add to it the certified VF and certify the Service v1.0
61         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
62         Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
63         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating Service: %s v1.0", serviceReqDetails.getName()));
64         Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
65         ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();
66         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Adding VF instance to Service"));
67         service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
68         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Certify the Service"));
69
70         return new ServiceContainer(service, resource, vendorSoftwareProductObject, amdocsLicenseMembers);
71     }
72
73     public static Resource GeneratePNFAndUpdateInput(String resourceName, String vendorModelNumber, User user) throws Exception {
74         Resource resource = getResourceByType(ResourceTypeEnum.PNF, resourceName, vendorModelNumber);
75         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating pnf %s and certify it", resource.getName()));
76         Component componentObject = AtomicOperationUtils.getComponentObject(resource, UserRoleEnum.DESIGNER);
77         UpdateResourceInputViaAPI(user, componentObject, "physicalProbe", "nf_role");
78         resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
79         return resource;
80     }
81
82     private static void UpdateResourceInputViaAPI(User user, Component componentObject, String defaultValue, String inputName) throws Exception {
83         List<InputDefinition> componentInputs = componentObject.getInputs();
84         PropertyObject propertyObject = new PropertyObject(defaultValue, inputName, componentInputs.get(1).getParentUniqueId(), componentInputs.get(1).getUniqueId());
85         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Update input %s to %s", "nf_role", "physicalProbe"));
86         PropertyRestUtils.updateInput(componentObject, propertyObject, user);
87     }
88
89     public static Resource getResourceByType(ResourceTypeEnum resourceTypeEnum, String resourceName, String vendorModelNumber) {
90         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResourceByType(resourceTypeEnum, resourceName, ResourceCategoryEnum.NETWORK_L2_3_INFRASTRUCTURE, resourceName, vendorModelNumber);
91         return AtomicOperationUtils.createResourceByResourceDetails(resourceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
92     }
93
94     public static String createProxyInstanceServiceName(String serviceName, String instanceId) {
95         String serviceProxyInstanceName = String.format("%s_proxy %s", serviceName, instanceId);
96         return serviceProxyInstanceName;
97     }
98
99     public static PortMirrioringConfigurationObject createPortMirriongConfigurationStructure(boolean isCapPropAssign) throws Throwable {
100
101         //Using API onboard and certify 2 zip files Source: vmmme and Collector: Vprobe
102         String filePath = FileHandling.getPortMirroringRepositoryPath();
103         ServiceContainer serviceContainerVmme_Source = PortMirroringUtils.createServiceFromHeatFile(filePath, PortMirroringEnum.VMME_ZIP.getValue());
104         ServiceContainer serviceContainerVprobe_Collector = PortMirroringUtils.createServiceFromHeatFile(filePath, PortMirroringEnum.VPROBE_ZIP.getValue());
105
106         // create service
107         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
108         //ServiceUIUtils.createService(serviceMetadata, getUser());
109
110         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating container %s: ", serviceReqDetails.getName()));
111         Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
112
113         String vmmeSourceName = serviceContainerVmme_Source.getService().getName();
114         String vprobeSourceName = serviceContainerVprobe_Collector.getService().getName();
115
116         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
117         GeneralUIUtils.findComponentAndClick(service.getName());
118
119         ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
120         CanvasManager canvasManager = CanvasManager.getCanvasManager();
121
122         CanvasElement serviceElementVmmeSourceName = canvasManager.createElementOnCanvas(vmmeSourceName);
123
124         CanvasElement serviceElementVprobeCollector = canvasManager.createElementOnCanvas(vprobeSourceName);
125
126         CompositionPage.searchForElement(PortMirroringEnum.PMC_ELEMENT_IN_PALLETE.getValue());
127         CanvasElement portMirroringConfigurationElement = canvasManager.createElementOnCanvas(PortMirroringEnum.PMC_ELEMENT_IN_PALLETE.getValue());
128
129         ConnectionWizardPopUpObject connectionWizardPopUpObjectVMME = new ConnectionWizardPopUpObject("", "",
130                 PortMirroringEnum.PM_REQ_TYPE.getValue(), PortMirroringEnum.PMC_SOURCE_CAP.getValue());
131         ConnectionWizardPopUpObject connectionWizardPopUpObjectVProbe = new ConnectionWizardPopUpObject("", "",
132                 PortMirroringEnum.PM_REQ_TYPE.getValue(), PortMirroringEnum.PMC_COLLECTOR_CAP.getValue());
133         Map<String, String> capPropValues1 = null;
134
135         if(isCapPropAssign){
136            capPropValues1 = canvasManager.linkElementsWithCapPropAssignment(serviceElementVmmeSourceName, portMirroringConfigurationElement, connectionWizardPopUpObjectVMME);
137            GeneralUIUtils.waitForLoader(2000);
138            canvasManager.linkElementsWithCapPropAssignment(serviceElementVprobeCollector, portMirroringConfigurationElement, connectionWizardPopUpObjectVProbe);}
139            else {
140                canvasManager.linkElementsAndSelectCapReqTypeAndCapReqName(serviceElementVmmeSourceName, portMirroringConfigurationElement, connectionWizardPopUpObjectVMME);
141                canvasManager.linkElementsAndSelectCapReqTypeAndCapReqName(serviceElementVprobeCollector, portMirroringConfigurationElement, connectionWizardPopUpObjectVProbe);
142         }
143
144
145         PortMirrioringConfigurationObject portMirrioringConfigurationObject = new PortMirrioringConfigurationObject(serviceReqDetails, vmmeSourceName,
146                 vprobeSourceName, canvasManager, serviceElementVmmeSourceName, serviceElementVprobeCollector, service,
147                 portMirroringConfigurationElement, serviceContainerVmme_Source.getService(), serviceContainerVprobe_Collector.getService());
148
149         if(capPropValues1!=null)
150           portMirrioringConfigurationObject.setCapPropValues(capPropValues1);
151
152         return portMirrioringConfigurationObject;
153     }
154
155 }