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.google.gson.JsonObject;
19 import com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
20 import com.nokia.cbam.lcm.v32.model.ResourceHandle;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.ArgumentCaptor;
24 import org.mockito.Mock;
25 import org.onap.aai.domain.yang.v11.L3Network;
26 import org.onap.aai.domain.yang.v11.ObjectFactory;
27 import org.onap.aai.domain.yang.v11.RelationshipList;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
31 import java.util.NoSuchElementException;
33 import static junit.framework.TestCase.assertEquals;
34 import static junit.framework.TestCase.assertFalse;
35 import static org.mockito.Matchers.eq;
36 import static org.mockito.Mockito.verify;
37 import static org.mockito.Mockito.when;
38 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
39 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
40 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
41 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
42 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
43 import static org.springframework.test.util.ReflectionTestUtils.setField;
45 public class TestL3NetworkManager extends TestBase {
46 private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
47 private ArgumentCaptor<L3Network> payload = ArgumentCaptor.forClass(L3Network.class);
48 private AffectedVirtualLink affectedVirtualLink = new AffectedVirtualLink();
50 private AAIRestApiProvider aaiRestApiProvider;
51 private L3NetworkManager l3NetworkManager;
55 l3NetworkManager = new L3NetworkManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
56 setField(L3NetworkManager.class, "logger", logger);
60 * test L3 network creation
63 public void testUpdate() throws Exception {
64 affectedVirtualLink.setId("vlId");
65 JsonObject additionalData = new JsonObject();
66 additionalData.addProperty("name", "netName");
67 additionalData.addProperty("tenantId", "myTenantId");
68 affectedVirtualLink.setResource(new ResourceHandle());
69 affectedVirtualLink.getResource().setAdditionalData(additionalData);
70 affectedVirtualLink.getResource().setResourceId("netProviderId");
71 when(aaiRestApiProvider.get(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId", L3Network.class)).thenThrow(new NoSuchElementException());
72 when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/l3-networks/l3-network/myVnfId_vlId"), payload.capture(), eq(Void.class))).thenReturn(null);
74 l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
76 assertEquals("myVnfId_vlId", payload.getValue().getNetworkId());
77 assertEquals("netName", payload.getValue().getNetworkName());
78 assertEquals("netProviderId", payload.getValue().getNeutronNetworkId());
79 assertFalse(payload.getValue().isIsBoundToVpn());
80 assertFalse(payload.getValue().isIsProviderNetwork());
81 assertFalse(payload.getValue().isIsSharedNetwork());
82 assertFalse(payload.getValue().isIsExternalNetwork());
83 assertEquals("active", payload.getValue().getOperationalStatus());
84 assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
85 assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
86 assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
90 * Test existing resource update
93 public void testExistingUpdate() throws Exception {
94 affectedVirtualLink.setId("vlId");
95 JsonObject additionalData = new JsonObject();
96 additionalData.addProperty("name", "netName");
97 additionalData.addProperty("tenantId", "myTenantId");
98 affectedVirtualLink.setResource(new ResourceHandle());
99 affectedVirtualLink.getResource().setAdditionalData(additionalData);
100 affectedVirtualLink.getResource().setResourceId("netProviderId");
101 L3Network l3Network = OBJECT_FACTORY.createL3Network();
102 l3Network.setResourceVersion("v3");
103 l3Network.setRelationshipList(new RelationshipList());
104 when(aaiRestApiProvider.get(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId", L3Network.class)).thenReturn(l3Network);
105 when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/l3-networks/l3-network/myVnfId_vlId"), payload.capture(), eq(Void.class))).thenReturn(null);
107 l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
109 assertEquals("myVnfId_vlId", payload.getValue().getNetworkId());
110 assertEquals("netName", payload.getValue().getNetworkName());
111 assertEquals("netProviderId", payload.getValue().getNeutronNetworkId());
112 assertFalse(payload.getValue().isIsBoundToVpn());
113 assertFalse(payload.getValue().isIsProviderNetwork());
114 assertFalse(payload.getValue().isIsSharedNetwork());
115 assertFalse(payload.getValue().isIsExternalNetwork());
116 assertEquals("active", payload.getValue().getOperationalStatus());
117 assertEquals("v3", payload.getValue().getResourceVersion());
118 assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
119 assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
120 assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
123 * test L3 network deletion
126 public void testDelete() throws Exception {
127 affectedVirtualLink.setId("vlId");
129 l3NetworkManager.delete(VNF_ID, affectedVirtualLink);
131 verify(aaiRestApiProvider).delete(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId");
138 public void testInheritence() {
139 assertEquals(logger, l3NetworkManager.getLogger());