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 org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Before
28 import org.junit.rules.ExpectedException
29 import org.junit.runner.RunWith
30 import org.mockito.ArgumentCaptor
31 import org.mockito.Captor
32 import org.mockito.Mockito
33 import org.mockito.MockitoAnnotations
34 import org.mockito.runners.MockitoJUnitRunner
35 import org.onap.aai.domain.yang.GenericVnf
36 import org.onap.aai.domain.yang.Volume
37 import org.onap.aai.domain.yang.VolumeGroup
38 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
39 import org.onap.so.bpmn.core.RollbackData
40 import org.onap.so.client.aai.AAIObjectPlurals
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.onap.so.constants.Defaults
46 import static org.junit.Assert.assertEquals
47 import static org.junit.Assert.assertNotNull
48 import static org.mockito.Matchers.anyObject
49 import static org.mockito.Mockito.spy
50 import static org.mockito.Mockito.times
51 import static org.mockito.Mockito.verify
52 import static org.mockito.Mockito.when
55 class DoCreateVfModuleVolumeV2Test extends MsoGroovyTest {
57 private DoCreateVfModuleVolumeV2 doCreateVfModuleVolumeV2;
60 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
62 def String volumeRollbackRequest = """
63 <rollbackVolumeGroupRequest>
65 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
66 <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
67 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
68 <cloudSiteId>mtwnj1a</cloudSiteId>
69 <volumeGroupCreated>true</volumeGroupCreated>
71 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
72 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
74 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
75 </volumeGroupRollback>
76 <skipAAI>true</skipAAI>
77 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
78 </rollbackVolumeGroupRequest>
81 def String volumeRollbackRequestWithStackId = """
82 <rollbackVolumeGroupRequest>
84 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
85 <volumeGroupStackId>mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8</volumeGroupStackId>
86 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
87 <cloudSiteId>mtwnj1a</cloudSiteId>
88 <volumeGroupCreated>true</volumeGroupCreated>
90 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
91 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
93 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
94 </volumeGroupRollback>
95 <skipAAI>true</skipAAI>
96 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
97 </rollbackVolumeGroupRequest>
105 super.init("DoCreateVfModuleVolumeV2")
106 doCreateVfModuleVolumeV2 = spy(DoCreateVfModuleVolumeV2.class)
107 when(doCreateVfModuleVolumeV2.getAAIClient()).thenReturn(client)
108 MockitoAnnotations.initMocks(this)
112 public void testBuildRollbackVolumeGroupRequestXml() {
113 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
114 String xml = process.buildRollbackVolumeGroupRequestXml(
115 "171907d6-cdf0-4e08-953d-81ee104005a7", // volumeGroupId
116 "mtwnj1a", // cloudSiteId
117 "c2141e3fcae940fcb4797ec9115e5a7a", // tenantId
118 "230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5", // requestId
119 "88c871d6-be09-4982-8490-96b1d243fb34", // serviceInstanceId
120 "9a5a91e8-3b79-463c-81c3-874a78f5b567", // messageId
121 "http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567") // notificationUrl
123 assertEquals(volumeRollbackRequest.replaceAll("\\s", ""), xml.replaceAll("\\s", ""))
128 public void testUpdateRollbackVolumeGroupRequestXml() {
129 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
130 String updatedXml = process.updateRollbackVolumeGroupRequestXml(volumeRollbackRequest, "mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8")
131 assertEquals(volumeRollbackRequestWithStackId.replaceAll("\\s", ""), updatedXml.replaceAll("\\s", ""))
135 public void testPrepareVnfAdapterCreateRequest (){
136 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV2')
138 when(mockExecution.getVariable("prefix")).thenReturn('DCVFMODVOLV2_')
139 when(mockExecution.getVariable("DCVFMODVOLV2_AAIQueryGenericVfnResponse")).thenReturn(new GenericVnf())
140 when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
141 when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
142 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
143 when(mockExecution.getVariable("volumeGroupId")).thenReturn('1234')
144 when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true")
145 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("http://localhost:28080/mso/WorkflowMesssage")
146 Map vfModuleInputParams = new HashMap()
147 vfModuleInputParams.put("param1","value1")
148 when(mockExecution.getVariable("vfModuleInputParams")).thenReturn(vfModuleInputParams)
149 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
150 process.prepareVnfAdapterCreateRequest(mockExecution,"true");
151 Mockito.verify(mockExecution,times(2)).setVariable(captor.capture(), captor.capture())
152 String DCVFMODVOLV2_createVnfARequest = captor.getValue();
153 assertNotNull(DCVFMODVOLV2_createVnfARequest)
157 void testcallRESTQueryAAIVolGrpName(){
158 String volumeGroupName = "volumeGroupName"
159 String lcpCloudRegionId = "lcpCloudRegionId"
160 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
161 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
162 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), lcpCloudRegionId).queryParam("volume-group-name", volumeGroupName)
163 VolumeGroup volumeGroup = new VolumeGroup()
164 volumeGroup.setVolumeGroupId("volumeGroupId")
165 when(client.get(VolumeGroup.class,uri)).thenReturn(Optional.of(volumeGroup))
166 doCreateVfModuleVolumeV2.callRESTQueryAAIVolGrpName(mockExecution,null)
167 verify(mockExecution).setVariable("DCVFMODVOLV2_AaiReturnCode",200)
171 void testcallRESTQueryAAIVolGrpName_NoData(){
172 String volumeGroupName = "volumeGroupName"
173 String lcpCloudRegionId = "lcpCloudRegionId"
174 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
175 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
176 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), lcpCloudRegionId).queryParam("volume-group-name", volumeGroupName)
177 when(client.get(VolumeGroup.class,uri)).thenReturn(Optional.empty())
178 thrown.expect(BpmnError.class)
179 doCreateVfModuleVolumeV2.callRESTQueryAAIVolGrpName(mockExecution,null)
183 void testcallRESTUpdateCreatedVolGrpName(){
184 String queriedVolumeGroupId = "queriedVolumeGroupId"
185 String modelCustomizationId = "modelCustomizationId"
186 String lcpCloudRegionId = "lcpCloudRegionId"
187 when(mockExecution.getVariable(queriedVolumeGroupId)).thenReturn(queriedVolumeGroupId)
188 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
189 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
190 when(mockExecution.getVariable("DCVFMODVOLV2_createVnfAResponse")).thenReturn("<createVnfAResponse><volumeGroupStackId>volumeGroupStackId</volumeGroupStackId></createVnfAResponse>")
191 doCreateVfModuleVolumeV2.callRESTUpdateCreatedVolGrpName(mockExecution,null)
192 verify(mockExecution).setVariable("DCVFMODVOLV2_heatStackId","volumeGroupStackId")
196 void testcallRESTUpdateCreatedVolGrpNameException(){
197 String queriedVolumeGroupId = "queriedVolumeGroupId"
198 String modelCustomizationId = "modelCustomizationId"
199 String lcpCloudRegionId = "lcpCloudRegionId"
200 when(mockExecution.getVariable(queriedVolumeGroupId)).thenReturn(queriedVolumeGroupId)
201 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
202 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
203 when(mockExecution.getVariable("DCVFMODVOLV2_createVnfAResponse")).thenReturn("<createVnfAResponse><volumeGroupStackId>volumeGroupStackId</volumeGroupStackId></createVnfAResponse>")
204 when(client.update(anyObject(),anyObject())).thenThrow(Exception.class)
205 thrown.expect(BpmnError.class)
206 doCreateVfModuleVolumeV2.callRESTUpdateCreatedVolGrpName(mockExecution,null)
207 verify(mockExecution).setVariable("DCVFMODVOLV2_heatStackId","volumeGroupStackId")
211 void testcallRESTQueryAAIGenericVnf(){
212 String vnfId = "vnfId"
213 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
214 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
215 GenericVnf genericVnf = new GenericVnf()
216 genericVnf.setVnfId(vnfId)
217 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.of(genericVnf))
218 doCreateVfModuleVolumeV2.callRESTQueryAAIGenericVnf(mockExecution,null)
219 verify(mockExecution).setVariable("DCVFMODVOLV2_AAIQueryGenericVfnResponse",genericVnf)
223 void testcallRESTQueryAAIGenericVnf_NotFound(){
224 String vnfId = "vnfId"
225 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
226 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
227 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.empty())
228 thrown.expect(BpmnError.class)
229 doCreateVfModuleVolumeV2.callRESTQueryAAIGenericVnf(mockExecution,null)
233 void testcallRESTCreateAAIVolGrpName(){
234 String vnfId = "vnfId"
235 String volumeGroupId = "volumeGroupId"
236 String volumeGroupName = "volumeGroupName"
237 String modelCustomizationId = "modelCustomizationId"
238 String vnfType= "vnfType"
239 String tenantId = "tenantId"
240 String lcpCloudRegionId= "lcpCloudRegionId"
241 String cloudOwner = "cloudOwner"
243 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
244 when(mockExecution.getVariable(volumeGroupId)).thenReturn(volumeGroupId)
245 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
246 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
247 when(mockExecution.getVariable(vnfType)).thenReturn(vnfType)
248 when(mockExecution.getVariable(tenantId)).thenReturn(tenantId)
249 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
250 when(mockExecution.getVariable(cloudOwner)).thenReturn(cloudOwner)
251 when(mockExecution.getVariable("rollbackData")).thenReturn(new RollbackData())
252 doCreateVfModuleVolumeV2.callRESTCreateAAIVolGrpName(mockExecution,null)
256 void testcallRESTCreateAAIVolGrpNameException(){
257 String vnfId = "vnfId"
258 String volumeGroupId = "volumeGroupId"
259 String volumeGroupName = "volumeGroupName"
260 String modelCustomizationId = "modelCustomizationId"
261 String vnfType= "vnfType"
262 String tenantId = "tenantId"
263 String lcpCloudRegionId= "lcpCloudRegionId"
264 String cloudOwner = "cloudOwner"
266 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
267 when(mockExecution.getVariable(volumeGroupId)).thenReturn(volumeGroupId)
268 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
269 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
270 when(mockExecution.getVariable(vnfType)).thenReturn(vnfType)
271 when(mockExecution.getVariable(tenantId)).thenReturn(tenantId)
272 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
273 when(mockExecution.getVariable(cloudOwner)).thenReturn(cloudOwner)
274 thrown.expect(BpmnError.class)
275 doCreateVfModuleVolumeV2.callRESTCreateAAIVolGrpName(mockExecution,null)