GeoLocationBasedServiceImpl implements GeoLocationBasedService { @Path("stats/device-locations") @GET @Consumes("application/json") @Produces("application/json") public Response getGeoDeviceLocations( @QueryParam("deviceType") String deviceType, @QueryParam("minLat") double minLat, @QueryParam("maxLat") double maxLat, @QueryParam("minLong") double minLong, @QueryParam("maxLong") double maxLong, @QueryParam("zoom") int zoom) { GeoHashLengthStrategy geoHashLengthStrategy = new ZoomGeoHashLengthStrategy(); GeoCoordinate southWest = new GeoCoordinate(minLat, minLong); GeoCoordinate northEast = new GeoCoordinate(maxLat, maxLong); int geohashLength = geoHashLengthStrategy.getGeohashLength(southWest, northEast, zoom); DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService(); List<GeoCluster> geoClusters; try { geoClusters = deviceManagementService.findGeoClusters(deviceType, southWest, northEast, geohashLength); } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving geo clusters "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); } return Response.ok().entity(geoClusters).build(); }  @Path("stats/{deviceType}/{deviceId}") @GET @Consumes("application/json") @Produces("application/json") Response getGeoDeviceStats(@PathParam("deviceId") String deviceId,
                                      @PathParam("deviceType") String deviceType,
                                      @QueryParam("from") long from, @QueryParam("to") long to); @Path("stats/device-locations") @GET @Consumes("application/json") @Produces("application/json") Response getGeoDeviceLocations(
            @QueryParam("deviceType") String deviceType,
            @QueryParam("minLat") double minLat,
            @QueryParam("maxLat") double maxLat,
            @QueryParam("minLong") double minLong,
            @QueryParam("maxLong") double maxLong,
            @QueryParam("zoom") int zoom); @Path("alerts/{alertType}/{deviceType}/{deviceId}") @POST @Consumes("application/json") @Produces("application/json") Response createGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId,
                                    @PathParam("deviceType") String deviceType,
                                    @PathParam("alertType") String alertType); @Path("alerts/{alertType}") @POST @Consumes("application/json") @Produces("application/json") Response createGeoAlertsForGeoClusters(Alert alert, @PathParam("alertType") String alertType); @Path("alerts/{alertType}/{deviceType}/{deviceId}") @PUT @Consumes("application/json") @Produces("application/json") Response updateGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId,
                                    @PathParam("deviceType") String deviceType,
                                    @PathParam("alertType") String alertType); @Path("alerts/{alertType}") @PUT @Consumes("application/json") @Produces("application/json") Response updateGeoAlertsForGeoClusters(Alert alert, @PathParam("alertType") String alertType); @Path("alerts/{alertType}/{deviceType}/{deviceId}") @DELETE @Consumes("application/json") @Produces("application/json") Response removeGeoAlerts(@PathParam("deviceId") String deviceId,
                                    @PathParam("deviceType") String deviceType,
                                    @PathParam("alertType") String alertType,
                                    @QueryParam("queryName") String queryName); @Path("alerts/{alertType}") @DELETE @Consumes("application/json") @Produces("application/json") Response removeGeoAlertsForGeoClusters(@PathParam("alertType") String alertType, @QueryParam("queryName") String queryName); @Path("alerts/{alertType}/{deviceType}/{deviceId}") @GET @Consumes("application/json") @Produces("application/json") Response getGeoAlerts(@PathParam("deviceId") String deviceId,
                                 @PathParam("deviceType") String deviceType,
                                 @PathParam("alertType") String alertType); @Path("alerts/{alertType}") @GET @Consumes("application/json") @Produces("application/json") Response getGeoAlertsForGeoClusters(@PathParam("alertType") String alertType); @Path("alerts/history/{deviceType}/{deviceId}") @GET @Consumes("application/json") @Produces("application/json") Response getGeoAlertsHistory(@PathParam("deviceId") String deviceId,
                                        @PathParam("deviceType") String deviceType,
                                        @QueryParam("from") long from, @QueryParam("to") long to); @Path("alerts/history") @GET @Consumes("application/json") @Produces("application/json") Response getGeoAlertsHistoryForGeoClusters(@QueryParam("from") long from, @QueryParam("to") long to);  }
@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<GeoCluster>()).when(deviceManagementProviderService) .findGeoClusters(null, Mockito.any(GeoCoordinate.class), Mockito.any(GeoCoordinate.class), Mockito.anyInt()); Response response = geoLocationBasedService.getGeoDeviceLocations(null, 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<GeoCluster> 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", "1234")); 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", "1234")); Mockito.doReturn(geoClusters).when(deviceManagementProviderService) .findGeoClusters(null, Mockito.any(GeoCoordinate.class), Mockito.any(GeoCoordinate.class), Mockito.anyInt()); Response response = geoLocationBasedService.getGeoDeviceLocations(null, 0.4, 15, 75.6, 90.1, 6); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "getGeoDeviceLocations request failed with valid parameters"); }