diff options
Diffstat (limited to 'nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap')
7 files changed, 770 insertions, 2 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java new file mode 100644 index 00000000..aa24bf3c --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java @@ -0,0 +1,208 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; + +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.client.ClientProtocolException; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.entity.EsrSystemInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryOperExecutionResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfContinueProcessorInf; + +public class VnfmDriverMgmrImplTest { + + @InjectMocks + private VnfmDriverMgmrImpl vnfmDriverMgmr = new VnfmDriverMgmrImpl(); + + @Mock + private CbamMgmrInf cbamMgmr; + + @Mock + private CatalogMgmrInf catalogMgmr; + + @Mock + private AaiMgmrInf aaiMgmr; + + @Mock + private NslcmMgmrInf nslcmMgmr;; + + @Mock + private VnfmJobExecutionRepository jobDbManager; + + @Mock + private VnfContinueProcessorInf vnfContinueProcessorInf; + + @Mock + AdaptorEnv adaptorEnv; + + @Rule + public ExpectedException thrown= ExpectedException.none(); + + private String vnfmId = "vnfmId_001"; + private String vnfInstanceId = "vnfInstanceId_001"; + + private String protocol = "https"; + private String ip = "139.234.34.43"; + private String port = "99"; + private String cbamHttpHead; + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + cbamHttpHead = protocol + "://" + ip + ":" + port; + + EsrSystemInfo esrSystemInfo = new EsrSystemInfo(); + esrSystemInfo.setProtocal(protocol); + esrSystemInfo.setIp(ip); + esrSystemInfo.setPort(port); + + List<EsrSystemInfo> esrSystemInfoList = new ArrayList<EsrSystemInfo>(); + esrSystemInfoList.add(esrSystemInfo); + AaiVnfmInfo mockVnfmInfo = new AaiVnfmInfo(); + mockVnfmInfo.setVnfmId(vnfmId); + mockVnfmInfo.setEsrSystemInfoList(esrSystemInfoList); + + Driver2CbamRequestConverter reqConverter = new Driver2CbamRequestConverter(); + Cbam2DriverResponseConverter rspConverter = new Cbam2DriverResponseConverter(); + vnfmDriverMgmr.setRequestConverter(reqConverter); + vnfmDriverMgmr.setResponseConverter(rspConverter); + + when(aaiMgmr.queryVnfm(vnfmId)).thenReturn(mockVnfmInfo); + + VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo(); + execInfo.setJobId(100L); + execInfo.setVnfmExecutionId("executionId_001"); + execInfo.setVnfInstanceId(vnfInstanceId); + + when(jobDbManager.save(Mockito.any(VnfmJobExecutionInfo.class))).thenReturn(execInfo); + } + + @Test + public void testBuildVnfmHttpPathById() throws ClientProtocolException, IOException { + String vnfmHttpPathHead = vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId); + Assert.assertEquals("result is ", cbamHttpHead, vnfmHttpPathHead); + } + + @Test(expected = VnfmDriverException.class) + public void testBuildVnfmHttpPathByIdException() throws ClientProtocolException, IOException{ + vnfmDriverMgmr.buildVnfmHttpPathById(vnfmId + "001"); + } + + @Test + public void testInstantiateVnf() throws ClientProtocolException, IOException { + CBAMCreateVnfResponse mockCbamResponse = new CBAMCreateVnfResponse(); + mockCbamResponse.setId("executionId_001"); + + when(cbamMgmr.createVnf(Mockito.any(CBAMCreateVnfRequest.class))).thenReturn(mockCbamResponse); + InstantiateVnfRequest driverRequest = new InstantiateVnfRequest(); + InstantiateVnfResponse response = vnfmDriverMgmr.instantiateVnf(driverRequest, vnfmId); + } + + @Test + public void testTerminateVnf() throws ClientProtocolException, IOException { + TerminateVnfRequest driverRequest = new TerminateVnfRequest(); + TerminateVnfResponse response = vnfmDriverMgmr.terminateVnf(driverRequest, vnfmId, vnfInstanceId); + } + + @Test + public void testHealVnf() throws ClientProtocolException, IOException { + CBAMHealVnfResponse mockCbamResponse = new CBAMHealVnfResponse(); + mockCbamResponse.setId("executionId_001"); + when(cbamMgmr.healVnf(Mockito.any(CBAMHealVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse); + HealVnfRequest request = new HealVnfRequest(); + HealVnfResponse response = vnfmDriverMgmr.healVnf(request, vnfmId, vnfInstanceId); + } + + @Test + public void testScaleVnf() throws ClientProtocolException, IOException { + CBAMScaleVnfResponse mockCbamResponse = new CBAMScaleVnfResponse(); + mockCbamResponse.setId("executionId_001"); + when(cbamMgmr.scaleVnf(Mockito.any(CBAMScaleVnfRequest.class), Mockito.anyString())).thenReturn(mockCbamResponse); + ScaleVnfRequest request = new ScaleVnfRequest(); + request.setType(CommonEnum.ScaleType.SCALE_IN); + ScaleVnfResponse response = vnfmDriverMgmr.scaleVnf(request, vnfmId, vnfInstanceId); + } + + @Test + public void testQueryVnf() throws ClientProtocolException, IOException { + CBAMQueryVnfResponse mockCbamResponse = new CBAMQueryVnfResponse(); + mockCbamResponse.setId("executionId_001"); + + when(cbamMgmr.queryVnf(Mockito.anyString())).thenReturn(mockCbamResponse); + ScaleVnfRequest request = new ScaleVnfRequest(); + request.setType(CommonEnum.ScaleType.SCALE_IN); + QueryVnfResponse response = vnfmDriverMgmr.queryVnf(vnfmId, vnfInstanceId); + } + + @Test + public void testGetOperStatus() throws ClientProtocolException, IOException + { + VnfmJobExecutionInfo execInfo = new VnfmJobExecutionInfo(); + execInfo.setJobId(1L); + execInfo.setVnfmExecutionId("executionId_001"); + when(jobDbManager.findOne(Mockito.anyLong())).thenReturn(execInfo); + + CBAMQueryOperExecutionResponse cbamResponse = new CBAMQueryOperExecutionResponse(); + cbamResponse.setId("executionId_001"); + cbamResponse.setStatus(CommonEnum.OperationStatus.STARTED); + cbamResponse.setGrantId("001002001"); + + when(cbamMgmr.queryOperExecution(Mockito.anyString())).thenReturn(cbamResponse); + ScaleVnfRequest request = new ScaleVnfRequest(); + OperStatusVnfResponse response = vnfmDriverMgmr.getOperStatus(vnfmId, "1"); + } + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImplTest.java new file mode 100644 index 00000000..7fac27b0 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImplTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.impl; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class CatalogMgmrImplTest { + + @Before + public void setUp() throws Exception { + } + + @Test + public void test() { +// fail("Not yet implemented"); + } + +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java new file mode 100644 index 00000000..b4cabfbe --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java @@ -0,0 +1,113 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.impl; + +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.HashMap; + +import org.apache.http.client.ClientProtocolException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; +import org.springframework.web.bind.annotation.RequestMethod; + +public class CbamMgmrImplTest { + @InjectMocks + private CbamMgmrImpl cbamMgmr; + + @Mock + private HttpClientProcessorInf httpClientProcessor; + + private String vnfInstanceId = "vnfInstanceId_001"; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + AdaptorEnv env = new AdaptorEnv(); + cbamMgmr.setAdaptorEnv(env); + MockitoAnnotations.initMocks(this); + + String json = "{\"access_token\":\"1234567\"}"; + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(json); + } + + @Test + public void testCreateVnf() throws ClientProtocolException, IOException + { + CBAMCreateVnfRequest cbamRequest = new CBAMCreateVnfRequest(); + CBAMCreateVnfResponse response = cbamMgmr.createVnf(cbamRequest); + } + + @Test + public void testInstantiateVnf() throws ClientProtocolException, IOException + { + CBAMInstantiateVnfRequest cbamRequest = new CBAMInstantiateVnfRequest(); + CBAMInstantiateVnfResponse response = cbamMgmr.instantiateVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testTerminateVnf() throws ClientProtocolException, IOException + { + CBAMTerminateVnfRequest cbamRequest = new CBAMTerminateVnfRequest(); + CBAMTerminateVnfResponse response = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testDeleteVnf() throws ClientProtocolException, IOException + { + cbamMgmr.deleteVnf(vnfInstanceId); + } + + @Test + public void testScaleVnf() throws ClientProtocolException, IOException + { + CBAMScaleVnfRequest cbamRequest = new CBAMScaleVnfRequest(); + CBAMScaleVnfResponse response = cbamMgmr.scaleVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testHealVnf() throws ClientProtocolException, IOException + { + CBAMHealVnfRequest cbamRequest = new CBAMHealVnfRequest(); + CBAMHealVnfResponse response = cbamMgmr.healVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testQueryVnf() throws ClientProtocolException, IOException + { + CBAMQueryVnfResponse response = cbamMgmr.queryVnf(vnfInstanceId); + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImplTest.java new file mode 100644 index 00000000..08587109 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/msb/impl/MsbMgmrImplTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.impl; + +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.HashMap; + +import org.apache.http.client.ClientProtocolException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.impl.NslcmMgmrImpl; +import org.springframework.web.bind.annotation.RequestMethod; + +public class MsbMgmrImplTest { + @InjectMocks + private MsbMgmrImpl msbMgmr; + + @Mock + private HttpClientProcessorInf httpClientProcessor; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + AdaptorEnv env = new AdaptorEnv(); + msbMgmr.setAdaptorEnv(env); + MockitoAnnotations.initMocks(this); + + String json = "{\"access_token\":\"1234567\"}"; + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(json); + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/impl/NslcmMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/impl/NslcmMgmrImplTest.java new file mode 100644 index 00000000..d445212a --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/impl/NslcmMgmrImplTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.impl; + +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.HashMap; + +import org.apache.http.client.ClientProtocolException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest; +import org.springframework.web.bind.annotation.RequestMethod; + +public class NslcmMgmrImplTest { + @InjectMocks + private NslcmMgmrImpl nslcmMgmr; + + @Mock + private HttpClientProcessorInf httpClientProcessor; + + private String vnfInstanceId = "vnfInstanceId_001"; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + AdaptorEnv env = new AdaptorEnv(); + nslcmMgmr.setAdaptorEnv(env); + MockitoAnnotations.initMocks(this); + + String json = "{\"access_token\":\"1234567\"}"; + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(json); + } + + @Test + public void testGrantVnf() throws ClientProtocolException, IOException + { + NslcmGrantVnfRequest cbamRequest = new NslcmGrantVnfRequest(); + NslcmGrantVnfResponse response = nslcmMgmr.grantVnf(cbamRequest); + } + + @Test + public void testNotifyVnf() throws ClientProtocolException, IOException + { + NslcmNotifyLCMEventsRequest cbamRequest = new NslcmNotifyLCMEventsRequest(); + nslcmMgmr.notifyVnf(cbamRequest, vnfInstanceId); + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vfcadaptor/VfcadaptorApplicationTests.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vfcadaptor/VfcadaptorApplicationTests.java index 288770f5..ecf77fc3 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vfcadaptor/VfcadaptorApplicationTests.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vfcadaptor/VfcadaptorApplicationTests.java @@ -21,12 +21,15 @@ import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) -@SpringBootTest +//@SpringBootTest public class VfcadaptorApplicationTests { @Test - public void contextLoads() { + public void aapTest() { + assertThat("kcom").isEqualTo("kcom"); } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverControllerTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverControllerTest.java new file mode 100644 index 00000000..82e06dfe --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverControllerTest.java @@ -0,0 +1,283 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.controller; + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.apache.http.HttpStatus; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.QueryVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.ScaleVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.TerminateVnfResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf.VnfmDriverMgmrInf; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +public class VnfmDriverControllerTest { + @Mock + private VnfmDriverMgmrInf vnfmDriverMgmr; + + @InjectMocks + private VnfmDriverController controller; + + private MockMvc mockMvc; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); + } + + @Test + public void testInstantiateVnf() throws Exception { + InstantiateVnfResponse mockResponse = new InstantiateVnfResponse(); + mockResponse.setJobId("job_001"); + mockResponse.setVnfInstanceId("vnfInstanceId_001"); + String jsonString = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}"; + + when(vnfmDriverMgmr.instantiateVnf(Mockito.any(InstantiateVnfRequest.class), Mockito.anyString())).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/vnfmId_001/vnfs"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isCreated()) + .andReturn().getResponse().getContentAsString(); + + JSONObject jsonObj = new JSONObject(responseString); + Assert.assertEquals("jobId is ", mockResponse.getJobId(), jsonObj.get("jobId")); + Assert.assertEquals("vnfInstanceId is ", mockResponse.getVnfInstanceId(), jsonObj.get("vnfInstanceId")); + } + + @Test + public void testTerminateVnf() throws Exception { + TerminateVnfResponse mockResponse = new TerminateVnfResponse(); + mockResponse.setJobId("job_002"); + String jsonString = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}"; + + when(vnfmDriverMgmr.terminateVnf(Mockito.any(TerminateVnfRequest.class), Mockito.anyString(), Mockito.anyString())).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_002/terminate"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isCreated()) + .andReturn().getResponse().getContentAsString(); + + JSONObject jsonObj = new JSONObject(responseString); + Assert.assertEquals("jobId is ", mockResponse.getJobId(), jsonObj.get("jobId")); + } + + @Test + public void testTerminateVnfException() throws Exception { + String jsonString = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}"; + VnfmDriverException exception = new VnfmDriverException(HttpStatus.SC_BAD_REQUEST, "vnfInstanceId is wrong"); + when(vnfmDriverMgmr.terminateVnf(Mockito.any(TerminateVnfRequest.class), Mockito.anyString(), Mockito.anyString())).thenThrow(exception); + + String erroMsg = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_002/terminate"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andReturn().getResponse().getErrorMessage(); + + Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); + } + + @Test + public void testGetOperStatus() throws Exception { + OperStatusVnfResponse mockResponse = new OperStatusVnfResponse(); + mockResponse.setJobId("jobId_003"); + when(vnfmDriverMgmr.getOperStatus(Mockito.anyString(), Mockito.anyString())).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + get("/api/nokiavnfmdriver/v1/vnfmId_002/jobs/jobId_001"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isCreated()) + .andReturn().getResponse().getContentAsString(); + + JSONObject jsonObj = new JSONObject(responseString); + Assert.assertEquals("jobId is ", mockResponse.getJobId(), jsonObj.get("jobId")); + } + + @Test + public void testGetOperStatusException() throws Exception { + VnfmDriverException exception = new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); + when(vnfmDriverMgmr.getOperStatus( Mockito.anyString(), Mockito.anyString())).thenThrow(exception); + + String erroMsg = mockMvc.perform( + get("/api/nokiavnfmdriver/v1/vnfmId_002/jobs/jobId_002"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isInternalServerError()) + .andReturn().getResponse().getErrorMessage(); + + Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); + } + + @Test + public void testQueryVnf() throws Exception { + QueryVnfResponse mockResponse = new QueryVnfResponse(); + mockResponse.setVnfdId("vnfdId_001"); + when(vnfmDriverMgmr.queryVnf(Mockito.anyString(), Mockito.anyString())).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + get("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_001"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isCreated()) + .andReturn().getResponse().getContentAsString(); + + JSONObject jsonObj = new JSONObject(responseString); + Assert.assertEquals("VnfdId is ", mockResponse.getVnfdId(), jsonObj.get("vnfdId")); + } + + @Test + public void testQueryVnfException() throws Exception { + VnfmDriverException exception = new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); + when(vnfmDriverMgmr.queryVnf( Mockito.anyString(), Mockito.anyString())).thenThrow(exception); + + String erroMsg = mockMvc.perform( + get("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_001"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isInternalServerError()) + .andReturn().getResponse().getErrorMessage(); + + Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); + } + + @Test + public void testScaleVnf() throws Exception { + ScaleVnfResponse mockResponse = new ScaleVnfResponse(); + mockResponse.setJobId("job_002"); + String jsonString = "{\"vnfInstanceId\":\"vnfInstanceId_003\",\"vnfPackageId\":\"1\"}"; + + when(vnfmDriverMgmr.scaleVnf(Mockito.any(ScaleVnfRequest.class), Mockito.anyString(), Mockito.anyString())).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_003/scale"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isCreated()) + .andReturn().getResponse().getContentAsString(); + + JSONObject jsonObj = new JSONObject(responseString); + Assert.assertEquals("jobId is ", mockResponse.getJobId(), jsonObj.get("jobId")); + } + + @Test + public void testScaleVnfException() throws Exception { + String jsonString = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}"; + VnfmDriverException exception = new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); + when(vnfmDriverMgmr.scaleVnf(Mockito.any(ScaleVnfRequest.class), Mockito.anyString(), Mockito.anyString())).thenThrow(exception); + + String erroMsg = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_002/scale"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isInternalServerError()) + .andReturn().getResponse().getErrorMessage(); + + Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); + } + @Test + public void testHealVnf() throws Exception { + HealVnfResponse mockResponse = new HealVnfResponse(); + mockResponse.setJobId("job_002"); + String jsonString = "{\"vnfInstanceId\":\"vnfInstanceId_003\",\"vnfPackageId\":\"1\"}"; + + when(vnfmDriverMgmr.healVnf(Mockito.any(HealVnfRequest.class), Mockito.anyString(), Mockito.anyString())).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_003/heal"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isCreated()) + .andReturn().getResponse().getContentAsString(); + + JSONObject jsonObj = new JSONObject(responseString); + Assert.assertEquals("jobId is ", mockResponse.getJobId(), jsonObj.get("jobId")); + } + + @Test + public void testHealVnfException() throws Exception { + String jsonString = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}"; + VnfmDriverException exception = new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); + when(vnfmDriverMgmr.healVnf(Mockito.any(HealVnfRequest.class), Mockito.anyString(), Mockito.anyString())).thenThrow(exception); + + String erroMsg = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/vnfmId_002/vnfs/vnfInstanceId_002/heal"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isInternalServerError()) + .andReturn().getResponse().getErrorMessage(); + + Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); + } + +} |