From fd5ada61afd5d95966775cecfbd474940a6ad44c Mon Sep 17 00:00:00 2001 From: Gathika94 Date: Tue, 28 Nov 2017 20:18:05 +0530 Subject: [PATCH 1/3] unit tests for geo device locations api --- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../impl/GeoLocationBasedServiceImplTest.java | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index e1e2c46e8c..28248146c6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -81,7 +81,7 @@ - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java new file mode 100644 index 0000000000..7e204a8eca --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java @@ -0,0 +1,71 @@ +package org.wso2.carbon.device.mgt.jaxrs.service.impl; + + +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.IObjectFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.ObjectFactory; +import org.testng.annotations.Test; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; +import org.wso2.carbon.device.mgt.core.geo.GeoCluster; +import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; +import org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceImpl; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; +import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoLocationBasedService; +import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService; +import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; + +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class GeoLocationBasedServiceImplTest { + private DeviceManagementProviderService deviceManagementProviderService; + private PrivilegedCarbonContext context; + private GeoLocationBasedService geoLocationBasedService; + + @BeforeClass + public void init() { + //groupManagementService = new GroupManagementServiceImpl(); + deviceManagementProviderService = Mockito.mock(DeviceManagementProviderService.class); + geoLocationBasedService = new GeoLocationBasedServiceImpl(); + context = Mockito.mock(PrivilegedCarbonContext.class); + Mockito.doReturn("admin").when(context).getUsername(); + } + + @Test(description = "This method tests the behaviour of getGeoDeviceLocations when there are no devices" + + "in the given map boundaries") + public void testGetGeoDeviceLocations1() throws DeviceManagementException { + Mockito.doReturn(new ArrayList()).when(deviceManagementProviderService) + .findGeoClusters(Mockito.any(GeoCoordinate.class), Mockito.any(GeoCoordinate.class), Mockito.anyInt()); + Response response = geoLocationBasedService.getGeoDeviceLocations(0.4,15,75.6, + 90.1,6); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), + "getGeoDeviceLocations request failed with valid parameters"); + } + + @Test(description = "This method tests the behaviour of getGeoDeviceLocations when there are devices" + + "in the given map boundaries") + public void testGetGeoDeviceLocations2() throws DeviceManagementException { + List geoClusters = new ArrayList<>(); + geoClusters.add(new GeoCluster(new GeoCoordinate(1.5,80.7), + new GeoCoordinate(1.1,79.5),new GeoCoordinate(1.9,82.1),3, + "tb32","aegtew234","android")); + geoClusters.add(new GeoCluster(new GeoCoordinate(10.2,86.1), + new GeoCoordinate(9.8,84.7),new GeoCoordinate(11.1,88.1),4, + "t1gd","swerty12s","android")); + Mockito.doReturn(geoClusters).when(deviceManagementProviderService) + .findGeoClusters(Mockito.any(GeoCoordinate.class), Mockito.any(GeoCoordinate.class), Mockito.anyInt()); + Response response = geoLocationBasedService.getGeoDeviceLocations(0.4,15,75.6, + 90.1,6); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), + "getGeoDeviceLocations request failed with valid parameters"); + } +} From 5308108899a133d02edab3da876bc9776e21bfe1 Mon Sep 17 00:00:00 2001 From: Gathika94 Date: Tue, 28 Nov 2017 20:22:40 +0530 Subject: [PATCH 2/3] unit tests- minor changes --- .../impl/GeoLocationBasedServiceImplTest.java | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java index 7e204a8eca..be7209a8e9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/test/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImplTest.java @@ -3,24 +3,14 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.mockito.Mockito; import org.testng.Assert; -import org.testng.IObjectFactory; import org.testng.annotations.BeforeClass; -import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; -import org.wso2.carbon.device.mgt.common.PaginationResult; -import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; -import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.core.geo.GeoCluster; import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; -import org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoLocationBasedService; -import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService; -import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.core.Response; import java.util.ArrayList; @@ -33,7 +23,6 @@ public class GeoLocationBasedServiceImplTest { @BeforeClass public void init() { - //groupManagementService = new GroupManagementServiceImpl(); deviceManagementProviderService = Mockito.mock(DeviceManagementProviderService.class); geoLocationBasedService = new GeoLocationBasedServiceImpl(); context = Mockito.mock(PrivilegedCarbonContext.class); @@ -45,8 +34,8 @@ public class GeoLocationBasedServiceImplTest { public void testGetGeoDeviceLocations1() throws DeviceManagementException { Mockito.doReturn(new ArrayList()).when(deviceManagementProviderService) .findGeoClusters(Mockito.any(GeoCoordinate.class), Mockito.any(GeoCoordinate.class), Mockito.anyInt()); - Response response = geoLocationBasedService.getGeoDeviceLocations(0.4,15,75.6, - 90.1,6); + Response response = geoLocationBasedService.getGeoDeviceLocations(0.4, 15, 75.6, + 90.1, 6); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getGeoDeviceLocations request failed with valid parameters"); } @@ -55,16 +44,16 @@ public class GeoLocationBasedServiceImplTest { "in the given map boundaries") public void testGetGeoDeviceLocations2() throws DeviceManagementException { List geoClusters = new ArrayList<>(); - geoClusters.add(new GeoCluster(new GeoCoordinate(1.5,80.7), - new GeoCoordinate(1.1,79.5),new GeoCoordinate(1.9,82.1),3, - "tb32","aegtew234","android")); - geoClusters.add(new GeoCluster(new GeoCoordinate(10.2,86.1), - new GeoCoordinate(9.8,84.7),new GeoCoordinate(11.1,88.1),4, - "t1gd","swerty12s","android")); + geoClusters.add(new GeoCluster(new GeoCoordinate(1.5, 80.7), + new GeoCoordinate(1.1, 79.5), new GeoCoordinate(1.9, 82.1), 3, + "tb32", "aegtew234", "android")); + geoClusters.add(new GeoCluster(new GeoCoordinate(10.2, 86.1), + new GeoCoordinate(9.8, 84.7), new GeoCoordinate(11.1, 88.1), 4, + "t1gd", "swerty12s", "android")); Mockito.doReturn(geoClusters).when(deviceManagementProviderService) .findGeoClusters(Mockito.any(GeoCoordinate.class), Mockito.any(GeoCoordinate.class), Mockito.anyInt()); - Response response = geoLocationBasedService.getGeoDeviceLocations(0.4,15,75.6, - 90.1,6); + Response response = geoLocationBasedService.getGeoDeviceLocations(0.4, 15, 75.6, + 90.1, 6); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getGeoDeviceLocations request failed with valid parameters"); } From d67877cfb1f4c108791ed117d4a53ae5b6072b37 Mon Sep 17 00:00:00 2001 From: Gathika94 Date: Tue, 28 Nov 2017 20:26:03 +0530 Subject: [PATCH 3/3] unit tests for geo device locations api- minor changes --- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 28248146c6..e1e2c46e8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -81,7 +81,7 @@ - +