From 10a05b024f7ab7f90ab7a136292dec566afe3a9b Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 12 Dec 2014 19:55:41 +0530 Subject: [PATCH] Device DAO unit tests implementation --- .../device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 5 +++++ .../wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java | 4 ++-- .../device/mgt/core/dao/util/DeviceManagementDAOUtil.java | 2 +- .../java/org/wso2/carbon/device/mgt/core/dto/Device.java | 6 +++--- .../carbon/device/mgt/core/common/TestDBConfiguration.java | 1 + .../carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java | 5 ++++- .../src/test/resources/sql/CreateH2TestDB.sql | 4 ++-- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 76a49c8719..e839f54070 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -73,6 +73,11 @@ org.apache.maven.plugins maven-surefire-plugin 2.18 + + + src/test/resources/testng.xml + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 94bdc06042..a9e4df8c00 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -61,10 +61,10 @@ public class DeviceDAOImpl implements DeviceDAO { stmt.setLong(4, new Date().getTime()); stmt.setString(5, device.getOwnerShip()); stmt.setString(6, device.getStatus().toString()); - stmt.setString(7, device.getDeviceType()); + stmt.setInt(7, device.getDeviceType()); stmt.setString(8, device.getDeviceIdentificationId()); stmt.setString(9, device.getOwnerId()); - stmt.setInt(10, DeviceManagementDAOUtil.getTenantId()); + stmt.setInt(10, device.getTenantId()); stmt.executeUpdate(); } catch (SQLException e) { String msg = "Error occurred while enrolling device '" + device.getName() + "'"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index b15f94d233..b71aaeaa15 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -113,7 +113,7 @@ public final class DeviceManagementDAOUtil { deviceBO.setOwnerId(device.getOwner()); deviceBO.setOwnerShip(device.getOwnership()); deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId()); - deviceBO.setDeviceType(device.getType()); + deviceBO.setDeviceType(Integer.parseInt(device.getType())); return deviceBO; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java index 8adbd5ff77..21c951cfae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java @@ -33,13 +33,13 @@ public class Device implements Serializable { private String ownerId; private String ownerShip; private int tenantId; - private String deviceType; + private Integer deviceType; - public String getDeviceType() { + public Integer getDeviceType() { return deviceType; } - public void setDeviceType(String deviceType) { + public void setDeviceType(Integer deviceType) { this.deviceType = deviceType; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java index 3b8dd365c1..9689cd2621 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/common/TestDBConfiguration.java @@ -47,6 +47,7 @@ public class TestDBConfiguration { public void setConnectionUrl(String connectionUrl) { this.connectionUrl = connectionUrl; } + @XmlElement(name = "driverclass", nillable = false) public String getDriverClass() { return driverClass; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java index 1616fc6eea..116a24907f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceMgtDAOTestSuite.java @@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.core.common.TestDBConfiguration; import org.wso2.carbon.device.mgt.core.common.TestDBConfigurations; import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.core.dto.OwnerShip; import org.wso2.carbon.device.mgt.core.dto.Status; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; @@ -146,8 +147,10 @@ public class DeviceMgtDAOTestSuite { device.setDescription("test description"); device.setStatus(Status.ACTIVE); device.setDeviceIdentificationId("111"); - device.setDeviceType(devType.getId().toString()); + device.setDeviceType(devType.getId().intValue()); + device.setOwnerShip(OwnerShip.BYOD.toString()); device.setOwnerId("111"); + device.setTenantId(-1234); deviceMgtDAO.addDevice(device); Long deviceId = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 0733f55520..afcd19ca06 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -10,8 +10,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ID INT auto_increment NOT NULL, DESCRIPTION TEXT NULL DEFAULT NULL, NAME VARCHAR(100) NULL DEFAULT NULL, - DATE_OF_ENROLLMENT INTEGER NULL DEFAULT NULL, - DATE_OF_LAST_UPDATE INTEGER NULL DEFAULT NULL, + DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL, + DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL, OWNERSHIP VARCHAR(45) NULL DEFAULT NULL, STATUS VARCHAR(15) NULL DEFAULT NULL, DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL,