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