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