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 java.util.Optional;
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;
50 @RunWith(MockitoJUnitRunner.class)
51 public class AAIVfModuleResourcesTest extends TestDataSetup{
53 private AAIVfModuleResources aaiVfModuleResources = new AAIVfModuleResources();
55 private VfModule vfModule;
56 private GenericVnf vnf;
59 protected AAIResourcesClient MOCK_aaiResourcesClient;
62 protected AAIObjectMapper MOCK_aaiObjectMapper;
65 protected InjectionHelper MOCK_injectionHelper;
68 public void before() {
69 vfModule = buildVfModule();
70 vnf = buildGenericVnf();
71 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
75 public void updateOrchestrationStatusVfModuleTest() throws Exception {
76 vfModule.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
78 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class));
80 aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.ACTIVE);
82 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VfModule.class));
84 assertEquals(OrchestrationStatus.ACTIVE, vfModule.getOrchestrationStatus());
88 public void createVfModuleTest() throws Exception {
89 vfModule.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
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);
95 verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
96 assertEquals(OrchestrationStatus.INVENTORIED, vfModule.getOrchestrationStatus());
100 public void deleteVfModuleTest() throws Exception {
101 doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
103 aaiVfModuleResources.deleteVfModule(vfModule, vnf);
105 verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
109 public void changeAssignVfModuleTest() throws Exception {
110 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class));
112 aaiVfModuleResources.changeAssignVfModule(vfModule, vnf);
114 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VfModule.class));
118 public void connectVfModuleToVolumeGroupTest() throws Exception {
119 VolumeGroup volumeGroup = buildVolumeGroup();
120 volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
122 CloudRegion cloudRegion = buildCloudRegion();
124 aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup, cloudRegion);
125 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
129 public void updateHeatStackIdVfModuleTest() throws Exception {
130 vfModule.setHeatStackId("testHeatStackId");
132 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class));
134 aaiVfModuleResources.updateHeatStackIdVfModule(vfModule, vnf);
136 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VfModule.class));
138 assertEquals("testHeatStackId", vfModule.getHeatStackId());