2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
23 import static org.junit.Assert.*
\r
24 import static org.mockito.Mockito.*
\r
26 import org.apache.commons.lang3.*
\r
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
\r
28 import org.junit.Assert
\r
29 import org.junit.Before
\r
30 import org.junit.Test
\r
31 import org.junit.runner.RunWith
\r
32 import org.mockito.ArgumentCaptor
\r
33 import org.mockito.MockitoAnnotations
\r
34 import org.mockito.runners.MockitoJUnitRunner
\r
35 import org.openecomp.mso.bpmn.common.scripts.MsoGroovyTest
\r
38 @RunWith(MockitoJUnitRunner.class)
\r
39 class DoCreateVfModuleVolumeV1Test extends MsoGroovyTest {
\r
42 """<volume-request xmlns="http://org.openecomp/mso/infra/vnf-request/v1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
\r
44 <test-data-only>123abc</test-data-only> <!-- don't remove this tag. Its used for junit test -->
\r
45 <request-id>d8d4fcfa-fd7e-4413-b19d-c95aa67291b8</request-id>
\r
46 <action>CREATE_VF_MODULE_VOL</action>
\r
47 <source>SoapUI-bns-create-base-vol-1001-1</source>
\r
50 <vnf-type>Test/vSAMP12</vnf-type>
\r
51 <vf-module-model-name>vSAMP12::base::module-0</vf-module-model-name>
\r
52 <backout-on-failure>true</backout-on-failure>
\r
53 <asdc-service-model-version>2.0</asdc-service-model-version>
\r
54 <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
\r
55 <aic-cloud-region>MDTWNJ21</aic-cloud-region>
\r
56 <tenant-id>897deadc2b954a6bac6d3c197fb3525e</tenant-id>
\r
57 <volume-group-name>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volume-group-name>
\r
61 <param name="param1">value1</param>"
\r
62 <param name="param2">value2</param>"
\r
63 <param name="param3">value3</param>"
\r
65 </volume-request>"""
\r
67 def genericVnfResponseXml = """
\r
68 <generic-vnf xmlns="http://org.openecomp.aai.inventory/v8">
\r
69 <vnf-id>TEST-VNF-ID-0123</vnf-id>
\r
70 <vnf-name>STMTN5MMSC20</vnf-name>
\r
71 <vnf-type>pcrf-capacity</vnf-type>
\r
72 <service-id>SDN-MOBILITY</service-id>
\r
73 <equipment-role>vPCRF</equipment-role>
\r
74 <orchestration-status>pending-create</orchestration-status>
\r
75 <in-maint>false</in-maint>
\r
76 <is-closed-loop-disabled>false</is-closed-loop-disabled>
\r
77 <persona-model-id>introvert</persona-model-id>
\r
78 <persona-model-version>2.0</persona-model-version>
\r
79 <resource-version>0000020</resource-version>
\r
82 <vf-module-id>lukewarm</vf-module-id>
\r
83 <vf-module-name>PCRF::module-0-0</vf-module-name>
\r
84 <persona-model-id>introvert</persona-model-id>
\r
85 <persona-model-version>2.0</persona-model-version>
\r
86 <is-base-vf-module>true</is-base-vf-module>
\r
87 <heat-stack-id>fastburn</heat-stack-id>
\r
88 <orchestration-status>pending-create</orchestration-status>
\r
89 <resource-version>0000074</resource-version>
\r
92 <vf-module-id>supercool</vf-module-id>
\r
93 <vf-module-name>PCRF::module-1-0</vf-module-name>
\r
94 <persona-model-id>extrovert</persona-model-id>
\r
95 <persona-model-version>2.0</persona-model-version>
\r
96 <is-base-vf-module>false</is-base-vf-module>
\r
97 <heat-stack-id>slowburn</heat-stack-id>
\r
98 <orchestration-status>pending-create</orchestration-status>
\r
99 <resource-version>0000075</resource-version>
\r
102 <relationship-list/>
\r
107 def String expectedCreateVnfRequestXml = """<createVolumeGroupRequest>
\r
108 <cloudSiteId>MDTWNJ21</cloudSiteId>
\r
109 <tenantId>897deadc2b954a6bac6d3c197fb3525e</tenantId>
\r
110 <vnfId>TEST-VNF-ID-0123</vnfId>
\r
111 <vnfName>STMTN5MMSC20</vnfName>
\r
112 <volumeGroupId>test-vol-group-id-123</volumeGroupId>
\r
113 <volumeGroupName>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volumeGroupName>
\r
114 <vnfType>Test/vSAMP12</vnfType>
\r
115 <vnfVersion>2.0</vnfVersion>
\r
116 <vfModuleType>vSAMP12::base::module-0</vfModuleType>
\r
117 <modelCustomizationUuid/>
\r
118 <volumeGroupParams>
\r
121 <value>TEST-VNF-ID-0123</value>
\r
124 <key>vnf_name</key>
\r
125 <value>STMTN5MMSC20</value>
\r
128 <key>vf_module_id</key>
\r
129 <value>test-vol-group-id-123</value>
\r
132 <key>vf_module_name</key>
\r
133 <value>MSOTESTVOL101a-vSAMP12_base_vol_module-0</value>
\r
137 <value>value1</value>
\r
141 <value>value2</value>
\r
145 <value>value3</value>
\r
147 </volumeGroupParams>
\r
148 <skipAAI>true</skipAAI>
\r
149 <backout>true</backout>
\r
150 <failIfExists>true</failIfExists>
\r
152 <requestId>d8d4fcfa-fd7e-4413-b19d-c95aa67291b8</requestId>
\r
153 <serviceInstanceId>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</serviceInstanceId>
\r
155 <messageId>111</messageId>
\r
156 <notificationUrl>http://localhost:28080/mso/WorkflowMessage/12345678</notificationUrl>
\r
157 </createVolumeGroupRequest>
\r
163 MockitoAnnotations.initMocks(this)
\r
168 public void TestPreProcessRequest() {
\r
170 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV1')
\r
172 when(mockExecution.getVariable("DoCreateVfModuleVolumeV1Request")).thenReturn(volumeRequest)
\r
173 when(mockExecution.getVariable("vnf-id")).thenReturn('test-vnf-id-123')
\r
174 when(mockExecution.getVariable("volume-group-id")).thenReturn('test-volume-group-id-123')
\r
175 when(mockExecution.getVariable("mso-request-id")).thenReturn('test-request-id-123')
\r
177 DoCreateVfModuleVolumeV1 myprocess = new DoCreateVfModuleVolumeV1()
\r
178 myprocess.preProcessRequest(mockExecution, 'true')
\r
180 verify(mockExecution).setVariable('DCVFMODVOLV1_serviceId', 'a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb')
\r
181 verify(mockExecution).setVariable('DCVFMODVOLV1_source', 'SoapUI-bns-create-base-vol-1001-1')
\r
182 verify(mockExecution, times(7)).setVariable(anyString(), anyString())
\r
186 public void TestPrepareVnfAdapterCreateRequest() {
\r
188 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV1')
\r
190 when(mockExecution.getVariable("DCVFMODVOLV1_Request")).thenReturn(volumeRequest)
\r
191 when(mockExecution.getVariable("DCVFMODVOLV1_requestId")).thenReturn('d8d4fcfa-fd7e-4413-b19d-c95aa67291b8')
\r
192 when(mockExecution.getVariable("DCVFMODVOLV1_serviceId")).thenReturn('a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb')
\r
193 when(mockExecution.getVariable("DCVFMODVOLV1_AAIQueryGenericVfnResponse")).thenReturn(genericVnfResponseXml)
\r
194 when(mockExecution.getVariable("DCVFMODVOLV1_rollbackEnabled")).thenReturn(true)
\r
195 when(mockExecution.getVariable("volume-group-id")).thenReturn('test-vol-group-id-123')
\r
196 when(mockExecution.getVariable("URN_mso_workflow_message_endpoint")).thenReturn('http://localhost:28080/mso/WorkflowMessage')
\r
197 when(mockExecution.getVariable("URN_mso_use_qualified_host")).thenReturn(true)
\r
199 DoCreateVfModuleVolumeV1 myprocess = new DoCreateVfModuleVolumeV1()
\r
200 myprocess.prepareVnfAdapterCreateRequest(mockExecution, 'true')
\r
202 // Capture the arguments to setVariable
\r
203 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
\r
204 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
\r
206 verify(mockExecution, times(2)).setVariable(captor1.capture(), captor2.capture())
\r
208 List<String> arg2List = captor2.getAllValues()
\r
209 String createVnfRequestXml = arg2List.get(0)
\r
211 //replace messageID value because it is random generated
\r
212 createVnfRequestXml = createVnfRequestXml.replaceAll("<messageId>(.+?)</messageId>", "<messageId>111</messageId>")
\r
213 .replaceAll("<notificationUrl>(.+?)</notificationUrl>", "<notificationUrl>http://localhost:28080/mso/WorkflowMessage/12345678</notificationUrl>")
\r
215 Assert.assertEquals(expectedCreateVnfRequestXml.trim(), createVnfRequestXml.trim())
\r