Add Unit Tests.
[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.db.bean.VnfmJobExecutionInfo;
51 import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository;
52 import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException;
53 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf;
54 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest;
55 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse;
56 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest;
57 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse;
58 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse;
59 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse;
60 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest;
61 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse;
62 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest;
63 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse;
64 import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfContinueProcessorInf;
65
66 public class VnfmDriverMgmrImplTest {
67
68         @InjectMocks
69         private VnfmDriverMgmrImpl vnfmDriverMgmr = new VnfmDriverMgmrImpl();
70         
71         @Mock
72         private CbamMgmrInf cbamMgmr;
73         
74         @Mock
75         private CatalogMgmrInf catalogMgmr;
76         
77         @Mock
78         private AaiMgmrInf aaiMgmr;
79         
80         @Mock
81         private NslcmMgmrInf nslcmMgmr;;
82         
83         @Mock
84         private VnfmJobExecutionRepository jobDbManager;
85         
86         @Mock
87         private VnfContinueProcessorInf vnfContinueProcessorInf;
88         
89         @Mock
90         AdaptorEnv adaptorEnv;
91         
92         @Rule
93         public ExpectedException thrown= ExpectedException.none();
94         
95         private String vnfmId = "vnfmId_001";
96         private String vnfInstanceId = "vnfInstanceId_001";
97         
98         private String protocol = "https";
99         private String ip = "139.234.34.43";
100         private String port = "99";
101         private String cbamHttpHead;
102         @Before
103         public void setUp() throws Exception {
104                 MockitoAnnotations.initMocks(this);
105                 cbamHttpHead = protocol + "://" + ip + ":" + port;
106                 
107                 EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
108                 esrSystemInfo.setProtocal(protocol);
109                 esrSystemInfo.setIp(ip);
110                 esrSystemInfo.setPort(port);
111                 
112                 List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>();
113                 esrSystemInfoList.add(esrSystemInfo);
114                 AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo();
115                 mockVnfmInfo.setVnfmId(vnfmId);
116                 mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList);
117                 
118                 Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter();
119                 Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter();
120                 vnfmDriverMgmr.setRequestConverter(reqConverter);
121                 vnfmDriverMgmr.setResponseConverter(rspConverter);
122                 
123                 when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo);
124                 
125                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
126                 execInfo.setJobId(100L);
127                 execInfo.setVnfmExecutionId("executionId_001");
128                 execInfo.setVnfInstanceId(vnfInstanceId);
129                 
130                 when(jobDbManager.save(Mockito.any(VnfmJobExecutionInfo.class))).thenReturn(execInfo);
131         }
132         
133         @Test
134         public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
135                 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId);
136                 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
137         }
138         
139         @Test(expected = VnfmDriverException.class)
140         public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
141                 vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId + "001");
142         }
143         
144         @Test
145         public void testInstantiateVnf() throws ClientProtocolException, IOException {
146                 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
147                 mockCbamResponse.setId("executionId_001");
148                 
149                 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
150                 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
151                 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
152         }
153         
154         @Test
155         public void testTerminateVnf() throws ClientProtocolException, IOException {
156                 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
157                 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
158         }
159         
160         @Test
161         public void testHealVnf() throws ClientProtocolException, IOException {
162                 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
163                 mockCbamResponse.setId("executionId_001");
164                 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
165                 HealVnfRequest request = new HealVnfRequest();
166                 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
167         }
168         
169         @Test
170         public void testScaleVnf() throws ClientProtocolException, IOException {
171                 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
172                 mockCbamResponse.setId("executionId_001");
173                 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
174                 ScaleVnfRequest request = new ScaleVnfRequest();
175                 request.setType(CommonEnum.ScaleType.SCALE_IN);
176                 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
177         }
178         
179         @Test
180         public void testQueryVnf() throws ClientProtocolException, IOException {
181                 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
182                 mockCbamResponse.setId("executionId_001");
183                 
184                 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
185                 ScaleVnfRequest request = new ScaleVnfRequest();
186                 request.setType(CommonEnum.ScaleType.SCALE_IN);
187                 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
188         }
189         
190         @Test
191         public void testGetOperStatus() throws ClientProtocolException, IOException
192         {
193                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
194                 execInfo.setJobId(1L);
195                 execInfo.setVnfmExecutionId("executionId_001");
196                 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
197                 
198                 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
199                 cbamResponse.setId("executionId_001");
200                 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
201                 cbamResponse.setGrantId("001002001");
202                 
203                 when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
204                 ScaleVnfRequest request = new ScaleVnfRequest();
205                 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
206         }
207
208 }