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