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.doNothing;
20 import static org.mockito.Mockito.when;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.apache.http.client.ClientProtocolException;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.junit.rules.ExpectedException;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.MockitoAnnotations;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.entity.EsrSystemInfo;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse;
42 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest;
43 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse;
44 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
45 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
46 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse;
47 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse;
48 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
49 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
50 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
51 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
52 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
53 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType;
54 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
55 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper;
56 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmSubscriptionsMapper;
57 import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException;
58 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
59 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionRequest;
60 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse;
61 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
62 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
63 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
64 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse;
65 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse;
66 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse;
67 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
68 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
69 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
70 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
71 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfContinueProcessorInf;
73 public class VnfmDriverMgmrImplTest {
76 private VnfmDriverMgmrImpl vnfmDriverMgmr = new VnfmDriverMgmrImpl();
79 private CbamMgmrInf cbamMgmr;
82 private CatalogMgmrInf catalogMgmr;
85 private AaiMgmrInf aaiMgmr;
88 private NslcmMgmrInf nslcmMgmr;;
91 private VnfmJobExecutionMapper jobDbManager;
94 private VnfmSubscriptionsMapper subscriptionsMapper;
97 private VnfContinueProcessorInf vnfContinueProcessorInf;
100 AdaptorEnv adaptorEnv;
103 public ExpectedException thrown= ExpectedException.none();
105 private String vnfmId = "vnfmId_001";
106 private String vnfInstanceId = "vnfInstanceId_001";
108 private ScaleType type;
110 private String protocol = "https";
111 private String ip = "139.234.34.43";
112 private String port = "99";
113 private String cbamHttpHead;
115 public void setUp() throws Exception {
116 MockitoAnnotations.initMocks(this);
117 cbamHttpHead = protocol + "://" + ip + ":" + port;
119 EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
120 esrSystemInfo.setEsrSystemId("esrSystemId");
121 esrSystemInfo.setPassword("password");
122 esrSystemInfo.setServiceUrl(cbamHttpHead);
123 esrSystemInfo.setType("type");
124 esrSystemInfo.setUserName("userName");
125 esrSystemInfo.setVendor("vendor");
126 esrSystemInfo.setVersion("version");
128 List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>();
129 esrSystemInfoList.add(esrSystemInfo);
130 AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo();
131 mockVnfmInfo.setVnfmId(vnfmId);
132 mockVnfmInfo.setVimId("vimId");
133 mockVnfmInfo.setResourceVersion("resourceVersion");
134 mockVnfmInfo.setCertificateUrl("certificateUrl");
135 mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList);
137 Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter();
138 Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter();
139 vnfmDriverMgmr.setRequestConverter(reqConverter);
140 vnfmDriverMgmr.setResponseConverter(rspConverter);
142 when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo);
144 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
145 execInfo.setJobId(100L);
146 execInfo.setVnfmExecutionId("executionId_001");
147 execInfo.setVnfInstanceId(vnfInstanceId);
148 execInfo.setOperateStartTime(1234567);
149 execInfo.setOperateEndTime(2345678);
150 when(jobDbManager.findNewestJobInfo()).thenReturn(execInfo);
154 public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
155 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId);
156 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
159 @Test(expected = VnfmDriverException.class)
160 public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
161 vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId + "001");
165 public void testInstantiateVnf() throws ClientProtocolException, IOException {
166 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
167 mockCbamResponse.setId("executionId_001");
169 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
170 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
171 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
175 public void testTerminateVnf() throws ClientProtocolException, IOException {
176 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
177 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
181 public void testHealVnf() throws ClientProtocolException, IOException {
182 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
183 mockCbamResponse.setId("executionId_001");
184 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
185 HealVnfRequest request = new HealVnfRequest();
186 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
190 public void testScaleVnf() throws ClientProtocolException, IOException {
191 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
192 mockCbamResponse.setId("executionId_001");
193 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
194 ScaleVnfRequest request = new ScaleVnfRequest();
195 request.setType(ScaleType.SCALE_IN);
196 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
200 public void testQueryVnf() throws ClientProtocolException, IOException {
201 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
202 mockCbamResponse.setId("executionId_001");
203 mockCbamResponse.setVnfdId(vnfInstanceId);
204 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
205 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
206 Assert.assertEquals(vnfInstanceId, response.getVnfdId());
210 public void testGetOperStatus() throws ClientProtocolException, IOException
212 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
213 execInfo.setJobId(1L);
214 execInfo.setVnfmExecutionId("executionId_001");
215 execInfo.setStatus("finished");
216 execInfo.setVnfInstanceId(vnfInstanceId);
218 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
220 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
221 cbamResponse.setId("executionId_001");
222 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
223 cbamResponse.setGrantId("001002001");
225 // when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
226 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
228 Assert.assertEquals(0, execInfo.getOperateStartTime());
229 Assert.assertEquals(0, execInfo.getOperateEndTime());
230 Assert.assertEquals(1, execInfo.getJobId());
231 Assert.assertEquals("executionId_001", execInfo.getVnfmExecutionId());
232 Assert.assertEquals("finished", execInfo.getStatus());
233 Assert.assertEquals(vnfInstanceId, execInfo.getVnfInstanceId());
237 public void testCreateSubscription() throws ClientProtocolException, IOException {
238 CBAMCreateSubscriptionResponse mockCbamResponse = new CBAMCreateSubscriptionResponse();
239 mockCbamResponse.setId("subscriptionId_001");
240 mockCbamResponse.setCallbackUrl("callbackUrl");
241 when(cbamMgmr.createSubscription(Mockito.any(CBAMCreateSubscriptionRequest.class))).thenReturn(mockCbamResponse);
242 doNothing().when(subscriptionsMapper).insert(Mockito.anyString());
243 CreateSubscriptionRequest request = new CreateSubscriptionRequest();
244 CreateSubscriptionResponse response = vnfmDriverMgmr.createSubscription(request);
245 Assert.assertEquals("callbackUrl", response.getCallbackUri());