DeviceManagementServiceImpl implements DeviceManagementService { @GET @Path("/{type}/{id}/info") @Override public Response getDeviceInformation( @PathParam("type") @Size(max = 45) String type, @PathParam("id") @Size(max = 45) String id, @HeaderParam("If-Modified-Since") String ifModifiedSince) { DeviceInformationManager informationManager; DeviceInfo deviceInfo; try { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(id); deviceIdentifier.setType(type); informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService(); deviceInfo = informationManager.getDeviceInfo(deviceIdentifier); } catch (DeviceDetailsMgtException e) { String msg = "Error occurred while getting the device information of id : " + id + " type : " + type ; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } return Response.status(Response.Status.OK).entity(deviceInfo).build(); }  @GET @Path("/{type}/{id}/status") @Override Response isEnrolled(@PathParam("type") String type, @PathParam("id") String id); @GET @Override Response getDevices(
            @QueryParam("name") String name,
            @QueryParam("type") String type,
            @QueryParam("user") String user,
            @QueryParam("userPattern") String userPattern,
            @QueryParam("role") String role,
            @QueryParam("ownership") String ownership,
            @QueryParam("status") String status,
            @QueryParam("groupId") int groupId,
            @QueryParam("since") String since,
            @HeaderParam("If-Modified-Since") String ifModifiedSince,
            @QueryParam("requireDeviceInfo") boolean requireDeviceInfo,
            @QueryParam("offset") int offset,
            @QueryParam("limit") int limit); @GET @Override @Path("/user-devices") Response getDeviceByUser(@QueryParam("requireDeviceInfo") boolean requireDeviceInfo,
                                    @QueryParam("offset") int offset,
                                    @QueryParam("limit") int limit); @DELETE @Override @Path("/type/{device-type}/id/{device-id}") Response deleteDevice(@PathParam("device-type") String deviceType, @PathParam("device-id") String deviceId); @POST @Override @Path("/type/{device-type}/id/{device-id}/rename") Response renameDevice(Device device, @PathParam("device-type") String deviceType,
                                 @PathParam("device-id") String deviceId); @GET @Path("/{type}/{id}") @Override Response getDevice(
            @PathParam("type") @Size(max = 45) String type,
            @PathParam("id") @Size(max = 45) String id,
            @QueryParam("owner") @Size(max = 100) String owner,
            @HeaderParam("If-Modified-Since") String ifModifiedSince); @GET @Path("/{type}/{id}/location") @Override Response getDeviceLocation(
            @PathParam("type") @Size(max = 45) String type,
            @PathParam("id") @Size(max = 45) String id,
            @HeaderParam("If-Modified-Since") String ifModifiedSince); @GET @Path("/{type}/{id}/info") @Override Response getDeviceInformation(
            @PathParam("type") @Size(max = 45) String type,
            @PathParam("id") @Size(max = 45) String id,
            @HeaderParam("If-Modified-Since") String ifModifiedSince); @GET @Path("/{type}/{id}/features") @Override Response getFeaturesOfDevice(
            @PathParam("type") @Size(max = 45) String type,
            @PathParam("id") @Size(max = 45) String id,
            @HeaderParam("If-Modified-Since") String ifModifiedSince); @POST @Path("/search-devices") @Override Response searchDevices(@QueryParam("offset") int offset,
                                  @QueryParam("limit") int limit, SearchContext searchContext); @GET @Path("/{type}/{id}/applications") @Override Response getInstalledApplications(
            @PathParam("type") @Size(max = 45) String type,
            @PathParam("id") @Size(max = 45) String id,
            @HeaderParam("If-Modified-Since") String ifModifiedSince,
            @QueryParam("offset") int offset,
            @QueryParam("limit") int limit); @GET @Path("/{type}/{id}/operations") @Override Response getDeviceOperations(
            @PathParam("type") @Size(max = 45) String type,
            @PathParam("id") @Size(max = 45) String id,
            @HeaderParam("If-Modified-Since") String ifModifiedSince,
            @QueryParam("offset") int offset,
            @QueryParam("limit") int limit,
            @QueryParam("owner") String owner); @GET @Path("/{type}/{id}/effective-policy") @Override Response getEffectivePolicyOfDevice(@PathParam("type") @Size(max = 45) String type,
                                               @PathParam("id") @Size(max = 45) String id,
                                               @HeaderParam("If-Modified-Since") String ifModifiedSince); @GET @Path("{type}/{id}/compliance-data") Response getComplianceDataOfDevice(@PathParam("type") @Size(max = 45) String type,
                                              @PathParam("id") @Size(max = 45) String id); @PUT @Path("/{type}/{id}/changestatus") Response changeDeviceStatus(@PathParam("type") @Size(max = 45) String type,
                                       @PathParam("id") @Size(max = 45) String id,
                                       @QueryParam("newStatus") EnrolmentInfo.Status newsStatus); @POST @Path("/{type}/operations") Response addOperation(@PathParam("type") String type, @Valid OperationRequest operationRequest); static final String DATE_FORMAT_NOW; }
@Test(description = "Testing getting device information") public void testGetDeviceInformation() { PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceInformationManagerService")). toReturn(Mockito.mock(DeviceInformationManagerImpl.class, Mockito.RETURNS_MOCKS)); Response response = this.deviceManagementService .getDeviceInformation(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); }
@Test(description = "Testing getting device information when unable to retrieve information") public void testGetDeviceInformationException() throws DeviceDetailsMgtException { DeviceInformationManager deviceInformationManager = Mockito .mock(DeviceInformationManagerImpl.class, Mockito.RETURNS_MOCKS); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceInformationManagerService")). toReturn(deviceInformationManager); Mockito.when(deviceInformationManager.getDeviceInfo(Mockito.any(DeviceIdentifier.class))) .thenThrow(new DeviceDetailsMgtException()); Response response = this.deviceManagementService .getDeviceInformation(TEST_DEVICE_TYPE, UUID.randomUUID().toString(), null); Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); }