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
26 import org.junit.Ignore
29 import org.junit.rules.ExpectedException
30 import org.junit.runner.RunWith
31 import org.mockito.ArgumentCaptor
32 import org.mockito.MockitoAnnotations
33 import org.mockito.runners.MockitoJUnitRunner
34 import org.onap.aai.domain.yang.ResultData
35 import org.onap.aai.domain.yang.SearchResults
36 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
37 import org.onap.so.client.aai.AAIObjectType
38 import org.onap.so.client.aai.entities.AAIResultWrapper
39 import org.onap.so.client.aai.entities.uri.AAIResourceUri
40 import org.onap.so.client.aai.entities.uri.AAIUriFactory
42 import static org.junit.Assert.assertEquals
43 import static org.mockito.Mockito.*
45 class CreateVfModuleVolumeInfraV1Test extends MsoGroovyTest {
48 public ExpectedException thrown = ExpectedException.none();
54 "modelType": "volumeGroup",
55 "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff",
56 "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe",
57 "modelName": "vSAMP12::base::module-0",
60 "cloudConfiguration": {
61 "lcpCloudRegionId": "mdt1",
62 "tenantId": "88a6ca3ee0394ade9403f075db23167e"
65 "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0",
67 "suppressRollback": false
69 "relatedInstanceList": [
72 "instanceId": "{service-instance-id}",
74 "modelType": "service",
75 "modelInvariantUuid": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
76 "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
83 "instanceId": "{vnf-instance-id}",
86 "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
87 "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
88 "modelName": "vSAMP12",
90 "modelInstanceName": "vSAMP12"
95 "requestParameters": {
96 "serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
98 {"name": "vnfName", "value": "STMTN5MMSC20" },
99 {"name": "vnfName2", "value": "US1117MTSNJVBR0246" },
100 {"name": "vnfNmInformation", "value": "" },
101 {"name": "vnfType", "value": "pcrf-capacity" },
102 {"name": "vnfId", "value": "skask" },
103 {"name": "vnfStackId", "value": "slowburn" },
104 {"name": "vnfStatus", "value": "created" },
105 {"name": "aicCloudRegion", "value": "MDTWNJ21" },
106 {"name": "availabilityZone", "value": "slcp3-esx-az01" },
107 {"name": "oamNetworkName", "value": "VLAN-OAM-1323" },
108 {"name": "vmName", "value": "slcp34246vbc246ceb" },
109 {"name": "ipagNetworkId", "value": "970cd2b9-7f09-4a12-af47-182ea38ba1f0" },
110 {"name": "vpeNetworkId", "value": "545cc2c3-1930-4100-b534-5d82d0e12bb6" }
117 def volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema">
119 <action>CREATE_VF_MODULE_VOL</action>
121 <service-instance-id/>
125 <volume-group-name>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volume-group-name>
126 <vnf-type>Test/vSAMP12</vnf-type>
127 <vf-module-model-name>vSAMP12::base::module-0</vf-module-model-name>
128 <asdc-service-model-version>2.0</asdc-service-model-version>
129 <aic-cloud-region>mdt1</aic-cloud-region>
130 <tenant-id>88a6ca3ee0394ade9403f075db23167e</tenant-id>
131 <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
132 <backout-on-failure>true</backout-on-failure>
133 <model-customization-id/>
136 <param name="vnf_name">STMTN5MMSC20</param>
137 <param name="vnf_name2">US1117MTSNJVBR0246</param>
138 <param name="vnf_nm_information"/>
139 <param name="vnf_type">pcrf-capacity</param>
140 <param name="vnf_id">skask</param>
141 <param name="vnf_stack_id">slowburn</param>
142 <param name="vnf_status">created</param>
143 <param name="aic_cloud_region">MDTWNJ21</param>
144 <param name="availability_zone">slcp3-esx-az01</param>
145 <param name="oam_network_name">VLAN-OAM-1323</param>
146 <param name="vm_name">slcp34246vbc246ceb</param>
147 <param name="ipag_network_id">970cd2b9-7f09-4a12-af47-182ea38ba1f0</param>
148 <param name="vpe_network_id">545cc2c3-1930-4100-b534-5d82d0e12bb6</param>
152 def completeMsoRequestXml = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
153 xmlns:ns="http://org.onap/so/request/types/v1"
154 xmlns="http://org.onap/so/infra/vnf-request/v1">
156 <request-id>1234</request-id>
157 <action>CREATE</action>
160 <aetgt:status-message>Volume Group has been created successfully.</aetgt:status-message>
161 <aetgt:mso-bpel-name>BPMN VF Module Volume action: CREATE</aetgt:mso-bpel-name>
162 </aetgt:MsoCompletionRequest>"""
168 super.init("CreateVfModuleVolumeInfraV1")
169 MockitoAnnotations.initMocks(this)
175 public void testPreProcessRequest() {
177 when(mockExecution.getVariable("prefix")).thenReturn('CVMVINFRAV1_')
178 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonRequest)
179 when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
180 when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
181 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
182 when(mockExecution.getVariable("mso.rollback")).thenReturn('true')
184 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
185 createVfModuleVolumeInfraV1.preProcessRequest(mockExecution, 'true')
187 // Capture the arguments to setVariable
188 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
189 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
191 verify(mockExecution, times(15)).setVariable(captor1.capture(), captor2.capture())
193 List<String> arg2List = captor2.getAllValues()
194 String volumeRequestActual = arg2List.get(6)
195 String isVidRequestActual = arg2List.get(8)
197 assertEquals(volumeRequestXml, volumeRequestActual.trim())
198 assertEquals('true', isVidRequestActual)
202 public void testPostProcessResponse() {
204 when(mockExecution.getVariable("dbReturnCode")).thenReturn('000')
205 when(mockExecution.getVariable("CVMVINFRAV1_createDBResponse")).thenReturn('')
206 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
207 when(mockExecution.getVariable("CVMVINFRAV1_source")).thenReturn('VID')
209 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
210 createVfModuleVolumeInfraV1.postProcessResponse(mockExecution, 'true')
212 verify(mockExecution).setVariable('CVMVINFRAV1_Success', true)
213 verify(mockExecution).setVariable('CVMVINFRAV1_CompleteMsoProcessRequest', completeMsoRequestXml)
217 public void testcallRESTQueryAAIServiceInstance() {
218 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = spy(CreateVfModuleVolumeInfraV1.class)
219 when(createVfModuleVolumeInfraV1.getAAIClient()).thenReturn(client)
220 AAIResultWrapper resultWrapper = new AAIResultWrapper(SEARCH_RESULT_AAI_WITH_RESULTDATA)
221 when(client.get(isA(AAIResourceUri.class))).thenReturn(resultWrapper)
222 createVfModuleVolumeInfraV1.callRESTQueryAAIServiceInstance(mockExecution,true)
226 public void testcallRESTQueryAAIServiceInstance_NoData() {
227 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = spy(CreateVfModuleVolumeInfraV1.class)
228 when(createVfModuleVolumeInfraV1.getAAIClient()).thenReturn(client)
229 AAIResultWrapper resultWrapper = new AAIResultWrapper("{}")
230 when(client.get(isA(AAIResourceUri.class))).thenReturn(resultWrapper)
231 thrown.expect(BpmnError.class)
232 createVfModuleVolumeInfraV1.callRESTQueryAAIServiceInstance(mockExecution,true)