Fix test failure and improve disenrolling API

revert-dabc3590
Dharmakeerthi Lasantha 5 years ago
commit 80b76c95d6

@ -63,10 +63,6 @@ public class TestDeviceManager implements DeviceManager {
return true;
}
@Override
public boolean deleteDevice(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
return true;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
@ -136,4 +132,9 @@ public class TestDeviceManager implements DeviceManager {
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(
name = "id",
value = "The unique device identifier.")
@PathParam("id") String id,
@ApiParam(
name = "permanentDelete",
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("permanentDelete") boolean permanentDelete);
@PathParam("id") String id);
}

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

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

@ -354,11 +354,6 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv
return TestUtils.getDeviceId().equals(deviceIdentifier.getId());
}
@Override
public boolean deleteDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
@ -626,4 +621,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv
AmbiguousConfigurationException{
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());
}
@Override
public boolean deleteDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
@ -626,4 +622,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv
AmbiguousConfigurationException{
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;
}
@Override
public boolean deleteDevice(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
//Returning false since AndroidDeviceManager is not used instead DeviceTypeManager is used.
return false;
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
@ -374,4 +369,9 @@ public class AndroidDeviceManager implements DeviceManager {
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