Fix sonar issues
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / restapi / TestSoApi.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
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
18
19 import junit.framework.TestCase;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.mockito.Mockito;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.so.SoLifecycleManager;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
27 import org.onap.vnfmadapter.so.model.*;
28
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
31 import static org.springframework.test.util.ReflectionTestUtils.setField;
32
33
34 public class TestSoApi extends TestBase {
35
36     @Mock
37     private SoLifecycleManager soLifecycleManager;
38     @InjectMocks
39     private SoApi soApi;
40     @Mock
41     private SoJobHandler jobHandler;
42
43     @Before
44     public void initMocks() throws Exception {
45         setField(SoApi.class, "logger", logger);
46     }
47
48     /**
49      * test create
50      */
51     @Test
52     public void testCreate() {
53         SoVnfCreationRequest soRequest = Mockito.mock(SoVnfCreationRequest.class);
54         SoVnfCreationResponse vnf = new SoVnfCreationResponse();
55         when(soLifecycleManager.create(VNFM_ID, soRequest)).thenReturn(vnf);
56         //when
57         SoVnfCreationResponse actual = soApi.createVnf(soRequest, VNFM_ID, httpResponse);
58         //verify
59         verify(logger).info("REST: Create the VNF");
60         TestCase.assertEquals(vnf, actual);
61     }
62
63     /**
64      * test activation
65      */
66     @Test
67     public void testActivate() {
68         SoVnfActivationRequest soRequest = Mockito.mock(SoVnfActivationRequest.class);
69         when(soLifecycleManager.activate(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler);
70         //when
71         SoJobHandler soJobHandler = soApi.activateVnf(soRequest, VNFM_ID, VNF_ID, httpResponse);
72         //verify
73         verify(logger).info("REST: Activate the VNF");
74         TestCase.assertEquals(jobHandler, soJobHandler);
75     }
76
77     /**
78      * test scale
79      */
80     @Test
81     public void testScale() {
82         SoVnfScaleRequest soRequest = Mockito.mock(SoVnfScaleRequest.class);
83         when(soLifecycleManager.scale(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler);
84         //when
85         SoJobHandler soJobHandler = soApi.scaleVnf(soRequest, VNFM_ID, VNF_ID, httpResponse);
86         //verify
87         verify(logger).info("REST: Scale the VNF");
88         TestCase.assertEquals(jobHandler, soJobHandler);
89     }
90
91     /**
92      * test heal
93      */
94     @Test
95     public void testHeal() {
96         SoVnfHealRequest soRequest = Mockito.mock(SoVnfHealRequest.class);
97         when(soLifecycleManager.heal(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler);
98         //when
99         SoJobHandler soJobHandler = soApi.healVnf(soRequest, VNFM_ID, VNF_ID, httpResponse);
100         //verify
101         verify(logger).info("REST: Heal the VNF");
102         TestCase.assertEquals(jobHandler, soJobHandler);
103     }
104
105
106     /**
107      * test custom
108      */
109     @Test
110     public void testCustom() {
111         SoVnfCustomOperation soRequest = Mockito.mock(SoVnfCustomOperation.class);
112         when(soLifecycleManager.customOperation(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler);
113         //when
114         SoJobHandler soJobHandler = soApi.executeCustomOperation(soRequest, VNFM_ID, VNF_ID, httpResponse);
115         //verify
116         verify(logger).info("REST: Execute custom operation on the VNF");
117         TestCase.assertEquals(jobHandler, soJobHandler);
118     }
119
120     /**
121      * test deactivation
122      */
123     @Test
124     public void testDeactivation() {
125         SoVnfTerminationRequest soRequest = Mockito.mock(SoVnfTerminationRequest.class);
126         when(soLifecycleManager.deactivate(VNFM_ID, VNF_ID, soRequest, httpResponse)).thenReturn(jobHandler);
127         //when
128         SoJobHandler soJobHandler = soApi.deactivateVnf(soRequest, VNFM_ID, VNF_ID, httpResponse);
129         //verify
130         verify(logger).info("REST: Deactivate the VNF");
131         TestCase.assertEquals(jobHandler, soJobHandler);
132     }
133
134     /**
135      * test delete
136      */
137     @Test
138     public void testDelete() {
139         //when
140         soApi.deleteVnf(VNFM_ID, VNF_ID, httpResponse);
141         //verify
142         verify(logger).info("REST: Delete the VNF");
143         verify(soLifecycleManager).delete(VNFM_ID, VNF_ID);
144     }
145
146     /**
147      * test deactivation
148      */
149     @Test
150     public void testGetJob() {
151         SoJobDetail jobDetail = new SoJobDetail();
152         when(soLifecycleManager.getJobDetails(VNFM_ID, JOB_ID)).thenReturn(jobDetail);
153         //when
154         SoJobDetail actial = soApi.getJob(VNFM_ID, JOB_ID, httpResponse);
155         //verify
156         verify(logger).trace("REST: Query the job");
157         TestCase.assertEquals(jobDetail, actial);
158     }
159
160 }