From bed56a60db795848a20ee2c3ed6f28553c023c83 Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 28 Sep 2017 17:41:34 +0530 Subject: [PATCH] Adding Integration tests for core and fixing bugs --- .../core/dao/impl/AbstractDeviceDAOImpl.java | 9 ++- .../DeviceManagementProviderServiceTest.java | 62 +++++++++---------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index decb956f1e..75c7ac7340 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -122,7 +122,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " + "t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " + "t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " + - "AND TENANT_ID = ? ORDER BY e.DATE_OF_LAST_UPDATE DESC"; + "AND TENANT_ID = ? ORDER BY e.DATE_OF_LAST_UPDATE DESC, e.STATUS ASC"; + // Status adeed as an orderby clause to fix a bug : when an existing device is + // re-enrolled, earlier enrollment is marked as removed and a new enrollment is added. + // However, both enrollments share the same time stamp. When retrieving the device + // due to same timestamp, enrollment information is incorrect, intermittently. Hence + // status also should be taken into consideration when ordering. This should not present a + // problem for other status transitions, as there would be an intermediary 'removed' + // state in between. stmt = conn.prepareStatement(sql); stmt.setString(1, deviceIdentifier.getType()); stmt.setString(2, deviceIdentifier.getId()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java index 144a3a4e6b..c70fe720a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java @@ -125,39 +125,39 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes } } -// @Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"}) -// public void testReEnrollmentofSameDeviceWithOtherUser() { -// -// EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); -// enrolmentInfo.setDateOfEnrolment(new Date().getTime()); -// enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); -// enrolmentInfo.setOwner("user1"); -// enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); -// enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED); -// -// Device alternateDevice = TestDataHolder.generateDummyDeviceData("12345", DEVICE_TYPE, -// enrolmentInfo); -// -// try { -// Device retrievedDevice1 = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE)); -// -// deviceMgtService.enrollDevice(alternateDevice); -// Device retrievedDevice2 = deviceMgtService.getDevice(new DeviceIdentifier(alternateDevice -// .getDeviceIdentifier(), alternateDevice.getType())); -// -// log.info(retrievedDevice1.getEnrolmentInfo().getOwner()); -// log.info(retrievedDevice2.getEnrolmentInfo().getOwner()); -// -// Assert.assertFalse(retrievedDevice1.getEnrolmentInfo().getOwner().equalsIgnoreCase -// (retrievedDevice2.getEnrolmentInfo().getOwner())); -// } catch (DeviceManagementException e) { -// String msg = "Error Occured while enrolling device"; -// Assert.fail(msg, e); -// } -// } + @Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"}) + public void testReEnrollmentofSameDeviceWithOtherUser() { + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); + enrolmentInfo.setDateOfEnrolment(new Date().getTime()); + enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); + enrolmentInfo.setOwner("user1"); + enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); + enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED); - @Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"}) + Device alternateDevice = TestDataHolder.generateDummyDeviceData("12345", DEVICE_TYPE, + enrolmentInfo); + + try { + Device retrievedDevice1 = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE)); + + deviceMgtService.enrollDevice(alternateDevice); + Device retrievedDevice2 = deviceMgtService.getDevice(new DeviceIdentifier(alternateDevice + .getDeviceIdentifier(), alternateDevice.getType())); + + log.info(retrievedDevice1.getEnrolmentInfo().getOwner()); + log.info(retrievedDevice2.getEnrolmentInfo().getOwner()); + + Assert.assertFalse(retrievedDevice1.getEnrolmentInfo().getOwner().equalsIgnoreCase + (retrievedDevice2.getEnrolmentInfo().getOwner())); + } catch (DeviceManagementException e) { + String msg = "Error Occured while enrolling device"; + Assert.fail(msg, e); + } + } + + + @Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"}) public void testDisenrollment() { Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);