rename package for external use
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / orchestration / AAIVolumeGroupResourcesTest.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.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.ArgumentMatchers.isA;
29 import static org.mockito.Mockito.doNothing;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.times;
32 import static org.mockito.Mockito.verify;
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.InjectionHelper;
41 import org.onap.so.bpmn.common.data.TestDataSetup;
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.VolumeGroup;
45 import org.onap.aaiclient.client.aai.AAIObjectPlurals;
46 import org.onap.aaiclient.client.aai.AAIResourcesClient;
47 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri;
48 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
49 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
50 import org.onap.so.client.aai.mapper.AAIObjectMapper;
51 import org.onap.so.db.catalog.beans.OrchestrationStatus;
52
53 @RunWith(MockitoJUnitRunner.Silent.class)
54 public class AAIVolumeGroupResourcesTest extends TestDataSetup {
55     @InjectMocks
56     private AAIVolumeGroupResources aaiVolumeGroupResources = new AAIVolumeGroupResources();
57
58     private CloudRegion cloudRegion;
59     private VolumeGroup volumeGroup;
60
61     @Mock
62     protected AAIResourcesClient MOCK_aaiResourcesClient;
63
64     @Mock
65     protected AAIObjectMapper MOCK_aaiObjectMapper;
66
67     @Mock
68     protected InjectionHelper MOCK_injectionHelper;
69
70     @Before
71     public void before() {
72         cloudRegion = buildCloudRegion();
73         volumeGroup = buildVolumeGroup();
74         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
75     }
76
77
78
79     @Test
80     public void updateOrchestrationStatusVolumeGroupTest() throws Exception {
81         volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
82
83         doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class),
84                 isA(org.onap.aai.domain.yang.VolumeGroup.class));
85
86         aaiVolumeGroupResources.updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
87                 OrchestrationStatus.ACTIVE);
88
89         verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull());
90
91         assertEquals(OrchestrationStatus.ACTIVE, volumeGroup.getOrchestrationStatus());
92     }
93
94     @Test
95     public void createVolumeGroupTest() throws Exception {
96         volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
97
98         doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class),
99                 isA(org.onap.aai.domain.yang.VolumeGroup.class));
100
101         aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
102
103         verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), ArgumentMatchers.isNull());
104
105         assertEquals(OrchestrationStatus.ASSIGNED, volumeGroup.getOrchestrationStatus());
106     }
107
108     @Test
109     public void connectVolumeGroupToVnfTest() throws Exception {
110
111         volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
112
113         doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
114
115         aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion);
116
117         verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
118     }
119
120     @Test
121     public void connectVolumeGroupToTenantTest() throws Exception {
122         GenericVnf genericVnf = buildGenericVnf();
123
124         volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
125
126         doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
127
128         aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
129
130         verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
131     }
132
133     @Test
134     public void deleteVolumeGroupTest() {
135         doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
136
137         aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
138
139         verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
140     }
141
142     @Test
143     public void updateHeatStackIdVolumeGroupTest() throws Exception {
144         volumeGroup.setHeatStackId("testVolumeHeatStackId");
145
146         doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class),
147                 isA(org.onap.aai.domain.yang.VolumeGroup.class));
148
149         aaiVolumeGroupResources.updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
150
151         verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull());
152
153         assertEquals("testVolumeHeatStackId", volumeGroup.getHeatStackId());
154     }
155
156     @Test
157     public void checkNameInUseTrueTest() {
158         AAIPluralResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP)
159                 .queryParam("volume-group-name", "testVolumeGroupName1");
160         doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(volumeGroupUri));
161         boolean nameInUse = aaiVolumeGroupResources.checkNameInUse(volumeGroup);
162         assertTrue(nameInUse);
163     }
164
165     @Test
166     public void checkNameInUseFalseTest() {
167         AAIPluralResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP)
168                 .queryParam("volume-group-name", "testVolumeGroupName1");
169         doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(volumeGroupUri));
170         boolean nameInUse = aaiVolumeGroupResources.checkNameInUse(volumeGroup);
171         assertFalse(nameInUse);
172     }
173 }