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.aaiclient.client.aai.AAIObjectType
38 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
39 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
40 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
41 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
42 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
44 import static org.junit.Assert.assertEquals
45 import static org.mockito.Mockito.*
47 class CreateVfModuleVolumeInfraV1Test extends MsoGroovyTest {
50 public ExpectedException thrown = ExpectedException.none();
52 String jsonRequest = """
56 "modelType": "volumeGroup",
57 "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff",
58 "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe",
59 "modelName": "vSAMP12::base::module-0",
62 "cloudConfiguration": {
63 "lcpCloudRegionId": "mdt1",
64 "tenantId": "88a6ca3ee0394ade9403f075db23167e"
67 "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0",
69 "suppressRollback": false
71 "relatedInstanceList": [
74 "instanceId": "{service-instance-id}",
76 "modelType": "service",
77 "modelInvariantUuid": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
78 "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
85 "instanceId": "{vnf-instance-id}",
88 "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
89 "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
90 "modelName": "vSAMP12",
92 "modelInstanceName": "vSAMP12"
97 "requestParameters": {
98 "serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
100 {"name": "vnfName", "value": "STMTN5MMSC20" },
101 {"name": "vnfName2", "value": "US1117MTSNJVBR0246" },
102 {"name": "vnfNmInformation", "value": "" },
103 {"name": "vnfType", "value": "pcrf-capacity" },
104 {"name": "vnfId", "value": "skask" },
105 {"name": "vnfStackId", "value": "slowburn" },
106 {"name": "vnfStatus", "value": "created" },
107 {"name": "aicCloudRegion", "value": "MDTWNJ21" },
108 {"name": "availabilityZone", "value": "slcp3-esx-az01" },
109 {"name": "oamNetworkName", "value": "VLAN-OAM-1323" },
110 {"name": "vmName", "value": "slcp34246vbc246ceb" },
111 {"name": "ipagNetworkId", "value": "970cd2b9-7f09-4a12-af47-182ea38ba1f0" },
112 {"name": "vpeNetworkId", "value": "545cc2c3-1930-4100-b534-5d82d0e12bb6" }
119 String volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema">
121 <action>CREATE_VF_MODULE_VOL</action>
123 <service-instance-id/>
127 <volume-group-name>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volume-group-name>
128 <vnf-type>Test/vSAMP12</vnf-type>
129 <vf-module-model-name>vSAMP12::base::module-0</vf-module-model-name>
130 <asdc-service-model-version>2.0</asdc-service-model-version>
131 <aic-cloud-region>mdt1</aic-cloud-region>
132 <tenant-id>88a6ca3ee0394ade9403f075db23167e</tenant-id>
133 <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
134 <backout-on-failure>true</backout-on-failure>
135 <model-customization-id/>
138 <param name="vnf_name">STMTN5MMSC20</param>
139 <param name="vnf_name2">US1117MTSNJVBR0246</param>
140 <param name="vnf_nm_information"/>
141 <param name="vnf_type">pcrf-capacity</param>
142 <param name="vnf_id">skask</param>
143 <param name="vnf_stack_id">slowburn</param>
144 <param name="vnf_status">created</param>
145 <param name="aic_cloud_region">MDTWNJ21</param>
146 <param name="availability_zone">slcp3-esx-az01</param>
147 <param name="oam_network_name">VLAN-OAM-1323</param>
148 <param name="vm_name">slcp34246vbc246ceb</param>
149 <param name="ipag_network_id">970cd2b9-7f09-4a12-af47-182ea38ba1f0</param>
150 <param name="vpe_network_id">545cc2c3-1930-4100-b534-5d82d0e12bb6</param>
154 String completeMsoRequestXml = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
155 xmlns:ns="http://org.onap/so/request/types/v1"
156 xmlns="http://org.onap/so/infra/vnf-request/v1">
158 <request-id>1234</request-id>
159 <action>CREATE</action>
162 <aetgt:status-message>Volume Group has been created successfully.</aetgt:status-message>
163 <aetgt:mso-bpel-name>BPMN VF Module Volume action: CREATE</aetgt:mso-bpel-name>
164 </aetgt:MsoCompletionRequest>"""
170 super.init("CreateVfModuleVolumeInfraV1")
171 MockitoAnnotations.initMocks(this)
177 public void testPreProcessRequest() {
179 when(mockExecution.getVariable("prefix")).thenReturn('CVMVINFRAV1_')
180 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonRequest)
181 when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
182 when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
183 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
184 when(mockExecution.getVariable("mso.rollback")).thenReturn('true')
186 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
187 createVfModuleVolumeInfraV1.preProcessRequest(mockExecution, 'true')
189 // Capture the arguments to setVariable
190 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
191 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
193 verify(mockExecution, times(15)).setVariable(captor1.capture(), captor2.capture())
195 List<String> arg2List = captor2.getAllValues()
196 String volumeRequestActual = arg2List.get(6)
197 String isVidRequestActual = arg2List.get(8)
199 assertEquals(volumeRequestXml, volumeRequestActual.trim())
200 assertEquals('true', isVidRequestActual)
204 public void testPostProcessResponse() {
206 when(mockExecution.getVariable("dbReturnCode")).thenReturn('000')
207 when(mockExecution.getVariable("CVMVINFRAV1_createDBResponse")).thenReturn('')
208 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
209 when(mockExecution.getVariable("CVMVINFRAV1_source")).thenReturn('VID')
211 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
212 createVfModuleVolumeInfraV1.postProcessResponse(mockExecution, 'true')
214 verify(mockExecution).setVariable('CVMVINFRAV1_Success', true)
215 verify(mockExecution).setVariable('CVMVINFRAV1_CompleteMsoProcessRequest', completeMsoRequestXml)
219 public void testcallRESTQueryAAIServiceInstance() {
220 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = spy(CreateVfModuleVolumeInfraV1.class)
221 when(createVfModuleVolumeInfraV1.getAAIClient()).thenReturn(client)
222 AAIResultWrapper resultWrapper = new AAIResultWrapper(SEARCH_RESULT_AAI_WITH_RESULTDATA)
223 when(client.get(isA(AAIResourceUri.class))).thenReturn(resultWrapper)
224 createVfModuleVolumeInfraV1.callRESTQueryAAIServiceInstance(mockExecution,true)
228 public void testcallRESTQueryAAIServiceInstance_NoData() {
229 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = spy(CreateVfModuleVolumeInfraV1.class)
230 when(createVfModuleVolumeInfraV1.getAAIClient()).thenReturn(client)
231 AAIResultWrapper resultWrapper = new AAIResultWrapper("{}")
232 when(client.get(isA(AAIResourceUri.class))).thenReturn(resultWrapper)
233 thrown.expect(BpmnError.class)
234 createVfModuleVolumeInfraV1.callRESTQueryAAIServiceInstance(mockExecution,true)