DeviceTypeManager implements DeviceManager { @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { if (deviceId == null) { throw new DeviceManagementException("Cannot check the enrollment status of a null device"); } if (propertiesExist) { boolean isEnrolled = false; try { if (log.isDebugEnabled()) { log.debug("Checking the enrollment of Android device : " + deviceId.getId()); } deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); Device device = deviceTypePluginDAOManager.getDeviceDAO().getDevice(deviceId.getId()); if (device != null) { isEnrolled = true; } } catch (DeviceTypeMgtPluginException e) { String msg = "Error while checking the enrollment status of " + deviceType + " device : " + deviceId.getId(); throw new DeviceManagementException(msg, e); } finally { try { deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection(); } catch (DeviceTypeMgtPluginException e) { String msg = "Error occurred while closing the transaction to check device " + deviceId.getId() + " is enrolled."; log.warn(msg, e); } } return isEnrolled; } return true; } DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
                             DeviceTypeConfiguration deviceTypeConfiguration); @Override FeatureManager getFeatureManager(); @Override boolean saveConfiguration(PlatformConfiguration tenantConfiguration); @Override PlatformConfiguration getConfiguration(); @Override boolean enrollDevice(Device device); @Override boolean modifyEnrollment(Device device); @Override boolean disenrollDevice(DeviceIdentifier deviceId); @Override boolean isEnrolled(DeviceIdentifier deviceId); @Override boolean isActive(DeviceIdentifier deviceId); @Override boolean setActive(DeviceIdentifier deviceId, boolean status); @Override Device getDevice(DeviceIdentifier deviceId); @Override boolean updateDeviceProperties(DeviceIdentifier deviceId, List<Device.Property> propertyList); @Override boolean setOwnership(DeviceIdentifier deviceId, String ownershipType); @Override boolean isClaimable(DeviceIdentifier deviceIdentifier); @Override boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
                             EnrolmentInfo.Status status); @Override License getLicense(String languageCode); @Override void addLicense(License license); @Override boolean requireDeviceAuthorization(); @Override boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device); @Override List<Device> getAllDevices();  }
@Test(description = "This test case tests IsEnrolled method of the DeviceTypeManager", dependsOnMethods = {"testEnrollDevice"}) public void testIsEnrolled() throws DeviceManagementException { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(), sampleDevice2.getType()); DeviceIdentifier nonExistingCustomDeviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(), customDevice.getType()); Assert.assertFalse(androidDeviceTypeManager.isEnrolled(nonExistingDeviceIdentifier), "Device with NON-Existing ID is not enrolled, but this shows as enrolled"); Assert.assertTrue(androidDeviceTypeManager.isEnrolled(deviceIdentifier), "Enrolled device is shown as un-enrolled"); Assert.assertFalse(customDeviceTypeManager.isEnrolled(nonExistingCustomDeviceIdentifier), "Custom device type manager returns an non-existing device as enrolled"); Assert.assertTrue(customDeviceTypeManager.isEnrolled(new DeviceIdentifier(customDeviceType, customDeviceType)) , "Enrolled device is shown as un-enrolled in custom device type manager"); }