Adding integration tests and removing un-necessary imports

revert-70aa11f8
Ace 7 years ago
parent b6498af095
commit 57ab21f76d

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

@ -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<Feature> features = new ArrayList<Feature>();
List<Device.Property> properties = new ArrayList<Device.Property>();
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

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

Loading…
Cancel
Save