From f89a6d9fb8afccb801825a25fd62d8f8b6b1199b Mon Sep 17 00:00:00 2001 From: Amanda Randombage <74random.amanda@gmail.com> Date: Thu, 19 Sep 2019 21:38:41 +0000 Subject: [PATCH] Fix test failure and improve disenrolling API -Remove query param from disenrolling API --- .../device/test/util/TestDeviceManager.java | 9 ++++---- .../services/DeviceManagementService.java | 6 +---- .../impl/DeviceManagementServiceImpl.java | 23 ++++--------------- .../android/DeviceManagementServiceTests.java | 4 ++-- .../DeviceManagementProviderServiceMock.java | 8 +++---- .../DeviceManagementProviderServiceMock.java | 7 +++--- .../android/impl/AndroidDeviceManager.java | 10 ++++---- 7 files changed, 24 insertions(+), 43 deletions(-) diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java index 58d8b77493..c8747186ce 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/java/org/wso2/extension/siddhi/device/test/util/TestDeviceManager.java @@ -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 deviceIdentifiers) throws DeviceManagementException { + //Does nothing since AndroidDeviceManager is not used instead DeviceTypeManager is used. + } + } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java index 59898ff893..d9bcf0ecf8 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java @@ -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); } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java index a595bdba7c..56eadb527a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -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); - } + 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"); - } + 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"); - } + msg = String.format(msg, "dis-enrolling"); log.error(msg, e); throw new UnexpectedServerErrorException( new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java index b1b3de01e6..dc16b5d43c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java @@ -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()); } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 414f232b67..b2d618f8e7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -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 deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException {return false;} } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 414f232b67..49a46503e1 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -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 deviceIdentifiers) throws DeviceManagementException, InvalidDeviceException {return false;} } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java index 33bb666b9f..9ac1f1f4f4 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android/src/main/java/org/wso2/carbon/device/mgt/mobile/android/impl/AndroidDeviceManager.java @@ -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 deviceIdentifiers) throws DeviceManagementException { + //Does nothing since AndroidDeviceManager is not used instead DeviceTypeManager is used. + } + }