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