2b437d875e8545e69cbee5dffc19164e024fc020
[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.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
25 import org.junit.Ignore
26 import org.junit.Test
27 import org.junit.runner.RunWith
28 import org.mockito.ArgumentCaptor
29 import org.mockito.MockitoAnnotations
30 import org.mockito.runners.MockitoJUnitRunner
31 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
32
33 import static org.junit.Assert.assertEquals
34 import static org.mockito.Mockito.*
35
36 @RunWith(MockitoJUnitRunner.class)
37 class CreateVfModuleVolumeInfraV1Test extends MsoGroovyTest {
38
39         def jsonRequest = """
40 {
41         "requestDetails": {
42                 "modelInfo": {
43                         "modelType": "volumeGroup",
44                         "modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff",
45                         "modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe",
46                         "modelName": "vSAMP12::base::module-0",
47                         "modelVersion": "1"
48                 },
49                 "cloudConfiguration": {
50                         "lcpCloudRegionId": "mdt1",
51                         "tenantId": "88a6ca3ee0394ade9403f075db23167e"
52                 },
53                 "requestInfo": {
54                         "instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0",
55                         "source": "VID",
56                         "suppressRollback": false
57                 },
58                 "relatedInstanceList": [
59                         {
60                                 "relatedInstance": {
61                                         "instanceId": "{service-instance-id}",
62                                         "modelInfo": {
63                                                 "modelType": "service",
64                                                 "modelInvariantUuid": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
65                                                 "modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
66                                                 "modelName": "Test",
67                                                 "modelVersion": "2.0"
68                                         }
69                                 }
70                         }, {
71                                 "relatedInstance": {
72                                         "instanceId": "{vnf-instance-id}",
73                                         "modelInfo": {
74                                                 "modelType": "vnf",
75                                                 "modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
76                                                 "modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
77                                                 "modelName": "vSAMP12",
78                                                 "modelVersion": "1",
79                                                 "modelInstanceName": "vSAMP12"
80                                         }
81                                 }
82                         }
83                 ],
84                 "requestParameters": {
85                         "serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
86                         "userParams": [
87                                 {"name": "vnfName", "value": "STMTN5MMSC20" },
88                                 {"name": "vnfName2", "value": "US1117MTSNJVBR0246" },
89                                 {"name": "vnfNmInformation", "value": "" },
90                                 {"name": "vnfType", "value": "pcrf-capacity" },
91                                 {"name": "vnfId", "value": "skask" },
92                                 {"name": "vnfStackId", "value": "slowburn" },
93                                 {"name": "vnfStatus", "value": "created" },
94                                 {"name": "aicCloudRegion", "value": "MDTWNJ21" },
95                                 {"name": "availabilityZone", "value": "slcp3-esx-az01" },
96                                 {"name": "oamNetworkName", "value": "VLAN-OAM-1323" },
97                                 {"name": "vmName", "value": "slcp34246vbc246ceb" },
98                                 {"name": "ipagNetworkId", "value": "970cd2b9-7f09-4a12-af47-182ea38ba1f0" },
99                                 {"name": "vpeNetworkId", "value": "545cc2c3-1930-4100-b534-5d82d0e12bb6" }
100                         ]
101                 }
102         }
103 }
104 """
105         
106         def volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema">
107    <request-info>
108       <action>CREATE_VF_MODULE_VOL</action>
109       <source>VID</source>
110       <service-instance-id/>
111    </request-info>
112    <volume-inputs>
113       <volume-group-id/>
114       <volume-group-name>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volume-group-name>
115       <vnf-type>Test/vSAMP12</vnf-type>
116       <vf-module-model-name>vSAMP12::base::module-0</vf-module-model-name>
117       <asdc-service-model-version>2.0</asdc-service-model-version>
118       <aic-cloud-region>mdt1</aic-cloud-region>
119       <tenant-id>88a6ca3ee0394ade9403f075db23167e</tenant-id>
120       <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
121       <backout-on-failure>true</backout-on-failure>
122       <model-customization-id/>
123    </volume-inputs>
124    <volume-params>
125       <param name="vnf_name">STMTN5MMSC20</param>
126       <param name="vnf_name2">US1117MTSNJVBR0246</param>
127       <param name="vnf_nm_information"/>
128       <param name="vnf_type">pcrf-capacity</param>
129       <param name="vnf_id">skask</param>
130       <param name="vnf_stack_id">slowburn</param>
131       <param name="vnf_status">created</param>
132       <param name="aic_cloud_region">MDTWNJ21</param>
133       <param name="availability_zone">slcp3-esx-az01</param>
134       <param name="oam_network_name">VLAN-OAM-1323</param>
135       <param name="vm_name">slcp34246vbc246ceb</param>
136       <param name="ipag_network_id">970cd2b9-7f09-4a12-af47-182ea38ba1f0</param>
137       <param name="vpe_network_id">545cc2c3-1930-4100-b534-5d82d0e12bb6</param>
138    </volume-params>
139 </volume-request>"""
140                 
141         def completeMsoRequestXml = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
142                             xmlns:ns="http://org.onap/so/request/types/v1"
143                             xmlns="http://org.onap/so/infra/vnf-request/v1">
144    <request-info>
145       <request-id>1234</request-id>
146       <action>CREATE</action>
147       <source>VID</source>
148    </request-info>
149    <aetgt:status-message>Volume Group has been created successfully.</aetgt:status-message>
150    <aetgt:mso-bpel-name>BPMN VF Module Volume action: CREATE</aetgt:mso-bpel-name>
151 </aetgt:MsoCompletionRequest>"""
152
153
154     @Before
155         public void init()
156         {
157                 MockitoAnnotations.initMocks(this)
158         }
159         
160
161         @Test
162         @Ignore
163         public void testPreProcessRequest() {
164                 
165                 ExecutionEntity mockExecution = setupMock('CreateVfModuleVolumeInfraV1')
166
167                 when(mockExecution.getVariable("prefix")).thenReturn('CVMVINFRAV1_')
168                 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonRequest)
169                 when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
170                 when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
171                 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
172                 when(mockExecution.getVariable("mso.rollback")).thenReturn('true')
173                                                                 
174                 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
175                 createVfModuleVolumeInfraV1.preProcessRequest(mockExecution, 'true')
176                 
177                 // Capture the arguments to setVariable
178                 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
179                 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
180                 
181                 verify(mockExecution, times(15)).setVariable(captor1.capture(), captor2.capture())
182                 
183                 List<String> arg2List = captor2.getAllValues()
184                 String volumeRequestActual = arg2List.get(6)
185                 String isVidRequestActual = arg2List.get(8) 
186                 
187                 assertEquals(volumeRequestXml, volumeRequestActual.trim())
188                 assertEquals('true', isVidRequestActual)
189         }
190         
191         @Test
192         public void testPostProcessResponse() {
193                 
194                 ExecutionEntity mockExecution = setupMock('CreateVfModuleVolumeInfraV1')
195                 when(mockExecution.getVariable("dbReturnCode")).thenReturn('000')
196                 when(mockExecution.getVariable("CVMVINFRAV1_createDBResponse")).thenReturn('')
197                 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
198                 when(mockExecution.getVariable("CVMVINFRAV1_source")).thenReturn('VID')
199                                                                 
200                 CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
201                 createVfModuleVolumeInfraV1.postProcessResponse(mockExecution, 'true')
202                 
203                 verify(mockExecution).setVariable('CVMVINFRAV1_Success', true)
204                 verify(mockExecution).setVariable('CVMVINFRAV1_CompleteMsoProcessRequest', completeMsoRequestXml)
205         }
206         
207
208 }