diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index bf0d93bc7eb..c3fa26c20b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -105,16 +105,6 @@ public interface DeviceDAO { */ boolean updateDevice(Device device, int tenantId) throws DeviceManagementDAOException; - /** - * This method is used to remove a device. - * - * @param deviceId id of the device that should be removed. - * @param tenantId tenant id. - * @return returns the id of removed device. - * @throws DeviceManagementDAOException - */ - int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; - /** * This method is used to retrieve a device of a given device-identifier and tenant-id. * @@ -212,16 +202,6 @@ public interface DeviceDAO { */ List getDevices(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; - /** - * This method is used to retrieve the devices of a given tenant and type as a paginated result. - * - * @param request PaginationRequest object holding the data for pagination and search. - * @param tenantId tenant id. - * @return returns paginated list of devices of provided type. - * @throws DeviceManagementDAOException - */ - List getDevicesByType(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; - /** * This method is used to retrieve all the devices of a given tenant and device type. * @@ -249,7 +229,7 @@ public interface DeviceDAO { * @param username user name. * @param type device type. * @param tenantId tenant id. - * @return + * @return List of devices. * @throws DeviceManagementDAOException */ List getDevicesOfUser(String username, String type, int tenantId) throws DeviceManagementDAOException; @@ -371,16 +351,6 @@ public interface DeviceDAO { EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException; - /** - * This method is used to retrieve current enrollment of a given device. - * - * @param deviceId device id. - * @param tenantId tenant id. - * @return returns EnrolmentInfo object. - * @throws DeviceManagementDAOException - */ - EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; - /** * This method is used to retrieve current active enrollment of a given device and tenant id. * @@ -423,29 +393,6 @@ public interface DeviceDAO { List getDevicesByStatus(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; - /** - * This method is used to retrieve the enrollment id of a given device and status. - * - * @param deviceId device id. - * @param status enrollment status. - * @param tenantId tenant id. - * @return returns the id of current enrollment. - * @throws DeviceManagementDAOException - */ - int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status, - int tenantId) throws DeviceManagementDAOException; - - /** - * This method is used to retrieve the enrollment info of a given list of devices and status. - * - * @param deviceIds A list of device identifiers. - * @param status enrollment status. - * @param tenantId tenant id. - * @return returns a list of enrolment info objects. - * @throws DeviceManagementDAOException - */ - List getEnrolmentsByStatus(List deviceIds, Status status, - int tenantId) throws DeviceManagementDAOException; List getDeviceEnrolledTenants() throws DeviceManagementDAOException; } 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 e083572b1ab..214e050d909 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 @@ -104,11 +104,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } - @Override - public int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException { - return 0; - } - @Override public Device getDevice(DeviceIdentifier deviceIdentifier, int tenantId) throws DeviceManagementDAOException { Connection conn; @@ -914,37 +909,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } - @Override - public EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - EnrolmentInfo enrolmentInfo = null; - try { - conn = this.getConnection(); - String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " + - "DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " + - "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + - "AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + - "AND TENANT_ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceId.getId()); - stmt.setString(2, deviceId.getType()); - stmt.setInt(3, tenantId); - stmt.setInt(4, tenantId); - rs = stmt.executeQuery(); - if (rs.next()) { - enrolmentInfo = DeviceManagementDAOUtil.loadMatchingEnrolment(rs); - } - return enrolmentInfo; - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " + - "of device '" + deviceId + "'", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - @Override public EnrolmentInfo getActiveEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException { Connection conn; @@ -977,81 +941,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } - public int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status, - int tenantId) throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - conn = this.getConnection(); - String sql = "SELECT e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) dtm " + - "WHERE e.DEVICE_ID = dtm.ID AND e.STATUS = ? AND e.TENANT_ID = ?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceId.getId()); - stmt.setString(2, deviceId.getType()); - stmt.setInt(3, tenantId); - stmt.setString(4, status.toString()); - stmt.setInt(5, tenantId); - rs = stmt.executeQuery(); - if (rs.next()) { - return rs.getInt("ENROLMENT_ID"); - } else { - return -1; // if no results found - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " + - "id of device '" + deviceId + "'", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - - public List getEnrolmentsByStatus(List deviceIds, Status status, - int tenantId) throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List enrolments = new ArrayList<>(); - try { - conn = this.getConnection(); - StringBuilder sql = new StringBuilder(); - sql.append("SELECT e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, " + - "e.STATUS FROM DM_ENROLMENT e WHERE e.DEVICE_ID IN (SELECT d.ID FROM DM_DEVICE d " + - "WHERE d.DEVICE_IDENTIFICATION IN ("); - - // adding arguments to the sql query - Iterator iterator = deviceIds.iterator(); - while (iterator.hasNext()) { - iterator.next(); - sql.append(" ?"); - if (iterator.hasNext()) { - sql.append(","); - } - } - sql.append(") AND d.TENANT_ID = ?) AND e.STATUS = ? AND e.TENANT_ID = ?"); - - stmt = conn.prepareStatement(sql.toString()); - int index = 1; - for (DeviceIdentifier id : deviceIds) { - stmt.setString(index++, id.getId()); - } - stmt.setInt(index++, tenantId); - stmt.setString(index++, status.toString()); - stmt.setInt(index, tenantId); - rs = stmt.executeQuery(); - while (rs.next()) { - enrolments.add(DeviceManagementDAOUtil.loadEnrolment(rs)); - } - return enrolments; - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " + - "ids of devices", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - public List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException { Connection conn; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 353eaedb38a..872ea7c2857 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -153,41 +153,6 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { return devices; } - @Override - public List getDevicesByType(PaginationRequest request, int tenantId) - throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List devices = null; - try { - conn = this.getConnection(); - String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + - "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + - "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " + - "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " + - "DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " + - "AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ?,?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, request.getDeviceType()); - stmt.setInt(2, tenantId); - stmt.setInt(3, tenantId); - stmt.setInt(4, request.getStartIndex()); - stmt.setInt(5, request.getRowCount()); - rs = stmt.executeQuery(); - devices = new ArrayList<>(); - while (rs.next()) { - Device device = DeviceManagementDAOUtil.loadDevice(rs); - devices.add(device); - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - return devices; - } - @Override public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index 2f96e94d003..33875fc9c78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -159,42 +159,6 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { return devices; } - @Override - public List getDevicesByType(PaginationRequest request, int tenantId) - throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List devices = null; - try { - conn = this.getConnection(); - String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " - + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " - + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " - + "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " - + "DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " - + "AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ? ORDER BY ENROLMENT_ID" - + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, request.getDeviceType()); - stmt.setInt(2, tenantId); - stmt.setInt(3, tenantId); - stmt.setInt(4, request.getStartIndex()); - stmt.setInt(5, request.getRowCount()); - rs = stmt.executeQuery(); - devices = new ArrayList<>(); - while (rs.next()) { - Device device = DeviceManagementDAOUtil.loadDevice(rs); - devices.add(device); - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - return devices; - } - @Override public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { @@ -401,36 +365,6 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { return devices; } - public int getEnrolmentByStatus(DeviceIdentifier deviceId, EnrolmentInfo.Status status, - int tenantId) throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - conn = this.getConnection(); - String sql = "SELECT e.ID ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) dtm " + - "WHERE e.DEVICE_ID = dtm.ID AND e.STATUS = ? AND e.TENANT_ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, deviceId.getId()); - stmt.setString(2, deviceId.getType()); - stmt.setInt(3, tenantId); - stmt.setString(4, status.toString()); - stmt.setInt(5, tenantId); - rs = stmt.executeQuery(); - if (rs.next()) { - return rs.getInt("ENROLMENT_ID"); - } else { - return -1; // if no results found - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " + - "id of device '" + deviceId + "'", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - } - private Connection getConnection() throws SQLException { return DeviceManagementDAOFactory.getConnection(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index 8578892885a..f8bce9b286b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -140,41 +140,6 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { return devices; } - @Override - public List getDevicesByType(PaginationRequest request, int tenantId) - throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List devices = null; - try { - conn = this.getConnection(); - String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + - "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + - "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " + - "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " + - "DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " + - "AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ? OFFSET ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, request.getDeviceType()); - stmt.setInt(2, tenantId); - stmt.setInt(3, tenantId); - stmt.setInt(4, request.getRowCount()); - stmt.setInt(5, request.getStartIndex()); - rs = stmt.executeQuery(); - devices = new ArrayList<>(); - while (rs.next()) { - Device device = DeviceManagementDAOUtil.loadDevice(rs); - devices.add(device); - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - return devices; - } - @Override public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index c1b4dc0529c..ee60068fa8f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -156,42 +156,6 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { return devices; } - @Override - public List getDevicesByType(PaginationRequest request, int tenantId) - throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - List devices = null; - try { - conn = this.getConnection(); - String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + - "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + - "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " + - "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " + - "DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " + - "AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ? ORDER BY ENROLMENT_ID" + - " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, request.getDeviceType()); - stmt.setInt(2, tenantId); - stmt.setInt(3, tenantId); - stmt.setInt(4, request.getStartIndex()); - stmt.setInt(5, request.getRowCount()); - rs = stmt.executeQuery(); - devices = new ArrayList<>(); - while (rs.next()) { - Device device = DeviceManagementDAOUtil.loadDevice(rs); - devices.add(device); - } - } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + request.getDeviceType() + "'", e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - return devices; - } - @Override public List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { 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 a828447c807..c78fc2e7489 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 @@ -739,13 +739,18 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes } @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) - public void testGetDeviesOfUserPaginated() throws DeviceManagementException { - if (!isMock()) { - PaginationRequest request = new PaginationRequest(0, 100); - request.setOwner("admin"); - PaginationResult result = deviceMgtService.getDevicesOfUser(request, true); - Assert.assertTrue(result.getRecordsTotal() > 0); + public void testGetDeviesOfUserPaginated() throws DeviceManagementException, NoSuchFieldException, + IllegalAccessException { + PaginationRequest request = new PaginationRequest(0, 100); + request.setOwner("admin"); + MockDataSource dataSource = setDatasourceForGetDevice(); + if (dataSource != null){ + setMockDeviceCount(dataSource.getConnection(0)); } + PaginationResult result = deviceMgtService.getDevicesOfUser(request, true); + cleanupMockDatasource(dataSource); + Assert.assertTrue(result.getRecordsTotal() > 0); + } @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions = @@ -756,13 +761,18 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes } @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) - public void testGetDeviesByOwnership() throws DeviceManagementException { - if (!isMock()) { - PaginationRequest request = new PaginationRequest(0, 100); - request.setOwnership(EnrolmentInfo.OwnerShip.BYOD.toString()); - PaginationResult result = deviceMgtService.getDevicesByOwnership(request); - Assert.assertTrue(result.getRecordsTotal() > 0); + public void testGetDeviesByOwnership() throws DeviceManagementException, NoSuchFieldException, + IllegalAccessException { + PaginationRequest request = new PaginationRequest(0, 100); + request.setOwnership(EnrolmentInfo.OwnerShip.BYOD.toString()); + MockDataSource dataSource = setDatasourceForGetDevice(); + if (dataSource != null){ + setMockDeviceCount(dataSource.getConnection(0)); } + PaginationResult result = deviceMgtService.getDevicesByOwnership(request); + cleanupMockDatasource(dataSource); + Assert.assertTrue(result.getRecordsTotal() > 0); + } @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})