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 c38638f00..dc16b5d43 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 @@ -45,7 +45,6 @@ import org.wso2.carbon.mdm.services.android.utils.TestUtils; import javax.ws.rs.core.Response; import java.util.ArrayList; import java.util.List; -import java.util.Properties; @PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*"}) @PrepareForTest(AndroidAPIUtils.class) @@ -246,5 +245,74 @@ public class DeviceManagementServiceTests { Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } + @Test + public void testIsEnrolledExists() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.isEnrolled(TestUtils.getDeviceId(), null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + } + + @Test + public void testIsEnrolledNonExist() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.isEnrolled("1234", null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); + } + + @Test + public void testIsEnrolledNull() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.isEnrolled(null, null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); + } + + @Test + public void testModifyEnrollmentSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockUser(); + Response response = deviceManagementService + .modifyEnrollment(TestUtils.getDeviceId(), TestUtils.getBasicAndroidDevice()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); + } + + @Test + public void testModifyEnrollmentUnSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockUser(); + AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); + androidDevice.setDeviceIdentifier("1234"); + Response response = deviceManagementService + .modifyEnrollment(TestUtils.getDeviceId(), androidDevice); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode()); + } + + @Test + public void testDisEnrollDeviceSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.disEnrollDevice(TestUtils.getDeviceId()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + } + + @Test + public void testDisenrollUnSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + 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 c7e43072d..d3c133ef7 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 @@ -101,7 +101,11 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv @Override public Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return null; + if (TestUtils.getDeviceId().equals(deviceIdentifier.getId())) { + return TestUtils.getDevice(); + } else { + return null; + } } @Override @@ -302,7 +306,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { - return false; + return TestUtils.getDeviceId().equals(device.getDeviceIdentifier()); } @Override @@ -317,7 +321,7 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv @Override public boolean disenrollDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { - return false; + return TestUtils.getDeviceId().equals(deviceIdentifier.getId()); } @Override