Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / onap / direct / notification / TestL3NetworkManager.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
17
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 java.util.ArrayList;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.ArgumentCaptor;
25 import org.mockito.Mock;
26 import org.onap.aai.api.NetworkApi;
27 import org.onap.aai.model.L3Network;
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;
30
31 import static junit.framework.TestCase.assertEquals;
32 import static junit.framework.TestCase.assertFalse;
33 import static org.mockito.Matchers.eq;
34 import static org.mockito.Mockito.when;
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;
40
41 public class TestL3NetworkManager extends TestBase {
42     private ArgumentCaptor<L3Network> payload = ArgumentCaptor.forClass(L3Network.class);
43     private AffectedVirtualLink affectedVirtualLink = new AffectedVirtualLink();
44     @Mock
45     private AAIRestApiProvider aaiRestApiProvider;
46     private L3NetworkManager l3NetworkManager;
47     @Mock
48     private NetworkApi networkApi;
49
50     @Before
51     public void init() {
52         l3NetworkManager = new L3NetworkManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
53         setField(L3NetworkManager.class, "logger", logger);
54         when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
55     }
56
57     /**
58      * test L3 network creation
59      */
60     @Test
61     public void testUpdate() throws Exception {
62         affectedVirtualLink.setId("vlId");
63         JsonObject additionalData = new JsonObject();
64         additionalData.addProperty("name", "netName");
65         additionalData.addProperty("tenantId", "myTenantId");
66         affectedVirtualLink.setResource(new ResourceHandle());
67         affectedVirtualLink.getResource().setAdditionalData(additionalData);
68         affectedVirtualLink.getResource().setResourceId("netProviderId");
69         L3Network existingNetwork = new L3Network();
70         when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingNetwork));
71         when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
72         //when
73         l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
74         //verify
75         assertEquals("myVnfId_vlId", payload.getValue().getNetworkId());
76         assertEquals("netName", payload.getValue().getNetworkName());
77         assertEquals("netProviderId", payload.getValue().getNeutronNetworkId());
78         assertFalse(payload.getValue().isIsBoundToVpn());
79         assertFalse(payload.getValue().isIsProviderNetwork());
80         assertFalse(payload.getValue().isIsSharedNetwork());
81         assertFalse(payload.getValue().isIsExternalNetwork());
82         assertEquals("active", payload.getValue().getOperationalStatus());
83         assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
84         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"));
85         assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
86     }
87
88     /**
89      * Test existing resource update
90      */
91     @Test
92     public void testExistingUpdate() throws Exception {
93         affectedVirtualLink.setId("vlId");
94         JsonObject additionalData = new JsonObject();
95         additionalData.addProperty("name", "netName");
96         additionalData.addProperty("tenantId", "myTenantId");
97         affectedVirtualLink.setResource(new ResourceHandle());
98         affectedVirtualLink.getResource().setAdditionalData(additionalData);
99         affectedVirtualLink.getResource().setResourceId("netProviderId");
100         L3Network l3Network = new L3Network();
101         l3Network.setResourceVersion("v3");
102         l3Network.setRelationshipList(new ArrayList<>());
103         when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
104         when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
105         //when
106         l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
107         //verify
108         assertEquals("myVnfId_vlId", payload.getValue().getNetworkId());
109         assertEquals("netName", payload.getValue().getNetworkName());
110         assertEquals("netProviderId", payload.getValue().getNeutronNetworkId());
111         assertFalse(payload.getValue().isIsBoundToVpn());
112         assertFalse(payload.getValue().isIsProviderNetwork());
113         assertFalse(payload.getValue().isIsSharedNetwork());
114         assertFalse(payload.getValue().isIsExternalNetwork());
115         assertEquals("active", payload.getValue().getOperationalStatus());
116         assertEquals("v3", payload.getValue().getResourceVersion());
117         assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
118         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"));
119         assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
120     }
121
122     /**
123      * test L3 network deletion
124      */
125     @Test
126     public void testDelete() throws Exception {
127         affectedVirtualLink.setId("vlId");
128         L3Network l3Network = new L3Network();
129         l3Network.setResourceVersion("v3");
130         when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
131         //when
132         l3NetworkManager.delete(VNF_ID, affectedVirtualLink);
133         //verify
134         networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3");
135     }
136
137     /**
138      * test inheritence
139      */
140     @Test
141     public void testInheritence() {
142         assertEquals(logger, l3NetworkManager.getLogger());
143     }
144
145
146 }