Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / orchestration / AAIVfModuleResourcesTest.java
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.client.orchestration;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.isA;
26 import static org.mockito.Mockito.doNothing;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30
31 import java.util.Optional;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.ArgumentMatchers;
37 import org.mockito.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.junit.MockitoJUnitRunner;
40 import org.onap.so.bpmn.common.data.TestDataSetup;
41 import org.onap.so.bpmn.common.InjectionHelper;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
46 import org.onap.so.client.aai.AAIResourcesClient;
47 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
48 import org.onap.so.client.aai.mapper.AAIObjectMapper;
49 import org.onap.so.db.catalog.beans.OrchestrationStatus;
50
51 @RunWith(MockitoJUnitRunner.Silent.class)
52 public class AAIVfModuleResourcesTest extends TestDataSetup{
53         @InjectMocks
54         private AAIVfModuleResources aaiVfModuleResources = new AAIVfModuleResources();
55
56         private VfModule vfModule;
57         private GenericVnf vnf;
58
59         @Mock
60         protected AAIResourcesClient MOCK_aaiResourcesClient;
61
62         @Mock
63         protected AAIObjectMapper MOCK_aaiObjectMapper;
64
65         @Mock
66         protected InjectionHelper MOCK_injectionHelper;
67
68         @Before
69         public void before() {
70                 vfModule = buildVfModule();
71                 vnf = buildGenericVnf();
72                  doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
73         }
74
75         @Test
76         public void updateOrchestrationStatusVfModuleTest() throws Exception {
77                 vfModule.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
78
79                 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class));
80
81                 aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.ACTIVE);
82
83                 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class),ArgumentMatchers.isNull());
84
85                 assertEquals(OrchestrationStatus.ACTIVE, vfModule.getOrchestrationStatus());
86         }
87
88         @Test
89         public void createVfModuleTest() throws Exception {
90                 vfModule.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
91
92                 doReturn(new org.onap.aai.domain.yang.VfModule()).when(MOCK_aaiObjectMapper).mapVfModule(vfModule);
93                 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
94                 aaiVfModuleResources.createVfModule(vfModule, vnf);
95
96                 verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
97                 assertEquals(OrchestrationStatus.INVENTORIED, vfModule.getOrchestrationStatus());
98         }
99
100         @Test
101         public void deleteVfModuleTest() throws Exception {
102                 doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
103
104                 aaiVfModuleResources.deleteVfModule(vfModule, vnf);
105
106                 verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));            
107         }
108
109         @Test
110         public void changeAssignVfModuleTest() throws Exception {
111                 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class));
112
113                 aaiVfModuleResources.changeAssignVfModule(vfModule, vnf);
114
115                 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull()); 
116         }
117
118         @Test
119         public void connectVfModuleToVolumeGroupTest() throws Exception {
120                 VolumeGroup volumeGroup = buildVolumeGroup();
121                 volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
122
123                 CloudRegion cloudRegion = buildCloudRegion();
124
125                 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup, cloudRegion);
126                 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
127         }
128         
129         @Test
130         public void updateHeatStackIdVfModuleTest() throws Exception {
131                 vfModule.setHeatStackId("testHeatStackId");
132                 
133                 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class));
134                 
135                 aaiVfModuleResources.updateHeatStackIdVfModule(vfModule, vnf);
136
137                 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class),ArgumentMatchers.isNull());
138                 
139                 assertEquals("testHeatStackId", vfModule.getHeatStackId());
140         }
141 }