d36a1d910e65f674c1f5b2f825546f4344c483d9
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / adaptor / VnfmDriverMgmrImplTest.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.adaptor;
18
19 import static org.mockito.Mockito.when;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.http.client.ClientProtocolException;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo;
36 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.entity.EsrSystemInfo;
37 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf;
38 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf;
39 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest;
40 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse;
41 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
42 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
43 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse;
44 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse;
45 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
46 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
47 import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf;
48 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
49 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum;
50 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType;
51 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo;
52 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository;
53 import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException;
54 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
55 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
56 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
57 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
58 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse;
59 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse;
60 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse;
61 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
62 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
63 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
64 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
65 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfContinueProcessorInf;
66
67 public class VnfmDriverMgmrImplTest {
68
69         @InjectMocks
70         private VnfmDriverMgmrImpl vnfmDriverMgmr = new VnfmDriverMgmrImpl();
71         
72         @Mock
73         private CbamMgmrInf cbamMgmr;
74         
75         @Mock
76         private CatalogMgmrInf catalogMgmr;
77         
78         @Mock
79         private AaiMgmrInf aaiMgmr;
80         
81         @Mock
82         private NslcmMgmrInf nslcmMgmr;;
83         
84         @Mock
85         private VnfmJobExecutionRepository jobDbManager;
86         
87         @Mock
88         private VnfContinueProcessorInf vnfContinueProcessorInf;
89         
90         @Mock
91         AdaptorEnv adaptorEnv;
92         
93         @Rule
94         public ExpectedException thrown= ExpectedException.none();
95         
96         private String vnfmId = "vnfmId_001";
97         private String vnfInstanceId = "vnfInstanceId_001";
98         
99         private String protocol = "https";
100         private String ip = "139.234.34.43";
101         private String port = "99";
102         private String cbamHttpHead;
103         @Before
104         public void setUp() throws Exception {
105                 MockitoAnnotations.initMocks(this);
106                 cbamHttpHead = protocol + "://" + ip + ":" + port;
107                 
108                 EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
109                 esrSystemInfo.setEsrSystemId("esrSystemId");
110                 esrSystemInfo.setPassword("password");
111                 esrSystemInfo.setServiceUrl(cbamHttpHead);
112                 esrSystemInfo.setType("type");
113                 esrSystemInfo.setUserName("userName");
114                 esrSystemInfo.setVendor("vendor");
115                 esrSystemInfo.setVersion("version");
116                 
117                 List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>();
118                 esrSystemInfoList.add(esrSystemInfo);
119                 AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo();
120                 mockVnfmInfo.setVnfmId(vnfmId);
121                 mockVnfmInfo.setVimId("vimId");
122                 mockVnfmInfo.setResourceVersion("resourceVersion");
123                 mockVnfmInfo.setCertificateUrl("certificateUrl");
124                 mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList);
125                 
126                 Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter();
127                 Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter();
128                 vnfmDriverMgmr.setRequestConverter(reqConverter);
129                 vnfmDriverMgmr.setResponseConverter(rspConverter);
130                 
131                 when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo);
132                 
133                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
134                 execInfo.setJobId(100L);
135                 execInfo.setVnfmExecutionId("executionId_001");
136                 execInfo.setVnfInstanceId(vnfInstanceId);
137                 
138                 when(jobDbManager.save(Mockito.any(VnfmJobExecutionInfo.class))).thenReturn(execInfo);
139         }
140         
141         @Test
142         public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
143                 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId);
144                 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
145         }
146         
147         @Test(expected = VnfmDriverException.class)
148         public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
149                 vnfmDriverMgmr.buildVnfmHttpPathByRealId(vnfmId + "001");
150         }
151         
152         @Test
153         public void testInstantiateVnf() throws ClientProtocolException, IOException {
154                 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
155                 mockCbamResponse.setId("executionId_001");
156                 
157                 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
158                 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
159                 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
160         }
161         
162         @Test
163         public void testTerminateVnf() throws ClientProtocolException, IOException {
164                 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
165                 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
166         }
167         
168         @Test
169         public void testHealVnf() throws ClientProtocolException, IOException {
170                 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
171                 mockCbamResponse.setId("executionId_001");
172                 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
173                 HealVnfRequest request = new HealVnfRequest();
174                 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
175         }
176         
177         @Test
178         public void testScaleVnf() throws ClientProtocolException, IOException {
179                 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
180                 mockCbamResponse.setId("executionId_001");
181                 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
182                 ScaleVnfRequest request = new ScaleVnfRequest();
183                 request.setType(ScaleType.SCALE_IN);
184                 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
185         }
186         
187         @Test
188         public void testQueryVnf() throws ClientProtocolException, IOException {
189                 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
190                 mockCbamResponse.setId("executionId_001");
191                 mockCbamResponse.setVnfdId(vnfInstanceId);
192                 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
193                 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
194                 Assert.assertEquals(vnfInstanceId, response.getVnfdId());
195         }
196         
197         @Test
198         public void testGetOperStatus() throws ClientProtocolException, IOException
199         {
200                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
201                 execInfo.setJobId(1L);
202                 execInfo.setVnfmExecutionId("executionId_001");
203                 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
204                 
205                 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
206                 cbamResponse.setId("executionId_001");
207                 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
208                 cbamResponse.setGrantId("001002001");
209                 
210                 when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
211                 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
212                 
213                 Assert.assertEquals("executionId_001", response.getJobId());
214         }
215
216 }