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.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor;
19 import static org.mockito.Mockito.when;
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.apache.http.client.ClientProtocolException;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.entity.EsrSystemInfo;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
42 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
43 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse;
44 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse;
45 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
46 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
47 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
48 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
49 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
50 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
51 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository;
52 import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException;
53 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
54 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
55 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
56 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
57 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse;
58 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse;
59 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse;
60 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
61 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
62 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
63 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
64 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfContinueProcessorInf;
66 public class VnfmDriverMgmrImplTest {
69 private VnfmDriverMgmrImpl vnfmDriverMgmr = new VnfmDriverMgmrImpl();
72 private CbamMgmrInf cbamMgmr;
75 private CatalogMgmrInf catalogMgmr;
78 private AaiMgmrInf aaiMgmr;
81 private NslcmMgmrInf nslcmMgmr;;
84 private VnfmJobExecutionRepository jobDbManager;
87 private VnfContinueProcessorInf vnfContinueProcessorInf;
90 AdaptorEnv adaptorEnv;
93 public ExpectedException thrown= ExpectedException.none();
95 private String vnfmId = "vnfmId_001";
96 private String vnfInstanceId = "vnfInstanceId_001";
98 private String protocol = "https";
99 private String ip = "139.234.34.43";
100 private String port = "99";
101 private String cbamHttpHead;
103 public void setUp() throws Exception {
104 MockitoAnnotations.initMocks(this);
105 cbamHttpHead = protocol + "://" + ip + ":" + port;
107 EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
108 esrSystemInfo.setProtocal(protocol);
109 esrSystemInfo.setIp(ip);
110 esrSystemInfo.setPort(port);
112 List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>();
113 esrSystemInfoList.add(esrSystemInfo);
114 AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo();
115 mockVnfmInfo.setVnfmId(vnfmId);
116 mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList);
118 Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter();
119 Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter();
120 vnfmDriverMgmr.setRequestConverter(reqConverter);
121 vnfmDriverMgmr.setResponseConverter(rspConverter);
123 when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo);
125 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
126 execInfo.setJobId(100L);
127 execInfo.setVnfmExecutionId("executionId_001");
128 execInfo.setVnfInstanceId(vnfInstanceId);
130 when(jobDbManager.save(Mockito.any(VnfmJobExecutionInfo.class))).thenReturn(execInfo);
134 public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
135 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId);
136 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
139 @Test(expected = VnfmDriverException.class)
140 public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
141 vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId + "001");
145 public void testInstantiateVnf() throws ClientProtocolException, IOException {
146 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
147 mockCbamResponse.setId("executionId_001");
149 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
150 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
151 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
155 public void testTerminateVnf() throws ClientProtocolException, IOException {
156 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
157 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
161 public void testHealVnf() throws ClientProtocolException, IOException {
162 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
163 mockCbamResponse.setId("executionId_001");
164 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
165 HealVnfRequest request = new HealVnfRequest();
166 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
170 public void testScaleVnf() throws ClientProtocolException, IOException {
171 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
172 mockCbamResponse.setId("executionId_001");
173 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
174 ScaleVnfRequest request = new ScaleVnfRequest();
175 request.setType(CommonEnum.ScaleType.SCALE_IN);
176 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
180 public void testQueryVnf() throws ClientProtocolException, IOException {
181 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
182 mockCbamResponse.setId("executionId_001");
183 mockCbamResponse.setVnfdId(vnfInstanceId);
184 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
185 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
186 Assert.assertEquals(vnfInstanceId, response.getVnfdId());
190 public void testGetOperStatus() throws ClientProtocolException, IOException
192 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
193 execInfo.setJobId(1L);
194 execInfo.setVnfmExecutionId("executionId_001");
195 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
197 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
198 cbamResponse.setId("executionId_001");
199 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
200 cbamResponse.setGrantId("001002001");
202 when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
203 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
205 Assert.assertEquals("executionId_001", response.getJobId());