Add UT for controller. 01/16601/1
authorLuji7 <lu.ji3@zte.com.cn>
Fri, 29 Sep 2017 08:54:20 +0000 (16:54 +0800)
committerLuji7 <lu.ji3@zte.com.cn>
Fri, 29 Sep 2017 08:54:24 +0000 (16:54 +0800)
Change-Id: I3d5aa322f106c1e88b75d2d692324817fe68c689
Issue-Id: USECASEUI-36
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java
server/src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java
server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java
server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java
server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateController.java
server/src/test/java/org/onap/usecaseui/server/controller/lcm/CustomerControllerTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionControllerTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceControllerTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateControllerTest.java [new file with mode: 0644]
server/src/test/java/org/onap/usecaseui/server/util/RestfulServicesTest.java [new file with mode: 0644]

index a1b8d0e..3d51bde 100644 (file)
@@ -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();
     }
 }
index 75db524..7014b2b 100644 (file)
@@ -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();
     }
 
index 3d51f64..350652c 100644 (file)
@@ -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(
index d0c9552..ded536f 100644 (file)
@@ -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);
     }
 
index 2d8333a..96c463b 100644 (file)
@@ -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 (file)
index 0000000..c1af3c5
--- /dev/null
@@ -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 (file)
index 0000000..7634057
--- /dev/null
@@ -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 (file)
index 0000000..d82913a
--- /dev/null
@@ -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 (file)
index 0000000..292d07c
--- /dev/null
@@ -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 (file)
index 0000000..5e52035
--- /dev/null
@@ -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 (file)
index 0000000..d229c27
--- /dev/null
@@ -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