Merge "Remove unused exception"
[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.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;
28
29 import java.util.NoSuchElementException;
30
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;
40
41 public class TestVnfcManager extends TestBase {
42     private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
43     private ArgumentCaptor<Vnfc> payload = ArgumentCaptor.forClass(Vnfc.class);
44
45     @Mock
46     private AAIRestApiProvider aaiRestApiProvider;
47     private VnfcManager vnfcManager;
48
49     @Before
50     public void init() {
51         vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
52         setField(VnfcManager.class, "logger", logger);
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         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);
66         //when
67         vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
68         //verify
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));
74
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"));
80     }
81
82     /**
83      * test delete
84      */
85     @Test
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);
93         //when
94         vnfcManager.delete(VNF_ID, affectedVnfc);
95         //verify
96         aaiRestApiProvider.delete(logger, NETWORK, "/vnfcs/vnfc/myVnfId_vnfcId");
97     }
98
99     /**
100      * test inheritence
101      */
102     @Test
103     public void testInheritence() {
104         assertEquals(logger, vnfcManager.getLogger());
105     }
106
107
108 }