diff options
author | Luji7 <lu.ji3@zte.com.cn> | 2017-09-29 16:54:20 +0800 |
---|---|---|
committer | Luji7 <lu.ji3@zte.com.cn> | 2017-09-29 16:54:24 +0800 |
commit | 658fac23071930ed1c8332b0b7323131f3b66eff (patch) | |
tree | 2ae337fa260644e18649ba35433ff43bb38dfeed | |
parent | 16f08c39a984fc0eff4060d7dcfe2a49a53afbb0 (diff) |
Add UT for controller.
Change-Id: I3d5aa322f106c1e88b75d2d692324817fe68c689
Issue-Id: USECASEUI-36
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
11 files changed, 312 insertions, 5 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java index a1b8d0ef..3d51bde0 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java @@ -24,7 +24,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.util.List; @Controller @@ -35,9 +34,13 @@ public class CustomerController { @Resource(name="CustomerService") private CustomerService customerService; + public void setCustomerService(CustomerService customerService) { + this.customerService = customerService; + } + @ResponseBody @RequestMapping(value = {"/lcm/customers"}, method = RequestMethod.GET , produces = "application/json") - public List<AAICustomer> getCustomers(HttpServletRequest request){ + public List<AAICustomer> getCustomers(){ return customerService.listCustomer(); } } diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java index 75db524c..7014b2b6 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java @@ -39,9 +39,13 @@ public class PackageDistributionController { @Resource(name="PackageDistributionService") private PackageDistributionService packageDistributionService; + public void setPackageDistributionService(PackageDistributionService packageDistributionService) { + this.packageDistributionService = packageDistributionService; + } + @ResponseBody @RequestMapping(value = {"/lcm/vf-ns-packages"}, method = RequestMethod.GET , produces = "application/json") - public VfNsPackageInfo instantiateService(){ + public VfNsPackageInfo retrievePackageInfo(){ return packageDistributionService.retrievePackageInfo(); } diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java index 3d51f649..350652c4 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java @@ -39,9 +39,13 @@ public class ServiceInstanceController { @Resource(name="ServiceInstanceService") private ServiceInstanceService serviceInstanceService; + public void setServiceInstanceService(ServiceInstanceService serviceInstanceService) { + this.serviceInstanceService = serviceInstanceService; + } + @ResponseBody @RequestMapping(value = {"/lcm/service-instances"}, method = RequestMethod.GET , produces = "application/json") - public List<ServiceInstance> getCustomers(HttpServletRequest request){ + public List<ServiceInstance> listServiceInstances(HttpServletRequest request){ String customerId = request.getParameter("customerId"); String serviceType = request.getParameter("serviceType"); logger.info(String.format( diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java index d0c95521..ded536f6 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java @@ -37,6 +37,10 @@ public class ServiceLcmController { @Resource(name="ServiceLcmService") private ServiceLcmService serviceLcmService; + public void setServiceLcmService(ServiceLcmService serviceLcmService) { + this.serviceLcmService = serviceLcmService; + } + @ResponseBody @RequestMapping(value = {"/lcm/services"}, method = RequestMethod.POST , produces = "application/json") public ServiceOperation instantiateService(@RequestBody ServiceInstantiationRequest request){ @@ -45,7 +49,7 @@ public class ServiceLcmController { @ResponseBody @RequestMapping(value = {"/lcm/services/{serviceId}/operations/{operationId}"}, method = RequestMethod.GET , produces = "application/json") - public OperationProgressInformation instantiateService(@PathVariable(value="serviceId") String serviceId, @PathVariable(value="operationId") String operationId){ + public OperationProgressInformation queryOperationProgress(@PathVariable(value="serviceId") String serviceId, @PathVariable(value="operationId") String operationId){ return serviceLcmService.queryOperationProgress(serviceId, operationId); } diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateController.java index 2d8333a4..96c463bc 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateController.java @@ -37,6 +37,10 @@ public class ServiceTemplateController { @Resource(name="ServiceTemplateService") private ServiceTemplateService serviceTemplateService; + public void setServiceTemplateService(ServiceTemplateService serviceTemplateService) { + this.serviceTemplateService = serviceTemplateService; + } + @ResponseBody @RequestMapping(value = {"/lcm/service-templates"}, method = RequestMethod.GET , produces = "application/json") public List<SDCServiceTemplate> getServiceTemplates(){ 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 new file mode 100644 index 00000000..c1af3c5f --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/CustomerControllerTest.java @@ -0,0 +1,34 @@ +/** + * Copyright 2016-2017 ZTE 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.usecaseui.server.controller.lcm; + +import org.junit.Test; +import org.onap.usecaseui.server.service.lcm.CustomerService; + +import static org.mockito.Mockito.*; + +public class CustomerControllerTest { + @Test + public void testGetCustomers() { + CustomerService customerService = mock(CustomerService.class); + CustomerController controller = new CustomerController(); + controller.setCustomerService(customerService); + + controller.getCustomers(); + + verify(customerService, times(1)).listCustomer(); + } +}
\ 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 new file mode 100644 index 00000000..76340579 --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionControllerTest.java @@ -0,0 +1,66 @@ +/** + * Copyright 2016-2017 ZTE 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.usecaseui.server.controller.lcm; + +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.server.service.lcm.PackageDistributionService; +import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar; + +import static org.mockito.Mockito.*; + +public class PackageDistributionControllerTest { + + private PackageDistributionService service; + private PackageDistributionController controller = new PackageDistributionController(); + + @Before + public void setUp() { + service = mock(PackageDistributionService.class); + controller.setPackageDistributionService(service); + } + + @Test + public void retrievePackageInfo() throws Exception { + controller.retrievePackageInfo(); + + verify(service, times(1)).retrievePackageInfo(); + } + + @Test + public void testDistributeNsPackage() throws Exception { + Csar csar = new Csar(); + controller.distributeNsPackage(csar); + + verify(service, times(1)).postNsPackage(csar); + } + + @Test + public void distributeVfPackage() throws Exception { + Csar csar = new Csar(); + controller.distributeVfPackage(csar); + + verify(service, times(1)).postVfPackage(csar); + } + + @Test + public void testGetJobStatus() throws Exception { + String jobId = "1"; + controller.getJobStatus(jobId); + + verify(service, times(1)).getJobStatus(jobId); + } +}
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceControllerTest.java new file mode 100644 index 00000000..d82913a4 --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceControllerTest.java @@ -0,0 +1,43 @@ +/** + * Copyright 2016-2017 ZTE 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.usecaseui.server.controller.lcm; + +import org.junit.Test; +import org.onap.usecaseui.server.service.lcm.ServiceInstanceService; + +import javax.servlet.http.HttpServletRequest; + +import static org.mockito.Mockito.*; + +public class ServiceInstanceControllerTest { + @Test + public void testListServiceInstances() throws Exception { + ServiceInstanceController controller = new ServiceInstanceController(); + ServiceInstanceService service = mock(ServiceInstanceService.class); + controller.setServiceInstanceService(service); + + HttpServletRequest request = mock(HttpServletRequest.class); + String customerId = "1"; + when(request.getParameter("customerId")).thenReturn(customerId); + String serviceType = "service"; + when(request.getParameter("serviceType")).thenReturn(serviceType); + + controller.listServiceInstances(request); + + verify(service, times(1)).listServiceInstances(customerId, serviceType); + } + +}
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java new file mode 100644 index 00000000..292d07c0 --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java @@ -0,0 +1,62 @@ +/** + * Copyright 2016-2017 ZTE 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.usecaseui.server.controller.lcm; + +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.server.service.lcm.ServiceLcmService; +import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceInstantiationRequest; + +import static org.mockito.Mockito.*; + +public class ServiceLcmControllerTest { + + private ServiceLcmService service; + + private ServiceLcmController controller = new ServiceLcmController(); + + @Before + public void setUp() { + service = mock(ServiceLcmService.class); + controller.setServiceLcmService(service); + } + + @Test + public void testInstantiateService() throws Exception { + ServiceInstantiationRequest request = mock(ServiceInstantiationRequest.class); + controller.instantiateService(request); + + verify(service, times(1)).instantiateService(request); + } + + @Test + public void testQueryOperationProgress() throws Exception { + String serviceId = "1"; + String operationId = "1"; + controller.queryOperationProgress(serviceId, operationId); + + verify(service, times(1)).queryOperationProgress(serviceId, operationId); + } + + @Test + public void testTerminateService() throws Exception { + String serviceId = "1"; + controller.terminateService(serviceId); + + verify(service, times(1)).terminateService(serviceId); + } + +}
\ 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 new file mode 100644 index 00000000..5e52035d --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateControllerTest.java @@ -0,0 +1,50 @@ +/** + * Copyright 2016-2017 ZTE 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.usecaseui.server.controller.lcm; + +import org.junit.Before; +import org.junit.Test; +import org.onap.usecaseui.server.service.lcm.ServiceTemplateService; + +import static org.mockito.Mockito.*; + +public class ServiceTemplateControllerTest { + + private ServiceTemplateService service; + private ServiceTemplateController controller = new ServiceTemplateController(); + + @Before + public void setUp() { + service = mock(ServiceTemplateService.class); + controller.setServiceTemplateService(service); + } + + @Test + public void testGetServiceTemplates() throws Exception { + controller.getServiceTemplates(); + + verify(service, times(1)).listDistributedServiceTemplate(); + } + + @Test + public void testGetServiceTemplateInput() throws Exception { + String uuid = "1"; + String modelPath = "modelPath"; + controller.getServiceTemplateInput(uuid, modelPath); + + verify(service, times(1)).fetchServiceTemplateInput(uuid, modelPath); + } +}
\ No newline at end of file diff --git a/server/src/test/java/org/onap/usecaseui/server/util/RestfulServicesTest.java b/server/src/test/java/org/onap/usecaseui/server/util/RestfulServicesTest.java new file mode 100644 index 00000000..d229c275 --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/util/RestfulServicesTest.java @@ -0,0 +1,33 @@ +/** + * Copyright 2016-2017 ZTE 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.usecaseui.server.util; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService; + +public class RestfulServicesTest { + @Test + public void testCreateServiceImpl() throws Exception { + Object aaiService = createService(AAIService.class); + + Assert.assertTrue(aaiService instanceof AAIService); + } + + private <T> Object createService(Class<T> clazz) { + return RestfulServices.create(clazz); + } +}
\ No newline at end of file |