Fix sonar issues
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / restapi / TestLcmApi.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 org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.InjectMocks;
22 import org.mockito.Mock;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
26 import org.onap.vnfmdriver.model.VnfHealRequest;
27 import org.onap.vnfmdriver.model.VnfInstantiateRequest;
28 import org.onap.vnfmdriver.model.VnfScaleRequest;
29 import org.onap.vnfmdriver.model.VnfTerminateRequest;
30
31 import static java.util.Optional.empty;
32
33 import static org.apache.http.HttpStatus.SC_CREATED;
34 import static org.mockito.Mockito.verify;
35 import static org.springframework.test.util.ReflectionTestUtils.setField;
36
37
38 public class TestLcmApi extends TestBase {
39
40     @Mock
41     private LifecycleManager lifecycleManager;
42     @Mock
43     private JobManager jobManager;
44     @InjectMocks
45     private LcmApi lcmApi;
46
47     @Before
48     public void initMocks() throws Exception {
49         setField(LcmApi.class, "logger", logger);
50     }
51
52     /**
53      * test instantiation handled by LCM
54      */
55     @Test
56     public void testInstantiation() {
57         VnfInstantiateRequest req = new VnfInstantiateRequest();
58         //when
59         lcmApi.instantiateVnf(req, VNFM_ID, httpResponse);
60         //verify
61         verify(lifecycleManager).createAndInstantiate(VNFM_ID, req, httpResponse);
62         verify(httpResponse).setStatus(SC_CREATED);
63         verify(logger).info("REST: Instantiate VNF");
64     }
65
66     /**
67      * test heal handled by LCM
68      */
69     @Test
70     public void testHeal() {
71         VnfHealRequest req = new VnfHealRequest();
72         //when
73         lcmApi.healVnf(req, VNFM_ID, VNF_ID, httpResponse);
74         //verify
75         verify(lifecycleManager).healVnf(VNFM_ID, VNF_ID, req, empty(), httpResponse);
76         verify(logger).info("REST: Heal VNF");
77     }
78
79     /**
80      * test query handled by LCM
81      */
82     @Test
83     public void testQuery() {
84         //when
85         lcmApi.queryVnf(VNFM_ID, VNF_ID, httpResponse);
86         //verify
87         verify(lifecycleManager).queryVnf(VNFM_ID, VNF_ID);
88         verify(logger).info("REST: Query VNF");
89
90     }
91
92     /**
93      * test scale handled by LCM
94      */
95     @Test
96     public void testScale() {
97         VnfScaleRequest req = new VnfScaleRequest();
98         //when
99         lcmApi.scaleVnf(req, VNFM_ID, VNF_ID, httpResponse);
100         //verify
101         verify(lifecycleManager).scaleVnf(VNFM_ID, VNF_ID, req, httpResponse);
102         verify(logger).info("REST: Scale VNF");
103
104     }
105
106     /**
107      * test terminate handled by LCM
108      */
109     @Test
110     public void testTerminate() {
111         VnfTerminateRequest req = new VnfTerminateRequest();
112         //when
113         lcmApi.terminateVnf(req, VNFM_ID, VNF_ID, httpResponse);
114         //verify
115         verify(lifecycleManager).terminateAndDelete(VNFM_ID, VNF_ID, req, httpResponse);
116         verify(logger).info("REST: Terminate VNF");
117
118     }
119
120     /**
121      * test job query handled by job manager
122      */
123     @Test
124     public void testJob() {
125         //when
126         lcmApi.getJob(VNFM_ID, JOB_ID, httpResponse);
127         //verify
128         verify(jobManager).getJob(VNFM_ID, JOB_ID);
129         verify(logger).debug("REST: Query job");
130
131     }
132 }