cf95ed30853387ad3dbb8e1b5cb16b2f2099c2a7
[so.git] /
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
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.apache.commons.lang3.*
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
28 import org.junit.Assert
29 import org.junit.Before
30 import org.junit.Test
31 import org.junit.runner.RunWith
32 import org.mockito.ArgumentCaptor
33 import org.mockito.MockitoAnnotations
34 import org.mockito.runners.MockitoJUnitRunner
35 import org.openecomp.mso.bpmn.common.scripts.MsoGroovyTest
36
37
38 @RunWith(MockitoJUnitRunner.class)
39 class DoCreateVfModuleVolumeV1Test extends MsoGroovyTest  {
40         
41         def volumeRequest =
42 """<volume-request xmlns="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
43         <request-info>
44                 <test-data-only>123abc</test-data-only> <!-- don't remove this tag. Its used for junit test -->
45                 <request-id>d8d4fcfa-fd7e-4413-b19d-c95aa67291b8</request-id>
46                 <action>CREATE_VF_MODULE_VOL</action>
47                 <source>SoapUI-bns-create-base-vol-1001-1</source>
48         </request-info>
49         <volume-inputs>
50                 <vnf-type>Test/vSAMP12</vnf-type>
51                 <vf-module-model-name>vSAMP12::base::module-0</vf-module-model-name>
52                 <backout-on-failure>true</backout-on-failure>
53                 <asdc-service-model-version>2.0</asdc-service-model-version>
54                 <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
55                 <aic-cloud-region>MDTWNJ21</aic-cloud-region>
56                 <tenant-id>897deadc2b954a6bac6d3c197fb3525e</tenant-id>
57                 <volume-group-name>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volume-group-name>
58                 <volume-group-id/>
59         </volume-inputs>
60         <volume-params>
61                 <param name="param1">value1</param>"
62                 <param name="param2">value2</param>"
63                 <param name="param3">value3</param>"
64         </volume-params>        
65 </volume-request>"""
66
67         def genericVnfResponseXml = """
68 <generic-vnf xmlns="http://org.openecomp.aai.inventory/v8">
69         <vnf-id>TEST-VNF-ID-0123</vnf-id>
70         <vnf-name>STMTN5MMSC20</vnf-name>
71         <vnf-type>pcrf-capacity</vnf-type>
72         <service-id>SDN-MOBILITY</service-id>
73         <equipment-role>vPCRF</equipment-role>
74         <orchestration-status>pending-create</orchestration-status>
75         <in-maint>false</in-maint>
76         <is-closed-loop-disabled>false</is-closed-loop-disabled>
77         <persona-model-id>introvert</persona-model-id>
78         <persona-model-version>2.0</persona-model-version>
79         <resource-version>0000020</resource-version>
80         <vf-modules>
81                 <vf-module>
82                         <vf-module-id>lukewarm</vf-module-id>
83                         <vf-module-name>PCRF::module-0-0</vf-module-name>
84                         <persona-model-id>introvert</persona-model-id>
85                         <persona-model-version>2.0</persona-model-version>
86                         <is-base-vf-module>true</is-base-vf-module>
87                         <heat-stack-id>fastburn</heat-stack-id>
88                         <orchestration-status>pending-create</orchestration-status>
89                         <resource-version>0000074</resource-version>
90                 </vf-module>
91                 <vf-module>
92                         <vf-module-id>supercool</vf-module-id>
93                         <vf-module-name>PCRF::module-1-0</vf-module-name>
94                         <persona-model-id>extrovert</persona-model-id>
95                         <persona-model-version>2.0</persona-model-version>
96                         <is-base-vf-module>false</is-base-vf-module>
97                         <heat-stack-id>slowburn</heat-stack-id>
98                         <orchestration-status>pending-create</orchestration-status>
99                         <resource-version>0000075</resource-version>
100                 </vf-module>
101         </vf-modules>
102         <relationship-list/>
103         <l-interfaces/>
104         <lag-interfaces/>
105 </generic-vnf>
106 """             
107         def String expectedCreateVnfRequestXml = """<createVolumeGroupRequest>
108    <cloudSiteId>MDTWNJ21</cloudSiteId>
109    <tenantId>897deadc2b954a6bac6d3c197fb3525e</tenantId>
110    <vnfId>TEST-VNF-ID-0123</vnfId>
111    <vnfName>STMTN5MMSC20</vnfName>
112    <volumeGroupId>test-vol-group-id-123</volumeGroupId>
113    <volumeGroupName>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volumeGroupName>
114    <vnfType>Test/vSAMP12</vnfType>
115    <vnfVersion>2.0</vnfVersion>
116    <vfModuleType>vSAMP12::base::module-0</vfModuleType>
117    <modelCustomizationUuid/>
118    <volumeGroupParams>
119       <entry>
120          <key>vnf_id</key>
121          <value>TEST-VNF-ID-0123</value>
122       </entry>
123       <entry>
124          <key>vnf_name</key>
125          <value>STMTN5MMSC20</value>
126       </entry>
127       <entry>
128          <key>vf_module_id</key>
129          <value>test-vol-group-id-123</value>
130       </entry>
131       <entry>
132          <key>vf_module_name</key>
133          <value>MSOTESTVOL101a-vSAMP12_base_vol_module-0</value>
134       </entry>
135       <entry>
136          <key>param1</key>
137          <value>value1</value>
138       </entry>
139       <entry>
140          <key>param2</key>
141          <value>value2</value>
142       </entry>
143       <entry>
144          <key>param3</key>
145          <value>value3</value>
146       </entry>
147    </volumeGroupParams>
148    <skipAAI>true</skipAAI>
149    <backout>true</backout>
150    <failIfExists>true</failIfExists>
151    <msoRequest>
152       <requestId>d8d4fcfa-fd7e-4413-b19d-c95aa67291b8</requestId>
153       <serviceInstanceId>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</serviceInstanceId>
154    </msoRequest>
155    <messageId>111</messageId>
156    <notificationUrl>http://localhost:28080/mso/WorkflowMessage/12345678</notificationUrl>
157 </createVolumeGroupRequest>
158 """
159
160     @Before
161         public void init()
162         {
163                 MockitoAnnotations.initMocks(this)
164                 
165         }
166         
167         @Test
168         public void TestPreProcessRequest() {
169                 
170                 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV1')
171                 
172                 when(mockExecution.getVariable("DoCreateVfModuleVolumeV1Request")).thenReturn(volumeRequest)
173                 when(mockExecution.getVariable("vnf-id")).thenReturn('test-vnf-id-123')
174                 when(mockExecution.getVariable("volume-group-id")).thenReturn('test-volume-group-id-123')
175                 when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123')
176                                                                 
177                 DoCreateVfModuleVolumeV1 myprocess = new DoCreateVfModuleVolumeV1()
178                 myprocess.preProcessRequest(mockExecution, 'true')
179                 
180                 verify(mockExecution).setVariable('DCVFMODVOLV1_serviceId', 'a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb')
181                 verify(mockExecution).setVariable('DCVFMODVOLV1_source', 'SoapUI-bns-create-base-vol-1001-1')
182                 verify(mockExecution, times(7)).setVariable(anyString(), anyString())
183         }
184         
185         @Test
186         public void TestPrepareVnfAdapterCreateRequest() {
187                 
188                 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV1')
189                 
190                 when(mockExecution.getVariable("DCVFMODVOLV1_Request")).thenReturn(volumeRequest)
191                 when(mockExecution.getVariable("DCVFMODVOLV1_requestId")).thenReturn('d8d4fcfa-fd7e-4413-b19d-c95aa67291b8')
192                 when(mockExecution.getVariable("DCVFMODVOLV1_serviceId")).thenReturn('a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb')
193                 when(mockExecution.getVariable("DCVFMODVOLV1_AAIQueryGenericVfnResponse")).thenReturn(genericVnfResponseXml)
194                 when(mockExecution.getVariable("DCVFMODVOLV1_rollbackEnabled")).thenReturn(true)
195                 when(mockExecution.getVariable("volume-group-id")).thenReturn('test-vol-group-id-123')
196                 when(mockExecution.getVariable("URN_mso_workflow_message_endpoint")).thenReturn('http://localhost:28080/mso/WorkflowMessage')
197                 when(mockExecution.getVariable("URN_mso_use_qualified_host")).thenReturn(true)
198                                                                 
199                 DoCreateVfModuleVolumeV1 myprocess = new DoCreateVfModuleVolumeV1()
200                 myprocess.prepareVnfAdapterCreateRequest(mockExecution, 'true')
201                 
202                 // Capture the arguments to setVariable
203                 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
204                 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
205                 
206                 verify(mockExecution, times(2)).setVariable(captor1.capture(), captor2.capture())
207                 
208                 List<String> arg2List = captor2.getAllValues()
209                 String createVnfRequestXml = arg2List.get(0)
210                 
211                 //replace messageID value because it is random generated
212                 createVnfRequestXml = createVnfRequestXml.replaceAll("<messageId>(.+?)</messageId>", "<messageId>111</messageId>")
213                                                                                                  .replaceAll("<notificationUrl>(.+?)</notificationUrl>", "<notificationUrl>http://localhost:28080/mso/WorkflowMessage/12345678</notificationUrl>")
214                 
215                 Assert.assertEquals(expectedCreateVnfRequestXml.trim(), createVnfRequestXml.trim())
216         }
217
218 }