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.nslcm.impl;
19 import static org.mockito.Mockito.when;
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
26 import org.apache.http.client.ClientProtocolException;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
34 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.KeyValuePair;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum.LifecycleOperation;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest;
42 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AccessInfo;
43 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AffectedVirtualStorage;
44 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.AffectedVnfc;
45 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.InterfaceInfo;
46 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.ResourceDefinition;
47 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VimAssets;
48 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VimInfo;
49 import org.springframework.web.bind.annotation.RequestMethod;
51 import com.google.gson.Gson;
53 public class NslcmMgmrImplTest {
55 private NslcmMgmrImpl nslcmMgmr;
58 private HttpClientProcessorInf httpClientProcessor;
60 private String vnfInstanceId = "vnfInstanceId_001";
62 private Gson gson = new Gson();
65 public void setUp() throws Exception {
66 MockitoAnnotations.initMocks(this);
67 AdaptorEnv env = new AdaptorEnv();
68 nslcmMgmr.setAdaptorEnv(env);
69 MockitoAnnotations.initMocks(this);
73 public void testGrantVnf() throws ClientProtocolException, IOException
75 ResourceDefinition resource = new ResourceDefinition();
76 resource.setResourceDefinitionId("resourceDefinitionId");
77 resource.setVdu("vdu");
79 NslcmGrantVnfResponse gresponse = new NslcmGrantVnfResponse();
80 List<KeyValuePair> additionalParam1 = new ArrayList<KeyValuePair>();
81 KeyValuePair pair = new KeyValuePair();
83 pair.setValue("value");
84 additionalParam1.add(pair);
86 List<ResourceDefinition> additionalParam2 = new ArrayList<ResourceDefinition>();
87 additionalParam2.add(resource);
88 gresponse.setAdditionalParam(additionalParam2);
90 VimInfo vim = new VimInfo();
91 vim.setInterfaceEndpoint("interfaceEndpoint");
92 vim.setVimId("vimId");
93 AccessInfo accessInfo = null;
94 vim.setAccessInfo(accessInfo );
95 InterfaceInfo interfaceInfo = null;
96 vim.setInterfaceInfo(interfaceInfo);
98 VimAssets vimAssets = null;
99 gresponse.setVimAssets(vimAssets);
101 gresponse.setVim(vim );
102 String json = gson.toJson(gresponse);
103 HttpResult httpResult = new HttpResult();
104 httpResult.setContent(json);
106 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
108 NslcmGrantVnfRequest cbamRequest = new NslcmGrantVnfRequest();
109 List<KeyValuePair> additionalParam = new ArrayList<KeyValuePair>();
110 pair = new KeyValuePair();
112 pair.setValue("value");
113 additionalParam.add(pair);
114 cbamRequest.setAdditionalParam(additionalParam);
117 List<ResourceDefinition> addResource = new ArrayList<ResourceDefinition>();
118 addResource.add(resource);
120 cbamRequest.setAddResource(addResource);
121 cbamRequest.setVnfInstanceId("vnfInstanceId");
122 cbamRequest.setJobId("jobId");
123 LifecycleOperation lifecycleOperation = CommonEnum.LifecycleOperation.Instantiate;
124 cbamRequest.setLifecycleOperation(lifecycleOperation);
125 cbamRequest.setRemoveResource(addResource);
127 NslcmGrantVnfResponse response = nslcmMgmr.grantVnf(cbamRequest);
131 public void testNotifyVnf() throws ClientProtocolException, IOException
134 HttpResult httpResult = new HttpResult();
135 httpResult.setContent(json);
137 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
138 NslcmNotifyLCMEventsRequest cbamRequest = new NslcmNotifyLCMEventsRequest();
139 cbamRequest.setJobId("jobId");
140 cbamRequest.setOperation("operation");
141 cbamRequest.setVnfInstanceId(vnfInstanceId);
142 AffectedVirtualStorage affectedVirtualStorage = new AffectedVirtualStorage();
143 cbamRequest.setAffectedVirtualStorage(affectedVirtualStorage );
144 AffectedVnfc affectedVnfc = new AffectedVnfc();
145 cbamRequest.setAffectedVnfc(affectedVnfc );
146 nslcmMgmr.notifyVnf(cbamRequest, vnfInstanceId);