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.setEsrSystemId("esrSystemId");
109 esrSystemInfo.setPassword("password");
110 esrSystemInfo.setServiceUrl(cbamHttpHead);
111 esrSystemInfo.setType("type");
112 esrSystemInfo.setUserName("userName");
113 esrSystemInfo.setVendor("vendor");
114 esrSystemInfo.setVersion("version");
116 List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>();
117 esrSystemInfoList.add(esrSystemInfo);
118 AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo();
119 mockVnfmInfo.setVnfmId(vnfmId);
120 mockVnfmInfo.setVimId("vimId");
121 mockVnfmInfo.setResourceVersion("resourceVersion");
122 mockVnfmInfo.setCertificateUrl("certificateUrl");
123 mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList);
125 Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter();
126 Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter();
127 vnfmDriverMgmr.setRequestConverter(reqConverter);
128 vnfmDriverMgmr.setResponseConverter(rspConverter);
130 when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo);
132 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
133 execInfo.setJobId(100L);
134 execInfo.setVnfmExecutionId("executionId_001");
135 execInfo.setVnfInstanceId(vnfInstanceId);
137 when(jobDbManager.save(Mockito.any(VnfmJobExecutionInfo.class))).thenReturn(execInfo);
141 public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
142 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId);
143 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
146 @Test(expected = VnfmDriverException.class)
147 public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
148 vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId + "001");
152 public void testInstantiateVnf() throws ClientProtocolException, IOException {
153 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
154 mockCbamResponse.setId("executionId_001");
156 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
157 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
158 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
162 public void testTerminateVnf() throws ClientProtocolException, IOException {
163 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
164 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
168 public void testHealVnf() throws ClientProtocolException, IOException {
169 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
170 mockCbamResponse.setId("executionId_001");
171 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
172 HealVnfRequest request = new HealVnfRequest();
173 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
177 public void testScaleVnf() throws ClientProtocolException, IOException {
178 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
179 mockCbamResponse.setId("executionId_001");
180 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
181 ScaleVnfRequest request = new ScaleVnfRequest();
182 request.setType(CommonEnum.ScaleType.SCALE_IN);
183 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
187 public void testQueryVnf() throws ClientProtocolException, IOException {
188 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
189 mockCbamResponse.setId("executionId_001");
190 mockCbamResponse.setVnfdId(vnfInstanceId);
191 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
192 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
193 Assert.assertEquals(vnfInstanceId, response.getVnfdId());
197 public void testGetOperStatus() throws ClientProtocolException, IOException
199 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
200 execInfo.setJobId(1L);
201 execInfo.setVnfmExecutionId("executionId_001");
202 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
204 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
205 cbamResponse.setId("executionId_001");
206 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
207 cbamResponse.setGrantId("001002001");
209 when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
210 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
212 Assert.assertEquals("executionId_001", response.getJobId());