Replaced all tabs with spaces in java and pom.xml
[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.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 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.ArgumentMatchers;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.so.bpmn.common.data.TestDataSetup;
38 import org.onap.so.bpmn.common.InjectionHelper;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
42 import org.onap.so.client.aai.AAIResourcesClient;
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
44 import org.onap.so.client.aai.mapper.AAIObjectMapper;
45 import org.onap.so.db.catalog.beans.OrchestrationStatus;
46
47 @RunWith(MockitoJUnitRunner.Silent.class)
48 public class AAIVolumeGroupResourcesTest extends TestDataSetup {
49     @InjectMocks
50     private AAIVolumeGroupResources aaiVolumeGroupResources = new AAIVolumeGroupResources();
51
52     private CloudRegion cloudRegion;
53     private VolumeGroup volumeGroup;
54
55     @Mock
56     protected AAIResourcesClient MOCK_aaiResourcesClient;
57
58     @Mock
59     protected AAIObjectMapper MOCK_aaiObjectMapper;
60
61     @Mock
62     protected InjectionHelper MOCK_injectionHelper;
63
64     @Before
65     public void before() {
66         cloudRegion = buildCloudRegion();
67         volumeGroup = buildVolumeGroup();
68         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
69     }
70
71
72
73     @Test
74     public void updateOrchestrationStatusVolumeGroupTest() throws Exception {
75         volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
76
77         doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class),
78                 isA(org.onap.aai.domain.yang.VolumeGroup.class));
79
80         aaiVolumeGroupResources.updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
81                 OrchestrationStatus.ACTIVE);
82
83         verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull());
84
85         assertEquals(OrchestrationStatus.ACTIVE, volumeGroup.getOrchestrationStatus());
86     }
87
88     @Test
89     public void createVolumeGroupTest() throws Exception {
90         volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
91
92         doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class),
93                 isA(org.onap.aai.domain.yang.VolumeGroup.class));
94
95         aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
96
97         verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), ArgumentMatchers.isNull());
98
99         assertEquals(OrchestrationStatus.ASSIGNED, volumeGroup.getOrchestrationStatus());
100     }
101
102     @Test
103     public void connectVolumeGroupToVnfTest() throws Exception {
104
105         volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
106
107         doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
108
109         aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion);
110
111         verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
112     }
113
114     @Test
115     public void connectVolumeGroupToTenantTest() throws Exception {
116         GenericVnf genericVnf = buildGenericVnf();
117
118         volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
119
120         doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
121
122         aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
123
124         verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
125     }
126
127     @Test
128     public void deleteVolumeGroupTest() {
129         doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
130
131         aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
132
133         verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
134     }
135
136     @Test
137     public void updateHeatStackIdVolumeGroupTest() throws Exception {
138         volumeGroup.setHeatStackId("testVolumeHeatStackId");
139
140         doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class),
141                 isA(org.onap.aai.domain.yang.VolumeGroup.class));
142
143         aaiVolumeGroupResources.updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
144
145         verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull());
146
147         assertEquals("testVolumeHeatStackId", volumeGroup.getHeatStackId());
148     }
149 }