diff options
author | Luji7 <lu.ji3@zte.com.cn> | 2018-03-29 16:30:07 +0800 |
---|---|---|
committer | Luji7 <lu.ji3@zte.com.cn> | 2018-03-29 16:30:15 +0800 |
commit | e51bccb930e5b8b58a1ab1a76f8d2714e4a110e9 (patch) | |
tree | 3c6a1c29de6445f546a91e1f0708caf87cf6b8a5 | |
parent | 0349d9a57424ddf68c0e4a499582c5e067628a60 (diff) |
Add unit test for uui lcm
Change-Id: I97662cbde16228212a47d9b306f415e86cac5072
Issue-ID: USECASEUI-103
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
9 files changed, 348 insertions, 10 deletions
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/CustomerControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/CustomerControllerTest.java index c1af3c5f..2aa66a29 100644 --- a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/CustomerControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/CustomerControllerTest.java @@ -31,4 +31,15 @@ public class CustomerControllerTest { verify(customerService, times(1)).listCustomer(); } + + @Test + public void testGetServiceSubscriptions() { + CustomerService customerService = mock(CustomerService.class); + CustomerController controller = new CustomerController(); + controller.setCustomerService(customerService); + + controller.getServiceSubscriptions("1"); + + verify(customerService, times(1)).listServiceSubscriptions("1"); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionControllerTest.java index c2da15b0..d7db3218 100644 --- a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionControllerTest.java @@ -68,4 +68,20 @@ public class PackageDistributionControllerTest { verify(service, times(1)).getJobStatus(jobId, responseId); } + + @Test + public void testDeleteNsPackage() { + String csarId = "1"; + controller.deleteNsPackage(csarId); + + verify(service, times(1)).deleteNsPackage(csarId); + } + + @Test + public void testDeleteVfPackage() { + String csarId = "1"; + controller.deleteVfPackage(csarId); + + verify(service, times(1)).deleteVfPackage(csarId); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateControllerTest.java index 5e52035d..86bb8e33 100644 --- a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateControllerTest.java @@ -47,4 +47,18 @@ public class ServiceTemplateControllerTest { verify(service, times(1)).fetchServiceTemplateInput(uuid, modelPath); } + + @Test + public void testGetLocations() throws Exception { + controller.getLocations(); + + verify(service, times(1)).listVim(); + } + + @Test + public void testGetSDNCControllers() throws Exception { + controller.getSDNCControllers(); + + verify(service, times(1)).listSDNCControllers(); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java index 889ce021..f0838005 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java @@ -21,6 +21,8 @@ import org.onap.usecaseui.server.service.lcm.CustomerService; import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService; import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer; import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomerRsp; +import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAIServiceSubscription; +import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceSubscriptionRsp; import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException; import retrofit2.Call; @@ -29,6 +31,7 @@ import java.util.List; import static java.util.Collections.singletonList; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall; import static org.onap.usecaseui.server.util.CallStub.failedCall; import static org.onap.usecaseui.server.util.CallStub.successfulCall; @@ -57,4 +60,52 @@ public class DefaultCustomerServiceTest { CustomerService customerService = new DefaultCustomerService(aaiService); customerService.listCustomer(); } + + @Test + public void itWillRetrieveEmptyListWhenNoCustomerInAAI() { + AAIService aaiService = mock(AAIService.class); + Call<AAICustomerRsp> call = emptyBodyCall(); + when(aaiService.listCustomer()).thenReturn(call); + + CustomerService customerService = new DefaultCustomerService(aaiService); + List<AAICustomer> customers = customerService.listCustomer(); + + Assert.assertTrue("customers should be empty list.", customers.isEmpty()); + } + + @Test + public void itCanRetrieveServiceSubscriptionsFromAAI() { + List<AAIServiceSubscription> serviceSubscriptions = singletonList(new AAIServiceSubscription("service type")); + + AAIService aaiService = mock(AAIService.class); + ServiceSubscriptionRsp rsp = new ServiceSubscriptionRsp(); + rsp.setServiceSubscriptions(serviceSubscriptions); + Call<ServiceSubscriptionRsp> call = successfulCall(rsp); + when(aaiService.listServiceSubscriptions("1")).thenReturn(call); + + CustomerService customerService = new DefaultCustomerService(aaiService); + Assert.assertSame(serviceSubscriptions, customerService.listServiceSubscriptions("1")); + } + + @Test(expected = AAIException.class) + public void listServiceSubscriptionsWillThrowExceptionWhenAAIIsNotAvailable() { + AAIService aaiService = mock(AAIService.class); + Call<ServiceSubscriptionRsp> call = failedCall("AAI is not available!"); + when(aaiService.listServiceSubscriptions("1")).thenReturn(call); + + CustomerService customerService = new DefaultCustomerService(aaiService); + customerService.listServiceSubscriptions("1"); + } + + @Test + public void itWillRetrieveEmptyListWhenNoServiceSubscriptionsInAAI() { + AAIService aaiService = mock(AAIService.class); + Call<ServiceSubscriptionRsp> call = emptyBodyCall(); + when(aaiService.listServiceSubscriptions("1")).thenReturn(call); + + CustomerService customerService = new DefaultCustomerService(aaiService); + List<AAIServiceSubscription> serviceSubscriptions = customerService.listServiceSubscriptions("1"); + + Assert.assertTrue("service subscription should be empty list.", serviceSubscriptions.isEmpty()); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java index 1b138ed9..f003157a 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java @@ -41,6 +41,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*; +import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall; import static org.onap.usecaseui.server.util.CallStub.failedCall; import static org.onap.usecaseui.server.util.CallStub.successfulCall; @@ -98,6 +99,22 @@ public class DefaultPackageDistributionServiceTest { } @Test + public void retrievePackageWillBeEmptyWhenNoNsServiceAndVfInSDC() { + SDCCatalogService sdcService = mock(SDCCatalogService.class); + Call<List<SDCServiceTemplate>> serviceCall = emptyBodyCall(); + when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall); + + Call<List<Vnf>> resourceCall = emptyBodyCall(); + when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(resourceCall); + + PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null); + VfNsPackageInfo vfNsPackageInfo = service.retrievePackageInfo(); + + Assert.assertTrue("ns should be empty!", vfNsPackageInfo.getNsPackage().isEmpty()); + Assert.assertTrue("vf should be empty!", vfNsPackageInfo.getVnfPackages().isEmpty()); + } + + @Test public void itCanPostNsPackageToVFC() { VfcService vfcService = mock(VfcService.class); Csar csar = new Csar(); @@ -120,6 +137,15 @@ public class DefaultPackageDistributionServiceTest { service.postNsPackage(csar); } + @Test(expected = VfcException.class) + public void postNsPackageWillThrowExceptionWhenVFCResponseError() { + VfcService vfcService = mock(VfcService.class); + Csar csar = new Csar(); + when(vfcService.distributeNsPackage(csar)).thenReturn(emptyBodyCall()); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + service.postNsPackage(csar); + } + @Test public void itCanPostVnfPackageToVFC() { VfcService vfcService = mock(VfcService.class); @@ -140,6 +166,15 @@ public class DefaultPackageDistributionServiceTest { service.postVfPackage(csar); } + @Test(expected = VfcException.class) + public void postVnfPackageWillThrowExceptionWhenVFCResponseError() { + VfcService vfcService = mock(VfcService.class); + Csar csar = new Csar(); + when(vfcService.distributeVnfPackage(csar)).thenReturn(emptyBodyCall()); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + service.postVfPackage(csar); + } + @Test public void itCanGetJobStatusFromVFC() { VfcService vfcService = mock(VfcService.class); @@ -161,4 +196,72 @@ public class DefaultPackageDistributionServiceTest { PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); service.getJobStatus(jobId, responseId); } + + @Test(expected = VfcException.class) + public void getJobStatusWillThrowExceptionWhenVFCResponseError() { + VfcService vfcService = mock(VfcService.class); + String jobId = "1"; + String responseId = "1"; + when(vfcService.getJobStatus(jobId, responseId)).thenReturn(emptyBodyCall()); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + service.getJobStatus(jobId, responseId); + } + + @Test + public void itCanDeleteNsPackage() { + String csarId = "1"; + DistributionResult result = new DistributionResult(); + VfcService vfcService = mock(VfcService.class); + when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result)); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + + Assert.assertSame(result, service.deleteNsPackage(csarId)); + } + + @Test(expected = VfcException.class) + public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() { + String csarId = "1"; + VfcService vfcService = mock(VfcService.class); + when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!")); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + service.deleteNsPackage(csarId); + } + + @Test(expected = VfcException.class) + public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() { + String csarId = "1"; + VfcService vfcService = mock(VfcService.class); + when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall()); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + service.deleteNsPackage(csarId); + } + + @Test + public void itCanDeleteVFPackage() { + String csarId = "1"; + Job job = new Job(); + VfcService vfcService = mock(VfcService.class); + when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job)); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + + Assert.assertSame(job, service.deleteVfPackage(csarId)); + } + + @Test(expected = VfcException.class) + public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() { + String csarId = "1"; + VfcService vfcService = mock(VfcService.class); + when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!")); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + service.deleteVfPackage(csarId); + } + + @Test(expected = VfcException.class) + public void deleteVfPackageWillThrowExceptionWhenVFCResponseError() { + String csarId = "1"; + VfcService vfcService = mock(VfcService.class); + when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall()); + PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService); + service.deleteVfPackage(csarId); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java index 54555fa9..0304e42d 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java @@ -28,6 +28,7 @@ import java.util.List; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall; import static org.onap.usecaseui.server.util.CallStub.failedCall; import static org.onap.usecaseui.server.util.CallStub.successfulCall; @@ -58,4 +59,17 @@ public class DefaultServiceInstanceServiceTest { ServiceInstanceService service = new DefaultServiceInstanceService(aaiService); service.listServiceInstances(customerId, serviceType); } + + @Test + public void retrieveServiceInstancesWillThrowExceptionWhenNoServiceInstancesInAAI() { + AAIService aaiService = mock(AAIService.class); + String customerId = "1"; + String serviceType = "service"; + when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(emptyBodyCall()); + + ServiceInstanceService service = new DefaultServiceInstanceService(aaiService); + List<ServiceInstance> serviceInstances = service.listServiceInstances(customerId, serviceType); + + Assert.assertTrue("service instances should be empty.", serviceInstances.isEmpty()); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java index a823bc2c..517e4b1c 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java @@ -31,8 +31,10 @@ import javax.servlet.http.HttpServletRequest; import java.io.IOException; import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall; import static org.onap.usecaseui.server.util.CallStub.failedCall; import static org.onap.usecaseui.server.util.CallStub.successfulCall; @@ -94,13 +96,24 @@ public class DefaultServiceLcmServiceTest { service.instantiateService(request); } + @Test(expected = SOException.class) + public void instantiateServiceWillThrowExceptionWhenSOResponseError() throws IOException { + SOService soService = mock(SOService.class); + when(soService.instantiateService(anyObject())).thenReturn(emptyBodyCall()); + HttpServletRequest request = mockRequest(); + + ServiceLcmService service = new DefaultServiceLcmService(soService); + + service.instantiateService(request); + } + @Test public void itCanTerminateService() throws IOException { SOService soService = mock(SOService.class); String serviceId = "1"; DeleteOperationRsp rsp = new DeleteOperationRsp(); rsp.setOperationId("1"); - when(soService.terminateService(serviceId, anyObject())).thenReturn(successfulCall(rsp)); + when(soService.terminateService(eq(serviceId), anyObject())).thenReturn(successfulCall(rsp)); HttpServletRequest request = mockRequest(); ServiceLcmService service = new DefaultServiceLcmService(soService); @@ -112,7 +125,19 @@ public class DefaultServiceLcmServiceTest { public void terminateServiceWillThrowExceptionWhenSOIsNotAvailable() throws IOException { SOService soService = mock(SOService.class); String serviceId = "1"; - when(soService.terminateService(serviceId, anyObject())).thenReturn(failedCall("SO is not available!")); + when(soService.terminateService(eq(serviceId), anyObject())).thenReturn(failedCall("SO is not available!")); + HttpServletRequest request = mockRequest(); + + ServiceLcmService service = new DefaultServiceLcmService(soService); + + service.terminateService(serviceId, request); + } + + @Test(expected = SOException.class) + public void terminateServiceWillThrowExceptionWhenSOResponseError() throws IOException { + SOService soService = mock(SOService.class); + String serviceId = "1"; + when(soService.terminateService(eq(serviceId), anyObject())).thenReturn(emptyBodyCall()); HttpServletRequest request = mockRequest(); ServiceLcmService service = new DefaultServiceLcmService(soService); @@ -144,4 +169,16 @@ public class DefaultServiceLcmServiceTest { service.queryOperationProgress(serviceId, operationId); } + + @Test(expected = SOException.class) + public void queryOperationProgressWillThrowExceptionWhenSOResponseError() { + SOService soService = mock(SOService.class); + String serviceId = "1"; + String operationId = "1"; + when(soService.queryOperationProgress(serviceId, operationId)).thenReturn(emptyBodyCall()); + + ServiceLcmService service = new DefaultServiceLcmService(soService); + + service.queryOperationProgress(serviceId, operationId); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateServiceTest.java index 943d3806..250c6980 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateServiceTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateServiceTest.java @@ -21,8 +21,11 @@ import org.onap.usecaseui.server.bean.lcm.ServiceTemplateInput; import org.onap.usecaseui.server.bean.lcm.TemplateInput; import org.onap.usecaseui.server.service.lcm.ServiceTemplateService; import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService; +import org.onap.usecaseui.server.service.lcm.domain.aai.bean.SDNCController; +import org.onap.usecaseui.server.service.lcm.domain.aai.bean.SDNCControllerRsp; import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo; import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp; +import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException; import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService; import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate; import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException; @@ -41,6 +44,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.CATEGORY_E2E_SERVICE; import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.DISTRIBUTION_STATUS_DISTRIBUTED; +import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall; import static org.onap.usecaseui.server.util.CallStub.failedCall; import static org.onap.usecaseui.server.util.CallStub.successfulCall; @@ -67,6 +71,17 @@ public class DefaultServiceTemplateServiceTest { } @Test + public void itWillRetrieveEmptyWhenNoServiceTemplateCanGet() { + SDCCatalogService sdcService = mock(SDCCatalogService.class); + when(sdcService.listServices(CATEGORY_E2E_SERVICE, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(emptyBodyCall()); + + ServiceTemplateService service = new DefaultServiceTemplateService(sdcService,null); + List<SDCServiceTemplate> sdcServiceTemplates = service.listDistributedServiceTemplate(); + + Assert.assertTrue("service templates should be empty.", sdcServiceTemplates.isEmpty()); + } + + @Test public void itCanRetrieveInputsFromServiceTemplate() throws IOException { final String uuid = "1"; String modelPath = "model_path"; @@ -126,6 +141,7 @@ public class DefaultServiceTemplateServiceTest { e2eAttributes.put("description", "VoLTE"); e2eAttributes.put("category", "service"); e2eAttributes.put("subcategory", ""); + e2eAttributes.put("version", ""); when(toscaTemplate.getMetaData()).thenReturn(new Metadata(e2eAttributes)); when(toscaTemplate.getInputs()).thenReturn(new ArrayList<>()); NodeTemplate nodeTemplate = mock(NodeTemplate.class); @@ -204,4 +220,70 @@ public class DefaultServiceTemplateServiceTest { }; service.fetchServiceTemplateInput("1", "url"); } + + @Test + public void itCanListVim() { + List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "region")); + VimInfoRsp rsp = new VimInfoRsp(); + rsp.setCloudRegion(vim); + AAIService aaiService = mock(AAIService.class); + when(aaiService.listVimInfo()).thenReturn(successfulCall(rsp)); + + ServiceTemplateService service = new DefaultServiceTemplateService(null,aaiService); + + Assert.assertSame(vim, service.listVim()); + } + + @Test + public void itCanRetrieveEmptyListWhenNoVimInfoInAAI() { + AAIService aaiService = mock(AAIService.class); + when(aaiService.listVimInfo()).thenReturn(emptyBodyCall()); + + ServiceTemplateService service = new DefaultServiceTemplateService(null,aaiService); + List<VimInfo> vimInfos = service.listVim(); + + Assert.assertTrue("vim should be empty.", vimInfos.isEmpty()); + } + + @Test(expected = AAIException.class) + public void itCanThrowExceptionWhenAAIServiceIsNotAvailable() { + AAIService aaiService = mock(AAIService.class); + when(aaiService.listVimInfo()).thenReturn(failedCall("AAI is not available!")); + + ServiceTemplateService service = new DefaultServiceTemplateService(null,aaiService); + service.listVim(); + } + + @Test + public void itCanListSDNController() { + List<SDNCController> controllers = Collections.singletonList(new SDNCController()); + SDNCControllerRsp rsp = new SDNCControllerRsp(); + rsp.setEsrThirdpartySdncList(controllers); + AAIService aaiService = mock(AAIService.class); + when(aaiService.listSdncControllers()).thenReturn(successfulCall(rsp)); + + ServiceTemplateService service = new DefaultServiceTemplateService(null,aaiService); + + Assert.assertSame(controllers, service.listSDNCControllers()); + } + + @Test + public void itCanRetrieveEmptyListWhenNoSDNControllerInAAI() { + AAIService aaiService = mock(AAIService.class); + when(aaiService.listSdncControllers()).thenReturn(emptyBodyCall()); + + ServiceTemplateService service = new DefaultServiceTemplateService(null,aaiService); + List<SDNCController> controllers = service.listSDNCControllers(); + + Assert.assertTrue("sdn controller should be empty.", controllers.isEmpty()); + } + + @Test(expected = AAIException.class) + public void itListSDNControllerThrowExceptionWhenAAIServiceIsNotAvailable() { + AAIService aaiService = mock(AAIService.class); + when(aaiService.listSdncControllers()).thenReturn(failedCall("AAI is not available!")); + + ServiceTemplateService service = new DefaultServiceTemplateService(null,aaiService); + service.listSDNCControllers(); + } }
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/util/CallStub.java b/server/src/test/java/org/onap/usecaseui/server/util/CallStub.java index 1fe7638e..a4f9153d 100644 --- a/server/src/test/java/org/onap/usecaseui/server/util/CallStub.java +++ b/server/src/test/java/org/onap/usecaseui/server/util/CallStub.java @@ -1,12 +1,12 @@ /** * Copyright 2016-2017 ZTE Corporation. - * + * <p> * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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. @@ -15,7 +15,9 @@ */ package org.onap.usecaseui.server.util; +import okhttp3.MediaType; import okhttp3.Request; +import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -27,20 +29,24 @@ public class CallStub<T> implements Call<T> { private boolean isSuccess; private T result; private String failMessage; + private boolean isEmpty; private CallStub(boolean isSuccess, T result, String message) { this.isSuccess = isSuccess; this.result = result; this.failMessage = message; + this.isEmpty = "empty body".equals(message); } @Override public Response<T> execute() throws IOException { - if (isSuccess) { + if (isSuccess) return Response.success(result); - } else { - throw new IOException(failMessage); - } + if (isEmpty) + return Response.error(404, ResponseBody.create(MediaType.parse("application/json"), new byte[0])); + + throw new IOException(failMessage); + } @Override @@ -80,4 +86,8 @@ public class CallStub<T> implements Call<T> { public static <T> CallStub<T> failedCall(String message) { return new CallStub<>(false, null, message); } + + public static <T> CallStub<T> emptyBodyCall() { + return new CallStub<>(false, null, "empty body"); + } } |