Add unit test cases
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / adaptor / Cbam2DriverResponseConverterTest.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
18 package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor;
19
20 import static org.mockito.Mockito.doNothing;
21 import static org.mockito.Mockito.when;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.Mockito;
28 import org.mockito.MockitoAnnotations;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.OperationExecution.OperationType;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
42
43 public class Cbam2DriverResponseConverterTest {
44         @InjectMocks
45         Cbam2DriverResponseConverter convertor;
46         
47         @Mock
48         private VnfmJobExecutionMapper jobDbManager;
49         
50         @Before
51         public void setUp() throws Exception {
52                 MockitoAnnotations.initMocks(this);
53                 AdaptorEnv adaptorEnv = new AdaptorEnv();
54                 adaptorEnv.setInitialProgress(10);
55                 adaptorEnv.setInstantiateTimeInterval(60);
56                 adaptorEnv.setTerminateTimeInterval(60);
57                 convertor.setAdaptorEnv(adaptorEnv);
58                 
59                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
60                 execInfo.setJobId(1L);
61                 execInfo.setOperateStartTime(123456);
62                 when(jobDbManager.findNewestJobInfo()).thenReturn(execInfo);
63                 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
64                 doNothing().when(jobDbManager).insert(Mockito.any(VnfmJobExecutionInfo.class));
65         }
66         
67         @Test
68         public void testTerminateRspConvert()
69         {
70                 CBAMTerminateVnfResponse cbamResponse = new CBAMTerminateVnfResponse();
71                 TerminateVnfResponse response = convertor.terminateRspConvert(cbamResponse);
72         }
73         
74         @Test
75         public void testCalculateProgressInstantiate()
76         {
77                 OperationExecution operationExecution = new OperationExecution();
78                 operationExecution.setOperationType(OperationType.INSTANTIATE);
79                 convertor.calculateProgress(operationExecution, "1");
80         }
81         
82         @Test
83         public void testCalculateProgressTerminate()
84         {
85                 OperationExecution operationExecution = new OperationExecution();
86                 operationExecution.setOperationType(OperationType.TERMINATE);
87                 convertor.calculateProgress(operationExecution, "1");
88         }
89         
90         @Test
91         public void testCalculateProgressScale()
92         {
93                 OperationExecution operationExecution = new OperationExecution();
94                 operationExecution.setOperationType(OperationType.SCALE);
95                 convertor.calculateProgress(operationExecution, "1");
96         }
97         
98         @Test
99         public void testScaleRspConvertOut()
100         {
101                 CBAMScaleVnfResponse cbamResponse = new CBAMScaleVnfResponse();
102                 ScaleVnfResponse response = convertor.scaleRspConvert(cbamResponse, ScaleType.SCALE_OUT);
103         }
104         
105         @Test
106         public void testScaleRspConvertIn()
107         {
108                 CBAMScaleVnfResponse cbamResponse = new CBAMScaleVnfResponse();
109                 ScaleVnfResponse response = convertor.scaleRspConvert(cbamResponse, ScaleType.SCALE_IN);
110         }
111         
112         @Test
113         public void testHeallRspConvert()
114         {
115                 CBAMHealVnfResponse cbamResponse = new CBAMHealVnfResponse();
116                 HealVnfResponse response = convertor.healRspConvert(cbamResponse);
117         }
118         
119         @Test
120         public void testOperRspConvertStarted()
121         {
122                 OperationExecution operationExecution = new OperationExecution();
123                 operationExecution.setStatus(CommonEnum.OperationStatus.STARTED);
124                 convertor.operRspConvert(operationExecution, "1");
125         }
126         
127         @Test
128         public void testOperRspConvertFinished()
129         {
130                 OperationExecution operationExecution = new OperationExecution();
131                 operationExecution.setStatus(CommonEnum.OperationStatus.FINISHED);
132                 convertor.operRspConvert(operationExecution, "1");
133         }
134         
135         @Test
136         public void testOperRspConvertOngoing()
137         {
138                 OperationExecution operationExecution = new OperationExecution();
139                 operationExecution.setStatus(CommonEnum.OperationStatus.OTHER);
140                 convertor.operRspConvert(operationExecution, "1");
141         }
142         
143         @Test
144         public void testOperRspConvertFailed()
145         {
146                 OperationExecution operationExecution = new OperationExecution();
147                 operationExecution.setStatus(CommonEnum.OperationStatus.FAILED);
148                 convertor.operRspConvert(operationExecution, "1");
149         }
150 }