Merge "SO API extenstion to retrieve all PNF workflow"
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / client / cds / AbstractVnfCDSRequestProviderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.so.client.cds;
21
22 import com.google.gson.JsonParser;
23 import org.camunda.bpm.engine.delegate.DelegateExecution;
24 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
25 import org.junit.Before;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mock;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.onap.so.bpmn.common.BuildingBlockExecution;
30 import org.onap.so.bpmn.common.DelegateExecutionImpl;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
34 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
35 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
36 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
37 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
38 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
39 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
40 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
42 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
43 import org.onap.so.serviceinstancebeans.*;
44 import java.util.ArrayList;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48
49 @RunWith(MockitoJUnitRunner.Silent.class)
50 public abstract class AbstractVnfCDSRequestProviderTest {
51
52     protected static final String GENERIC_VNF_ID = "vnfId_configVnfTest1";
53     protected static final String VF_MODULE_ID = "vf-module-id-1";
54     protected static final String VF_MODULE_NAME = "vf-module-name-1";
55     protected static final String VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1";
56     protected static final String GENERIC_VNF_NAME = "vnf-name-1";
57     protected static final String SERVICE_INSTANCE_ID = "serviceInst_configTest";
58     protected static final String SERVICE_MODEL_UUID = "b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4";
59     protected static final String SERVICE_INSTANCE_NAME = "test-service-instance";
60     protected static final String VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
61     protected static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput";
62     protected static final String VNF_SCOPE = "vnf";
63     protected static final String SERVICE_SCOPE = "service";
64     protected static final String SERVICE_ACTION = "create";
65     protected static final String VF_SCOPE = "vfModule";
66     protected static final String ASSIGN_ACTION = "configAssign";
67     protected static final String DEPLOY_ACTION = "configDeploy";
68     protected static final String MSO_REQUEST_ID = "1234";
69     protected static final String BUILDING_BLOCK = "buildingBlock";
70     protected static final String PUBLIC_NET_ID = "public-net-id";
71     protected static final String CLOUD_REGION = "acl-cloud-region";
72
73     @Mock
74     protected ExtractPojosForBB extractPojosForBB;
75
76     protected BuildingBlockExecution buildingBlockExecution;
77
78     protected ExecuteBuildingBlock executeBuildingBlock;
79
80
81     @Before
82     public void setUp() {
83         buildingBlockExecution = createBuildingBlockExecution();
84         executeBuildingBlock = new ExecuteBuildingBlock();
85     }
86
87     protected BuildingBlockExecution createBuildingBlockExecution() {
88         DelegateExecution execution = new DelegateExecutionFake();
89         execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock());
90         return new DelegateExecutionImpl(execution);
91     }
92
93     protected GeneralBuildingBlock createGeneralBuildingBlock() {
94         GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
95         RequestContext requestContext = new RequestContext();
96         RequestParameters requestParameters = new RequestParameters();
97         requestParameters.setUserParams(createRequestUserParams());
98         requestContext.setRequestParameters(requestParameters);
99         requestContext.setMsoRequestId(MSO_REQUEST_ID);
100         generalBuildingBlock.setRequestContext(requestContext);
101         return generalBuildingBlock;
102     }
103
104     protected ServiceInstance createServiceInstance() {
105         ServiceInstance serviceInstance = new ServiceInstance();
106         serviceInstance.setServiceInstanceName(SERVICE_INSTANCE_NAME);
107         serviceInstance.setServiceInstanceId(SERVICE_INSTANCE_ID);
108         ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
109         modelInfoServiceInstance.setModelUuid(SERVICE_MODEL_UUID);
110         serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
111         return serviceInstance;
112     }
113
114     protected GenericVnf createGenericVnf() {
115         GenericVnf genericVnf = new GenericVnf();
116         genericVnf.setVnfId(GENERIC_VNF_ID);
117         genericVnf.setVnfName(GENERIC_VNF_NAME);
118         genericVnf.setBlueprintName("test");
119         genericVnf.setBlueprintVersion("1.0.0");
120         ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
121         modelInfoGenericVnf.setModelCustomizationUuid(VNF_MODEL_CUSTOMIZATION_UUID);
122         genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
123         return genericVnf;
124     }
125
126     protected VfModule createVfModule() {
127         VfModule vfModule = new VfModule();
128         vfModule.setVfModuleId(VF_MODULE_ID);
129         vfModule.setVfModuleName(VF_MODULE_NAME);
130         ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule();
131         modelInfoVfModule.setModelCustomizationUUID(VF_MODULE_CUSTOMIZATION_UUID);
132         vfModule.setModelInfoVfModule(modelInfoVfModule);
133         return vfModule;
134     }
135
136     protected List<Map<String, Object>> createRequestUserParams() {
137         List<Map<String, Object>> userParams = new ArrayList<>();
138         Map<String, Object> userParamMap = new HashMap<>();
139         userParamMap.put("service", getUserParams());
140         userParams.add(userParamMap);
141         return userParams;
142     }
143
144     protected Service getUserParams() {
145         Service service = new Service();
146         Resources resources = new Resources();
147         resources.setVnfs(createVnfList());
148         service.setResources(resources);
149         return service;
150     }
151
152     protected List<Vnfs> createVnfList() {
153         List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>();
154         Map<String, String> instanceParam = new HashMap<>();
155         instanceParam.put("public_net_id", PUBLIC_NET_ID);
156         instanceParam.put("acl-cloud-region", CLOUD_REGION);
157         instanceParamsListSearchedVnf.add(instanceParam);
158         Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf);
159         List<Vnfs> vnfList = new ArrayList<>();
160         vnfList.add(searchedVnf);
161         return vnfList;
162     }
163
164     protected Vnfs createVnf(List<Map<String, String>> instanceParamsList) {
165         Vnfs vnf = new Vnfs();
166         ModelInfo modelInfo = new ModelInfo();
167         modelInfo.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_UUID);
168         vnf.setModelInfo(modelInfo);
169         vnf.setInstanceParams(instanceParamsList);
170
171         // Set instance parameters and modelinfo for vf-module
172         VfModules vfModule = new VfModules();
173         ModelInfo modelInfoForVfModule = new ModelInfo();
174         modelInfoForVfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_UUID);
175         vfModule.setModelInfo(modelInfoForVfModule);
176
177         List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
178         Map<String, String> instanceParams = new HashMap<>();
179         instanceParams.put("public-net-vf-module-id", PUBLIC_NET_ID);
180         instanceParams.put("aci-cloud-region-vf-module", CLOUD_REGION);
181
182         instanceParamsListSearchedVfModule.add(instanceParams);
183         vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
184
185         List<VfModules> vfModules = new ArrayList<>();
186         vfModules.add(vfModule);
187
188         vnf.setVfModules(vfModules);
189
190         return vnf;
191     }
192
193     protected boolean verfiyJsonFromString(String payload) {
194         JsonParser parser = new JsonParser();
195         return parser.parse(payload).isJsonObject();
196     }
197
198     protected void setScopeAndAction(String scope, String action) {
199         BuildingBlock buildingBlock = new BuildingBlock();
200         buildingBlock.setBpmnScope(scope);
201         buildingBlock.setBpmnAction(action);
202         executeBuildingBlock.setBuildingBlock(buildingBlock);
203         buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock);
204     }
205 }