From 66c4a345fd53888e3e5f13f5e77f0a9a506112d3 Mon Sep 17 00:00:00 2001 From: Ace Date: Fri, 13 Oct 2017 14:24:49 +0530 Subject: [PATCH] Fixing bugs when getting device by status and adding test cases --- .../core/dao/impl/AbstractDeviceDAOImpl.java | 6 +++--- .../device/mgt/core/TestDeviceManager.java | 2 +- .../DeviceManagementProviderServiceTest.java | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 1dc588f0e1..e083572b1a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1062,9 +1062,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { conn = this.getConnection(); String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + - "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + - "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " + - "WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " + + "e.DATE_OF_ENROLMENT, e.ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e" + + ".OWNERSHIP, e.STATUS, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS " + + "ENROLMENT_ID FROM DM_ENROLMENT e WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " + "WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java index e30edc3f48..b67a0ceb27 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -95,7 +95,7 @@ public class TestDeviceManager implements DeviceManager { @Override public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { - return false; + return true; } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java index 64efeb76a4..63fd3dbec0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java @@ -388,6 +388,17 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes Assert.assertTrue(device != null); } + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) + public void testUpdateDeviceInfo() throws DeviceManagementException, + TransactionManagementException, DeviceDetailsMgtDAOException { + Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID, + DEVICE_TYPE)); + + boolean status = deviceMgtService.updateDeviceInfo(new DeviceIdentifier(DEVICE_ID, + DEVICE_TYPE), device); + Assert.assertTrue(status); + } + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) public void testDeviceByDateWithNonExistentDevice() throws DeviceManagementException, TransactionManagementException, DeviceDetailsMgtDAOException { @@ -466,6 +477,12 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) public void testGetAllDevicesByStatus() throws DeviceManagementException { + List devices = deviceMgtService.getDevicesByStatus(EnrolmentInfo.Status.ACTIVE); + Assert.assertTrue(!devices.isEmpty()); + } + + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) + public void testGetDevicesByStatus() throws DeviceManagementException { PaginationRequest request = new PaginationRequest(0, 100); request.setStatus(EnrolmentInfo.Status.ACTIVE.toString()); PaginationResult result = deviceMgtService.getDevicesByStatus(request, true);