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);
149 when(jobDbManager.findNewestJobInfo()).thenReturn(execInfo);
153 public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
154 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId);
155 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
158 @Test(expected = VnfmDriverException.class)
159 public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
160 vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId + "001");
164 public void testInstantiateVnf() throws ClientProtocolException, IOException {
165 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
166 mockCbamResponse.setId("executionId_001");
168 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
169 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
170 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
174 public void testTerminateVnf() throws ClientProtocolException, IOException {
175 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
176 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
180 public void testHealVnf() throws ClientProtocolException, IOException {
181 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
182 mockCbamResponse.setId("executionId_001");
183 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
184 HealVnfRequest request = new HealVnfRequest();
185 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
189 public void testScaleVnf() throws ClientProtocolException, IOException {
190 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
191 mockCbamResponse.setId("executionId_001");
192 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
193 ScaleVnfRequest request = new ScaleVnfRequest();
194 request.setType(ScaleType.SCALE_IN);
195 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
199 public void testQueryVnf() throws ClientProtocolException, IOException {
200 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
201 mockCbamResponse.setId("executionId_001");
202 mockCbamResponse.setVnfdId(vnfInstanceId);
203 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
204 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
205 Assert.assertEquals(vnfInstanceId, response.getVnfdId());
209 public void testGetOperStatus() throws ClientProtocolException, IOException
211 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
212 execInfo.setJobId(1L);
213 execInfo.setVnfmExecutionId("executionId_001");
214 execInfo.setStatus("finished");
215 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
217 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
218 cbamResponse.setId("executionId_001");
219 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
220 cbamResponse.setGrantId("001002001");
222 // when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
223 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
225 // Assert.assertEquals("executionId_001", response.getJobId());
229 public void testCreateSubscription() throws ClientProtocolException, IOException {
230 CBAMCreateSubscriptionResponse mockCbamResponse = new CBAMCreateSubscriptionResponse();
231 mockCbamResponse.setId("subscriptionId_001");
232 mockCbamResponse.setCallbackUrl("callbackUrl");
233 when(cbamMgmr.createSubscription(Mockito.any(CBAMCreateSubscriptionRequest.class))).thenReturn(mockCbamResponse);
234 doNothing().when(subscriptionsMapper).insert(Mockito.anyString());
235 CreateSubscriptionRequest request = new CreateSubscriptionRequest();
236 CreateSubscriptionResponse response = vnfmDriverMgmr.createSubscription(request);
237 Assert.assertEquals("callbackUrl", response.getCallbackUri());