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.onap.so.bpmn.infrastructure.scripts
23 import com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.ProcessEngineServices
25 import org.camunda.bpm.engine.RepositoryService
26 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
27 import org.camunda.bpm.engine.repository.ProcessDefinition
28 import org.junit.Assert
29 import org.junit.Before
30 import org.junit.Ignore
33 import org.junit.runner.RunWith
34 import org.mockito.ArgumentCaptor
35 import org.mockito.Captor
36 import org.mockito.Mockito
37 import org.mockito.MockitoAnnotations
38 import org.mockito.runners.MockitoJUnitRunner
39 import org.onap.so.bpmn.common.scripts.VfModule
40 import org.onap.so.bpmn.core.WorkflowException
41 import org.onap.so.bpmn.mock.FileUtil
43 import static com.github.tomakehurst.wiremock.client.WireMock.*
44 import static org.mockito.Mockito.*
45 import org.onap.so.bpmn.common.scripts.utils.XmlComparator
47 @RunWith(MockitoJUnitRunner.class)
48 class DoUpdateVfModuleTest {
50 def prefix = "DOUPVfMod_"
51 String doUpdateVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/DoUpdateVfModuleRequest.xml");
52 String sdncChangeAssignRequest = FileUtil.readResourceFile("__files/DoUpdateVfModule/sdncChangeAssignRequest.xml")
53 String sdncTopologyRequest = FileUtil.readResourceFile("__files/DoUpdateVfModule/sdncTopologyRequest.xml")
56 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
59 public WireMockRule wireMockRule = new WireMockRule(28090);
63 MockitoAnnotations.initMocks(this)
67 void testPreProcessRequest() {
68 ExecutionEntity mockExecution = setupMock()
69 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
70 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
71 when(mockExecution.getVariable("DoUpdateVfModuleRequest")).thenReturn(doUpdateVfModuleRequest)
72 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:28080/mso/SDNCAdapterCallbackService")
74 DoUpdateVfModule obj = new DoUpdateVfModule()
75 obj.preProcessRequest(mockExecution)
77 Mockito.verify(mockExecution, atLeastOnce()).getVariable("mso.workflow.sdncadapter.callback")
83 void testPrepConfirmVolumeGroupTenant() {
84 ExecutionEntity mockExecution = setupMock()
85 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
86 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
87 when(mockExecution.getVariable(prefix + "aicCloudRegion")).thenReturn("CloudOwner")
88 when(mockExecution.getVariable("mso.workflow.default.aai.v8.cloud-region.uri")).thenReturn("/aai/v8/cloud-infrastructure/cloud-regions/cloud-region")
89 when(mockExecution.getVariable("mso.workflow.default.aai.cloud-region.version")).thenReturn("8")
90 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
91 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
94 DoUpdateVfModule obj = new DoUpdateVfModule()
95 obj.prepConfirmVolumeGroupTenant(mockExecution)
97 Mockito.verify(mockExecution).setVariable(prefix + "queryCloudRegionRequest", "http://localhost:28090/aai/v8/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner")
98 Mockito.verify(mockExecution).setVariable(prefix + "queryCloudRegionReturnCode", "200")
99 Mockito.verify(mockExecution).setVariable(prefix + "cloudRegionForVolume", "AAIAIC25")
100 Mockito.verify(mockExecution).setVariable(prefix + "isCloudRegionGood", true)
105 void testPrepSDNCTopologyChg() {
106 ExecutionEntity mockExecution = setupMock()
107 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
108 when(mockExecution.getVariable(prefix + "requestId")).thenReturn("12345")
109 when(mockExecution.getVariable("testReqId")).thenReturn("testReqId")
112 when(mockExecution.getVariable(prefix + "cloudSiteId")).thenReturn("RDM2WAGPLCP")
113 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("cb510af0-5b21-4bc7-86d9-323cb396ce32")
114 when(mockExecution.getVariable("volumeGroupStackId")).thenReturn("12345")
115 when(mockExecution.getVariable(prefix + "vfModuleName")).thenReturn("PCRF::module-0-2")
116 when(mockExecution.getVariable(prefix + "aicCloudRegion")).thenReturn("MDTWNJ21")
117 when(mockExecution.getVariable(prefix + "usePreload")).thenReturn("Y")
118 when(mockExecution.getVariable(prefix + "vnfNameFromAAI")).thenReturn("skask-test")
120 def node = new Node(null, 'vfModule')
121 new Node(node, 'vf-module-name', "abc")
122 VfModule vfModule = new VfModule(node, true);
123 when(mockExecution.getVariable(prefix + "vfModule")).thenReturn(vfModule)
125 when(mockExecution.getVariable(prefix + "tenantId")).thenReturn("fba1bd1e195a404cacb9ce17a9b2b421")
126 when(mockExecution.getVariable(prefix + "vnfType")).thenReturn("vRRaas")
127 when(mockExecution.getVariable(prefix + "vnfName")).thenReturn("skask-test")
128 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
129 when(mockExecution.getVariable(prefix + "vfModuleModelName")).thenReturn("PCRF::module-0-2")
130 when(mockExecution.getVariable(prefix + "requestId")).thenReturn("testRequestId")
131 when(mockExecution.getVariable(prefix + "serviceId")).thenReturn("12345")
132 when(mockExecution.getVariable(prefix + "serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
133 Map<String, String> map = new HashMap<String, String>();
134 map.put("vrr_image_name", "MDT17");
135 map.put("availability_zone_0", "nova");
136 map.put("vrr_flavor_name", "ns.c16r32d128.v1");
137 when(mockExecution.getVariable("vnfParamsMap")).thenReturn(map)
138 when(mockExecution.getVariable("mso-request-id")).thenReturn("testRequestId-1503410089303")
139 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapter")
142 DoUpdateVfModule obj = new DoUpdateVfModule()
143 obj.prepSDNCTopologyChg(mockExecution)
145 Mockito.verify(mockExecution).setVariable(prefix + "vnfName", "skask-test")
147 Mockito.verify(mockExecution, times(2)).setVariable(captor.capture(), captor.capture())
148 XmlComparator.assertXMLEquals(sdncChangeAssignRequest, captor.getValue())
154 void testPrepSDNCTopologyQuery() {
155 ExecutionEntity mockExecution = setupMock()
156 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
157 when(mockExecution.getVariable("testReqId")).thenReturn("testReqId")
158 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("12345")
159 when(mockExecution.getVariable(prefix + "serviceId")).thenReturn("12345")
160 when(mockExecution.getVariable(prefix + "serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
161 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapter")
164 DoUpdateVfModule obj = new DoUpdateVfModule()
165 obj.prepSDNCTopologyQuery(mockExecution)
167 Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
168 XmlComparator.assertXMLEquals(sdncTopologyRequest, captor.getValue())
174 void testPrepVnfAdapterRest() {
175 ExecutionEntity mockExecution = setupMock()
176 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
177 when(mockExecution.getVariable(prefix + "aicCloudRegion")).thenReturn("RDM2WAGPLCP")
178 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("cb510af0-5b21-4bc7-86d9-323cb396ce32")
179 when(mockExecution.getVariable(prefix + "volumeGroupStackId")).thenReturn("12345")
180 when(mockExecution.getVariable(prefix + "vfModuleName")).thenReturn("PCRF::module-0-2")
181 when(mockExecution.getVariable(prefix + "tenantId")).thenReturn("fba1bd1e195a404cacb9ce17a9b2b421")
182 when(mockExecution.getVariable(prefix + "vnfType")).thenReturn("vRRaas")
183 when(mockExecution.getVariable(prefix + "vnfName")).thenReturn("skask-test")
184 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
185 when(mockExecution.getVariable(prefix + "vfModuleModelName")).thenReturn("PCRF::module-0-2")
186 when(mockExecution.getVariable(prefix + "vfModuleIndex")).thenReturn("index")
187 when(mockExecution.getVariable(prefix + "requestId")).thenReturn("testRequestId")
188 when(mockExecution.getVariable(prefix + "serviceId")).thenReturn("12345")
189 when(mockExecution.getVariable(prefix + "serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
190 when(mockExecution.getVariable(prefix + "backoutOnFailure")).thenReturn("12345")
191 when(mockExecution.getVariable(prefix + "volumeGroupId")).thenReturn("12345")
192 when(mockExecution.getVariable(prefix + "asdcServiceModelVersion")).thenReturn("1.0")
193 when(mockExecution.getVariable(prefix + "modelCustomizationUuid")).thenReturn("cb510af0-5b21-4bc7-86d9-323cb396ced3")
194 when(mockExecution.getVariable(prefix + "baseVfModuleId")).thenReturn("12345")
195 when(mockExecution.getVariable(prefix + "baseVfModuleHeatStackId")).thenReturn("12345")
197 def node = new Node(null, 'vfModule')
198 new Node(node, 'heat-stack-id', "abc")
199 VfModule vfModule = new VfModule(node, true);
200 when(mockExecution.getVariable(prefix + "vfModule")).thenReturn(vfModule)
202 String sdncGetResponse = FileUtil.readResourceFile("__files/DoUpdateVfModule/sdncGetResponse.xml");
203 when(mockExecution.getVariable(prefix + "sdncTopologyResponse")).thenReturn(sdncGetResponse)
204 Map<String, String> map = new HashMap<String, String>();
205 map.put("vrr_image_name", "MDT17");
206 map.put("availability_zone_0", "nova");
207 map.put("vrr_flavor_name", "ns.c16r32d128.v1");
208 when(mockExecution.getVariable(prefix + "vnfParamsMap")).thenReturn(map)
209 when(mockExecution.getVariable("mso-request-id")).thenReturn("testRequestId-1503410089303")
210 when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true")
211 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("http://localhost:28080/mso/WorkflowMesssage")
214 DoUpdateVfModule obj = new DoUpdateVfModule()
215 obj.prepVnfAdapterRest(mockExecution)
217 String createVnfARequest = FileUtil.readResourceFile("__files/DoUpdateVfModule/vnfAdapterRestRequest.xml")
218 Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
219 XmlComparator.assertXMLEquals(createVnfARequest, captor.getValue(), "messageId", "notificationUrl")
225 void testPrepSDNCTopologyAct() {
226 ExecutionEntity mockExecution = setupMock()
227 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
228 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
229 when(mockExecution.getVariable(prefix + "aicCloudRegion")).thenReturn("RDM2WAGPLCP")
230 when(mockExecution.getVariable("testReqId")).thenReturn("testReqId")
231 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("cb510af0-5b21-4bc7-86d9-323cb396ce32")
232 when(mockExecution.getVariable(prefix + "tenantId")).thenReturn("fba1bd1e195a404cacb9ce17a9b2b421")
233 when(mockExecution.getVariable(prefix + "vnfType")).thenReturn("vRRaas")
234 when(mockExecution.getVariable(prefix + "vnfName")).thenReturn("skask-test")
235 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
236 when(mockExecution.getVariable(prefix + "vfModuleModelName")).thenReturn("PCRF::module-0-2")
237 when(mockExecution.getVariable(prefix + "requestId")).thenReturn("testRequestId")
238 when(mockExecution.getVariable(prefix + "serviceId")).thenReturn("12345")
239 when(mockExecution.getVariable(prefix + "serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
240 when(mockExecution.getVariable(prefix + "usePreload")).thenReturn("Y")
241 when(mockExecution.getVariable(prefix + "modelCustomizationUuid")).thenReturn("cb510af0-5b21-4bc7-86d9-323cb396ced3")
243 def node = new Node(null, 'vfModule')
244 new Node(node, 'vf-module-name', "abc")
245 VfModule vfModule = new VfModule(node, true);
246 when(mockExecution.getVariable(prefix + "vfModule")).thenReturn(vfModule)
248 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapter")
251 DoUpdateVfModule obj = new DoUpdateVfModule()
252 obj.prepSDNCTopologyAct(mockExecution)
254 String createVnfARequest = FileUtil.readResourceFile("__files/DoUpdateVfModule/sdncActivateRequest.xml")
255 Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
256 XmlComparator.assertXMLEquals(createVnfARequest, captor.getValue())
260 void testQueryAAIVfModule() {
261 ExecutionEntity mockExecution = setupMock()
262 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
263 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
264 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("12345")
265 when(mockExecution.getVariable("mso.workflow.default.aai.generic-vnf.version")).thenReturn("8")
266 when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
267 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
270 DoUpdateVfModule obj = new DoUpdateVfModule()
271 obj.queryAAIVfModule(mockExecution)
272 Mockito.verify(mockExecution).setVariable(prefix + "queryAAIVfModuleResponseCode", 200)
276 private static ExecutionEntity setupMock() {
277 ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)
278 when(mockProcessDefinition.getKey()).thenReturn("DoUpdateVfModule")
279 RepositoryService mockRepositoryService = mock(RepositoryService.class)
280 when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)
281 when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("DoUpdateVfModule")
282 when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")
283 ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)
284 when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)
286 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
287 // Initialize prerequisite variables
288 when(mockExecution.getId()).thenReturn("100")
289 when(mockExecution.getProcessDefinitionId()).thenReturn("DoUpdateVfModule")
290 when(mockExecution.getProcessInstanceId()).thenReturn("DoUpdateVfModule")
291 when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)
292 when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)
297 private static void mockData() {
298 stubFor(get(urlMatching(".*/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner"))
299 .willReturn(aResponse()
300 .withStatus(200).withHeader("Content-Type", "text/xml")
301 .withBodyFile("DoUpdateVfModule/cloudRegion_AAIResponse_Success.xml")))
303 stubFor(get(urlMatching(".*/aai/v[0-9]+/network/generic-vnfs/generic-vnf/12345[?]depth=1"))
304 .willReturn(aResponse()
305 .withStatus(200).withHeader("Content-Type", "text/xml")
306 .withBodyFile("DoUpdateVfModule/getGenericVnfResponse.xml")))