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.eq;
26 import static org.mockito.Matchers.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.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.runners.MockitoJUnitRunner;
40 import org.onap.so.bpmn.common.data.TestDataSetup;
41 import org.onap.so.bpmn.common.InjectionHelper;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
46 import org.onap.so.client.aai.AAIResourcesClient;
47 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
48 import org.onap.so.client.aai.mapper.AAIObjectMapper;
49 import org.onap.so.db.catalog.beans.OrchestrationStatus;
51 @RunWith(MockitoJUnitRunner.class)
52 public class AAIVnfResourcesTest extends TestDataSetup {
54 private GenericVnf genericVnf;
56 private ServiceInstance serviceInstance;
58 protected AAIResourcesClient MOCK_aaiResourcesClient;
61 protected AAIObjectMapper MOCK_aaiObjectMapper;
64 protected InjectionHelper MOCK_injectionHelper;
67 AAIVnfResources aaiVnfResources = new AAIVnfResources();
70 public void before() {
71 serviceInstance = buildServiceInstance();
72 genericVnf = buildGenericVnf();
73 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
77 public void createVnfandConnectServiceInstanceTest() {
78 doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf);
79 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
80 doNothing().when(MOCK_aaiResourcesClient).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
81 genericVnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
83 aaiVnfResources.createVnfandConnectServiceInstance(genericVnf, serviceInstance);
85 assertEquals(OrchestrationStatus.INVENTORIED, genericVnf.getOrchestrationStatus());
86 verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf);
87 verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
88 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
92 public void createPlatformandConnectVnfTest() {
93 Platform platform = new Platform();
94 platform.setPlatformName("a123");
95 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class));
96 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
97 aaiVnfResources.createPlatformandConnectVnf(platform, genericVnf);
98 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class));
102 public void createLineOfBusinessandConnectVnfTest() {
103 LineOfBusiness lob = new LineOfBusiness();
104 lob.setLineOfBusinessName("a123");
105 doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class));
106 doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class));
107 aaiVnfResources.createLineOfBusinessandConnectVnf(lob, genericVnf);
108 verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class));
112 public void deleteVnfTest() {
113 doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class));
115 aaiVnfResources.deleteVnf(genericVnf);
117 verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class));
121 public void updateOrchestrationStatusVnfTest() {
122 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Vnf.class));
124 aaiVnfResources.updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
126 verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.Vnf.class));
128 assertEquals(OrchestrationStatus.ACTIVE, genericVnf.getOrchestrationStatus());
132 public void updateObjectVnfTest() {
133 doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf);
134 doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class));
136 aaiVnfResources.updateObjectVnf(genericVnf);
138 verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf);
139 verify(MOCK_aaiResourcesClient, times(1)).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class));
143 public void getGenericVnfTest () {
144 Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf());
145 vnf.get().setVnfId("vnfId");
146 doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
147 aaiVnfResources.getGenericVnf("vnfId");
148 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
152 public void checkInMaintFlagTest () {
153 Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf());
154 vnf.get().setVnfId("vnfId");
155 vnf.get().setInMaint(true);
156 doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
157 boolean inMaintFlag = aaiVnfResources.checkInMaintFlag("vnfId");
158 verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class));
159 assertEquals(inMaintFlag, true);