Fix test failure and improve disenrolling API

-Remove query param from disenrolling API
revert-dabc3590
Amanda Randombage 5 years ago committed by Dharmakeerthi Lasantha
parent f5ce222701
commit f89a6d9fb8

@ -63,10 +63,6 @@ public class TestDeviceManager implements DeviceManager {
return true; return true;
} }
@Override
public boolean deleteDevice(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
return true;
}
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
@ -136,4 +132,9 @@ public class TestDeviceManager implements DeviceManager {
return false; return false;
} }
@Override
public void deleteDevices(List<String> deviceIdentifiers) throws DeviceManagementException {
//Does nothing since AndroidDeviceManager is not used instead DeviceTypeManager is used.
}
} }

@ -423,10 +423,6 @@ public interface DeviceManagementService {
@ApiParam( @ApiParam(
name = "id", name = "id",
value = "The unique device identifier.") value = "The unique device identifier.")
@PathParam("id") String id, @PathParam("id") String id);
@ApiParam(
name = "permanentDelete",
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("permanentDelete") boolean permanentDelete);
} }

@ -447,26 +447,17 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@DELETE @DELETE
@Path("/{id}") @Path("/{id}")
@Override @Override
public Response disEnrollDevice(@PathParam("id") String id, public Response disEnrollDevice(@PathParam("id") String id) {
@QueryParam("permanentDelete") boolean permanentDelete) {
boolean result; boolean result;
DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id);
try { try {
if (permanentDelete) {
result = AndroidAPIUtils.getDeviceManagementService().deleteDevice(deviceIdentifier);
} else {
AndroidDeviceUtils.updateDisEnrollOperationStatus(deviceIdentifier); AndroidDeviceUtils.updateDisEnrollOperationStatus(deviceIdentifier);
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
}
if (result) { if (result) {
String msg = "Android device that carries id '" + id + "' is successfully "; String msg = "Android device that carries id '" + id + "' is successfully ";
Message responseMessage = new Message(); Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString()); responseMessage.setResponseCode(Response.Status.OK.toString());
if (permanentDelete) {
responseMessage.setResponseMessage(msg + "deleted");
} else {
responseMessage.setResponseMessage(msg + "dis-enrolled"); responseMessage.setResponseMessage(msg + "dis-enrolled");
}
return Response.status(Response.Status.OK).entity(responseMessage).build(); return Response.status(Response.Status.OK).entity(responseMessage).build();
} else { } else {
Message responseMessage = new Message(); Message responseMessage = new Message();
@ -476,11 +467,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while %s the Android device that carries the id '" + id + "'"; String msg = "Error occurred while %s the Android device that carries the id '" + id + "'";
if (permanentDelete) {
msg = String.format(msg, "deleting");
} else {
msg = String.format(msg, "dis-enrolling"); msg = String.format(msg, "dis-enrolling");
}
log.error(msg, e); log.error(msg, e);
throw new UnexpectedServerErrorException( throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());

@ -300,7 +300,7 @@ public class DeviceManagementServiceTests {
public void testDisEnrollDeviceSuccess() public void testDisEnrollDeviceSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService(); mockDeviceManagementService();
Response response = deviceManagementService.disEnrollDevice(TestUtils.getDeviceId(), false); Response response = deviceManagementService.disEnrollDevice(TestUtils.getDeviceId());
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
} }
@ -309,7 +309,7 @@ public class DeviceManagementServiceTests {
public void testDisenrollUnSuccess() public void testDisenrollUnSuccess()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException { throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService(); mockDeviceManagementService();
Response response = deviceManagementService.disEnrollDevice("1234", false); Response response = deviceManagementService.disEnrollDevice("1234");
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
} }

@ -354,11 +354,6 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv
return TestUtils.getDeviceId().equals(deviceIdentifier.getId()); return TestUtils.getDeviceId().equals(deviceIdentifier.getId());
} }
@Override
public boolean deleteDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false; return false;
@ -626,4 +621,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv
AmbiguousConfigurationException{ AmbiguousConfigurationException{
return null; return null;
} }
@Override
public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException {return false;}
} }

@ -354,10 +354,6 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv
return TestUtils.getDeviceId().equals(deviceIdentifier.getId()); return TestUtils.getDeviceId().equals(deviceIdentifier.getId());
} }
@Override
public boolean deleteDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
@ -626,4 +622,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv
AmbiguousConfigurationException{ AmbiguousConfigurationException{
return null; return null;
} }
@Override
public boolean deleteDevices(List<String> deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException {return false;}
} }

@ -220,11 +220,6 @@ public class AndroidDeviceManager implements DeviceManager {
return true; return true;
} }
@Override
public boolean deleteDevice(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
//Returning false since AndroidDeviceManager is not used instead DeviceTypeManager is used.
return false;
}
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
@ -374,4 +369,9 @@ public class AndroidDeviceManager implements DeviceManager {
return devices; return devices;
} }
@Override
public void deleteDevices(List<String> deviceIdentifiers) throws DeviceManagementException {
//Does nothing since AndroidDeviceManager is not used instead DeviceTypeManager is used.
}
} }

Loading…
Cancel
Save