diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
index 05ee728ef6..8a9640603d 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml
@@ -139,7 +139,11 @@
file:src/test/resources/log4j.properties
- src/test/resources/testng.xml
+ src/test/resources/testng.xml
+ src/test/resources/mysql-testng.xml
+ src/test/resources/mssql-testng.xml
+ src/test/resources/oracle-testng.xml
+ src/test/resources/postgre-testng.xml
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 bf0d93bc7e..c3fa26c20b 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 e083572b1a..214e050d90 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 353eaedb38..872ea7c285 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 2f96e94d00..33875fc9c7 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 8578892885..f8bce9b286 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 c1b4dc0529..ee60068fa8 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/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 607f47f8b2..da64cb2a84 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
@@ -254,9 +254,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
DeviceManagementDAOFactory.beginTransaction();
DeviceType type = deviceTypeDAO.getDeviceType(device.getType(), tenantId);
- int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
- enrolmentId = enrollmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
- DeviceManagementDAOFactory.commitTransaction();
+ if (type != null) {
+ int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
+ enrolmentId = enrollmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
+ DeviceManagementDAOFactory.commitTransaction();
+ } else {
+ DeviceManagementDAOFactory.rollbackTransaction();
+ throw new DeviceManagementException("No device type registered with name - " + device.getType()
+ + " and hence unable to find succeed the enrollment of device - "
+ + device.getDeviceIdentifier());
+ }
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while adding metadata of '" + device.getType() +
@@ -282,8 +289,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} 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);
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
index 57ac66a1ea..b5565814b4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/BaseDeviceManagementTest.java
@@ -24,6 +24,8 @@ import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Optional;
+import org.testng.annotations.Parameters;
import org.w3c.dom.Document;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@@ -35,6 +37,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
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.mock.MockDataSource;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
@@ -59,11 +62,18 @@ import java.sql.Connection;
import java.sql.Statement;
public abstract class BaseDeviceManagementTest {
-
+ protected static final String DATASOURCE_EXT = ".xml";
private DataSource dataSource;
+ private static String datasourceLocation;
+ private static boolean mock;
@BeforeSuite
- public void setupDataSource() throws Exception {
+ @Parameters({"datasource", "isMock"})
+ public void setupDataSource(@Optional("src/test/resources/config/datasource/data-source-config") String datasource,
+ @Optional("false") boolean isMock)
+ throws Exception {
+ datasourceLocation = datasource;
+ mock = isMock;
this.initDataSource();
this.initSQLScript();
this.initializeCarbonContext();
@@ -72,7 +82,7 @@ public abstract class BaseDeviceManagementTest {
protected void initDataSource() throws Exception {
this.dataSource = this.getDataSource(this.
- readDataSourceConfig("src/test/resources/config/datasource/data-source-config.xml"));
+ readDataSourceConfig(datasourceLocation + DATASOURCE_EXT));
DeviceManagementDAOFactory.init(dataSource);
GroupManagementDAOFactory.init(dataSource);
OperationManagementDAOFactory.init(dataSource);
@@ -112,12 +122,16 @@ public abstract class BaseDeviceManagementTest {
public abstract void init() throws Exception;
protected DataSource getDataSource(DataSourceConfig config) {
- PoolProperties properties = new PoolProperties();
- properties.setUrl(config.getUrl());
- properties.setDriverClassName(config.getDriverClassName());
- properties.setUsername(config.getUser());
- properties.setPassword(config.getPassword());
- return new org.apache.tomcat.jdbc.pool.DataSource(properties);
+ if (!isMock()) {
+ PoolProperties properties = new PoolProperties();
+ properties.setUrl(config.getUrl());
+ properties.setDriverClassName(config.getDriverClassName());
+ properties.setUsername(config.getUser());
+ properties.setPassword(config.getPassword());
+ return new org.apache.tomcat.jdbc.pool.DataSource(properties);
+ } else {
+ return new MockDataSource(config.getUrl());
+ }
}
private void initializeCarbonContext() {
@@ -174,4 +188,14 @@ public abstract class BaseDeviceManagementTest {
return dataSource;
}
+ protected String getDatasourceLocation() throws Exception {
+ if (datasourceLocation == null) {
+ throw new Exception("Data source location is null!!!");
+ }
+ return datasourceLocation;
+ }
+
+ protected boolean isMock() {
+ return mock;
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java
index 5065109f35..68079eeb24 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDataHolder.java
@@ -107,7 +107,7 @@ public class TestDataHolder {
device.setDescription("Test Description");
device.setDeviceIdentifier(deviceIdentifier);
device.setType(deviceType);
- device.setName(deviceType+"-"+deviceIdentifier);
+ device.setName(deviceType + "-" + deviceIdentifier);
return device;
}
@@ -137,7 +137,7 @@ public class TestDataHolder {
device.setDescription("Test Description");
device.setDeviceIdentifier(deviceIdentifier.getId());
device.setType(deviceIdentifier.getType());
- device.setName(deviceIdentifier.getType()+"-"+deviceIdentifier.getId());
+ device.setName(deviceIdentifier.getType() + "-" + deviceIdentifier.getId());
return device;
}
@@ -171,7 +171,7 @@ public class TestDataHolder {
}
public static OperationMonitoringTaskConfig generateMonitoringTaskConfig(boolean enabled, int frequency,
- int numberOfOperations) {
+ int numberOfOperations) {
OperationMonitoringTaskConfig taskConfig = new OperationMonitoringTaskConfig();
List operationList = new ArrayList<>();
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/ApplicationPersistenceTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/ApplicationPersistenceTests.java
index 7d697ca6c7..6bbeb5393a 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/ApplicationPersistenceTests.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/ApplicationPersistenceTests.java
@@ -56,9 +56,10 @@ public class ApplicationPersistenceTests extends BaseDeviceManagementTest {
Assert.fail(msg, e);
}
- Assert.assertEquals(target.getApplicationIdentifier(), testAppIdentifier, "Application added is not as same as " +
- "what's " +
- "retrieved");
+ if (!isMock()) {
+ Assert.assertEquals(target.getApplicationIdentifier(), testAppIdentifier,
+ "Application added is not as same as what's retrieved");
+ }
}
private Application getApplication(String appIdentifier, 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/dao/DevicePersistTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DevicePersistTests.java
index 22914836b7..c1143b9198 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DevicePersistTests.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DevicePersistTests.java
@@ -174,8 +174,7 @@ public class DevicePersistTests extends BaseDeviceManagementTest {
}
@Test(dependsOnMethods = "testAddDeviceTest")
- public void testSetEnrolmentStatus() {
-
+ public void testSetEnrolmentStatus() throws DeviceManagementDAOException, TransactionManagementException {
Device device = TestDataHolder.initialTestDevice;
try {
DeviceManagementDAOFactory.beginTransaction();
@@ -203,9 +202,11 @@ public class DevicePersistTests extends BaseDeviceManagementTest {
log.error(msg, e);
Assert.fail(msg, e);
}
- Assert.assertNotNull(target, "Enrolment status retrieved for the device carrying its identifier as '" +
- device.getDeviceIdentifier() + "' is null");
- Assert.assertEquals(target, Status.ACTIVE, "Enrolment status retrieved is not as same as what's configured");
+ if (!isMock()) {
+ Assert.assertNotNull(target, "Enrolment status retrieved for the device carrying its identifier as '" +
+ device.getDeviceIdentifier() + "' is null");
+ Assert.assertEquals(target, Status.ACTIVE, "Enrolment status retrieved is not as same as what's configured");
+ }
}
private Status getEnrolmentStatus(String identifier, String deviceType, int tenantId)
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/EnrolmentPersistenceTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/EnrolmentPersistenceTests.java
index 7ba74caa10..5ab8c7577d 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/EnrolmentPersistenceTests.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/EnrolmentPersistenceTests.java
@@ -85,5 +85,4 @@ public class EnrolmentPersistenceTests extends BaseDeviceManagementTest {
public void init() throws Exception {
this.initDataSource();
}
-
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java
index cc57e51b85..442e4ae06a 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/GroupPersistTests.java
@@ -70,8 +70,10 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
Assert.fail(msg, e);
}
DeviceGroup group = getGroupById(groupId);
- Assert.assertNotNull(group, "Group is null");
- log.debug("Group name: " + group.getName());
+ if (!isMock()) {
+ Assert.assertNotNull(group, "Group is null");
+ log.debug("Group name: " + group.getName());
+ }
}
@Test(dependsOnMethods = {"addGroupTest"})
@@ -83,9 +85,11 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
request.setOwner(null);
List groups = groupDAO.getGroups(request, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
- Assert.assertNotEquals(groups.size(), 0, "No groups found");
- Assert.assertNotNull(groups.get(0), "Group is null");
- log.debug("No of Groups found: " + groups.size());
+ if (!isMock()) {
+ Assert.assertNotEquals(groups.size(), 0, "No groups found");
+ Assert.assertNotNull(groups.get(0), "Group is null");
+ log.debug("No of Groups found: " + groups.size());
+ }
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while find group by name.";
@@ -112,7 +116,9 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
GroupManagementDAOFactory.commitTransaction();
List roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
- Assert.assertEquals(roles, addedRoles, "Added roles are not equal to returned roles.");
+ if (!isMock()) {
+ Assert.assertEquals(roles, addedRoles, "Added roles are not equal to returned roles.");
+ }
log.debug("Group shared with roles.");
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
@@ -132,11 +138,15 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
try {
GroupManagementDAOFactory.openConnection();
List roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
- roles.remove(0);
+ if (!isMock()) {
+ roles.remove(0);
+ }
List deviceGroups = groupDAO.getGroups(roles.toArray(new String[roles.size()]), TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
- Assert.assertEquals(deviceGroups.size(), 1, "Unexpected number of device groups found with role.");
- Assert.assertEquals(deviceGroups.get(0).getGroupId(), groupId, "Unexpected groupId found with role.");
+ if (!isMock()) {
+ Assert.assertEquals(deviceGroups.size(), 1, "Unexpected number of device groups found with role.");
+ Assert.assertEquals(deviceGroups.get(0).getGroupId(), groupId, "Unexpected groupId found with role.");
+ }
log.debug("Group found for given roles.");
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
@@ -162,7 +172,9 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
GroupManagementDAOFactory.commitTransaction();
List roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
- Assert.assertNotEquals(roles, rolesToRemove, "Roles not removed.");
+ if (!isMock()) {
+ Assert.assertNotEquals(roles, rolesToRemove, "Roles not removed.");
+ }
log.debug("Group unshared with given roles.");
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
@@ -205,9 +217,11 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
GroupManagementDAOFactory.openConnection();
List groupedDevices = groupDAO.getDevices(deviceGroup.getGroupId(), 0, 10, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
- Assert.assertNotEquals(groupedDevices.size(), 0, "No device found");
- Assert.assertNotNull(groupedDevices.get(0), "Device is null");
- Assert.assertEquals(groupedDevices.get(0).getId(), initialTestDevice.getId(), "Device ids not matched");
+ if (!isMock()) {
+ Assert.assertNotEquals(groupedDevices.size(), 0, "No device found");
+ Assert.assertNotNull(groupedDevices.get(0), "Device is null");
+ Assert.assertEquals(groupedDevices.get(0).getId(), initialTestDevice.getId(), "Device ids not matched");
+ }
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
String msg = "Error occurred while retrieving group details.";
@@ -272,11 +286,12 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
log.error(msg, e);
Assert.fail(msg, e);
}
-
- group = getGroupById(groupId);
- Assert.assertNotNull(group, "Group is null");
- Assert.assertEquals(group.getName(), name, "Group name");
- Assert.assertEquals(group.getDescription(), desc, "Group description");
+ if (!isMock()) {
+ group = getGroupById(groupId);
+ Assert.assertNotNull(group, "Group is null");
+ Assert.assertEquals(group.getName(), name, "Group name");
+ Assert.assertEquals(group.getDescription(), desc, "Group description");
+ }
}
@Test(dependsOnMethods = {"updateGroupTest"})
@@ -302,14 +317,20 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
Assert.fail(msg, e);
}
group = getGroupById(groupId);
- Assert.assertNull(group, "Group is not deleted");
+ if (!isMock()) {
+ Assert.assertNull(group, "Group is not deleted");
+ }
}
private DeviceGroup getGroupById(int groupId) {
try {
GroupManagementDAOFactory.openConnection();
- DeviceGroup deviceGroup = groupDAO.getGroup(groupId, TestDataHolder.SUPER_TENANT_ID);
+ DeviceGroup deviceGroup = groupDAO.getGroup(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
+ if (deviceGroup == null && isMock()) {
+ deviceGroup = new DeviceGroup();
+ deviceGroup.setGroupId(groupId);
+ }
return deviceGroup;
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockConnection.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockConnection.java
index f7a3e1bdf4..1425005f71 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockConnection.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockConnection.java
@@ -25,6 +25,8 @@ import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.RowIdLifetime;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
@@ -32,6 +34,8 @@ import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
@@ -40,14 +44,32 @@ import java.util.concurrent.Executor;
* This is mock class which provides mock database connection.
*/
public class MockConnection implements Connection {
+
+ private String url;
+ private List statements = new ArrayList<>();
+ private int statementCounter = 0;
+
+ public MockConnection(String url) {
+ this.url = url;
+ }
+
@Override
public Statement createStatement() throws SQLException {
- return null;
+ return getStatement();
+ }
+
+ private MockStatement getStatement() {
+ if (!statements.isEmpty()) {
+ MockStatement statement = this.statements.get(this.statementCounter);
+ statementCounter++;
+ return statement;
+ }
+ return new MockStatement();
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
- return null;
+ return getStatement();
}
@Override
@@ -92,7 +114,7 @@ public class MockConnection implements Connection {
@Override
public DatabaseMetaData getMetaData() throws SQLException {
- return null;
+ return new MockDatabaseMetaData(this.url);
}
@Override
@@ -221,7 +243,7 @@ public class MockConnection implements Connection {
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
- return null;
+ return new MockStatement();
}
@Override
@@ -313,4 +335,8 @@ public class MockConnection implements Connection {
public boolean isWrapperFor(Class> iface) throws SQLException {
return false;
}
+
+ public void addMockStatement(MockStatement mockStatement) {
+ this.statements.add(mockStatement);
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockDataSource.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockDataSource.java
index e9231bbe42..6c799a1fcc 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockDataSource.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockDataSource.java
@@ -17,30 +17,45 @@
*/
package org.wso2.carbon.device.mgt.core.mock;
+import org.mockito.Mock;
+
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.logging.Logger;
import javax.sql.DataSource;
/**
* This is the mock data source implementation that will be used in the test cases.
- *
*/
public class MockDataSource implements DataSource {
private boolean throwException = false;
- private Connection connection;
+ private List connections = new ArrayList<>();
+ private int connectionCounter = 0;
+ private String url;
+
+ public MockDataSource(String url) {
+ this.url = url;
+ }
@Override
public Connection getConnection() throws SQLException {
if (throwException) {
throw new SQLException("Cannot created test connection.");
} else {
- if (connection != null) {
- return connection;
+ if (!connections.isEmpty()) {
+ if (this.connectionCounter < this.connections.size()) {
+ Connection connection = this.connections.get(this.connectionCounter);
+ this.connectionCounter++;
+ return connection;
+ } else {
+ return new MockConnection(url);
+ }
}
- return new MockConnection();
+ return new MockConnection(url);
}
}
@@ -90,10 +105,20 @@ public class MockDataSource implements DataSource {
public void reset() {
this.throwException = false;
- this.connection = null;
+ this.connections.clear();
+ this.connectionCounter = 0;
+ }
+
+ public void setConnection(Connection connection) {
+ this.connections.add(connection);
+ }
+
+ public String getUrl() {
+ return this.url;
}
- private void setConnection(Connection connection) {
- this.connection = connection;
+ public MockConnection getConnection(int id) {
+ return (MockConnection) this.connections.get(id);
}
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockDatabaseMetaData.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockDatabaseMetaData.java
new file mode 100644
index 0000000000..2ab645ba9b
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockDatabaseMetaData.java
@@ -0,0 +1,926 @@
+/*
+* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+package org.wso2.carbon.device.mgt.core.mock;
+
+import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.RowIdLifetime;
+import java.sql.SQLException;
+
+public class MockDatabaseMetaData implements DatabaseMetaData {
+ private String url;
+
+ public MockDatabaseMetaData(String url) {
+ this.url = url;
+ }
+
+ @Override
+ public boolean allProceduresAreCallable() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean allTablesAreSelectable() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getURL() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getUserName() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean nullsAreSortedHigh() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean nullsAreSortedLow() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean nullsAreSortedAtStart() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean nullsAreSortedAtEnd() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getDatabaseProductName() throws SQLException {
+ if (this.url.contains("mysql")) {
+ return DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL;
+ } else if (this.url.contains("h2")) {
+ return DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2;
+ } else if (this.url.contains("oracle")) {
+ return DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE;
+ } else if (this.url.contains("postgresql")) {
+ return DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL;
+ } else if (this.url.contains("sqlserver")) {
+ return DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getDatabaseProductVersion() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getDriverName() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getDriverVersion() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int getDriverMajorVersion() {
+ return 0;
+ }
+
+ @Override
+ public int getDriverMinorVersion() {
+ return 0;
+ }
+
+ @Override
+ public boolean usesLocalFiles() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean usesLocalFilePerTable() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsMixedCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean storesUpperCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean storesLowerCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean storesMixedCaseIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getIdentifierQuoteString() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getSQLKeywords() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getNumericFunctions() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getStringFunctions() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getSystemFunctions() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getTimeDateFunctions() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getSearchStringEscape() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getExtraNameCharacters() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean supportsAlterTableWithAddColumn() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsAlterTableWithDropColumn() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsColumnAliasing() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean nullPlusNonNullIsNull() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsConvert() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsConvert(int fromType, int toType) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsTableCorrelationNames() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsDifferentTableCorrelationNames() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsExpressionsInOrderBy() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOrderByUnrelated() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsGroupBy() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsGroupByUnrelated() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsGroupByBeyondSelect() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsLikeEscapeClause() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsMultipleResultSets() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsMultipleTransactions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsNonNullableColumns() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsMinimumSQLGrammar() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCoreSQLGrammar() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsExtendedSQLGrammar() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsANSI92EntryLevelSQL() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsANSI92IntermediateSQL() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsANSI92FullSQL() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsIntegrityEnhancementFacility() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOuterJoins() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsFullOuterJoins() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsLimitedOuterJoins() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getSchemaTerm() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getProcedureTerm() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getCatalogTerm() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isCatalogAtStart() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getCatalogSeparator() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean supportsSchemasInDataManipulation() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSchemasInProcedureCalls() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSchemasInTableDefinitions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSchemasInIndexDefinitions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCatalogsInDataManipulation() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCatalogsInProcedureCalls() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCatalogsInTableDefinitions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsPositionedDelete() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsPositionedUpdate() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSelectForUpdate() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsStoredProcedures() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSubqueriesInComparisons() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSubqueriesInExists() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSubqueriesInIns() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSubqueriesInQuantifieds() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCorrelatedSubqueries() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsUnion() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsUnionAll() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public int getMaxBinaryLiteralLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxCharLiteralLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxColumnNameLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxColumnsInGroupBy() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxColumnsInIndex() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxColumnsInOrderBy() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxColumnsInSelect() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxColumnsInTable() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxConnections() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxCursorNameLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxIndexLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxSchemaNameLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxProcedureNameLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxCatalogNameLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxRowSize() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public int getMaxStatementLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxStatements() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxTableNameLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxTablesInSelect() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getMaxUserNameLength() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getDefaultTransactionIsolation() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean supportsTransactions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getSchemas() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getCatalogs() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getTableTypes() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getTypeInfo() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean supportsResultSetType(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean ownUpdatesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean ownDeletesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean ownInsertsAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean othersUpdatesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean othersDeletesAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean othersInsertsAreVisible(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean updatesAreDetected(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean deletesAreDetected(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean insertsAreDetected(int type) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsBatchUpdates() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean supportsSavepoints() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsNamedParameters() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsMultipleOpenResults() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsGetGeneratedKeys() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean supportsResultSetHoldability(int holdability) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public int getResultSetHoldability() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getDatabaseMajorVersion() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getDatabaseMinorVersion() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getJDBCMajorVersion() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getJDBCMinorVersion() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getSQLStateType() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean locatorsUpdateCopy() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean supportsStatementPooling() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public RowIdLifetime getRowIdLifetime() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public ResultSet getClientInfoProperties() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean generatedKeyAlwaysReturned() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public T unwrap(Class iface) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isWrapperFor(Class> iface) throws SQLException {
+ return false;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockJDBCDriver.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockJDBCDriver.java
index 1ce52f5544..d19a6b9fb6 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockJDBCDriver.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockJDBCDriver.java
@@ -32,7 +32,7 @@ public class MockJDBCDriver implements Driver {
@Override
public Connection connect(String url, Properties info) throws SQLException {
- return null;
+ return new MockConnection(url);
}
@Override
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockResultSet.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockResultSet.java
new file mode 100644
index 0000000000..f8882653d7
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockResultSet.java
@@ -0,0 +1,1112 @@
+/*
+* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+package org.wso2.carbon.device.mgt.core.mock;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class MockResultSet implements ResultSet {
+ private List stringList = new ArrayList<>();
+ private List integerList = new ArrayList<>();
+ private List doubleList = new ArrayList<>();
+ private List booleanList = new ArrayList<>();
+ private List timestamps = new ArrayList<>();
+
+ private AtomicInteger stringCounter = new AtomicInteger(0);
+ private AtomicInteger integerCounter = new AtomicInteger(0);
+ private AtomicInteger doubleCounter = new AtomicInteger(0);
+ private AtomicInteger booleanCounter = new AtomicInteger(0);
+ private AtomicInteger timestampCounter = new AtomicInteger(0);
+
+ private boolean iterated = false;
+ private boolean hasData = false;
+
+ @Override
+ public boolean next() throws SQLException {
+ if (!this.iterated && this.hasData) {
+ this.iterated = true;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public void close() throws SQLException {
+
+ }
+
+ @Override
+ public boolean wasNull() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getString(int columnIndex) throws SQLException {
+ Object item = getItem(this.stringList, this.stringCounter);
+ if (item != null) {
+ return (String) item;
+ } else {
+ return "";
+ }
+ }
+
+ private Object getItem(List list, AtomicInteger counter) {
+ if (!list.isEmpty()) {
+ return list.get(counter.getAndIncrement());
+ }
+ return null;
+ }
+
+ @Override
+ public boolean getBoolean(int columnIndex) throws SQLException {
+ Object item = getItem(this.booleanList, this.booleanCounter);
+ if (item != null) {
+ return (Boolean) item;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public byte getByte(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public short getShort(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getInt(int columnIndex) throws SQLException {
+ Object item = getItem(this.integerList, this.integerCounter);
+ if (item != null) {
+ return (Integer) item;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public long getLong(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public float getFloat(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public double getDouble(int columnIndex) throws SQLException {
+ Object item = getItem(this.doubleList, this.doubleCounter);
+ if (item != null) {
+ return (Double) item;
+ } else {
+ return 0.0;
+ }
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public byte[] getBytes(int columnIndex) throws SQLException {
+ return new byte[0];
+ }
+
+ @Override
+ public Date getDate(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ Object item = getItem(this.timestamps, this.timestampCounter);
+ if (item != null) {
+ return (Timestamp) item;
+ } else {
+ return new Timestamp(System.currentTimeMillis());
+ }
+ }
+
+ @Override
+ public InputStream getAsciiStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getBinaryStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getString(String columnLabel) throws SQLException {
+ Object item = getItem(this.stringList, this.stringCounter);
+ if (item != null) {
+ return (String) item;
+ } else {
+ return "";
+ }
+ }
+
+ @Override
+ public boolean getBoolean(String columnLabel) throws SQLException {
+ Object item = getItem(this.booleanList, this.booleanCounter);
+ if (item != null) {
+ return (Boolean) item;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public byte getByte(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public short getShort(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getInt(String columnLabel) throws SQLException {
+ Object item = getItem(this.integerList, this.integerCounter);
+ if (item != null) {
+ return (Integer) item;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public long getLong(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public float getFloat(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public double getDouble(String columnLabel) throws SQLException {
+ Object item = getItem(this.doubleList, this.doubleCounter);
+ if (item != null) {
+ return (Double) item;
+ } else {
+ return 0.0;
+ }
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public byte[] getBytes(String columnLabel) throws SQLException {
+ return new byte[0];
+ }
+
+ @Override
+ public Date getDate(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Timestamp getTimestamp(String columnLabel) throws SQLException {
+ Object item = getItem(this.timestamps, this.timestampCounter);
+ if (item != null) {
+ return (Timestamp) item;
+ } else {
+ return new Timestamp(System.currentTimeMillis());
+ }
+ }
+
+ @Override
+ public InputStream getAsciiStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getUnicodeStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getBinaryStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLWarning getWarnings() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void clearWarnings() throws SQLException {
+
+ }
+
+ @Override
+ public String getCursorName() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public ResultSetMetaData getMetaData() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int findColumn(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public Reader getCharacterStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Reader getCharacterStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isBeforeFirst() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isAfterLast() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isFirst() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isLast() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void beforeFirst() throws SQLException {
+
+ }
+
+ @Override
+ public void afterLast() throws SQLException {
+
+ }
+
+ @Override
+ public boolean first() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean last() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public int getRow() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean absolute(int row) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean relative(int rows) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean previous() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void setFetchDirection(int direction) throws SQLException {
+
+ }
+
+ @Override
+ public int getFetchDirection() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public void setFetchSize(int rows) throws SQLException {
+
+ }
+
+ @Override
+ public int getFetchSize() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getType() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getConcurrency() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean rowUpdated() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean rowInserted() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean rowDeleted() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void updateNull(int columnIndex) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateByte(int columnIndex, byte x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateShort(int columnIndex, short x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateInt(int columnIndex, int x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateLong(int columnIndex, long x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateFloat(int columnIndex, float x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDouble(int columnIndex, double x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateString(int columnIndex, String x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDate(int columnIndex, Date x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTime(int columnIndex, Time x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(int columnIndex, Object x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNull(String columnLabel) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBoolean(String columnLabel, boolean x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateByte(String columnLabel, byte x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateShort(String columnLabel, short x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateInt(String columnLabel, int x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateLong(String columnLabel, long x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateFloat(String columnLabel, float x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDouble(String columnLabel, double x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateString(String columnLabel, String x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBytes(String columnLabel, byte[] x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDate(String columnLabel, Date x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTime(String columnLabel, Time x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(String columnLabel, Object x) throws SQLException {
+
+ }
+
+ @Override
+ public void insertRow() throws SQLException {
+
+ }
+
+ @Override
+ public void updateRow() throws SQLException {
+
+ }
+
+ @Override
+ public void deleteRow() throws SQLException {
+
+ }
+
+ @Override
+ public void refreshRow() throws SQLException {
+
+ }
+
+ @Override
+ public void cancelRowUpdates() throws SQLException {
+
+ }
+
+ @Override
+ public void moveToInsertRow() throws SQLException {
+
+ }
+
+ @Override
+ public void moveToCurrentRow() throws SQLException {
+
+ }
+
+ @Override
+ public Statement getStatement() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(int columnIndex, Map> map) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Ref getRef(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Blob getBlob(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Clob getClob(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Array getArray(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(String columnLabel, Map> map) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Ref getRef(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Blob getBlob(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Clob getClob(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Array getArray(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Date getDate(String columnLabel, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(String columnLabel, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+ Object item = getItem(this.timestamps, this.timestampCounter);
+ if (item != null) {
+ return (Timestamp) item;
+ } else {
+ return new Timestamp(System.currentTimeMillis());
+ }
+ }
+
+ @Override
+ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
+ Object item = getItem(this.timestamps, this.timestampCounter);
+ if (item != null) {
+ return (Timestamp) item;
+ } else {
+ return new Timestamp(System.currentTimeMillis());
+ }
+ }
+
+ @Override
+ public URL getURL(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public URL getURL(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateRef(String columnLabel, Ref x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, Blob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, Blob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Clob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Clob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateArray(int columnIndex, Array x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateArray(String columnLabel, Array x) throws SQLException {
+
+ }
+
+ @Override
+ public RowId getRowId(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public RowId getRowId(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateRowId(String columnLabel, RowId x) throws SQLException {
+
+ }
+
+ @Override
+ public int getHoldability() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean isClosed() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void updateNString(int columnIndex, String nString) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNString(String columnLabel, String nString) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
+
+ }
+
+ @Override
+ public NClob getNClob(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public NClob getNClob(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLXML getSQLXML(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLXML getSQLXML(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
+
+ }
+
+ @Override
+ public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
+
+ }
+
+ @Override
+ public String getNString(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getNString(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Reader getNCharacterStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Reader getNCharacterStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public T getObject(int columnIndex, Class type) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public T getObject(String columnLabel, Class type) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public T unwrap(Class iface) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isWrapperFor(Class> iface) throws SQLException {
+ return false;
+ }
+
+ public void addString(String string) {
+ this.stringList.add(string);
+ this.hasData = true;
+ }
+
+ public void addInteger(Integer integer) {
+ this.integerList.add(integer);
+ this.hasData = true;
+ }
+
+ public void addBoolean(Boolean bool) {
+ this.booleanList.add(bool);
+ this.hasData = true;
+ }
+
+ public void addDouble(Double doubleVal) {
+ this.doubleList.add(doubleVal);
+ this.hasData = true;
+ }
+
+ public void addTimestamp(Timestamp timestamp){
+ this.timestamps.add(timestamp);
+ this.hasData = true;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockStatement.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockStatement.java
index f717f67660..3b8fa5fe60 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockStatement.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/mock/MockStatement.java
@@ -17,20 +17,52 @@
*/
package org.wso2.carbon.device.mgt.core.mock;
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.ParameterMetaData;
+import java.sql.PreparedStatement;
+import java.sql.Ref;
import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLWarning;
+import java.sql.SQLXML;
import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
/**
- * This is the mock statement for the testcases.
+ * This is the mock statement for the test cases.
*/
-public class MockStatement implements Statement {
+public class MockStatement implements PreparedStatement {
+ private List resultSets = new ArrayList<>();
+ private int resultSetCounter;
@Override
public ResultSet executeQuery(String sql) throws SQLException {
- return null;
+ return this.getMockResultSet();
+ }
+
+ private ResultSet getMockResultSet() {
+ if (!this.resultSets.isEmpty()) {
+ ResultSet resultSet = this.resultSets.get(this.resultSetCounter);
+ this.resultSetCounter++;
+ return resultSet;
+ } else {
+ return new MockResultSet();
+ }
}
@Override
@@ -105,7 +137,7 @@ public class MockStatement implements Statement {
@Override
public ResultSet getResultSet() throws SQLException {
- return null;
+ return getMockResultSet();
}
@Override
@@ -175,7 +207,7 @@ public class MockStatement implements Statement {
@Override
public ResultSet getGeneratedKeys() throws SQLException {
- return null;
+ return getMockResultSet();
}
@Override
@@ -247,4 +279,283 @@ public class MockStatement implements Statement {
public boolean isWrapperFor(Class> iface) throws SQLException {
return false;
}
+
+ @Override
+ public ResultSet executeQuery() throws SQLException {
+ return getMockResultSet();
+ }
+
+ @Override
+ public int executeUpdate() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public void setNull(int parameterIndex, int sqlType) throws SQLException {
+
+ }
+
+ @Override
+ public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+
+ }
+
+ @Override
+ public void setByte(int parameterIndex, byte x) throws SQLException {
+
+ }
+
+ @Override
+ public void setShort(int parameterIndex, short x) throws SQLException {
+
+ }
+
+ @Override
+ public void setInt(int parameterIndex, int x) throws SQLException {
+
+ }
+
+ @Override
+ public void setLong(int parameterIndex, long x) throws SQLException {
+
+ }
+
+ @Override
+ public void setFloat(int parameterIndex, float x) throws SQLException {
+
+ }
+
+ @Override
+ public void setDouble(int parameterIndex, double x) throws SQLException {
+
+ }
+
+ @Override
+ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
+
+ }
+
+ @Override
+ public void setString(int parameterIndex, String x) throws SQLException {
+
+ }
+
+ @Override
+ public void setBytes(int parameterIndex, byte[] x) throws SQLException {
+
+ }
+
+ @Override
+ public void setDate(int parameterIndex, Date x) throws SQLException {
+
+ }
+
+ @Override
+ public void setTime(int parameterIndex, Time x) throws SQLException {
+
+ }
+
+ @Override
+ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
+
+ }
+
+ @Override
+ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void clearParameters() throws SQLException {
+
+ }
+
+ @Override
+ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
+
+ }
+
+ @Override
+ public void setObject(int parameterIndex, Object x) throws SQLException {
+
+ }
+
+ @Override
+ public boolean execute() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void addBatch() throws SQLException {
+
+ }
+
+ @Override
+ public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void setRef(int parameterIndex, Ref x) throws SQLException {
+
+ }
+
+ @Override
+ public void setBlob(int parameterIndex, Blob x) throws SQLException {
+
+ }
+
+ @Override
+ public void setClob(int parameterIndex, Clob x) throws SQLException {
+
+ }
+
+ @Override
+ public void setArray(int parameterIndex, Array x) throws SQLException {
+
+ }
+
+ @Override
+ public ResultSetMetaData getMetaData() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+
+ }
+
+ @Override
+ public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+
+ }
+
+ @Override
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
+
+ }
+
+ @Override
+ public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
+
+ }
+
+ @Override
+ public void setURL(int parameterIndex, URL x) throws SQLException {
+
+ }
+
+ @Override
+ public ParameterMetaData getParameterMetaData() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void setRowId(int parameterIndex, RowId x) throws SQLException {
+
+ }
+
+ @Override
+ public void setNString(int parameterIndex, String value) throws SQLException {
+
+ }
+
+ @Override
+ public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void setNClob(int parameterIndex, NClob value) throws SQLException {
+
+ }
+
+ @Override
+ public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
+
+ }
+
+ @Override
+ public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
+
+ }
+
+ @Override
+ public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
+
+ }
+
+ @Override
+ public void setClob(int parameterIndex, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
+
+ }
+
+ @Override
+ public void setNClob(int parameterIndex, Reader reader) throws SQLException {
+
+ }
+
+ public void addResultSet(MockResultSet resultSet){
+ this.resultSets.add(resultSet);
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java
index 981fbd5c3b..767cde63ed 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNegativeDBOperationTest.java
@@ -45,7 +45,7 @@ import java.util.List;
import javax.sql.DataSource;
/**
- * Negative testcases for {@link OperationManagerImpl}
+ * Negative test cases for {@link OperationManagerImpl}
* regarding the database connectivity.
*/
public class OperationManagementNegativeDBOperationTest extends BaseDeviceManagementTest {
@@ -64,7 +64,7 @@ public class OperationManagementNegativeDBOperationTest extends BaseDeviceManage
@Override
public void init() throws Exception {
DataSource datasource = this.getDataSource(this.
- readDataSourceConfig("src/test/resources/config/datasource/mock-data-source-config.xml"));
+ readDataSourceConfig(getDatasourceLocation() + "-mock" + DATASOURCE_EXT));
OperationManagementDAOFactory.init(datasource);
for (int i = 0; i < NO_OF_DEVICES; i++) {
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
@@ -216,13 +216,13 @@ public class OperationManagementNegativeDBOperationTest extends BaseDeviceManage
private void setMockDataSource() throws NoSuchFieldException, IllegalAccessException {
Field datasource = OperationManagementDAOFactory.class.getDeclaredField("dataSource");
datasource.setAccessible(true);
- this.dataSource = new MockDataSource();
+ this.dataSource = new MockDataSource(null);
datasource.set(datasource, this.dataSource);
}
@AfterClass
- public void resetDatabase() throws DeviceManagementException {
+ public void resetDatabase() throws Exception {
OperationManagementDAOFactory.init(this.getDataSource(this.
- readDataSourceConfig("src/test/resources/config/datasource/data-source-config.xml")));
+ readDataSourceConfig(getDatasourceLocation() + DATASOURCE_EXT)));
}
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java
index 3292b4960e..4bc7b45278 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/operation/OperationManagementNoDBSchemaTests.java
@@ -63,7 +63,7 @@ public class OperationManagementNoDBSchemaTests extends BaseDeviceManagementTest
@BeforeClass
public void init() throws Exception {
DataSource datasource = this.getDataSource(this.
- readDataSourceConfig("src/test/resources/config/datasource/no-table-data-source-config.xml"));
+ readDataSourceConfig(getDatasourceLocation() + "-no-table" + DATASOURCE_EXT));
OperationManagementDAOFactory.init(datasource);
for (int i = 0; i < NO_OF_DEVICES; i++) {
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
@@ -189,8 +189,8 @@ public class OperationManagementNoDBSchemaTests extends BaseDeviceManagementTest
}
@AfterClass
- public void resetDatabase() throws DeviceManagementException {
+ public void resetDatabase() throws Exception {
OperationManagementDAOFactory.init(this.getDataSource(this.
- readDataSourceConfig("src/test/resources/config/datasource/data-source-config.xml")));
+ readDataSourceConfig(getDatasourceLocation() + DATASOURCE_EXT)));
}
}
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 63fd3dbec0..badedd8d56 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
@@ -17,6 +17,7 @@ package org.wso2.carbon.device.mgt.core.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.mockito.Mock;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
@@ -41,6 +42,10 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDA
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
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.mock.MockConnection;
+import org.wso2.carbon.device.mgt.core.mock.MockDataSource;
+import org.wso2.carbon.device.mgt.core.mock.MockResultSet;
+import org.wso2.carbon.device.mgt.core.mock.MockStatement;
import org.wso2.carbon.registry.core.config.RegistryContext;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
@@ -52,17 +57,19 @@ import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.io.InputStream;
import java.lang.reflect.Field;
+import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
+import javax.sql.DataSource;
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
public static final String DEVICE_ID = "9999";
- public static final String ALTERNATE_DEVICE_ID = "1128";
+ private static final String ALTERNATE_DEVICE_ID = "1128";
private DeviceManagementProviderService providerService;
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
private DeviceDetailsDAO deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
@@ -98,13 +105,17 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test
public void testGetAvailableDeviceTypes() throws DeviceManagementException {
List deviceTypes = deviceMgtService.getDeviceTypes();
- Assert.assertTrue(deviceTypes.size() > 0);
+ if (!isMock()) {
+ Assert.assertTrue(deviceTypes.size() > 0);
+ }
}
@Test
public void testGetAvailableDeviceType() throws DeviceManagementException {
DeviceType deviceType = deviceMgtService.getDeviceType(DEVICE_TYPE);
- Assert.assertTrue(deviceType.getName().equalsIgnoreCase(DEVICE_TYPE));
+ if (!isMock()) {
+ Assert.assertTrue(deviceType.getName().equalsIgnoreCase(DEVICE_TYPE));
+ }
}
@Test
@@ -121,10 +132,36 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
}
@Test
- public void testSuccessfulDeviceEnrollment() throws DeviceManagementException {
+ public void testSuccessfulDeviceEnrollment() throws DeviceManagementException, NoSuchFieldException,
+ IllegalAccessException {
Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
- boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
- Assert.assertTrue(enrollmentStatus);
+ MockDataSource dataSource = null;
+ if (isMock()) {
+ Field datasourceField = DeviceManagementDAOFactory.class.getDeclaredField("dataSource");
+ datasourceField.setAccessible(true);
+ dataSource = (MockDataSource) getDataSource();
+ dataSource.setConnection(new MockConnection(dataSource.getUrl()));
+
+ MockConnection connection = new MockConnection(dataSource.getUrl());
+ dataSource.setConnection(connection);
+ MockStatement mockStatement = new MockStatement();
+ MockResultSet resultSet = new MockResultSet();
+ resultSet.addInteger(1);
+ resultSet.addString(null);
+
+ mockStatement.addResultSet(resultSet);
+ connection.addMockStatement(mockStatement);
+
+ datasourceField.set(datasourceField, dataSource);
+ }
+ try {
+ boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
+ Assert.assertTrue(enrollmentStatus);
+ } finally {
+ if (dataSource != null) {
+ dataSource.reset();
+ }
+ }
}
@Test(dependsOnMethods = "testSuccessfulDeviceEnrollment")
@@ -133,7 +170,9 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
deviceIdentifier.setId(DEVICE_ID);
deviceIdentifier.setType(DEVICE_TYPE);
boolean enrollmentStatus = deviceMgtService.isEnrolled(deviceIdentifier);
- Assert.assertTrue(enrollmentStatus);
+ if (!isMock()) {
+ Assert.assertTrue(enrollmentStatus);
+ }
}
@Test
@@ -160,43 +199,47 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testReEnrollmentofSameDeviceUnderSameUser() throws DeviceManagementException {
- Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
- boolean enrollment = deviceMgtService.enrollDevice(device);
- Assert.assertTrue(enrollment);
+ if (!isMock()) {
+ Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
+ boolean enrollment = deviceMgtService.enrollDevice(device);
+ Assert.assertTrue(enrollment);
+ }
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
public void testReEnrollmentofSameDeviceWithOtherUser() throws DeviceManagementException {
-
- EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
- enrolmentInfo.setDateOfEnrolment(new Date().getTime());
- enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
- enrolmentInfo.setOwner("user1");
- enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
- enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
-
- Device alternateDevice = TestDataHolder.generateDummyDeviceData(DEVICE_ID, DEVICE_TYPE,
- enrolmentInfo);
- Device retrievedDevice1 = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
- DEVICE_TYPE));
-
- deviceMgtService.enrollDevice(alternateDevice);
- Device retrievedDevice2 = deviceMgtService.getDevice(new DeviceIdentifier(alternateDevice
- .getDeviceIdentifier(), alternateDevice.getType()));
-
- Assert.assertFalse(retrievedDevice1.getEnrolmentInfo().getOwner().equalsIgnoreCase
- (retrievedDevice2.getEnrolmentInfo().getOwner()));
+ if (!isMock()) {
+ EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
+ enrolmentInfo.setDateOfEnrolment(new Date().getTime());
+ enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
+ enrolmentInfo.setOwner("user1");
+ enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
+ enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
+
+ Device alternateDevice = TestDataHolder.generateDummyDeviceData(DEVICE_ID, DEVICE_TYPE,
+ enrolmentInfo);
+ Device retrievedDevice1 = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
+ DEVICE_TYPE));
+
+ deviceMgtService.enrollDevice(alternateDevice);
+ Device retrievedDevice2 = deviceMgtService.getDevice(new DeviceIdentifier(alternateDevice
+ .getDeviceIdentifier(), alternateDevice.getType()));
+
+ Assert.assertFalse(retrievedDevice1.getEnrolmentInfo().getOwner().equalsIgnoreCase
+ (retrievedDevice2.getEnrolmentInfo().getOwner()));
+ }
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"})
public void testDisenrollment() throws DeviceManagementException {
- Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
- boolean disenrollmentStatus = deviceMgtService.disenrollDevice(new DeviceIdentifier
- (device.getDeviceIdentifier(), device.getType()));
- log.info(disenrollmentStatus);
-
- Assert.assertTrue(disenrollmentStatus);
+ if (!isMock()) {
+ Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
+ boolean disenrollmentStatus = deviceMgtService.disenrollDevice(new DeviceIdentifier
+ (device.getDeviceIdentifier(), device.getType()));
+ log.info(disenrollmentStatus);
+ Assert.assertTrue(disenrollmentStatus);
+ }
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"}, expectedExceptions =
@@ -225,23 +268,29 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testDisenrollment"})
public void testDisenrollAlreadyDisEnrolledDevice() throws DeviceManagementException {
- Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID,
- DEVICE_TYPE));
- boolean result = deviceMgtService.disenrollDevice(new DeviceIdentifier(
- device.getDeviceIdentifier(), device.getType()));
- Assert.assertTrue(result);
+ if (!isMock()) {
+ Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID,
+ DEVICE_TYPE));
+ boolean result = deviceMgtService.disenrollDevice(new DeviceIdentifier(
+ device.getDeviceIdentifier(), device.getType()));
+ Assert.assertTrue(result);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviceCount() throws DeviceManagementException {
int count = deviceMgtService.getDeviceCount();
- Assert.assertTrue(count > 0);
+ if (!isMock()) {
+ Assert.assertTrue(count > 0);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviceCountForUser() throws DeviceManagementException {
int count = deviceMgtService.getDeviceCount(TestDataHolder.OWNER);
- Assert.assertTrue(count > 0);
+ if (!isMock()) {
+ Assert.assertTrue(count > 0);
+ }
}
@Test
@@ -290,12 +339,16 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviceEnrolledTenants() throws DeviceManagementException {
List tenants = deviceMgtService.getDeviceEnrolledTenants();
- Assert.assertEquals(tenants.size(), 1);
+ if (!isMock()) {
+ Assert.assertEquals(tenants.size(), 1);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetDevice() throws DeviceManagementException {
+ public void testGetDevice() throws DeviceManagementException, NoSuchFieldException, IllegalAccessException {
+ MockDataSource dataSource = setDatasourceForGetDevice();
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(device.getDeviceIdentifier().equalsIgnoreCase(DEVICE_ID));
}
@@ -304,12 +357,17 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
public void testGetDeviceWithInfo() throws DeviceManagementException {
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE)
, true);
- Assert.assertTrue(device.getDeviceInfo() != null);
+ if (!isMock()) {
+ Assert.assertTrue(device.getDeviceInfo() != null);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetDeviceTypeWithProps() throws DeviceManagementException {
+ public void testGetDeviceTypeWithProps() throws DeviceManagementException, NoSuchFieldException,
+ IllegalAccessException {
+ MockDataSource dataSource = setDatasourceForGetDevice();
Device device = deviceMgtService.getDeviceWithTypeProperties(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(!device.getProperties().isEmpty());
}
@@ -317,12 +375,16 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
public void testGetDeviceWithOutInfo() throws DeviceManagementException {
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE)
, false);
- Assert.assertTrue(device.getDeviceInfo() == null);
+ if (!isMock()) {
+ Assert.assertTrue(device.getDeviceInfo() == null);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetAllDevicesOfRole() throws DeviceManagementException {
+ public void testGetAllDevicesOfRole() throws DeviceManagementException, NoSuchFieldException, IllegalAccessException {
+ MockDataSource dataSource = setDatasourceForGetDevice();
List devices = deviceMgtService.getAllDevicesOfRole("admin");
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(devices.size() > 0);
}
@@ -359,7 +421,9 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
public void testDeviceByOwner() throws DeviceManagementException {
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
DEVICE_TYPE), "admin", true);
- Assert.assertTrue(device != null);
+ if (!isMock()) {
+ Assert.assertTrue(device != null);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
@@ -377,26 +441,50 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testDeviceByDate() throws DeviceManagementException, TransactionManagementException, DeviceDetailsMgtDAOException {
+ public void testDeviceByDate() throws DeviceManagementException, TransactionManagementException,
+ DeviceDetailsMgtDAOException, NoSuchFieldException, IllegalAccessException {
+ MockDataSource dataSource = setDatasourceForGetDevice();
+ if (dataSource != null) {
+ setMockDeviceCount(dataSource.getConnection(0));
+ }
Device initialDevice = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
DEVICE_TYPE));
-
addDeviceInformation(initialDevice);
-
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
DEVICE_TYPE), yesterday());
- Assert.assertTrue(device != null);
+ cleanupMockDatasource(dataSource);
+ if (!isMock()) {
+ Assert.assertTrue(device != null);
+ }
+ }
+
+ private MockResultSet getMockGetDeviceResult() {
+ MockResultSet resultSet = new MockResultSet();
+ resultSet.addInteger(1);
+ resultSet.addString("Test");
+ resultSet.addString(null);
+ resultSet.addString(DEVICE_TYPE);
+ resultSet.addString(DEVICE_ID);
+ resultSet.addInteger(0);
+ resultSet.addString("admin");
+ resultSet.addString("BYOD");
+ resultSet.addTimestamp(new Timestamp(System.currentTimeMillis()));
+ resultSet.addTimestamp(new Timestamp(System.currentTimeMillis()));
+ resultSet.addString("ACTIVE");
+ return resultSet;
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testUpdateDeviceInfo() throws DeviceManagementException,
TransactionManagementException, DeviceDetailsMgtDAOException {
- Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
- DEVICE_TYPE));
+ if (!isMock()) {
+ Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
+ DEVICE_TYPE));
- boolean status = deviceMgtService.updateDeviceInfo(new DeviceIdentifier(DEVICE_ID,
- DEVICE_TYPE), device);
- Assert.assertTrue(status);
+ boolean status = deviceMgtService.updateDeviceInfo(new DeviceIdentifier(DEVICE_ID,
+ DEVICE_TYPE), device);
+ Assert.assertTrue(status);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
@@ -426,28 +514,64 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testDeviceByDate"})
public void testDeviceByDateAndOwner() throws DeviceManagementException {
- Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
- DEVICE_TYPE), "admin", yesterday(), true);
- Assert.assertTrue(device != null);
+ if (!isMock()) {
+ Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
+ DEVICE_TYPE), "admin", yesterday(), true);
+ Assert.assertTrue(device != null);
+ }
}
@Test
public void testGetAvaliableDeviceTypes() throws DeviceManagementException {
List deviceTypes = deviceMgtService.getAvailableDeviceTypes();
- Assert.assertTrue(!deviceTypes.isEmpty());
+ if (!isMock()) {
+ Assert.assertTrue(!deviceTypes.isEmpty());
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetAllDevices() throws DeviceManagementException {
+ public void testGetAllDevices() throws DeviceManagementException, NoSuchFieldException, IllegalAccessException {
+ MockDataSource dataSource = setDatasourceForGetDevice();
List devices = deviceMgtService.getAllDevices();
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(!devices.isEmpty());
}
+ private MockDataSource setDatasourceForGetDevice() throws IllegalAccessException, NoSuchFieldException {
+ MockDataSource dataSource = null;
+ if (isMock()) {
+ Field datasourceField = DeviceManagementDAOFactory.class.getDeclaredField("dataSource");
+ datasourceField.setAccessible(true);
+ dataSource = (MockDataSource) getDataSource();
+
+ //connection used for first get device operation.
+ MockConnection connection = new MockConnection(dataSource.getUrl());
+ dataSource.setConnection(connection);
+ MockStatement mockStatement = new MockStatement();
+ mockStatement.addResultSet(getMockGetDeviceResult());
+ connection.addMockStatement(mockStatement);
+
+ datasourceField.set(datasourceField, dataSource);
+ }
+ return dataSource;
+ }
+
+ private void cleanupMockDatasource(MockDataSource dataSource) {
+ if (isMock()) {
+ if (dataSource != null) {
+ dataSource.reset();
+ }
+ }
+ }
+
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetAllDevicesPaginated() throws DeviceManagementException {
+ public void testGetAllDevicesPaginated() throws DeviceManagementException, NoSuchFieldException,
+ IllegalAccessException {
PaginationRequest request = new PaginationRequest(0, 100);
request.setOwnerRole("admin");
+ MockDataSource dataSource = setDatasourceForGetDevice();
PaginationResult result = deviceMgtService.getAllDevices(request);
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(result.getRecordsTotal() > 0);
}
@@ -459,65 +583,92 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetAllDevicesByName() throws DeviceManagementException {
+ public void testGetAllDevicesByName() throws DeviceManagementException, NoSuchFieldException, IllegalAccessException {
PaginationRequest request = new PaginationRequest(0, 100);
request.setDeviceName(DEVICE_TYPE + "-" + DEVICE_ID);
+ MockDataSource dataSource = setDatasourceForGetDevice();
+ if (dataSource != null) {
+ setMockDeviceCount(dataSource.getConnection(0));
+ }
PaginationResult result = deviceMgtService.getDevicesByName(request);
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(result.getRecordsTotal() > 0);
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetAllDevicesByNameAndType() throws DeviceManagementException {
+ public void testGetAllDevicesByNameAndType() throws DeviceManagementException, NoSuchFieldException, IllegalAccessException {
PaginationRequest request = new PaginationRequest(0, 100);
request.setDeviceName(DEVICE_TYPE + "-" + DEVICE_ID);
request.setDeviceType(DEVICE_TYPE);
+ MockDataSource dataSource = setDatasourceForGetDevice();
List devices = deviceMgtService.getDevicesByNameAndType(request, true);
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(!devices.isEmpty());
}
@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 {
+ public void testGetAllDevicesByStatus() throws DeviceManagementException, NoSuchFieldException,
+ IllegalAccessException {
PaginationRequest request = new PaginationRequest(0, 100);
request.setStatus(EnrolmentInfo.Status.ACTIVE.toString());
+ MockDataSource dataSource = setDatasourceForGetDevice();
+ if (dataSource != null) {
+ setMockDeviceCount(dataSource.getConnection(0));
+ }
PaginationResult result = deviceMgtService.getDevicesByStatus(request, true);
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(result.getRecordsTotal() > 0);
}
+ private void setMockDeviceCount(MockConnection connection) {
+ MockStatement statement = new MockStatement();
+ connection.addMockStatement(statement);
+ MockResultSet resultSet = new MockResultSet();
+ resultSet.addInteger(1);
+ statement.addResultSet(resultSet);
+ }
+
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDevicesOfTypePaginated() throws DeviceManagementException {
- PaginationRequest request = new PaginationRequest(0, 100);
- request.setDeviceType(DEVICE_TYPE);
- PaginationResult result = deviceMgtService.getDevicesByType(request);
- Assert.assertTrue(result.getRecordsTotal() > 0);
+ if (!isMock()) {
+ PaginationRequest request = new PaginationRequest(0, 100);
+ request.setDeviceType(DEVICE_TYPE);
+ PaginationResult result = deviceMgtService.getDevicesByType(request);
+ Assert.assertTrue(result.getRecordsTotal() > 0);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetAllDevicesWithInfo() throws DeviceManagementException {
+ public void testGetAllDevicesWithInfo() throws DeviceManagementException, NoSuchFieldException,
+ IllegalAccessException {
+ MockDataSource dataSource = setDatasourceForGetDevice();
List devices = deviceMgtService.getAllDevices(true);
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(!devices.isEmpty());
Assert.assertTrue(devices.get(0).getDeviceInfo() != null);
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetAllDevicesWithInfoPaginated() throws DeviceManagementException {
+ public void testGetAllDevicesWithInfoPaginated() throws DeviceManagementException, NoSuchFieldException,
+ IllegalAccessException {
PaginationRequest request = new PaginationRequest(0, 100);
+ MockDataSource dataSource = setDatasourceForGetDevice();
+ if (dataSource != null) {
+ setMockDeviceCount(dataSource.getConnection(0));
+ }
PaginationResult result = deviceMgtService.getAllDevices(request, true);
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(result.getRecordsTotal() > 0);
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetTenantedDevice() throws DeviceManagementException {
- PaginationRequest request = new PaginationRequest(0, 100);
HashMap deviceMap = deviceMgtService.getTenantedDevice(new
DeviceIdentifier
(DEVICE_ID, DEVICE_TYPE));
- Assert.assertTrue(!deviceMap.isEmpty());
+ if (!isMock()) {
+ Assert.assertTrue(!deviceMap.isEmpty());
+ }
}
@Test
@@ -541,29 +692,42 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviesOfUserWhileUserNull() throws DeviceManagementException {
- List devices = deviceMgtService.getDevicesOfUser("admin");
- Assert.assertTrue(!devices.isEmpty());
+ if (!isMock()) {
+ List devices = deviceMgtService.getDevicesOfUser("admin");
+ Assert.assertTrue(!devices.isEmpty());
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDevieByStatus() throws DeviceManagementException {
- Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
- DEVICE_TYPE), EnrolmentInfo.Status.ACTIVE);
- Assert.assertTrue(device != null);
+ if (!isMock()) {
+ Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
+ DEVICE_TYPE), EnrolmentInfo.Status.ACTIVE);
+ Assert.assertTrue(device != null);
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDevieByDate() throws DeviceManagementException {
- List devices = deviceMgtService.getDevices(yesterday());
- Assert.assertTrue(!devices.isEmpty());
+ if (!isMock()) {
+ List devices = deviceMgtService.getDevices(yesterday());
+ Assert.assertTrue(!devices.isEmpty());
+ }
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetDeviesOfUserPaginated() throws DeviceManagementException {
+ 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 =
@@ -574,11 +738,18 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetDeviesByOwnership() throws DeviceManagementException {
+ 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"})
@@ -602,24 +773,34 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
- public void testGetDeviesByStatus() throws DeviceManagementException {
+ public void testGetDeviesByStatus() throws DeviceManagementException, NoSuchFieldException,
+ IllegalAccessException {
PaginationRequest request = new PaginationRequest(0, 100);
request.setStatus("ACTIVE");
+ MockDataSource dataSource = setDatasourceForGetDevice();
+ if (dataSource != null) {
+ setMockDeviceCount(dataSource.getConnection(0));
+ }
PaginationResult result = deviceMgtService.getDevicesByStatus(request);
+ cleanupMockDatasource(dataSource);
Assert.assertTrue(result.getRecordsTotal() > 0);
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
public void testUpdateDevicesStatus() throws DeviceManagementException {
- boolean status = deviceMgtService.setStatus("user1", EnrolmentInfo.Status.REMOVED);
- Assert.assertTrue(status);
+ if (!isMock()) {
+ boolean status = deviceMgtService.setStatus("user1", EnrolmentInfo.Status.REMOVED);
+ Assert.assertTrue(status);
+ }
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
public void testUpdateDevicesStatusWithDeviceID() throws DeviceManagementException {
- boolean status = deviceMgtService.setStatus(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE),"user1",
- EnrolmentInfo.Status.ACTIVE);
- Assert.assertTrue(status);
+ if (!isMock()) {
+ boolean status = deviceMgtService.setStatus(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE), "user1",
+ EnrolmentInfo.Status.ACTIVE);
+ Assert.assertTrue(status);
+ }
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
@@ -630,9 +811,11 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviesOfUserAndDeviceType() throws DeviceManagementException {
- List devices = deviceMgtService.getDevicesOfUser("admin", DEVICE_TYPE, true);
- Assert.assertTrue(!devices.isEmpty() && devices.get(0).getType().equalsIgnoreCase
- (DEVICE_TYPE) && devices.get(0).getDeviceInfo() != null);
+ if (!isMock()) {
+ List devices = deviceMgtService.getDevicesOfUser("admin", DEVICE_TYPE, true);
+ Assert.assertTrue(!devices.isEmpty() && devices.get(0).getType().equalsIgnoreCase
+ (DEVICE_TYPE) && devices.get(0).getDeviceInfo() != null);
+ }
}
@Test
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java
index c8ebdd37d2..ccaf84652e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceNegativeTest.java
@@ -42,7 +42,7 @@ public class GroupManagementProviderServiceNegativeTest extends BaseDeviceManage
@Override
public void init() throws Exception {
DataSource datasource = this.getDataSource(this.
- readDataSourceConfig("src/test/resources/config/datasource/no-table-data-source-config.xml"));
+ readDataSourceConfig(getDatasourceLocation() + "-no-table" + DATASOURCE_EXT));
GroupManagementDAOFactory.init(datasource);
groupManagementProviderService = new GroupManagementProviderServiceImpl();
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mock-data-source-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/data-source-config-mock.xml
similarity index 100%
rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mock-data-source-config.xml
rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/data-source-config-mock.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/no-table-data-source-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/data-source-config-no-table.xml
similarity index 100%
rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/no-table-data-source-config.xml
rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/data-source-config-no-table.xml
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config-mock.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config-mock.xml
new file mode 100644
index 0000000000..bdd1fca814
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config-mock.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config-no-table.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config-no-table.xml
new file mode 100644
index 0000000000..bdd1fca814
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config-no-table.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config.xml
new file mode 100644
index 0000000000..bdd1fca814
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mssql/data-source-config.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config-mock.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config-mock.xml
new file mode 100644
index 0000000000..e89ec94229
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config-mock.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:mysql://localhost/test
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config-no-table.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config-no-table.xml
new file mode 100644
index 0000000000..1f129e7e6e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config-no-table.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:mysql://localhost/noTableTest
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config.xml
new file mode 100644
index 0000000000..e89ec94229
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/mysql/data-source-config.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:mysql://localhost/test
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config-mock.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config-mock.xml
new file mode 100644
index 0000000000..badd2738f2
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config-mock.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:oracle:thin:@myhost:1521:orcl
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config-no-table.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config-no-table.xml
new file mode 100644
index 0000000000..f5ec80f750
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config-no-table.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:oracle:thin:@myhost:1521:orclt
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config.xml
new file mode 100644
index 0000000000..badd2738f2
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/oracle/data-source-config.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:oracle:thin:@myhost:1521:orcl
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config-mock.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config-mock.xml
new file mode 100644
index 0000000000..e89ec94229
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config-mock.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:mysql://localhost/test
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config-no-table.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config-no-table.xml
new file mode 100644
index 0000000000..1f129e7e6e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config-no-table.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:mysql://localhost/noTableTest
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config.xml
new file mode 100644
index 0000000000..acd82eb55f
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/datasource/postgre/data-source-config.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ jdbc:postgresql://localhost/test
+ org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver
+ wso2carbon
+ wso2carbon
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/mssql-testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/mssql-testng.xml
new file mode 100644
index 0000000000..5c1f4cbe4e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/mssql-testng.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/mysql-testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/mysql-testng.xml
new file mode 100644
index 0000000000..7b02276ea6
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/mysql-testng.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/oracle-testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/oracle-testng.xml
new file mode 100644
index 0000000000..cb41dfc620
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/oracle-testng.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/postgre-testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/postgre-testng.xml
new file mode 100644
index 0000000000..6c516bc74d
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/postgre-testng.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml
index 6b0ff32523..c0fd2360d2 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml
@@ -20,6 +20,8 @@
+
+
@@ -34,6 +36,7 @@
+