diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index da64cb2a84c..a57bc75bc73 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -282,18 +282,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.closeConnection(); } - if (device.getDeviceInfo() != null) { - DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl(); - try { - deviceInformationManager.addDeviceInfo(deviceIdentifier, device.getDeviceInfo()); - } catch (DeviceDetailsMgtException e) { - String msg = "Error occurred while adding device info for the device " + - device.getDeviceIdentifier(); - log.error(msg, e); - throw new DeviceManagementException(msg, e); - } - } - if (log.isDebugEnabled()) { log.debug("An enrolment is successfully created with the id '" + enrolmentId + "' associated with " + "the device identified by key '" + device.getDeviceIdentifier() + "', which belongs to " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java index 9e137829452..49641d16ab1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/SearchManagementServiceTest.java @@ -24,11 +24,16 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.search.Condition; import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException; @@ -46,7 +51,7 @@ import java.util.List; /** * This class contains unit tests for the class SearchManagerService - * */ + */ public class SearchManagementServiceTest extends BaseDeviceManagementTest { private static final Log log = LogFactory.getLog(SearchManagementServiceTest.class); @@ -66,12 +71,24 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest { DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)); + DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl(); List devices = TestDataHolder.generateDummyDeviceData(deviceIdentifiers); for (Device device : devices) { - device.setDeviceInfo(Utils.getDeviceInfo()); deviceMgtService.enrollDevice(device); } + + for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { + DeviceInfo deviceInfo = Utils.getDeviceInfo(); + try { + deviceInformationManager.addDeviceInfo(deviceIdentifier, deviceInfo); + } catch (DeviceDetailsMgtException e) { + String msg = "Error occurred while adding device info for the device " + deviceIdentifier; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + } + List returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE, true); for (Device device : returnedDevices) { if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {