Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / UpdateVfModuleVolumeTest.groovy
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
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.onap.so.bpmn.infrastructure.scripts
22
23
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.junit.Assert
27 import org.junit.Before
28 import org.junit.Rule
29 import org.junit.Test
30 import org.junit.rules.ExpectedException
31 import org.junit.runner.RunWith
32 import org.mockito.ArgumentCaptor
33 import org.mockito.Captor
34 import org.mockito.MockitoAnnotations
35 import org.mockito.runners.MockitoJUnitRunner
36 import org.onap.aai.domain.yang.GenericVnf
37 import org.onap.aai.domain.yang.VfModule
38 import org.onap.aai.domain.yang.VolumeGroup
39 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
40 import org.onap.so.bpmn.mock.FileUtil
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.AAIResultWrapper
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory
45 import org.onap.so.constants.Defaults
46
47 import javax.ws.rs.core.UriBuilder
48
49 import static org.mockito.Mockito.*
50
51 @RunWith(MockitoJUnitRunner.class)
52 class UpdateVfModuleVolumeTest extends MsoGroovyTest{
53         
54     def prefix = "UPDVfModVol_"
55     @Captor
56     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
57
58     @Rule
59     public ExpectedException thrown = ExpectedException.none()
60         
61
62         @Before
63         public void init(){
64         super.init("UpdateVfModuleVolume")
65                 MockitoAnnotations.initMocks(this)
66     }
67
68
69     @Test
70     void testQueryAAIForVolumeGroup() {
71         String aicCloudRegion = "aicCloudRegionId"
72         String volumeGroupId = "volumeGroupId"
73         when(mockExecution.getVariable("UPDVfModVol_volumeGroupId")).thenReturn(volumeGroupId)
74         when(mockExecution.getVariable("UPDVfModVol_aicCloudRegion")).thenReturn(aicCloudRegion)
75
76         UpdateVfModuleVolume obj = spy(UpdateVfModuleVolume.class)
77         when(obj.getAAIClient()).thenReturn(client)
78         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
79         VolumeGroup volumeGroup = new VolumeGroup();
80         volumeGroup.setVolumeGroupId(volumeGroupId)
81
82         AAIResultWrapper wrapper = new AAIResultWrapper(FileUtil.readResourceFile("__files/aai/VolumeGroupWithTenant.json"))
83         when(client.get(uri)).thenReturn(wrapper)
84         obj.queryAAIForVolumeGroup(mockExecution)
85         verify(mockExecution).setVariable("UPDVfModVol_volumeGroupHeatStackId","heatStackId")
86     }
87
88     @Test
89     void testQueryAAIForVolumeGroupNoTenant() {
90         String aicCloudRegion = "aicCloudRegionId"
91         String volumeGroupId = "volumeGroupId"
92         when(mockExecution.getVariable("UPDVfModVol_volumeGroupId")).thenReturn(volumeGroupId)
93         when(mockExecution.getVariable("UPDVfModVol_aicCloudRegion")).thenReturn(aicCloudRegion)
94
95         UpdateVfModuleVolume obj = spy(UpdateVfModuleVolume.class)
96         when(obj.getAAIClient()).thenReturn(client)
97         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
98         VolumeGroup volumeGroup = new VolumeGroup();
99         volumeGroup.setVolumeGroupId(volumeGroupId)
100
101         AAIResultWrapper wrapper = new AAIResultWrapper(FileUtil.readResourceFile("__files/aai/VolumeGroupWithTenant.json"))
102         when(client.get(uri)).thenThrow(Exception.class)
103         thrown.expect(BpmnError.class)
104         obj.queryAAIForVolumeGroup(mockExecution)
105     }
106 }