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.constant.ScaleType;
51 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
52 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper;
53 import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException;
54 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
55 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
56 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
57 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
58 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse;
59 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse;
60 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse;
61 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
62 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
63 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
64 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
65 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfContinueProcessorInf;
67 public class VnfmDriverMgmrImplTest {
70 private VnfmDriverMgmrImpl vnfmDriverMgmr = new VnfmDriverMgmrImpl();
73 private CbamMgmrInf cbamMgmr;
76 private CatalogMgmrInf catalogMgmr;
79 private AaiMgmrInf aaiMgmr;
82 private NslcmMgmrInf nslcmMgmr;;
85 private VnfmJobExecutionMapper jobDbManager;
88 private VnfContinueProcessorInf vnfContinueProcessorInf;
91 AdaptorEnv adaptorEnv;
94 public ExpectedException thrown= ExpectedException.none();
96 private String vnfmId = "vnfmId_001";
97 private String vnfInstanceId = "vnfInstanceId_001";
99 private ScaleType type;
101 private String protocol = "https";
102 private String ip = "139.234.34.43";
103 private String port = "99";
104 private String cbamHttpHead;
106 public void setUp() throws Exception {
107 MockitoAnnotations.initMocks(this);
108 cbamHttpHead = protocol + "://" + ip + ":" + port;
110 EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
111 esrSystemInfo.setEsrSystemId("esrSystemId");
112 esrSystemInfo.setPassword("password");
113 esrSystemInfo.setServiceUrl(cbamHttpHead);
114 esrSystemInfo.setType("type");
115 esrSystemInfo.setUserName("userName");
116 esrSystemInfo.setVendor("vendor");
117 esrSystemInfo.setVersion("version");
119 List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>();
120 esrSystemInfoList.add(esrSystemInfo);
121 AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo();
122 mockVnfmInfo.setVnfmId(vnfmId);
123 mockVnfmInfo.setVimId("vimId");
124 mockVnfmInfo.setResourceVersion("resourceVersion");
125 mockVnfmInfo.setCertificateUrl("certificateUrl");
126 mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList);
128 Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter();
129 Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter();
130 vnfmDriverMgmr.setRequestConverter(reqConverter);
131 vnfmDriverMgmr.setResponseConverter(rspConverter);
133 when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo);
135 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
136 execInfo.setJobId(100L);
137 execInfo.setVnfmExecutionId("executionId_001");
138 execInfo.setVnfInstanceId(vnfInstanceId);
140 when(jobDbManager.findNewestJobInfo()).thenReturn(execInfo);
144 public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
145 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId);
146 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
149 @Test(expected = VnfmDriverException.class)
150 public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
151 vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId + "001");
155 public void testInstantiateVnf() throws ClientProtocolException, IOException {
156 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
157 mockCbamResponse.setId("executionId_001");
159 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
160 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
161 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
165 public void testTerminateVnf() throws ClientProtocolException, IOException {
166 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
167 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
171 public void testHealVnf() throws ClientProtocolException, IOException {
172 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
173 mockCbamResponse.setId("executionId_001");
174 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
175 HealVnfRequest request = new HealVnfRequest();
176 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
180 public void testScaleVnf() throws ClientProtocolException, IOException {
181 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
182 mockCbamResponse.setId("executionId_001");
183 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
184 ScaleVnfRequest request = new ScaleVnfRequest();
185 request.setType(ScaleType.SCALE_IN);
186 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
190 public void testQueryVnf() throws ClientProtocolException, IOException {
191 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
192 mockCbamResponse.setId("executionId_001");
193 mockCbamResponse.setVnfdId(vnfInstanceId);
194 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
195 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
196 Assert.assertEquals(vnfInstanceId, response.getVnfdId());
200 public void testGetOperStatus() throws ClientProtocolException, IOException
202 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
203 execInfo.setJobId(1L);
204 execInfo.setVnfmExecutionId("executionId_001");
205 execInfo.setStatus("finished");
206 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
208 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
209 cbamResponse.setId("executionId_001");
210 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
211 cbamResponse.setGrantId("001002001");
213 // when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
214 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
216 // Assert.assertEquals("executionId_001", response.getJobId());