DeviceTypeManager implements DeviceManager { @Override public boolean enrollDevice(Device device) throws DeviceManagementException { if (device == null) { throw new DeviceManagementException("Device is null. Cannot enroll the device."); } if (propertiesExist) { boolean status = false; boolean isEnrolled = this.isEnrolled( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); try { if (log.isDebugEnabled()) { log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); } if (isEnrolled) { this.modifyEnrollment(device); } else { deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); status = deviceTypePluginDAOManager.getDeviceDAO().addDevice(device); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); } } catch (DeviceTypeMgtPluginException e) { try { deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); } catch (DeviceTypeMgtPluginException ex) { String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); log.warn(msg, ex); } String msg = "Error while enrolling the " + deviceType + " device : " + device.getDeviceIdentifier(); throw new DeviceManagementException(msg, e); } return status; } 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 the enrollment of the device") public void testEnrollDevice() throws DeviceManagementException { Assert.assertTrue(androidDeviceTypeManager.enrollDevice(sampleDevice1), "New android device enrollment failed"); Assert.assertFalse(androidDeviceTypeManager.enrollDevice(sampleDevice2), "Modification to existing android " + "device enrollment failed"); Assert.assertTrue(customDeviceTypeManager.enrollDevice(customDevice), "Custom device type enrollment failed."); List<Device.Property> properties = customDevice.getProperties(); Device.Property property = new Device.Property(); property.setName(Utils.TEST_STRING); property.setValue(Utils.TEST_STRING); properties.add(property); customDevice.setProperties(properties); Assert.assertFalse(customDeviceTypeManager.enrollDevice(customDevice), "Custom device type re-enrollment " + "failed."); }