Merge pull request #1075 from sinthuja/origin-wso2-master

Adding mock datasources to cover the source from different databases.
revert-70aa11f8
Megala Uthayakumar 7 years ago committed by GitHub
commit 76938fc44d

@ -139,7 +139,11 @@
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
<file>src/test/resources/testng.xml</file>
<file>src/test/resources/mysql-testng.xml</file>
<file>src/test/resources/mssql-testng.xml</file>
<file>src/test/resources/oracle-testng.xml</file>
<file>src/test/resources/postgre-testng.xml</file>
</suiteXmlFiles>
</configuration>
</plugin>

@ -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<Device> 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<Device> 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<Device> 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<Device> 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<EnrolmentInfo> getEnrolmentsByStatus(List<DeviceIdentifier> deviceIds, Status status,
int tenantId) throws DeviceManagementDAOException;
List<Integer> getDeviceEnrolledTenants() throws DeviceManagementDAOException;
}

@ -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<EnrolmentInfo> getEnrolmentsByStatus(List<DeviceIdentifier> deviceIds, Status status,
int tenantId) throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<EnrolmentInfo> 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<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId)
throws DeviceManagementDAOException {
Connection conn;

@ -153,41 +153,6 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
return devices;
}
@Override
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Device> 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<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {

@ -159,42 +159,6 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
return devices;
}
@Override
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Device> 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<Device> 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();
}

@ -140,41 +140,6 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
return devices;
}
@Override
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Device> 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<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {

@ -156,42 +156,6 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
return devices;
}
@Override
public List<Device> getDevicesByType(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Device> 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<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
throws DeviceManagementDAOException {

@ -254,9 +254,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
DeviceManagementDAOFactory.beginTransaction();
DeviceType type = deviceTypeDAO.getDeviceType(device.getType(), tenantId);
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() +

@ -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) {
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;
}
}

@ -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;
}

@ -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 {

@ -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,10 +202,12 @@ public class DevicePersistTests extends BaseDeviceManagementTest {
log.error(msg, e);
Assert.fail(msg, e);
}
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)
throws DeviceManagementDAOException {

@ -85,5 +85,4 @@ public class EnrolmentPersistenceTests extends BaseDeviceManagementTest {
public void init() throws Exception {
this.initDataSource();
}
}

@ -70,9 +70,11 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
Assert.fail(msg, e);
}
DeviceGroup group = getGroupById(groupId);
if (!isMock()) {
Assert.assertNotNull(group, "Group is null");
log.debug("Group name: " + group.getName());
}
}
@Test(dependsOnMethods = {"addGroupTest"})
public void getGroupTest() {
@ -83,9 +85,11 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
request.setOwner(null);
List<DeviceGroup> groups = groupDAO.getGroups(request, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
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<String> roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
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<String> roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
if (!isMock()) {
roles.remove(0);
}
List<DeviceGroup> deviceGroups = groupDAO.getGroups(roles.toArray(new String[roles.size()]), TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
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<String> roles = groupDAO.getRoles(groupId, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
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<Device> groupedDevices = groupDAO.getDevices(deviceGroup.getGroupId(), 0, 10, TestDataHolder.SUPER_TENANT_ID);
GroupManagementDAOFactory.closeConnection();
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,12 +286,13 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
log.error(msg, e);
Assert.fail(msg, e);
}
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"})
public void deleteGroupTest() {
@ -302,14 +317,20 @@ public class GroupPersistTests extends BaseDeviceManagementTest {
Assert.fail(msg, e);
}
group = getGroupById(groupId);
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);
GroupManagementDAOFactory.closeConnection();
if (deviceGroup == null && isMock()) {
deviceGroup = new DeviceGroup();
deviceGroup.setGroupId(groupId);
}
return deviceGroup;
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.closeConnection();

@ -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<MockStatement> 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);
}
}

@ -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<Connection> 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) {
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;
}
private void setConnection(Connection connection) {
this.connection = connection;
public void setConnection(Connection connection) {
this.connections.add(connection);
}
public String getUrl() {
return this.url;
}
public MockConnection getConnection(int id) {
return (MockConnection) this.connections.get(id);
}
}

@ -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> T unwrap(Class<T> iface) throws SQLException {
return null;
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
}
}

@ -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

@ -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<MockResultSet> 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);
}
}

@ -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)));
}
}

@ -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)));
}
}

