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.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
26 import org.junit.runner.RunWith
27 import org.mockito.ArgumentCaptor
28 import org.mockito.Captor
29 import org.mockito.Mockito
30 import org.mockito.MockitoAnnotations
31 import org.mockito.runners.MockitoJUnitRunner
32 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
34 import static org.junit.Assert.assertEquals
35 import static org.junit.Assert.assertNotNull
36 import static org.mockito.Mockito.times
37 import static org.mockito.Mockito.when
40 @RunWith(MockitoJUnitRunner.class)
41 class DoCreateVfModuleVolumeV2Test extends MsoGroovyTest {
44 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
46 def String volumeRollbackRequest = """
47 <rollbackVolumeGroupRequest>
49 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
50 <volumeGroupStackId>{{VOLUMEGROUPSTACKID}}</volumeGroupStackId>
51 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
52 <cloudSiteId>mtwnj1a</cloudSiteId>
53 <volumeGroupCreated>true</volumeGroupCreated>
55 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
56 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
58 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
59 </volumeGroupRollback>
60 <skipAAI>true</skipAAI>
61 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
62 </rollbackVolumeGroupRequest>
65 def String volumeRollbackRequestWithStackId = """
66 <rollbackVolumeGroupRequest>
68 <volumeGroupId>171907d6-cdf0-4e08-953d-81ee104005a7</volumeGroupId>
69 <volumeGroupStackId>mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8</volumeGroupStackId>
70 <tenantId>c2141e3fcae940fcb4797ec9115e5a7a</tenantId>
71 <cloudSiteId>mtwnj1a</cloudSiteId>
72 <volumeGroupCreated>true</volumeGroupCreated>
74 <requestId>230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5</requestId>
75 <serviceInstanceId>88c871d6-be09-4982-8490-96b1d243fb34</serviceInstanceId>
77 <messageId>9a5a91e8-3b79-463c-81c3-874a78f5b567</messageId>
78 </volumeGroupRollback>
79 <skipAAI>true</skipAAI>
80 <notificationUrl>http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567</notificationUrl>
81 </rollbackVolumeGroupRequest>
89 MockitoAnnotations.initMocks(this)
93 public void testBuildRollbackVolumeGroupRequestXml() {
94 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
95 String xml = process.buildRollbackVolumeGroupRequestXml(
96 "171907d6-cdf0-4e08-953d-81ee104005a7", // volumeGroupId
97 "mtwnj1a", // cloudSiteId
98 "c2141e3fcae940fcb4797ec9115e5a7a", // tenantId
99 "230fd6ac-2a39-4be4-9b1e-7b7e1cc039b5", // requestId
100 "88c871d6-be09-4982-8490-96b1d243fb34", // serviceInstanceId
101 "9a5a91e8-3b79-463c-81c3-874a78f5b567", // messageId
102 "http://localhost:8080/mso/WorkflowMessage/VNFAResponse/9a5a91e8-3b79-463c-81c3-874a78f5b567") // notificationUrl
104 assertEquals(volumeRollbackRequest.replaceAll("\\s", ""), xml.replaceAll("\\s", ""))
109 public void testUpdateRollbackVolumeGroupRequestXml() {
110 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
111 String updatedXml = process.updateRollbackVolumeGroupRequestXml(volumeRollbackRequest, "mdt22avrr_volume01/0f1aaae8-efe3-45ce-83e1-bfad01db58d8")
112 assertEquals(volumeRollbackRequestWithStackId.replaceAll("\\s", ""), updatedXml.replaceAll("\\s", ""))
116 public void testPrepareVnfAdapterCreateRequest (){
117 ExecutionEntity mockExecution = setupMock('DoCreateVfModuleVolumeV2')
119 when(mockExecution.getVariable("prefix")).thenReturn('DCVFMODVOLV2_')
120 when(mockExecution.getVariable("serviceInstanceId")).thenReturn('')
121 when(mockExecution.getVariable("vnfId")).thenReturn('test-vnf-id')
122 when(mockExecution.getVariable("mso-request-id")).thenReturn('1234')
123 when(mockExecution.getVariable("volumeGroupId")).thenReturn('1234')
124 when(mockExecution.getVariable("mso.use.qualified.host")).thenReturn("true")
125 when(mockExecution.getVariable("mso.workflow.message.endpoint")).thenReturn("http://localhost:28080/mso/WorkflowMesssage")
126 Map vfModuleInputParams = new HashMap()
127 vfModuleInputParams.put("param1","value1")
128 when(mockExecution.getVariable("vfModuleInputParams")).thenReturn(vfModuleInputParams)
129 DoCreateVfModuleVolumeV2 process = new DoCreateVfModuleVolumeV2()
130 process.prepareVnfAdapterCreateRequest(mockExecution,"true");
131 Mockito.verify(mockExecution,times(2)).setVariable(captor.capture(), captor.capture())
132 String DCVFMODVOLV2_createVnfARequest = captor.getValue();
133 assertNotNull(DCVFMODVOLV2_createVnfARequest)