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 / 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                 esrSystemInfo.setCloudDomain("cloudDomain");
112                 esrSystemInfo.setDefaultTenant("defaultTenant");
113                 esrSystemInfo.setEsrSystemId("esrSystemId");
114                 esrSystemInfo.setPassword("password");
115                 esrSystemInfo.setServiceUrl("serviceUrl");
116                 esrSystemInfo.setSslCacert("sslCacert");
117                 esrSystemInfo.setSslInsecure("sslInsecure");
118                 esrSystemInfo.setType("type");
119                 esrSystemInfo.setUserName("userName");
120                 esrSystemInfo.setVendor("vendor");
121                 esrSystemInfo.setVersion("version");
122                 
123                 List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>();
124                 esrSystemInfoList.add(esrSystemInfo);
125                 AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo();
126                 mockVnfmInfo.setVnfmId(vnfmId);
127                 mockVnfmInfo.setVimId("vimId");
128                 mockVnfmInfo.setResourceVersion("resourceVersion");
129                 mockVnfmInfo.setCertificateUrl("certificateUrl");
130                 mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList);
131                 
132                 Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter();
133                 Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter();
134                 vnfmDriverMgmr.setRequestConverter(reqConverter);
135                 vnfmDriverMgmr.setResponseConverter(rspConverter);
136                 
137                 when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo);
138                 
139                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
140                 execInfo.setJobId(100L);
141                 execInfo.setVnfmExecutionId("executionId_001");
142                 execInfo.setVnfInstanceId(vnfInstanceId);
143                 
144                 when(jobDbManager.save(Mockito.any(VnfmJobExecutionInfo.class))).thenReturn(execInfo);
145         }
146         
147         @Test
148         public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException {
149                 String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId);
150                 Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead);
151         }
152         
153         @Test(expected = VnfmDriverException.class)
154         public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{
155                 vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId + "001");
156         }
157         
158         @Test
159         public void testInstantiateVnf() throws ClientProtocolException, IOException {
160                 CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse();
161                 mockCbamResponse.setId("executionId_001");
162                 
163                 when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse);
164                 InstantiateVnfRequest driverRequest = new InstantiateVnfRequest();
165                 InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId);
166         }
167         
168         @Test
169         public void testTerminateVnf() throws ClientProtocolException, IOException {
170                 TerminateVnfRequest driverRequest = new TerminateVnfRequest();
171                 TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId);
172         }
173         
174         @Test
175         public void testHealVnf() throws ClientProtocolException, IOException {
176                 CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse();
177                 mockCbamResponse.setId("executionId_001");
178                 when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
179                 HealVnfRequest request = new HealVnfRequest();
180                 HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId);
181         }
182         
183         @Test
184         public void testScaleVnf() throws ClientProtocolException, IOException {
185                 CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse();
186                 mockCbamResponse.setId("executionId_001");
187                 when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse);
188                 ScaleVnfRequest request = new ScaleVnfRequest();
189                 request.setType(CommonEnum.ScaleType.SCALE_IN);
190                 ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId);
191         }
192         
193         @Test
194         public void testQueryVnf() throws ClientProtocolException, IOException {
195                 CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse();
196                 mockCbamResponse.setId("executionId_001");
197                 mockCbamResponse.setVnfdId(vnfInstanceId);
198                 when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse);
199                 QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId);
200                 Assert.assertEquals(vnfInstanceId, response.getVnfdId());
201         }
202         
203         @Test
204         public void testGetOperStatus() throws ClientProtocolException, IOException
205         {
206                 VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo();
207                 execInfo.setJobId(1L);
208                 execInfo.setVnfmExecutionId("executionId_001");
209                 when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo);
210                 
211                 CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse();
212                 cbamResponse.setId("executionId_001");
213                 cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED);
214                 cbamResponse.setGrantId("001002001");
215                 
216                 when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse);
217                 OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1");
218                 
219                 Assert.assertEquals("executionId_001", response.getJobId());
220         }
221
222 }