2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.orchestration;
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;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.runners.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;
47 @RunWith(MockitoJUnitRunner.class)
48 public class AAIVolumeGroupResourcesTest extends TestDataSetup{
50 private AAIVolumeGroupResources aaiVolumeGroupResources = new AAIVolumeGroupResources();
52 private CloudRegion cloudRegion;
53 private VolumeGroup volumeGroup;
56 protected AAIResourcesClient MOCK_aaiResourcesClient;
59 protected AAIObjectMapper MOCK_aaiObjectMapper;
62 protected InjectionHelper MOCK_injectionHelper;
65 public void before() {
66 cloudRegion = buildCloudRegion();
67 volumeGroup = buildVolumeGroup();
68 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
74 public void updateOrchestrationStatusVolumeGroupTest() throws Exception {
75 volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
77 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VolumeGroup.class));
79 aaiVolumeGroupResources.updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
81 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VolumeGroup.class));
83 assertEquals(OrchestrationStatus.ACTIVE, volumeGroup.getOrchestrationStatus());
87 public void createVolumeGroupTest() throws Exception {
88 volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
90 doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VolumeGroup.class));
92 aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion);
94 verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VolumeGroup.class));
96 assertEquals(OrchestrationStatus.ASSIGNED, volumeGroup.getOrchestrationStatus());
100 public void connectVolumeGroupToVnfTest() throws Exception {
102 volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
104 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
106 aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion);
108 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
112 public void connectVolumeGroupToTenantTest() throws Exception {
113 GenericVnf genericVnf = buildGenericVnf();
115 volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
117 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
119 aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion);
121 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
125 public void deleteVolumeGroupTest() {
126 doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
128 aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion);
130 verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
134 public void updateHeatStackIdVolumeGroupTest() throws Exception {
135 volumeGroup.setHeatStackId("testVolumeHeatStackId");
137 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VolumeGroup.class));
139 aaiVolumeGroupResources.updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
141 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VolumeGroup.class));
143 assertEquals("testVolumeHeatStackId", volumeGroup.getHeatStackId());