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.cbam.impl;
19 import static org.mockito.Mockito.when;
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.List;
25 import org.apache.http.client.ClientProtocolException;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfRequest;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMModifyVnfResponse;
42 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse;
43 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse;
44 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
45 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
46 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest;
47 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
48 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationRequest;
49 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationResponse;
50 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription;
51 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo;
52 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
53 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
54 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult;
55 import org.springframework.web.bind.annotation.RequestMethod;
57 public class CbamMgmrImplTest {
59 private CbamMgmrImpl cbamMgmr;
62 private HttpClientProcessorInf httpClientProcessor;
64 private String vnfInstanceId = "vnfInstanceId_001";
67 public void setUp() throws Exception {
68 MockitoAnnotations.initMocks(this);
69 AdaptorEnv env = new AdaptorEnv();
70 cbamMgmr.setAdaptorEnv(env);
72 String json = "{\"access_token\":\"1234567\"}";
73 HttpResult httpResult = new HttpResult();
74 httpResult.setStatusCode(200);
75 httpResult.setContent(json);
77 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
81 public void testCreateVnf() throws ClientProtocolException, IOException
83 CBAMCreateVnfRequest cbamRequest = new CBAMCreateVnfRequest();
84 CBAMCreateVnfResponse response = cbamMgmr.createVnf(cbamRequest);
88 public void testInstantiateVnf() throws ClientProtocolException, IOException
90 CBAMInstantiateVnfRequest cbamRequest = new CBAMInstantiateVnfRequest();
91 CBAMInstantiateVnfResponse response = cbamMgmr.instantiateVnf(cbamRequest, vnfInstanceId);
95 public void testModifyVnf() throws ClientProtocolException, IOException
97 CBAMModifyVnfRequest cbamRequest = new CBAMModifyVnfRequest();
98 CBAMModifyVnfResponse response = cbamMgmr.modifyVnf(cbamRequest, vnfInstanceId);
102 public void testTerminateVnf() throws ClientProtocolException, IOException
104 CBAMTerminateVnfRequest cbamRequest = new CBAMTerminateVnfRequest();
105 CBAMTerminateVnfResponse response = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId);
109 public void testDeleteVnf() throws ClientProtocolException, IOException
111 cbamMgmr.deleteVnf(vnfInstanceId);
115 public void testScaleVnf() throws ClientProtocolException, IOException
117 CBAMScaleVnfRequest cbamRequest = new CBAMScaleVnfRequest();
118 CBAMScaleVnfResponse response = cbamMgmr.scaleVnf(cbamRequest, vnfInstanceId);
122 public void testHealVnf() throws ClientProtocolException, IOException
124 CBAMHealVnfRequest cbamRequest = new CBAMHealVnfRequest();
125 CBAMHealVnfResponse response = cbamMgmr.healVnf(cbamRequest, vnfInstanceId);
129 public void testQueryVnf() throws ClientProtocolException, IOException
131 CBAMQueryVnfResponse response = cbamMgmr.queryVnf(vnfInstanceId);
135 public void testCreateSubscription() throws ClientProtocolException, IOException
137 CBAMCreateSubscriptionRequest cbamRequest = new CBAMCreateSubscriptionRequest();
138 CBAMCreateSubscriptionResponse response = cbamMgmr.createSubscription(cbamRequest);
142 public void testGetNotification() throws ClientProtocolException, IOException
144 CBAMVnfNotificationRequest cbamRequest = new CBAMVnfNotificationRequest();
145 CBAMVnfNotificationResponse response = cbamMgmr.getNotification(cbamRequest);
149 public void testGetSubscription() throws ClientProtocolException, IOException
151 String subscriptionId = "subscriptionId_001";
152 Subscription response = cbamMgmr.getSubscription(subscriptionId);
156 public void testQueryVnfcResource() throws ClientProtocolException, IOException
158 String json = "[{'id':'id_001'}]";
159 HttpResult httpResult = new HttpResult();
160 httpResult.setStatusCode(200);
161 httpResult.setContent(json);
163 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
164 List<VnfcResourceInfo> response = cbamMgmr.queryVnfcResource(vnfInstanceId);
168 public void testQueryOperExecution() throws ClientProtocolException, IOException
170 String execId = "execId_001";
171 CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId);
175 public void testUploadVnfPackage() throws ClientProtocolException, IOException
177 String cbamPackageFilePath = "cbamPackageFilePath_001";
178 cbamMgmr.uploadVnfPackage(cbamPackageFilePath);