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.openecomp.mso.bpmn.infrastructure.scripts;
23 import static org.junit.Assert.*
24 import static org.mockito.Mockito.*
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
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
38 @RunWith(MockitoJUnitRunner.class)
39 class DoCreateVfModuleVolumeV1Test extends MsoGroovyTest {
42 """<volume-request xmlns="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
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>
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>
61 <param name="param1">value1</param>"
62 <param name="param2">value2</param>"
63 <param name="param3">value3</param>"
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>
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>
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>
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/>
121 <value>TEST-VNF-ID-0123</value>
125 <value>STMTN5MMSC20</value>
128 <key>vf_module_id</key>
129 <value>test-vol-group-id-123</value>
132 <key>vf_module_name</key>
133 <value>MSOTESTVOL101a-vSAMP12_base_vol_module-0</value>
137 <value>value1</value>
141 <value>value2</value>
145 <value>value3</value>
148 <skipAAI>true</skipAAI>
149 <backout>true</backout>
150 <failIfExists>true</failIfExists>
152 <requestId>d8d4fcfa-fd7e-4413-b19d-c95aa67291b8</requestId>
153 <serviceInstanceId>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</serviceInstanceId>
155 <messageId>111</messageId>
156 <notificationUrl>http://localhost:28080/mso/WorkflowMessage/12345678</notificationUrl>
157 </createVolumeGroupRequest>
163 MockitoAnnotations.initMocks(this)
168 public void TestPreProcessRequest() {
170 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV1')
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')
177 DoCreateVfModuleVolumeV1 myprocess = new DoCreateVfModuleVolumeV1()
178 myprocess.preProcessRequest(mockExecution, 'true')
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())
186 public void TestPrepareVnfAdapterCreateRequest() {
188 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV1')
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)
199 DoCreateVfModuleVolumeV1 myprocess = new DoCreateVfModuleVolumeV1()
200 myprocess.prepareVnfAdapterCreateRequest(mockExecution, 'true')
202 // Capture the arguments to setVariable
203 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
204 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
206 verify(mockExecution, times(2)).setVariable(captor1.capture(), captor2.capture())
208 List<String> arg2List = captor2.getAllValues()
209 String createVnfRequestXml = arg2List.get(0)
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>")
215 Assert.assertEquals(expectedCreateVnfRequestXml.trim(), createVnfRequestXml.trim())