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.NslcmVimInfo;
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 List<NslcmVimInfo> vim = new ArrayList<NslcmVimInfo>();
91 NslcmVimInfo vims=new NslcmVimInfo();
93 vims.setInterfaceEndpoint("interfaceEndpoint");
94 vims.setVimId("vimId");
95 List<AccessInfo> accessInfo = null;
96 vims.setAccessInfo(accessInfo);
97 List<InterfaceInfo> interfaceInfo = null;
98 vims.setInterfaceInfo(interfaceInfo);
101 VimAssets vimAssets = null;
102 gresponse.setVimAssets(vimAssets);
104 gresponse.setVim(vim);
105 String json = gson.toJson(gresponse);
106 HttpResult httpResult = new HttpResult();
107 httpResult.setContent(json);
109 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
111 NslcmGrantVnfRequest cbamRequest = new NslcmGrantVnfRequest();
112 List<KeyValuePair> additionalParam = new ArrayList<KeyValuePair>();
113 pair = new KeyValuePair();
115 pair.setValue("value");
116 additionalParam.add(pair);
117 cbamRequest.setAdditionalParam(additionalParam);
120 List<ResourceDefinition> addResource = new ArrayList<ResourceDefinition>();
121 addResource.add(resource);
123 cbamRequest.setAddResource(addResource);
124 cbamRequest.setVnfInstanceId("vnfInstanceId");
125 cbamRequest.setJobId("jobId");
126 LifecycleOperation lifecycleOperation = CommonEnum.LifecycleOperation.Instantiate;
127 cbamRequest.setLifecycleOperation(lifecycleOperation);
128 cbamRequest.setRemoveResource(addResource);
130 NslcmGrantVnfResponse response = nslcmMgmr.grantVnf(cbamRequest);
134 public void testNotifyVnf() throws ClientProtocolException, IOException
137 HttpResult httpResult = new HttpResult();
138 httpResult.setContent(json);
140 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
141 NslcmNotifyLCMEventsRequest cbamRequest = new NslcmNotifyLCMEventsRequest();
142 cbamRequest.setJobId("jobId");
143 cbamRequest.setOperation("operation");
144 cbamRequest.setVnfInstanceId(vnfInstanceId);
145 List<AffectedVirtualStorage> affectedVirtualStorage = new ArrayList<AffectedVirtualStorage>();
146 cbamRequest.setAffectedVirtualStorage(affectedVirtualStorage );
147 List<AffectedVnfc> affectedVnfc = new ArrayList<AffectedVnfc>();
148 cbamRequest.setAffectedVnfc(affectedVnfc );
149 nslcmMgmr.notifyVnf(cbamRequest, vnfInstanceId);