Improve unit-test coverage
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / adaptor / InstantiateVnfContinueRunnableTest.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.adaptor;
18
19 import static org.mockito.Mockito.doNothing;
20 import static org.mockito.Mockito.when;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfRequest;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfResponse;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ComputeResource;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.OperationStatus;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper;
42 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper;
43 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
44 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse;
45 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AffectedVnfc;
46 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
47 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
48
49 public class InstantiateVnfContinueRunnableTest{
50         @InjectMocks
51         private InstantiateVnfContinueRunnable instantiateVnfContinueRunnable;
52         
53         @Mock
54         private CbamMgmrInf cbamMgmr;
55         
56         @Mock
57         private NslcmMgmrInf nslcmMgmr;
58         
59         @Mock
60         private VnfmJobExecutionMapper jobDbMgmr;
61         
62         @Mock
63         private VnfcResourceInfoMapper vnfcDbMgmr;
64         
65         @Before
66         public void setUp() throws Exception {
67                 MockitoAnnotations.initMocks(this);
68                 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
69                 Driver2CbamRequestConverter requestConverter = new Driver2CbamRequestConverter();
70                 
71                 instantiateVnfContinueRunnable.setDriverRequest(driverRequest);
72                 instantiateVnfContinueRunnable.setJobId("1");
73                 instantiateVnfContinueRunnable.setVnfInstanceId("001");
74                 instantiateVnfContinueRunnable.setVnfmId("001");
75                 instantiateVnfContinueRunnable.setRequestConverter(requestConverter);
76                 
77                 NslcmGrantVnfResponse grantResponse = new NslcmGrantVnfResponse();
78                 CBAMInstantiateVnfResponse cbamResponse = new CBAMInstantiateVnfResponse();
79                 cbamResponse.setId("1");
80                 CBAMModifyVnfResponse modifyResponse = new CBAMModifyVnfResponse();
81                 modifyResponse.setId("2");
82                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
83                 execInfo.setJobId(1L);
84                 
85                 CBAMQueryOperExecutionResponse exeResponse = new CBAMQueryOperExecutionResponse();
86                 exeResponse.setStatus(OperationStatus.FINISHED);
87                 
88                 List<VnfcResourceInfo> vnfcResources = new ArrayList<>();
89                 VnfcResourceInfo res = new VnfcResourceInfo();
90                 res.setId("1");
91                 res.setVduId("vduId");
92                 ComputeResource computeResource = new ComputeResource();
93                 computeResource.setResourceId("resourceId");
94                 computeResource.setResourceType("OS::Nova::Server");
95                 computeResource.setVimId("vimId");
96                 res.setComputeResource(computeResource);
97                 
98                 vnfcResources.add(res);
99                 
100                 when(nslcmMgmr.grantVnf(Mockito.any(NslcmGrantVnfRequest.class))).thenReturn(grantResponse);
101                 when(cbamMgmr.instantiateVnf(Mockito.any(CBAMInstantiateVnfRequest.class), Mockito.anyString())).thenReturn(cbamResponse);
102                 when(cbamMgmr.modifyVnf(Mockito.any(CBAMModifyVnfRequest.class), Mockito.anyString())).thenReturn(modifyResponse);
103                 when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(exeResponse);
104                 when(cbamMgmr.queryVnfcResource(Mockito.anyString())).thenReturn(vnfcResources);
105                 when(jobDbMgmr.findOne(Mockito.anyLong())).thenReturn(execInfo);
106                 doNothing().when(jobDbMgmr).update(Mockito.any(VnfmJobExecutionInfo.class));
107                 doNothing().when(vnfcDbMgmr).insert(Mockito.any(AffectedVnfc.class));
108         }
109         
110         @Test
111         public void testRun()
112         {
113                 instantiateVnfContinueRunnable.run();
114         }
115 }