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 / TestVnfcManager.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.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.api.NetworkApi;
25 import org.onap.aai.model.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;
28
29 import static junit.framework.TestCase.assertEquals;
30 import static org.mockito.Matchers.eq;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.when;
33 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
34 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
35 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
36 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
37 import static org.springframework.test.util.ReflectionTestUtils.setField;
38
39 public class TestVnfcManager extends TestBase {
40     private ArgumentCaptor<Vnfc> payload = ArgumentCaptor.forClass(Vnfc.class);
41
42     @Mock
43     private AAIRestApiProvider aaiRestApiProvider;
44     private VnfcManager vnfcManager;
45     @Mock
46     private NetworkApi networkApi;
47
48     @Before
49     public void init() {
50         vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
51         setField(VnfcManager.class, "logger", logger);
52         when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
53     }
54
55     /**
56      * test update
57      */
58     @Test
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         Vnfc existingVnfc = new Vnfc();
65         when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
66         when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(null);
67         //when
68         vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
69         //verify
70         Vnfc vnfc = payload.getValue();
71         assertEquals("myVnfId_vnfcId", vnfc.getVnfcName());
72         assertEquals("vnfcId", vnfc.getNfcFunction());
73         assertEquals("vnfcId", vnfc.getNfcNamingCode());
74         assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
75
76         assertRelation(vnfc.getRelationshipList(), "vserver",
77                 buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
78                 buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
79                 buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
80                 buildRelationshipData("vserver.vserver-id", "serverProviderId"));
81     }
82
83     /**
84      * test delete
85      */
86     @Test
87     public void testDelete() throws Exception {
88         AffectedVnfc affectedVnfc = new AffectedVnfc();
89         affectedVnfc.setComputeResource(new ResourceHandle());
90         affectedVnfc.getComputeResource().setResourceId("serverProviderId");
91         affectedVnfc.setId("vnfcId");
92         Vnfc existingVnfc = new Vnfc();
93         existingVnfc.setResourceVersion("v3");
94         existingVnfc.setVnfcName("myVnfId_vnfcId");
95         when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
96         //when
97         vnfcManager.delete(VNF_ID, affectedVnfc);
98         //verify
99         verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3");
100     }
101
102     /**
103      * test inheritence
104      */
105     @Test
106     public void testInheritence() {
107         assertEquals(logger, vnfcManager.getLogger());
108     }
109
110
111 }