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.aai.domain.yang.VolumeGroups
39 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
40 import org.onap.so.bpmn.core.RollbackData
41 import org.onap.so.client.aai.AAIObjectPlurals
42 import org.onap.so.client.aai.AAIObjectType
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory
45 import org.onap.so.constants.Defaults
47 import static org.junit.Assert.assertEquals
48 import static org.junit.Assert.assertNotNull
49 import static org.mockito.Matchers.anyObject
50 import static org.mockito.Mockito.spy
51 import static org.mockito.Mockito.times
52 import static org.mockito.Mockito.verify
53 import static org.mockito.Mockito.when
56 class DoCreateVfModuleVolumeV2Test extends MsoGroovyTest {
58 private DoCreateVfModuleVolumeV2 doCreateVfModuleVolumeV2;
61 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
63 def String volumeRollbackRequest = """
64 <rollbackVolumeGroupRequest>
66 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
67 <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
68 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
69 <cloudSiteId>mtwnj1a</cloudSiteId>
70 <volumeGroupCreated>true</volumeGroupCreated>
72 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
73 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
75 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
76 </volumeGroupRollback>
77 <skipAAI>true</skipAAI>
78 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
79 </rollbackVolumeGroupRequest>
82 def String volumeRollbackRequestWithStackId = """
83 <rollbackVolumeGroupRequest>
85 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
86 <volumeGroupStackId>mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8</volumeGroupStackId>
87 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
88 <cloudSiteId>mtwnj1a</cloudSiteId>
89 <volumeGroupCreated>true</volumeGroupCreated>
91 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
92 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
94 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
95 </volumeGroupRollback>
96 <skipAAI>true</skipAAI>
97 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
98 </rollbackVolumeGroupRequest>
106 super.init("DoCreateVfModuleVolumeV2")
107 doCreateVfModuleVolumeV2 = spy(DoCreateVfModuleVolumeV2.class)
108 when(doCreateVfModuleVolumeV2.getAAIClient()).thenReturn(client)
109 MockitoAnnotations.initMocks(this)
113 public void testBuildRollbackVolumeGroupRequestXml() {
114 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
115 String xml = process.buildRollbackVolumeGroupRequestXml(
116 "171907d6-cdf0-4e08-953d-81ee104005a7", // volumeGroupId
117 "mtwnj1a", // cloudSiteId
118 "c2141e3fcae940fcb4797ec9115e5a7a", // tenantId
119 "230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5", // requestId
120 "88c871d6-be09-4982-8490-96b1d243fb34", // serviceInstanceId
121 "9a5a91e8-3b79-463c-81c3-874a78f5b567", // messageId
122 "http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567") // notificationUrl
124 assertEquals(volumeRollbackRequest.replaceAll("\\s", ""), xml.replaceAll("\\s", ""))
129 public void testUpdateRollbackVolumeGroupRequestXml() {
130 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
131 String updatedXml = process.updateRollbackVolumeGroupRequestXml(volumeRollbackRequest, "mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8")
132 assertEquals(volumeRollbackRequestWithStackId.replaceAll("\\s", ""), updatedXml.replaceAll("\\s", ""))
136 public void testPrepareVnfAdapterCreateRequest (){
137 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV2')
139 when(mockExecution.getVariable("prefix")).thenReturn('DCVFMODVOLV2_')
140 when(mockExecution.getVariable("DCVFMODVOLV2_AAIQueryGenericVfnResponse")).thenReturn(new GenericVnf())
141 when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
142 when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
143 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
144 when(mockExecution.getVariable("volumeGroupId")).thenReturn('1234')
145 when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true")
146 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("http://localhost:28080/mso/WorkflowMesssage")
147 Map vfModuleInputParams = new HashMap()
148 vfModuleInputParams.put("param1","value1")
149 when(mockExecution.getVariable("vfModuleInputParams")).thenReturn(vfModuleInputParams)
150 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
151 process.prepareVnfAdapterCreateRequest(mockExecution,"true");
152 Mockito.verify(mockExecution,times(2)).setVariable(captor.capture(), captor.capture())
153 String DCVFMODVOLV2_createVnfARequest = captor.getValue();
154 assertNotNull(DCVFMODVOLV2_createVnfARequest)
158 void testcallRESTQueryAAIVolGrpName(){
159 String volumeGroupName = "volumeGroupName"
160 String lcpCloudRegionId = "lcpCloudRegionId"
161 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
162 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
163 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), lcpCloudRegionId).queryParam("volume-group-name", volumeGroupName)
164 VolumeGroups volumeGroups = new VolumeGroups();
165 VolumeGroup volumeGroup = new VolumeGroup()
166 volumeGroup.setVolumeGroupId("volumeGroupId")
167 volumeGroups.getVolumeGroup().add(volumeGroup);
168 when(client.get(VolumeGroups.class,uri)).thenReturn(Optional.of(volumeGroups))
169 doCreateVfModuleVolumeV2.callRESTQueryAAIVolGrpName(mockExecution,null)
170 verify(mockExecution).setVariable("DCVFMODVOLV2_AaiReturnCode",200)
174 void testcallRESTQueryAAIVolGrpName_NoData(){
175 String volumeGroupName = "volumeGroupName"
176 String lcpCloudRegionId = "lcpCloudRegionId"
177 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
178 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
179 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), lcpCloudRegionId).queryParam("volume-group-name", volumeGroupName)
180 when(client.get(VolumeGroup.class,uri)).thenReturn(Optional.empty())
181 thrown.expect(BpmnError.class)
182 doCreateVfModuleVolumeV2.callRESTQueryAAIVolGrpName(mockExecution,null)
186 void testcallRESTUpdateCreatedVolGrpName(){
187 String queriedVolumeGroupId = "queriedVolumeGroupId"
188 String modelCustomizationId = "modelCustomizationId"
189 String lcpCloudRegionId = "lcpCloudRegionId"
190 when(mockExecution.getVariable(queriedVolumeGroupId)).thenReturn(queriedVolumeGroupId)
191 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
192 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
193 when(mockExecution.getVariable("DCVFMODVOLV2_createVnfAResponse")).thenReturn("<createVnfAResponse><volumeGroupStackId>volumeGroupStackId</volumeGroupStackId></createVnfAResponse>")
194 doCreateVfModuleVolumeV2.callRESTUpdateCreatedVolGrpName(mockExecution,null)
195 verify(mockExecution).setVariable("DCVFMODVOLV2_heatStackId","volumeGroupStackId")
199 void testcallRESTUpdateCreatedVolGrpNameException(){
200 String queriedVolumeGroupId = "queriedVolumeGroupId"
201 String modelCustomizationId = "modelCustomizationId"
202 String lcpCloudRegionId = "lcpCloudRegionId"
203 when(mockExecution.getVariable(queriedVolumeGroupId)).thenReturn(queriedVolumeGroupId)
204 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
205 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
206 when(mockExecution.getVariable("DCVFMODVOLV2_createVnfAResponse")).thenReturn("<createVnfAResponse><volumeGroupStackId>volumeGroupStackId</volumeGroupStackId></createVnfAResponse>")
207 when(client.update(anyObject(),anyObject())).thenThrow(Exception.class)
208 thrown.expect(BpmnError.class)
209 doCreateVfModuleVolumeV2.callRESTUpdateCreatedVolGrpName(mockExecution,null)
210 verify(mockExecution).setVariable("DCVFMODVOLV2_heatStackId","volumeGroupStackId")
214 void testcallRESTQueryAAIGenericVnf(){
215 String vnfId = "vnfId"
216 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
217 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
218 GenericVnf genericVnf = new GenericVnf()
219 genericVnf.setVnfId(vnfId)
220 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.of(genericVnf))
221 doCreateVfModuleVolumeV2.callRESTQueryAAIGenericVnf(mockExecution,null)
222 verify(mockExecution).setVariable("DCVFMODVOLV2_AAIQueryGenericVfnResponse",genericVnf)
226 void testcallRESTQueryAAIGenericVnf_NotFound(){
227 String vnfId = "vnfId"
228 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
229 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
230 when(client.get(GenericVnf.class,uri)).thenReturn(Optional.empty())
231 thrown.expect(BpmnError.class)
232 doCreateVfModuleVolumeV2.callRESTQueryAAIGenericVnf(mockExecution,null)
236 void testcallRESTCreateAAIVolGrpName(){
237 String vnfId = "vnfId"
238 String volumeGroupId = "volumeGroupId"
239 String volumeGroupName = "volumeGroupName"
240 String modelCustomizationId = "modelCustomizationId"
241 String vnfType= "vnfType"
242 String tenantId = "tenantId"
243 String lcpCloudRegionId= "lcpCloudRegionId"
244 String cloudOwner = "cloudOwner"
246 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
247 when(mockExecution.getVariable(volumeGroupId)).thenReturn(volumeGroupId)
248 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
249 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
250 when(mockExecution.getVariable(vnfType)).thenReturn(vnfType)
251 when(mockExecution.getVariable(tenantId)).thenReturn(tenantId)
252 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
253 when(mockExecution.getVariable(cloudOwner)).thenReturn(cloudOwner)
254 when(mockExecution.getVariable("rollbackData")).thenReturn(new RollbackData())
255 doCreateVfModuleVolumeV2.callRESTCreateAAIVolGrpName(mockExecution,null)
256 verify(mockExecution).setVariable("queriedVolumeGroupId", "volumeGroupId")
260 void testcallRESTCreateAAIVolGrpNameException(){
261 String vnfId = "vnfId"
262 String volumeGroupId = "volumeGroupId"
263 String volumeGroupName = "volumeGroupName"
264 String modelCustomizationId = "modelCustomizationId"
265 String vnfType= "vnfType"
266 String tenantId = "tenantId"
267 String lcpCloudRegionId= "lcpCloudRegionId"
268 String cloudOwner = "cloudOwner"
270 when(mockExecution.getVariable(vnfId)).thenReturn(vnfId)
271 when(mockExecution.getVariable(volumeGroupId)).thenReturn(volumeGroupId)
272 when(mockExecution.getVariable(volumeGroupName)).thenReturn(volumeGroupName)
273 when(mockExecution.getVariable(modelCustomizationId)).thenReturn(modelCustomizationId)
274 when(mockExecution.getVariable(vnfType)).thenReturn(vnfType)
275 when(mockExecution.getVariable(tenantId)).thenReturn(tenantId)
276 when(mockExecution.getVariable(lcpCloudRegionId)).thenReturn(lcpCloudRegionId)
277 when(mockExecution.getVariable(cloudOwner)).thenReturn(cloudOwner)
278 thrown.expect(BpmnError.class)
279 doCreateVfModuleVolumeV2.callRESTCreateAAIVolGrpName(mockExecution,null)