@ -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,14 +105,18 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test
public void testGetAvailableDeviceTypes() throws DeviceManagementException {
List<DeviceType> deviceTypes = deviceMgtService.getDeviceTypes();
if (!isMock()) {
Assert.assertTrue(deviceTypes.size() > 0);
}
}
@Test
public void testGetAvailableDeviceType() throws DeviceManagementException {
DeviceType deviceType = deviceMgtService.getDeviceType(DEVICE_TYPE);
if (!isMock()) {
Assert.assertTrue(deviceType.getName().equalsIgnoreCase(DEVICE_TYPE));
}
}
@Test
public void addLicense() throws DeviceManagementException {
@ -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));
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,8 +170,10 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
deviceIdentifier.setId(DEVICE_ID);
deviceIdentifier.setType(DEVICE_TYPE);
boolean enrollmentStatus = deviceMgtService.isEnrolled(deviceIdentifier);
if (!isMock()) {
Assert.assertTrue(enrollmentStatus);
}
}
@Test
public void testIsEnrolledForNonExistingDevice() throws DeviceManagementException {
@ -160,14 +199,16 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testReEnrollmentofSameDeviceUnderSameUser() throws DeviceManagementException {
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 {
if (!isMock()) {
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
@ -187,17 +228,19 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
Assert.assertFalse(retrievedDevice1.getEnrolmentInfo().getOwner().equalsIgnoreCase
(retrievedDevice2.getEnrolmentInfo().getOwner()));
}
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"})
public void testDisenrollment() throws DeviceManagementException {
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 =
DeviceManagementException.class)
@ -225,24 +268,30 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testDisenrollment"})
public void testDisenrollAlreadyDisEnrolledDevice() throws DeviceManagementException {
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();
if (!isMock()) {
Assert.assertTrue(count > 0);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviceCountForUser() throws DeviceManagementException {
int count = deviceMgtService.getDeviceCount(TestDataHolder.OWNER);
if (!isMock()) {
Assert.assertTrue(count > 0);
}
}
@Test
public void testGetDeviceCountForNonExistingUser() throws DeviceManagementException {
@ -290,12 +339,16 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviceEnrolledTenants() throws DeviceManagementException {
List<Integer> tenants = deviceMgtService.getDeviceEnrolledTenants();
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);
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);
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<Device> devices = deviceMgtService.getAllDevicesOfRole("admin");
cleanupMockDatasource(dataSource);
Assert.assertTrue(devices.size() > 0);
}
@ -359,8 +421,10 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
public void testDeviceByOwner() throws DeviceManagementException {
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
DEVICE_TYPE), "admin", true);
if (!isMock()) {
Assert.assertTrue(device != null);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testDeviceByOwnerAndNonExistentDeviceID() throws DeviceManagementException {
@ -377,20 +441,43 @@ 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());
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 {
if (!isMock()) {
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
DEVICE_TYPE));
@ -398,6 +485,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
DEVICE_TYPE), device);
Assert.assertTrue(status);
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testDeviceByDateWithNonExistentDevice() throws DeviceManagementException,
@ -426,28 +514,64 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testDeviceByDate"})
public void testDeviceByDateAndOwner() throws DeviceManagementException {
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<String> deviceTypes = deviceMgtService.getAvailableDeviceTypes();
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<Device> 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,66 +583,93 @@ 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<Device> devices = deviceMgtService.getDevicesByNameAndType(request, true);
cleanupMockDatasource(dataSource);
Assert.assertTrue(!devices.isEmpty());
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetAllDevicesByStatus() throws DeviceManagementException {
List<Device> 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 {
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<Device> 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<Integer, Device> deviceMap = deviceMgtService.getTenantedDevice(new
DeviceIdentifier
(DEVICE_ID, DEVICE_TYPE));
if (!isMock()) {
Assert.assertTrue(!deviceMap.isEmpty());
}
}
@Test
public void testGetLicense() throws DeviceManagementException {
@ -541,29 +692,42 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviesOfUserWhileUserNull() throws DeviceManagementException {
if (!isMock()) {
List<Device> devices = deviceMgtService.getDevicesOfUser("admin");
Assert.assertTrue(!devices.isEmpty());
}
}
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDevieByStatus() throws DeviceManagementException {
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 {
if (!isMock()) {
List<Device> 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,25 +773,35 @@ 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 {
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",
if (!isMock()) {
boolean status = deviceMgtService.setStatus(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE), "user1",
EnrolmentInfo.Status.ACTIVE);
Assert.assertTrue(status);
}
}
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
public void testUpdateDevicesStatusOfNonExistingUser() throws DeviceManagementException {
@ -630,10 +811,12 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testGetDeviesOfUserAndDeviceType() throws DeviceManagementException {
if (!isMock()) {
List<Device> devices = deviceMgtService.getDevicesOfUser("admin", DEVICE_TYPE, true);
Assert.assertTrue(!devices.isEmpty() && devices.get(0).getType().equalsIgnoreCase
(DEVICE_TYPE) && devices.get(0).getDeviceInfo() != null);
}
}
@Test
public void testSendRegistrationEmailSuccessFlow() throws ConfigurationManagementException, DeviceManagementException {

@ -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();
}

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:mysql://localhost/test</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:mysql://localhost/noTableTest</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:mysql://localhost/test</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:oracle:thin:@myhost:1521:orcl</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:oracle:thin:@myhost:1521:orclt</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:oracle:thin:@myhost:1521:orcl</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:mysql://localhost/test</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:mysql://localhost/noTableTest</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<DataSourceConfig>
<Url>jdbc:postgresql://localhost/test</Url>
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
<!-- For MySql -->
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
<!--<User>root</User>-->
<!--<Password></Password>-->
</DataSourceConfig>

@ -0,0 +1,62 @@
<!--
~ 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.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MSSQLDeviceManagementCore">
<parameter name="useDefaultListeners" value="false"/>
<parameter name="datasource" value="src/test/resources/config/datasource/mssql/data-source-config"/>
<parameter name="isMock" value="true"/>
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="MySql"/>
<classes>
<class name="org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.DevicePersistTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
<class name="org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceTests"/>
<class name="org.wso2.carbon.device.mgt.core.search.DeviceDetails"/>
<class name="org.wso2.carbon.device.mgt.core.dao.GroupPersistTests"/>
</classes>
</test>
<!--TODO: Uncomment below once the tests are passing-->
<test name="Service Unit Tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
<!--<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNoDBSchemaTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNegativeDBOperationTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.ScheduledTaskOperationTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImplTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.push.notification.mgt.task.PushNotificationSchedulerTaskTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchManagementServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.ProcessorImplTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchMgtUtilTest"/>-->
</classes>
</test>
</suite>

@ -0,0 +1,62 @@
<!--
~ 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.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MySQLDeviceManagementCore">
<parameter name="useDefaultListeners" value="false"/>
<parameter name="datasource" value="src/test/resources/config/datasource/mysql/data-source-config"/>
<parameter name="isMock" value="true"/>
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="MySql"/>
<classes>
<class name="org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.DevicePersistTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
<class name="org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceTests"/>
<class name="org.wso2.carbon.device.mgt.core.search.DeviceDetails"/>
<class name="org.wso2.carbon.device.mgt.core.dao.GroupPersistTests"/>
</classes>
</test>
<!--TODO: Uncomment below once the tests are passing-->
<test name="Service Unit Tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
<!--<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNoDBSchemaTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNegativeDBOperationTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.ScheduledTaskOperationTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImplTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.push.notification.mgt.task.PushNotificationSchedulerTaskTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchManagementServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.ProcessorImplTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchMgtUtilTest"/>-->
</classes>
</test>
</suite>

@ -0,0 +1,62 @@
<!--
~ 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.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="OracleLDeviceManagementCore">
<parameter name="useDefaultListeners" value="false"/>
<parameter name="datasource" value="src/test/resources/config/datasource/oracle/data-source-config"/>
<parameter name="isMock" value="true"/>
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="MySql"/>
<classes>
<class name="org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.DevicePersistTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
<class name="org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceTests"/>
<class name="org.wso2.carbon.device.mgt.core.search.DeviceDetails"/>
<class name="org.wso2.carbon.device.mgt.core.dao.GroupPersistTests"/>
</classes>
</test>
<!--TODO: Uncomment below once the tests are passing-->
<test name="Service Unit Tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
<!--<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNoDBSchemaTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNegativeDBOperationTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.ScheduledTaskOperationTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImplTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.push.notification.mgt.task.PushNotificationSchedulerTaskTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchManagementServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.ProcessorImplTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchMgtUtilTest"/>-->
</classes>
</test>
</suite>

@ -0,0 +1,62 @@
<!--
~ 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.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="PostGreDeviceManagementCore">
<parameter name="useDefaultListeners" value="false"/>
<parameter name="datasource" value="src/test/resources/config/datasource/postgre/data-source-config"/>
<parameter name="isMock" value="true"/>
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="MySql"/>
<classes>
<class name="org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.DevicePersistTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
<class name="org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceTests"/>
<class name="org.wso2.carbon.device.mgt.core.search.DeviceDetails"/>
<class name="org.wso2.carbon.device.mgt.core.dao.GroupPersistTests"/>
</classes>
</test>
<!--TODO: Uncomment below once the tests are passing-->
<test name="Service Unit Tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
<!--<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNoDBSchemaTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementNegativeDBOperationTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.operation.ScheduledTaskOperationTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.permission.mgt.PermissionManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImplTests"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.push.notification.mgt.task.PushNotificationSchedulerTaskTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchManagementServiceTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.ProcessorImplTest"/>-->
<!--<class name="org.wso2.carbon.device.mgt.core.search.SearchMgtUtilTest"/>-->
</classes>
</test>
</suite>

@ -20,6 +20,8 @@
<suite name="DeviceManagementCore">
<parameter name="useDefaultListeners" value="false"/>
<parameter name="datasource" value="src/test/resources/config/datasource/data-source-config"/>
<parameter name="isMock" value="false"/>
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="MySql"/>
@ -34,6 +36,7 @@
<class name="org.wso2.carbon.device.mgt.core.dao.GroupPersistTests"/>
</classes>
</test>
<test name="Service Unit Tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>

Loading…
Cancel
Save