diff options
Diffstat (limited to 'nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org')
5 files changed, 401 insertions, 18 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java index 01c256bd..a2eece33 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java @@ -53,10 +53,21 @@ public class AaiMgmrInfImplTest { String json = "{" + "\"vnfm-id\":\"vnfm-id_001\"," + + "\"resource-version\" : \"resource-version\"," + "\"vim-id\":\"vim-id_001\"," + "\"certificate-url\":\"certificate-url_001\"," - + "\"resource-version\":\"resource-version_001\"," - + "\"esr-system-info\":[{\"type\" : \"vnfm\"}]" + + "\"esr-system-info\":[{" + + "\"type\" : \"vnfm\"," + + "\"system-name\" : \"system-name\"," + + "\"vendor\" : \"vendor\"," + + "\"esr-system-info-id\" : \"esr-system-info-id\"," + + "\"version\" : \"version\"," + + "\"service-url\" : \"service-url\"," + + "\"user-name\" : \"user-name\"," + + "\"password\" : \"password\"," + + "\"system-type\" : \"system-type\"," + + "\"resource-version\" : \"resource-version\"" + + "}]" + "}" + ""; HttpResult httpResult = new HttpResult(); @@ -69,6 +80,22 @@ public class AaiMgmrInfImplTest { public void testQueryVnfPackage() throws ClientProtocolException, IOException { AaiVnfmInfo vnfmInfo = aaiMgmr.queryVnfm(vnfmId); + vnfmInfo.getEsrSystemInfoList().get(0).setEsrSystemName("system-name"); + vnfmInfo.getEsrSystemInfoList().get(0).setSystemType("system-type"); + vnfmInfo.getEsrSystemInfoList().get(0).setResourceVersion("resource-version"); Assert.assertEquals("vnfm", vnfmInfo.getEsrSystemInfoList().get(0).getType()); + Assert.assertEquals("esr-system-info-id", vnfmInfo.getEsrSystemInfoList().get(0).getEsrSystemId()); + Assert.assertEquals("system-name", vnfmInfo.getEsrSystemInfoList().get(0).getEsrSystemName()); + Assert.assertEquals("vendor", vnfmInfo.getEsrSystemInfoList().get(0).getVendor()); + Assert.assertEquals("version", vnfmInfo.getEsrSystemInfoList().get(0).getVersion()); + Assert.assertEquals("user-name", vnfmInfo.getEsrSystemInfoList().get(0).getUserName()); + Assert.assertEquals("password", vnfmInfo.getEsrSystemInfoList().get(0).getPassword()); + Assert.assertEquals("system-type", vnfmInfo.getEsrSystemInfoList().get(0).getSystemType()); + Assert.assertEquals("resource-version", vnfmInfo.getEsrSystemInfoList().get(0).getResourceVersion()); + + Assert.assertEquals("vnfm-id_001", vnfmInfo.getVnfmId()); + Assert.assertEquals("vim-id_001", vnfmInfo.getVimId()); + Assert.assertEquals("certificate-url_001", vnfmInfo.getCertificateUrl()); + Assert.assertEquals("resource-version", vnfmInfo.getResourceVersion()); } } 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 index f3fb6f3b..1810820e 100644 --- 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 @@ -16,6 +16,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; import java.io.IOException; @@ -36,6 +37,8 @@ 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.CBAMCreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; 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; @@ -50,8 +53,11 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmSubscriptionsMapper; 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.CreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; 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; @@ -85,6 +91,9 @@ public class VnfmDriverMgmrImplTest { private VnfmJobExecutionMapper jobDbManager; @Mock + private VnfmSubscriptionsMapper subscriptionsMapper; + + @Mock private VnfContinueProcessorInf vnfContinueProcessorInf; @Mock @@ -215,5 +224,17 @@ public class VnfmDriverMgmrImplTest { // // Assert.assertEquals("executionId_001", response.getJobId()); } + + @Test + public void testCreateSubscription() throws ClientProtocolException, IOException { + CBAMCreateSubscriptionResponse mockCbamResponse = new CBAMCreateSubscriptionResponse(); + mockCbamResponse.setId("subscriptionId_001"); + mockCbamResponse.setCallbackUrl("callbackUrl"); + when(cbamMgmr.createSubscription(Mockito.any(CBAMCreateSubscriptionRequest.class))).thenReturn(mockCbamResponse); + doNothing().when(subscriptionsMapper).insert(Mockito.anyString()); + CreateSubscriptionRequest request = new CreateSubscriptionRequest(); + CreateSubscriptionResponse response = vnfmDriverMgmr.createSubscription(request); + Assert.assertEquals("callbackUrl", response.getCallbackUri()); + } } 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 index d1df4dbb..f7320998 100644 --- 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 @@ -95,6 +95,9 @@ public class CatalogMgmrImplTest { packageInfo.setVnfdProvider("vnfdProvider"); packageInfo.setVnfdVersion("vnfdVersion"); packageInfo.setVnfVersion("vnfVersion"); + packageInfo.setProvider("provider"); + packageInfo.setVnfdProvider("vnfdProvider"); + packageInfo.setVersion("version"); Deletionpending deletionPending = CommonEnum.Deletionpending.fALSE; packageInfo.setDeletionPending(deletionPending ); @@ -108,6 +111,26 @@ public class CatalogMgmrImplTest { when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); VnfPackageInfo packageInfo1 = catalogMgmr.queryVnfPackage(vnfPackageId); Assert.assertEquals("1.3.5.6", packageInfo.getDownloadUri()); + Assert.assertEquals("name", packageInfo.getName()); + Assert.assertEquals("onBoardState", packageInfo.getOnBoardState()); + Assert.assertEquals("vnfdId", packageInfo.getVnfdId()); + Assert.assertEquals("provider", packageInfo.getProvider()); + Assert.assertEquals("vnfdProvider", packageInfo.getVnfdProvider()); + Assert.assertEquals("vnfdVersion", packageInfo.getVnfdVersion()); + Assert.assertEquals("vnfVersion", packageInfo.getVnfVersion()); + Assert.assertEquals("version", packageInfo.getVersion()); + Assert.assertEquals(CommonEnum.Deletionpending.fALSE, packageInfo.getDeletionPending()); + + Assert.assertEquals("csarId", response.getCsarId()); + Assert.assertEquals("fileName", response.getImageInfo().getFileName()); + Assert.assertEquals("imageId", response.getImageInfo().getImageId()); + Assert.assertEquals("index", response.getImageInfo().getIndex()); + Assert.assertEquals("status", response.getImageInfo().getStatus()); + Assert.assertEquals("tenant", response.getImageInfo().getTenant()); + Assert.assertEquals("vimId", response.getImageInfo().getVimId()); + Assert.assertEquals("vimUser", response.getImageInfo().getVimUser()); + Assert.assertEquals("vnfInstanceId", response.getVnfInstanceInfo().get(0).getVnfInstanceId()); + Assert.assertEquals("vnfInstanceName", response.getVnfInstanceInfo().get(0).getVnfInstanceName()); } } 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 index aba3d88b..92561966 100644 --- 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 @@ -19,10 +19,12 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.impl; import static org.mockito.Mockito.when; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.http.client.ClientProtocolException; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -47,8 +49,16 @@ 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.cbam.bo.CBAMVnfNotificationRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ExtManagedVirtualLinkData; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ExtVirtualLinkData; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.NetworkAddress; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VimComputeResourceFlavour; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VimInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VimSoftwareImage; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfExtCpData; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ZoneInfo; 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.http.client.HttpResult; @@ -63,76 +73,294 @@ public class CbamMgmrImplTest { private String vnfInstanceId = "vnfInstanceId_001"; + private String json = "{" + + "'access_token':'1234567'," + + "'id':'id'," + + "'name':'name'," + + "'description':'description'," + + "'vnfdId':'vnfdId'," + + "'vnfProvider':'vnfProvider'," + + "'onboardedVnfPkgInfoId':'onboardedVnfPkgInfoId'," + + "'vnfProductName':'vnfProductName'" + + "}"; + + HttpResult httpResult = new HttpResult(); + private int statusCode = 200; + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); AdaptorEnv env = new AdaptorEnv(); cbamMgmr.setAdaptorEnv(env); - String json = "{\"access_token\":\"1234567\"}"; - HttpResult httpResult = new HttpResult(); - httpResult.setStatusCode(200); + httpResult.setStatusCode(statusCode); httpResult.setContent(json); when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); } @Test - public void testCreateVnf() throws ClientProtocolException, IOException + public void testCreateVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(201); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMCreateVnfRequest cbamRequest = new CBAMCreateVnfRequest(); + CBAMCreateVnfResponse response = cbamMgmr.createVnf(cbamRequest); + } + + @Test + public void testCreateVnfError() throws ClientProtocolException, IOException { CBAMCreateVnfRequest cbamRequest = new CBAMCreateVnfRequest(); CBAMCreateVnfResponse response = cbamMgmr.createVnf(cbamRequest); } @Test - public void testInstantiateVnf() throws ClientProtocolException, IOException + public void testInstantiateVnfSucess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMInstantiateVnfRequest cbamRequest = new CBAMInstantiateVnfRequest(); + cbamRequest.setFlavourId("flavourId"); + cbamRequest.setGrantlessMode(false); + + VimInfo vimInfo = new VimInfo(); + vimInfo.setId("id"); + vimInfo.setInterfaceEndpoint("interfaceEndpoint"); + + List<VimInfo> vims = new ArrayList<>(); + vims.add(vimInfo); + cbamRequest.setVims(vims); + + cbamRequest.setInstantiationLevelId("instantiationLevelId"); + + ExtVirtualLinkData linkData = new ExtVirtualLinkData(); + linkData.setExtVirtualLinkId("extVirtualLinkId"); + linkData.setResourceId("resourceId"); + linkData.setVimId("vimId"); + + List<VnfExtCpData> extCps = new ArrayList<>(); + VnfExtCpData vnfExtCpData = new VnfExtCpData(); + vnfExtCpData.setCpdId("cpdId"); + vnfExtCpData.setNumDynamicAddresses(10000); + List<NetworkAddress> addresses = new ArrayList<>(); + NetworkAddress address = new NetworkAddress(); + address.setIp("ip"); + address.setMac("mac"); + address.setSubnetId("subnetId"); + addresses.add(address); + vnfExtCpData.setAddresses(addresses ); + + extCps.add(vnfExtCpData); + linkData.setExtCps(extCps); + + List<ExtVirtualLinkData> extVirtualLinks = new ArrayList<>(); + extVirtualLinks.add(linkData); + cbamRequest.setExtVirtualLinks(extVirtualLinks); + + + List<ExtManagedVirtualLinkData> managedVirtualLinks = new ArrayList<>(); + ExtManagedVirtualLinkData managedVirtualLink = new ExtManagedVirtualLinkData(); + managedVirtualLink.setResourceId("resourceId"); + managedVirtualLink.setExtManagedVirtualLinkId("extManagedVirtualLinkId"); + managedVirtualLink.setVimId("vimId"); + managedVirtualLink.setVirtualLinkDescId("virtualLinkDescId"); + managedVirtualLinks.add(managedVirtualLink ); + + cbamRequest.setExtManagedVirtualLinks(managedVirtualLinks); + + + List<VimSoftwareImage> softwareImages = new ArrayList<>(); + VimSoftwareImage vimSoftwareImage = new VimSoftwareImage(); + vimSoftwareImage.setResourceId("resourceId"); + vimSoftwareImage.setVimId("vimId"); + vimSoftwareImage.setVnfdSoftwareImageId("vnfdSoftwareImageId"); + softwareImages.add(vimSoftwareImage); + cbamRequest.setSoftwareImages(softwareImages); + + + List<VimComputeResourceFlavour> computeResourceFlavours = new ArrayList<>(); + VimComputeResourceFlavour computeResourceFlavour = new VimComputeResourceFlavour(); + computeResourceFlavour.setResourceId("resourceId"); + computeResourceFlavour.setVimId("vimId"); + computeResourceFlavour.setVnfdVirtualComputeDescId("vnfdVirtualComputeDescId"); + computeResourceFlavours.add(computeResourceFlavour); + cbamRequest.setComputeResourceFlavours(computeResourceFlavours); + + List<ZoneInfo> zoneInfos = new ArrayList<>(); + ZoneInfo zoneInfo = new ZoneInfo(); + zoneInfo.setResourceId("resourceId"); + zoneInfo.setId("id"); + zoneInfos.add(zoneInfo); + cbamRequest.setZones(zoneInfos); + + cbamRequest.setAdditionalParams("additionalParams"); + + CBAMInstantiateVnfResponse response = cbamMgmr.instantiateVnf(cbamRequest, vnfInstanceId); + + Assert.assertEquals("result is ", "instantiationLevelId", cbamRequest.getInstantiationLevelId()); + Assert.assertEquals("result is ", "flavourId", cbamRequest.getFlavourId()); + Assert.assertEquals("result is ", false, cbamRequest.isGrantlessMode()); + Assert.assertEquals("result is ", "id", cbamRequest.getVims().get(0).getId()); + Assert.assertEquals("result is ", "interfaceEndpoint", cbamRequest.getVims().get(0).getInterfaceEndpoint()); + + Assert.assertEquals("result is ", "extVirtualLinkId", cbamRequest.getExtVirtualLinks().get(0).getExtVirtualLinkId()); + Assert.assertEquals("result is ", "resourceId", cbamRequest.getExtVirtualLinks().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getExtVirtualLinks().get(0).getVimId()); + + Assert.assertEquals("result is ", "cpdId", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getCpdId()); + Assert.assertEquals("result is ", "ip", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getAddresses().get(0).getIp()); + Assert.assertEquals("result is ", "mac", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getAddresses().get(0).getMac()); + Assert.assertEquals("result is ", "subnetId", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getAddresses().get(0).getSubnetId()); + + Assert.assertEquals("result is ", "extManagedVirtualLinkId", cbamRequest.getExtManagedVirtualLinks().get(0).getExtManagedVirtualLinkId()); + Assert.assertEquals("result is ", "resourceId", cbamRequest.getExtManagedVirtualLinks().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getExtManagedVirtualLinks().get(0).getVimId()); + Assert.assertEquals("result is ", "virtualLinkDescId", cbamRequest.getExtManagedVirtualLinks().get(0).getVirtualLinkDescId()); + + Assert.assertEquals("result is ", "resourceId", cbamRequest.getSoftwareImages().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getSoftwareImages().get(0).getVimId()); + Assert.assertEquals("result is ", "vnfdSoftwareImageId", cbamRequest.getSoftwareImages().get(0).getVnfdSoftwareImageId()); + + Assert.assertEquals("result is ", "resourceId", cbamRequest.getComputeResourceFlavours().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getComputeResourceFlavours().get(0).getVimId()); + Assert.assertEquals("result is ", "vnfdVirtualComputeDescId", cbamRequest.getComputeResourceFlavours().get(0).getVnfdVirtualComputeDescId()); + + Assert.assertEquals("result is ", "id", cbamRequest.getZones().get(0).getId()); + Assert.assertEquals("result is ", "resourceId", cbamRequest.getZones().get(0).getResourceId()); + + Assert.assertEquals("result is ", "additionalParams", cbamRequest.getAdditionalParams()); + } + + @Test + public void testInstantiateVnfError() throws ClientProtocolException, IOException { CBAMInstantiateVnfRequest cbamRequest = new CBAMInstantiateVnfRequest(); CBAMInstantiateVnfResponse response = cbamMgmr.instantiateVnf(cbamRequest, vnfInstanceId); } @Test - public void testModifyVnf() throws ClientProtocolException, IOException + public void testModifyVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + + CBAMModifyVnfRequest cbamRequest = new CBAMModifyVnfRequest(); + CBAMModifyVnfResponse response = cbamMgmr.modifyVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testModifyVnfError() throws ClientProtocolException, IOException { CBAMModifyVnfRequest cbamRequest = new CBAMModifyVnfRequest(); CBAMModifyVnfResponse response = cbamMgmr.modifyVnf(cbamRequest, vnfInstanceId); } @Test - public void testTerminateVnf() throws ClientProtocolException, IOException + public void testTerminateVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMTerminateVnfRequest cbamRequest = new CBAMTerminateVnfRequest(); + CBAMTerminateVnfResponse response = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testTerminateVnfError() throws ClientProtocolException, IOException { CBAMTerminateVnfRequest cbamRequest = new CBAMTerminateVnfRequest(); CBAMTerminateVnfResponse response = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId); } @Test - public void testDeleteVnf() throws ClientProtocolException, IOException + public void testDeleteVnfSuccess() throws ClientProtocolException, IOException { + httpResult.setStatusCode(204); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + cbamMgmr.deleteVnf(vnfInstanceId); } @Test - public void testScaleVnf() throws ClientProtocolException, IOException + public void testDeleteVnfError() throws ClientProtocolException, IOException { + cbamMgmr.deleteVnf(vnfInstanceId); + } + + @Test + public void testScaleVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + CBAMScaleVnfRequest cbamRequest = new CBAMScaleVnfRequest(); CBAMScaleVnfResponse response = cbamMgmr.scaleVnf(cbamRequest, vnfInstanceId); } @Test - public void testHealVnf() throws ClientProtocolException, IOException + public void testScaleVnfError() throws ClientProtocolException, IOException + { + CBAMScaleVnfRequest cbamRequest = new CBAMScaleVnfRequest(); + CBAMScaleVnfResponse response = cbamMgmr.scaleVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testHealVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMHealVnfRequest cbamRequest = new CBAMHealVnfRequest(); + CBAMHealVnfResponse response = cbamMgmr.healVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testHealVnfError() throws ClientProtocolException, IOException { CBAMHealVnfRequest cbamRequest = new CBAMHealVnfRequest(); CBAMHealVnfResponse response = cbamMgmr.healVnf(cbamRequest, vnfInstanceId); } @Test + public void testQueryVnfSuccess() throws ClientProtocolException, IOException + { + CBAMQueryVnfResponse response = cbamMgmr.queryVnf(vnfInstanceId); + } + + @Test public void testQueryVnf() throws ClientProtocolException, IOException { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + CBAMQueryVnfResponse response = cbamMgmr.queryVnf(vnfInstanceId); } @Test - public void testCreateSubscription() throws ClientProtocolException, IOException + public void testCreateSubscriptionSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(201); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMCreateSubscriptionRequest cbamRequest = new CBAMCreateSubscriptionRequest(); + CBAMCreateSubscriptionResponse response = cbamMgmr.createSubscription(cbamRequest); + } + + @Test + public void testCreateSubscriptionError() throws ClientProtocolException, IOException { CBAMCreateSubscriptionRequest cbamRequest = new CBAMCreateSubscriptionRequest(); CBAMCreateSubscriptionResponse response = cbamMgmr.createSubscription(cbamRequest); @@ -146,14 +374,25 @@ public class CbamMgmrImplTest { } @Test - public void testGetSubscription() throws ClientProtocolException, IOException + public void testGetSubscriptionSuccess() throws ClientProtocolException, IOException { String subscriptionId = "subscriptionId_001"; Subscription response = cbamMgmr.getSubscription(subscriptionId); } @Test - public void testQueryVnfcResource() throws ClientProtocolException, IOException + public void testGetSubscriptionError() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + String subscriptionId = "subscriptionId_001"; + Subscription response = cbamMgmr.getSubscription(subscriptionId); + } + + @Test + public void testQueryVnfcResourceSuccess() throws ClientProtocolException, IOException { String json = "[{'id':'id_001'}]"; HttpResult httpResult = new HttpResult(); @@ -165,15 +404,62 @@ public class CbamMgmrImplTest { } @Test - public void testQueryOperExecution() throws ClientProtocolException, IOException + public void testQueryVnfcResourceErrot() throws ClientProtocolException, IOException { + String json = "[{'id':'id_001'}]"; + HttpResult httpResult = new HttpResult(); + httpResult.setStatusCode(400); + httpResult.setContent(json); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + List<VnfcResourceInfo> response = cbamMgmr.queryVnfcResource(vnfInstanceId); + } + + @Test + public void testQueryOperExecutionSuccess() throws ClientProtocolException, IOException + { + String execId = "execId_001"; + CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId); + } + + @Test + public void testQueryOperExecutionOngoing() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + String execId = "execId_001"; CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId); } @Test - public void testUploadVnfPackage() throws ClientProtocolException, IOException + public void testQueryOperExecutionError() throws ClientProtocolException, IOException { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + + String execId = "execId_001"; + CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId); + } + + @Test + public void testUploadVnfPackageSuccess() throws ClientProtocolException, IOException + { + String cbamPackageFilePath = "cbamPackageFilePath_001"; + cbamMgmr.uploadVnfPackage(cbamPackageFilePath); + } + + @Test + public void testUploadVnfPackageError() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + String cbamPackageFilePath = "cbamPackageFilePath_001"; cbamMgmr.uploadVnfPackage(cbamPackageFilePath); } 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 index 82e06dfe..97659a7b 100644 --- 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 @@ -22,6 +22,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import javax.servlet.http.HttpServletResponse; + import org.apache.http.HttpStatus; import org.json.JSONObject; import org.junit.Assert; @@ -32,8 +34,9 @@ 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.CreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; 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; @@ -239,6 +242,7 @@ public class VnfmDriverControllerTest { Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); } + @Test public void testHealVnf() throws Exception { HealVnfResponse mockResponse = new HealVnfResponse(); @@ -279,5 +283,27 @@ public class VnfmDriverControllerTest { Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); } + + @Test + public void testCreateSubscripiton() throws Exception { + CreateSubscriptionResponse mockResponse = new CreateSubscriptionResponse(); + mockResponse.setCallbackUri("callbackUri"); + String jsonString = "{\"callbackUri\":\"callbackUri\",\"callbackUri\":\"callbackUrl\"," + "\"authentication\":{\"userName\":\"userName\",\"password\":\"password\",\"clientName\":\"clientName\"}}"; + + when(vnfmDriverMgmr.createSubscription(Mockito.any(CreateSubscriptionRequest.class))).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/createSubscripiton"). + 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.getCallbackUri(), jsonObj.get("callbackUri")); + } } |