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.ArgumentMatchers.any;
25 import static org.mockito.Matchers.eq;
26 import static org.mockito.ArgumentMatchers.isA;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
32 import java.util.Optional;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.ArgumentMatchers;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.junit.MockitoJUnitRunner;
41 import org.onap.so.bpmn.common.data.TestDataSetup;
42 import org.onap.so.bpmn.common.InjectionHelper;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
47 import org.onap.so.client.aai.AAIResourcesClient;
48 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
49 import org.onap.so.client.aai.mapper.AAIObjectMapper;
50 import org.onap.so.db.catalog.beans.OrchestrationStatus;
52 @RunWith(MockitoJUnitRunner.Silent.class)
53 public class AAIVnfResourcesTest extends TestDataSetup {
55 private GenericVnf genericVnf;
57 private ServiceInstance serviceInstance;
59 protected AAIResourcesClient MOCK_aaiResourcesClient;
62 protected AAIObjectMapper MOCK_aaiObjectMapper;
65 protected InjectionHelper MOCK_injectionHelper;
68 AAIVnfResources aaiVnfResources = new AAIVnfResources();
71 public void before() {
72 serviceInstance = buildServiceInstance();
73 genericVnf = buildGenericVnf();
74 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
78 public void createVnfandConnectServiceInstanceTest() {
79 doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf);
80 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
81 doNothing().when(MOCK_aaiResourcesClient).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
82 genericVnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
84 aaiVnfResources.createVnfandConnectServiceInstance(genericVnf, serviceInstance);
86 assertEquals(OrchestrationStatus.INVENTORIED, genericVnf.getOrchestrationStatus());
87 verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf);
88 verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
89 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
93 public void createPlatformandConnectVnfTest() {
94 Platform platform = new Platform();
95 platform.setPlatformName("a123");
96 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class));
97 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
98 aaiVnfResources.createPlatformandConnectVnf(platform, genericVnf);
99 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class));
103 public void createLineOfBusinessandConnectVnfTest() {
104 LineOfBusiness lob = new LineOfBusiness();
105 lob.setLineOfBusinessName("a123");
106 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class));
107 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
108 aaiVnfResources.createLineOfBusinessandConnectVnf(lob, genericVnf);
109 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class));
113 public void deleteVnfTest() {
114 doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
116 aaiVnfResources.deleteVnf(genericVnf);
118 verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
122 public void updateOrchestrationStatusVnfTest() {
123 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Vnf.class));
125 aaiVnfResources.updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
127 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), ArgumentMatchers.isNull());
129 assertEquals(OrchestrationStatus.ACTIVE, genericVnf.getOrchestrationStatus());
133 public void updateObjectVnfTest() {
134 doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf);
135 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class));
137 aaiVnfResources.updateObjectVnf(genericVnf);
139 verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf);
140 verify(MOCK_aaiResourcesClient, times(1)).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class));
144 public void getGenericVnfTest () {
145 Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf());
146 vnf.get().setVnfId("vnfId");
147 doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
148 aaiVnfResources.getGenericVnf("vnfId");
149 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
153 public void checkInMaintFlagTest () {
154 Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf());
155 vnf.get().setVnfId("vnfId");
156 vnf.get().setInMaint(true);
157 doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
158 boolean inMaintFlag = aaiVnfResources.checkInMaintFlag("vnfId");
159 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
160 assertEquals(inMaintFlag, true);