47c33bf1bd1ded364419a982417537c34ce6c887
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nslcm / impl / NslcmMgmrImplTest.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.impl;
18
19 import static org.mockito.Mockito.when;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25
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;
50
51 import com.google.gson.Gson;
52
53 public class NslcmMgmrImplTest {
54         @InjectMocks
55         private NslcmMgmrImpl nslcmMgmr;
56         
57         @Mock
58         private HttpClientProcessorInf httpClientProcessor;
59         
60         private String vnfInstanceId = "vnfInstanceId_001";
61         
62         private Gson gson = new Gson();
63         
64         @Before
65         public void setUp() throws Exception {
66                 MockitoAnnotations.initMocks(this);
67                 AdaptorEnv env = new AdaptorEnv();
68                 nslcmMgmr.setAdaptorEnv(env);
69                 MockitoAnnotations.initMocks(this);
70         }
71         
72         @Test
73         public void testGrantVnf() throws ClientProtocolException, IOException
74         {
75                 ResourceDefinition resource = new ResourceDefinition();
76                 resource.setResourceDefinitionId("resourceDefinitionId");
77                 resource.setVdu("vdu");
78                 
79                 NslcmGrantVnfResponse gresponse = new NslcmGrantVnfResponse();
80                 List<KeyValuePair> additionalParam1 = new ArrayList<KeyValuePair>();
81                 KeyValuePair pair = new KeyValuePair();
82                 pair.setKey("key");
83                 pair.setValue("value");
84                 additionalParam1.add(pair);
85                 
86                 List<ResourceDefinition> additionalParam2 = new ArrayList<ResourceDefinition>();
87                 additionalParam2.add(resource);
88                 gresponse.setAdditionalParam(additionalParam2);
89                 
90                 List<NslcmVimInfo> vim = new ArrayList<NslcmVimInfo>();
91                 NslcmVimInfo vims=new NslcmVimInfo();
92                 
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);
99                 
100                 vim.add(vims);
101                 VimAssets vimAssets = null;
102                 gresponse.setVimAssets(vimAssets);
103                 
104                 gresponse.setVim(vim);
105                 String json = gson.toJson(gresponse);
106                 HttpResult httpResult = new HttpResult();
107                 httpResult.setContent(json);
108                 
109                 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
110                 
111                 NslcmGrantVnfRequest cbamRequest = new NslcmGrantVnfRequest();
112                 List<KeyValuePair> additionalParam = new ArrayList<KeyValuePair>();
113                 pair = new KeyValuePair();
114                 pair.setKey("key");
115                 pair.setValue("value");
116                 additionalParam.add(pair);
117                 cbamRequest.setAdditionalParam(additionalParam);
118                 
119                 
120                 List<ResourceDefinition> addResource = new ArrayList<ResourceDefinition>();
121                 addResource.add(resource);
122                 
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);
129                 
130                 NslcmGrantVnfResponse response = nslcmMgmr.grantVnf(cbamRequest);
131         }
132         
133         @Test
134         public void testNotifyVnf() throws ClientProtocolException, IOException
135         {
136                 String json = "{}";
137                 HttpResult httpResult = new HttpResult();
138                 httpResult.setContent(json);
139                 
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);
150         }
151 }