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 org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.ArgumentCaptor;
23 import org.mockito.Mock;
24 import org.onap.aai.domain.yang.v11.ObjectFactory;
25 import org.onap.aai.domain.yang.v11.Vnfc;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
29 import java.util.NoSuchElementException;
31 import static junit.framework.TestCase.assertEquals;
32 import static org.mockito.Matchers.eq;
33 import static org.mockito.Mockito.when;
34 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
35 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
36 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
37 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
38 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
39 import static org.springframework.test.util.ReflectionTestUtils.setField;
41 public class TestVnfcManager extends TestBase {
42 private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
43 private ArgumentCaptor<Vnfc> payload = ArgumentCaptor.forClass(Vnfc.class);
46 private AAIRestApiProvider aaiRestApiProvider;
47 private VnfcManager vnfcManager;
51 vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
52 setField(VnfcManager.class, "logger", logger);
59 public void testUpdate() throws Exception {
60 AffectedVnfc affectedVnfc = new AffectedVnfc();
61 affectedVnfc.setComputeResource(new ResourceHandle());
62 affectedVnfc.getComputeResource().setResourceId("serverProviderId");
63 affectedVnfc.setId("vnfcId");
64 when(aaiRestApiProvider.get(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), eq(Vnfc.class))).thenThrow(new NoSuchElementException());
65 when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), payload.capture(), eq(Void.class))).thenReturn(null);
67 vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
69 Vnfc vnfc = payload.getValue();
70 assertEquals("myVnfId_vnfcId", vnfc.getVnfcName());
71 assertEquals("vnfcId", vnfc.getNfcFunction());
72 assertEquals("vnfcId", vnfc.getNfcNamingCode());
73 assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
75 assertRelation(vnfc.getRelationshipList(), "vserver",
76 buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
77 buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
78 buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
79 buildRelationshipData("vserver.vserver-id", "serverProviderId"));
86 public void testDelete() throws Exception {
87 AffectedVnfc affectedVnfc = new AffectedVnfc();
88 affectedVnfc.setComputeResource(new ResourceHandle());
89 affectedVnfc.getComputeResource().setResourceId("serverProviderId");
90 affectedVnfc.setId("vnfcId");
91 when(aaiRestApiProvider.get(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), eq(Vnfc.class))).thenThrow(new NoSuchElementException());
92 when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), payload.capture(), eq(Void.class))).thenReturn(null);
94 vnfcManager.delete(VNF_ID, affectedVnfc);
96 aaiRestApiProvider.delete(logger, NETWORK, "/vnfcs/vnfc/myVnfId_vnfcId");
103 public void testInheritence() {
104 assertEquals(logger, vnfcManager.getLogger());