Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / CreateVfModuleVolumeInfraV1Test.groovy
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
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 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
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========================================================= 
19  */ 
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
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
27 import org.junit.Rule
28 import org.junit.Test
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
41
42 import static org.junit.Assert.assertEquals
43 import static org.mockito.Mockito.*
44
45 class CreateVfModuleVolumeInfraV1Test extends MsoGroovyTest {
46
47         @Rule
48         public ExpectedException thrown = ExpectedException.none();
49         
50         def jsonRequest = """
51 {
52         "requestDetails": {
53                 "modelInfo": {
54                         "modelType": "volumeGroup",
55                         "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff",
56                         "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe",
57                         "modelName": "vSAMP12::base::module-0",
58                         "modelVersion": "1"
59                 },
60                 "cloudConfiguration": {
61                         "lcpCloudRegionId": "mdt1",
62                         "tenantId": "88a6ca3ee0394ade9403f075db23167e"
63                 },
64                 "requestInfo": {
65                         "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0",
66                         "source": "VID",
67                         "suppressRollback": false
68                 },
69                 "relatedInstanceList": [
70                         {
71                                 "relatedInstance": {
72                                         "instanceId": "{service-instance-id}",
73                                         "modelInfo": {
74                                                 "modelType": "service",
75                                                 "modelInvariantUuid": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
76                                                 "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
77                                                 "modelName": "Test",
78                                                 "modelVersion": "2.0"
79                                         }
80                                 }
81                         }, {
82                                 "relatedInstance": {
83                                         "instanceId": "{vnf-instance-id}",
84                                         "modelInfo": {
85                                                 "modelType": "vnf",
86                                                 "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
87                                                 "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
88                                                 "modelName": "vSAMP12",
89                                                 "modelVersion": "1",
90                                                 "modelInstanceName": "vSAMP12"
91                                         }
92                                 }
93                         }
94                 ],
95                 "requestParameters": {
96                         "serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
97                         "userParams": [
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" }
111                         ]
112                 }
113         }
114 }
115 """
116         
117         def volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema">
118    <request-info>
119       <action>CREATE_VF_MODULE_VOL</action>
120       <source>VID</source>
121       <service-instance-id/>
122    </request-info>
123    <volume-inputs>
124       <volume-group-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/>
134    </volume-inputs>
135    <volume-params>
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>
149    </volume-params>
150 </volume-request>"""
151                 
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">
155    <request-info>
156       <request-id>1234</request-id>
157       <action>CREATE</action>
158       <source>VID</source>
159    </request-info>
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>"""
163
164
165     @Before
166         public void init()
167         {
168                 super.init("CreateVfModuleVolumeInfraV1")
169                 MockitoAnnotations.initMocks(this)
170         }
171         
172
173         @Test
174         @Ignore
175         public void testPreProcessRequest() {
176                 
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')
183                                                                 
184                 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
185                 createVfModuleVolumeInfraV1.preProcessRequest(mockExecution, 'true')
186                 
187                 // Capture the arguments to setVariable
188                 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
189                 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
190                 
191                 verify(mockExecution, times(15)).setVariable(captor1.capture(), captor2.capture())
192                 
193                 List<String> arg2List = captor2.getAllValues()
194                 String volumeRequestActual = arg2List.get(6)
195                 String isVidRequestActual = arg2List.get(8) 
196                 
197                 assertEquals(volumeRequestXml, volumeRequestActual.trim())
198                 assertEquals('true', isVidRequestActual)
199         }
200         
201         @Test
202         public void testPostProcessResponse() {
203                 
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')
208                                                                 
209                 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
210                 createVfModuleVolumeInfraV1.postProcessResponse(mockExecution, 'true')
211                 
212                 verify(mockExecution).setVariable('CVMVINFRAV1_Success', true)
213                 verify(mockExecution).setVariable('CVMVINFRAV1_CompleteMsoProcessRequest', completeMsoRequestXml)
214         }
215
216         @Test
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)
223         }
224
225         @Test
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)
233         }
234 }