Modify POM parent oparent version as 0.1.1
[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.VimInfo;
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                 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);
97                 
98                 VimAssets vimAssets = null;
99                 gresponse.setVimAssets(vimAssets);
100                 
101                 gresponse.setVim(vim );
102                 String json = gson.toJson(gresponse);
103                 HttpResult httpResult = new HttpResult();
104                 httpResult.setContent(json);
105                 
106                 when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
107                 
108                 NslcmGrantVnfRequest cbamRequest = new NslcmGrantVnfRequest();
109                 List<KeyValuePair> additionalParam = new ArrayList<KeyValuePair>();
110                 pair = new KeyValuePair();
111                 pair.setKey("key");
112                 pair.setValue("value");
113                 additionalParam.add(pair);
114                 cbamRequest.setAdditionalParam(additionalParam);
115                 
116                 
117                 List<ResourceDefinition> addResource = new ArrayList<ResourceDefinition>();
118                 addResource.add(resource);
119                 
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);
126                 
127                 NslcmGrantVnfResponse response = nslcmMgmr.grantVnf(cbamRequest);
128         }
129         
130         @Test
131         public void testNotifyVnf() throws ClientProtocolException, IOException
132         {
133                 String json = "{}";
134                 HttpResult httpResult = new HttpResult();
135                 httpResult.setContent(json);
136                 
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);
147         }
148 }