From 57ab21f76d4220a29d91419411f1f6bd394b74ba Mon Sep 17 00:00:00 2001 From: Ace Date: Fri, 13 Oct 2017 06:55:33 +0530 Subject: [PATCH] Adding integration tests and removing un-necessary imports --- .../mgt/core/dao/impl/EnrollmentDAOImpl.java | 11 +++-- .../device/mgt/core/TestDeviceManager.java | 13 +++++- .../DeviceManagementProviderServiceTest.java | 40 +++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java index 619201e567..b7a4086d0e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java @@ -18,24 +18,23 @@ */ package org.wso2.carbon.device.mgt.core.dao.impl; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.Date; import java.util.List; public class EnrollmentDAOImpl implements EnrollmentDAO { - private static final Log log = LogFactory.getLog(EnrollmentDAOImpl.class); - @Override public int addEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId) throws DeviceManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java index 010b47b8d0..e30edc3f48 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -20,6 +20,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import java.util.ArrayList; import java.util.List; public class TestDeviceManager implements DeviceManager { @@ -80,7 +81,15 @@ public class TestDeviceManager implements DeviceManager { @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return null; + List features = new ArrayList(); + List properties = new ArrayList(); + Device.Property prop1 = new Device.Property(); + prop1.setName("Prop1"); + prop1.setValue("Prop1-value"); + properties.add(prop1); + Device device = new Device(deviceId.getType()+"-"+deviceId.getId(), deviceId.getType(), + "This is a test Device", deviceId.getId(), null, features, properties); + return device; } @Override @@ -92,7 +101,7 @@ public class TestDeviceManager implements DeviceManager { @Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - return false; + return true; } @Override 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 99c0fd3f23..64efeb76a4 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 @@ -101,6 +101,20 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes Assert.assertTrue(deviceTypes.size() > 0); } + @Test + public void testGetAvailableDeviceType() throws DeviceManagementException { + DeviceType deviceType = deviceMgtService.getDeviceType(DEVICE_TYPE); + Assert.assertTrue(deviceType.getName().equalsIgnoreCase(DEVICE_TYPE)); + } + + @Test + public void addLicense() throws DeviceManagementException { + License license = new License(); + license.setLanguage("ENG"); + license.setName("RANDON_DEVICE_LICENSE"); + deviceMgtService.addLicense(DEVICE_TYPE, license); + } + @Test(expectedExceptions = DeviceManagementException.class) public void testNullDeviceEnrollment() throws DeviceManagementException { deviceMgtService.enrollDevice(null); @@ -293,6 +307,12 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes Assert.assertTrue(device.getDeviceInfo() != null); } + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) + public void testGetDeviceTypeWithProps() throws DeviceManagementException { + Device device = deviceMgtService.getDeviceWithTypeProperties(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE)); + Assert.assertTrue(!device.getProperties().isEmpty()); + } + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) public void testGetDeviceWithOutInfo() throws DeviceManagementException { Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE) @@ -544,6 +564,26 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes Assert.assertTrue(result.getRecordsTotal() > 0); } + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) + public void testSetOwnership() throws DeviceManagementException { + boolean status = deviceMgtService.setOwnership(new DeviceIdentifier(DEVICE_ID, + DEVICE_TYPE), EnrolmentInfo.OwnerShip.COPE.toString()); + Assert.assertTrue(status); + } + + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) + public void testSetOwnershipNonExistentDT() throws DeviceManagementException { + boolean status = deviceMgtService.setOwnership(new DeviceIdentifier(DEVICE_ID, + "non-existent-dt"), EnrolmentInfo.OwnerShip.COPE.toString()); + Assert.assertFalse(status); + } + + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions = + DeviceManagementException.class) + public void testSetOwnershipOfNullDevice() throws DeviceManagementException { + deviceMgtService.setOwnership(null, EnrolmentInfo.OwnerShip.COPE.toString()); + } + @Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}) public void testGetDeviesByStatus() throws DeviceManagementException { PaginationRequest request = new PaginationRequest(0, 100);