2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
18 import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
19 import com.nokia.cbam.lcm.v32.model.ResourceHandle;
20 import io.reactivex.Observable;
21 import java.util.ArrayList;
22 import java.util.NoSuchElementException;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.ArgumentCaptor;
26 import org.mockito.Mock;
27 import org.onap.aai.api.NetworkApi;
28 import org.onap.aai.model.Vnfc;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
32 import static junit.framework.TestCase.assertEquals;
33 import static org.mockito.Matchers.eq;
34 import static org.mockito.Mockito.verify;
35 import static org.mockito.Mockito.when;
36 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
37 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
38 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
39 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
40 import static org.springframework.test.util.ReflectionTestUtils.setField;
42 public class TestVnfcManager extends TestBase {
43 private ArgumentCaptor<Vnfc> payload = ArgumentCaptor.forClass(Vnfc.class);
46 private AAIRestApiProvider aaiRestApiProvider;
47 private VnfcManager vnfcManager;
49 private NetworkApi networkApi;
53 vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
54 setField(VnfcManager.class, "logger", logger);
55 when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
62 public void testCreate() throws Exception {
63 AffectedVnfc affectedVnfc = new AffectedVnfc();
64 affectedVnfc.setComputeResource(new ResourceHandle());
65 affectedVnfc.getComputeResource().setResourceId("serverProviderId");
66 affectedVnfc.setId("vnfcId");
67 when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(Observable.error(new NoSuchElementException()));
68 when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
70 vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
72 Vnfc vnfc = payload.getValue();
73 assertEquals("myVnfId_vnfcId", vnfc.getVnfcName());
74 assertEquals("vnfcId", vnfc.getNfcFunction());
75 assertEquals("vnfcId", vnfc.getNfcNamingCode());
76 assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
78 assertRelation(vnfc.getRelationshipList(), "vserver",
79 buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
80 buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
81 buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
82 buildRelationshipData("vserver.vserver-id", "serverProviderId"));
83 assertEquals(2, vnfc.getRelationshipList().size());
84 VOID_OBSERVABLE.assertCalled();
91 public void testUpdate() throws Exception {
92 AffectedVnfc affectedVnfc = new AffectedVnfc();
93 affectedVnfc.setComputeResource(new ResourceHandle());
94 affectedVnfc.getComputeResource().setResourceId("serverProviderId");
95 affectedVnfc.setId("vnfcId");
96 Vnfc existingVnfc = new Vnfc();
97 existingVnfc.setRelationshipList(new ArrayList<>());
98 existingVnfc.getRelationshipList().add(GenericVnfManager.linkTo("any"));
99 when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
100 when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
102 vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
104 Vnfc vnfc = payload.getValue();
105 assertEquals("myVnfId_vnfcId", vnfc.getVnfcName());
106 assertEquals("vnfcId", vnfc.getNfcFunction());
107 assertEquals("vnfcId", vnfc.getNfcNamingCode());
108 assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
110 assertRelation(vnfc.getRelationshipList(), "vserver",
111 buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
112 buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
113 buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
114 buildRelationshipData("vserver.vserver-id", "serverProviderId"));
115 assertEquals(2, vnfc.getRelationshipList().size());
116 VOID_OBSERVABLE.assertCalled();
123 public void testDelete() throws Exception {
124 AffectedVnfc affectedVnfc = new AffectedVnfc();
125 affectedVnfc.setComputeResource(new ResourceHandle());
126 affectedVnfc.getComputeResource().setResourceId("serverProviderId");
127 affectedVnfc.setId("vnfcId");
128 Vnfc existingVnfc = new Vnfc();
129 existingVnfc.setResourceVersion("v3");
130 existingVnfc.setVnfcName("myVnfId_vnfcId");
131 when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
132 when(networkApi.deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3")).thenReturn(VOID_OBSERVABLE.value());
134 vnfcManager.delete(VNF_ID, affectedVnfc);
136 verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3");
137 VOID_OBSERVABLE.assertCalled();
141 * test VNFC id conversion
144 public void testCbamId() {
145 assertEquals("b", VnfcManager.buildCbamId("a_b"));
153 public void testInheritence() {
154 assertEquals(logger, vnfcManager.getLogger());