2 * Copyright 2016-2017, Nokia Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor;
20 import static org.mockito.Mockito.doNothing;
21 import static org.mockito.Mockito.when;
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;
43 public class Cbam2DriverResponseConverterTest {
45 Cbam2DriverResponseConverter convertor;
48 private VnfmJobExecutionMapper jobDbManager;
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);
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));
68 public void testTerminateRspConvert()
70 CBAMTerminateVnfResponse cbamResponse = new CBAMTerminateVnfResponse();
71 TerminateVnfResponse response = convertor.terminateRspConvert(cbamResponse);
75 public void testCalculateProgressInstantiate()
77 OperationExecution operationExecution = new OperationExecution();
78 operationExecution.setOperationType(OperationType.INSTANTIATE);
79 convertor.calculateProgress(operationExecution, "1");
83 public void testCalculateProgressTerminate()
85 OperationExecution operationExecution = new OperationExecution();
86 operationExecution.setOperationType(OperationType.TERMINATE);
87 convertor.calculateProgress(operationExecution, "1");
91 public void testCalculateProgressScale()
93 OperationExecution operationExecution = new OperationExecution();
94 operationExecution.setOperationType(OperationType.SCALE);
95 convertor.calculateProgress(operationExecution, "1");
99 public void testScaleRspConvertOut()
101 CBAMScaleVnfResponse cbamResponse = new CBAMScaleVnfResponse();
102 ScaleVnfResponse response = convertor.scaleRspConvert(cbamResponse, ScaleType.SCALE_OUT);
106 public void testScaleRspConvertIn()
108 CBAMScaleVnfResponse cbamResponse = new CBAMScaleVnfResponse();
109 ScaleVnfResponse response = convertor.scaleRspConvert(cbamResponse, ScaleType.SCALE_IN);
113 public void testHeallRspConvert()
115 CBAMHealVnfResponse cbamResponse = new CBAMHealVnfResponse();
116 HealVnfResponse response = convertor.healRspConvert(cbamResponse);
120 public void testOperRspConvertStarted()
122 OperationExecution operationExecution = new OperationExecution();
123 operationExecution.setStatus(CommonEnum.OperationStatus.STARTED);
124 convertor.operRspConvert(operationExecution, "1");
128 public void testOperRspConvertFinished()
130 OperationExecution operationExecution = new OperationExecution();
131 operationExecution.setStatus(CommonEnum.OperationStatus.FINISHED);
132 convertor.operRspConvert(operationExecution, "1");
136 public void testOperRspConvertOngoing()
138 OperationExecution operationExecution = new OperationExecution();
139 operationExecution.setStatus(CommonEnum.OperationStatus.OTHER);
140 convertor.operRspConvert(operationExecution, "1");
144 public void testOperRspConvertFailed()
146 OperationExecution operationExecution = new OperationExecution();
147 operationExecution.setStatus(CommonEnum.OperationStatus.FAILED);
148 convertor.operRspConvert(operationExecution, "1");