aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOInfrastructureBPMN/src/test/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateVfModuleVolumeInfraV1Test.groovy
blob: df0613185f7abad2f7d0be0179d1585a4dc6309c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*- 
 * ============LICENSE_START======================================================= 
 * ONAP - SO 
 * ================================================================================ 
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
 * ================================================================================ 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * ============LICENSE_END========================================================= 
 */ 

package org.openecomp.mso.bpmn.infrastructure.scripts;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*

import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
import org.mockito.ArgumentCaptor
import org.mockito.MockitoAnnotations
import org.mockito.runners.MockitoJUnitRunner
import org.openecomp.mso.bpmn.common.scripts.MsoGroovyTest
import org.junit.Before
import org.junit.Ignore;
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(MockitoJUnitRunner.class)
import org.apache.commons.lang3.*


class CreateVfModuleVolumeInfraV1Test extends MsoGroovyTest {

	def jsonRequest = """
{
	"requestDetails": {
		"modelInfo": {
			"modelType": "volumeGroup",
			"modelId": "ff5256d2-5a33-55df-13ab-12abad84e7ff",
			"modelNameVersionId": "fe6478e5-ea33-3346-ac12-ab121484a3fe",
			"modelName": "vSAMP12::base::module-0",
			"modelVersion": "1"
		},
		"cloudConfiguration": {
			"lcpCloudRegionId": "mdt1",
			"tenantId": "88a6ca3ee0394ade9403f075db23167e"
		},
		"requestInfo": {
			"instanceName": "MSOTESTVOL101a-vSAMP12_base_vol_module-0",
			"source": "VID",
			"suppressRollback": false
		},
		"relatedInstanceList": [
			{
				"relatedInstance": {
					"instanceId": "{service-instance-id}",
					"modelInfo": {
						"modelType": "service",
						"modelInvariantUuid": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
						"modelUuid": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
						"modelName": "Test",
						"modelVersion": "2.0"
					}
				}
			}, {
				"relatedInstance": {
					"instanceId": "{vnf-instance-id}",
					"modelInfo": {
						"modelType": "vnf",
						"modelId": "ff5256d1-5a33-55df-13ab-12abad84e7ff",
						"modelNameVersionId": "fe6478e4-ea33-3346-ac12-ab121484a3fe",
						"modelName": "vSAMP12",
						"modelVersion": "1",
						"modelInstanceName": "vSAMP12"
					}
				}
			}
		],
		"requestParameters": {
			"serviceId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
			"userParams": [
				{"name": "vnfName", "value": "STMTN5MMSC20" },
				{"name": "vnfName2", "value": "US1117MTSNJVBR0246" },
				{"name": "vnfNmInformation", "value": "" },
				{"name": "vnfType", "value": "pcrf-capacity" },
				{"name": "vnfId", "value": "skask" },
				{"name": "vnfStackId", "value": "slowburn" },
				{"name": "vnfStatus", "value": "created" },
				{"name": "aicCloudRegion", "value": "MDTWNJ21" },
				{"name": "availabilityZone", "value": "slcp3-esx-az01" },
				{"name": "oamNetworkName", "value": "VLAN-OAM-1323" },
				{"name": "vmName", "value": "slcp34246vbc246ceb" },
				{"name": "ipagNetworkId", "value": "970cd2b9-7f09-4a12-af47-182ea38ba1f0" },
				{"name": "vpeNetworkId", "value": "545cc2c3-1930-4100-b534-5d82d0e12bb6" }
			]
		}
	}
}
"""
	
	def volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema">
   <request-info>
      <action>CREATE_VF_MODULE_VOL</action>
      <source>VID</source>
      <service-instance-id/>
   </request-info>
   <volume-inputs>
      <volume-group-id/>
      <volume-group-name>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volume-group-name>
      <vnf-type>Test/vSAMP12</vnf-type>
      <vf-module-model-name>vSAMP12::base::module-0</vf-module-model-name>
      <asdc-service-model-version>2.0</asdc-service-model-version>
      <aic-cloud-region>mdt1</aic-cloud-region>
      <tenant-id>88a6ca3ee0394ade9403f075db23167e</tenant-id>
      <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
      <backout-on-failure>true</backout-on-failure>
      <model-customization-id/>
   </volume-inputs>
   <volume-params>
      <param name="vnf_name">STMTN5MMSC20</param>
      <param name="vnf_name2">US1117MTSNJVBR0246</param>
      <param name="vnf_nm_information"/>
      <param name="vnf_type">pcrf-capacity</param>
      <param name="vnf_id">skask</param>
      <param name="vnf_stack_id">slowburn</param>
      <param name="vnf_status">created</param>
      <param name="aic_cloud_region">MDTWNJ21</param>
      <param name="availability_zone">slcp3-esx-az01</param>
      <param name="oam_network_name">VLAN-OAM-1323</param>
      <param name="vm_name">slcp34246vbc246ceb</param>
      <param name="ipag_network_id">970cd2b9-7f09-4a12-af47-182ea38ba1f0</param>
      <param name="vpe_network_id">545cc2c3-1930-4100-b534-5d82d0e12bb6</param>
   </volume-params>
</volume-request>"""
	 	
	def completeMsoRequestXml = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
                            xmlns:ns="http://org.openecomp/mso/request/types/v1"
                            xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
   <request-info>
      <request-id>1234</request-id>
      <action>CREATE</action>
      <source>VID</source>
   </request-info>
   <aetgt:status-message>Volume Group has been created successfully.</aetgt:status-message>
   <aetgt:mso-bpel-name>BPMN VF Module Volume action: CREATE</aetgt:mso-bpel-name>
</aetgt:MsoCompletionRequest>"""


    @Before
	public void init()
	{
		MockitoAnnotations.initMocks(this)
	}
	

	@Test
	@Ignore
	public void testPreProcessRequest() {
		
		ExecutionEntity mockExecution = setupMock('CreateVfModuleVolumeInfraV1')

		when(mockExecution.getVariable("prefix")).thenReturn('CVMVINFRAV1_')
		when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonRequest)
		when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
		when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
		when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
		when(mockExecution.getVariable("URN_mso_rollback")).thenReturn('true')
								
		CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
		createVfModuleVolumeInfraV1.preProcessRequest(mockExecution, 'true')
		
		// Capture the arguments to setVariable
		ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
		ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
		
		verify(mockExecution, times(15)).setVariable(captor1.capture(), captor2.capture())
		
		List<String> arg2List = captor2.getAllValues()
		String volumeRequestActual = arg2List.get(6)
		String isVidRequestActual = arg2List.get(8) 
		
		assertEquals(volumeRequestXml, volumeRequestActual.trim())
		assertEquals('true', isVidRequestActual)
	}
	
	@Test
	public void testPostProcessResponse() {
		
		ExecutionEntity mockExecution = setupMock('CreateVfModuleVolumeInfraV1')
		when(mockExecution.getVariable("dbReturnCode")).thenReturn('000')
		when(mockExecution.getVariable("CVMVINFRAV1_createDBResponse")).thenReturn('')
		when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
		when(mockExecution.getVariable("CVMVINFRAV1_source")).thenReturn('VID')
								
		CreateVfModuleVolumeInfraV1 createVfModuleVolumeInfraV1 = new CreateVfModuleVolumeInfraV1()
		createVfModuleVolumeInfraV1.postProcessResponse(mockExecution, 'true')
		
		verify(mockExecution).setVariable('CVMVINFRAV1_Success', true)
		verify(mockExecution).setVariable('CVMVINFRAV1_CompleteMsoProcessRequest', completeMsoRequestXml)
	}
	

}