|
|
|
@ -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.Mockito;
|
|
|
|
|
import org.testng.Assert;
|
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
@ -45,10 +46,12 @@ import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
|
|
|
|
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
|
|
|
|
|
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
|
|
|
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
import org.wso2.carbon.user.core.service.RealmService;
|
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -98,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);
|
|
|
|
@ -176,14 +193,45 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
public void testDisenrollment() throws DeviceManagementException {
|
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
|
|
|
|
|
boolean disenrollmentStatus = deviceMgtService.disenrollDevice(new DeviceIdentifier
|
|
|
|
|
(device
|
|
|
|
|
.getDeviceIdentifier(),
|
|
|
|
|
device.getType()));
|
|
|
|
|
(device.getDeviceIdentifier(), device.getType()));
|
|
|
|
|
log.info(disenrollmentStatus);
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(disenrollmentStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testDisenrollmentWithNullDeviceID() throws DeviceManagementException {
|
|
|
|
|
deviceMgtService.disenrollDevice(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"})
|
|
|
|
|
public void testDisenrollmentWithNonExistentDT() throws DeviceManagementException {
|
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID,
|
|
|
|
|
"NON_EXISTENT_DT"));
|
|
|
|
|
boolean result = deviceMgtService.disenrollDevice(new DeviceIdentifier(
|
|
|
|
|
device.getDeviceIdentifier(), device.getType()));
|
|
|
|
|
Assert.assertTrue(!result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceWithOtherUser"})
|
|
|
|
|
public void testDisenrollmentWithNonExistentDevice() throws DeviceManagementException {
|
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(ALTERNATE_DEVICE_ID,
|
|
|
|
|
DEVICE_TYPE));
|
|
|
|
|
boolean result = deviceMgtService.disenrollDevice(new DeviceIdentifier(
|
|
|
|
|
device.getDeviceIdentifier(), device.getType()));
|
|
|
|
|
Assert.assertTrue(!result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testDisenrollment"})
|
|
|
|
|
public void testDisenrollAlreadyDisEnrolledDevice() throws DeviceManagementException {
|
|
|
|
|
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();
|
|
|
|
@ -259,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)
|
|
|
|
@ -272,6 +326,35 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
Assert.assertTrue(devices.size() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testGetAllDevicesOfRoleFailureFlow() throws DeviceManagementException, UserStoreException, NoSuchFieldException, IllegalAccessException {
|
|
|
|
|
int tenantID = -1234;
|
|
|
|
|
RealmService mockRealmService = Mockito.mock(RealmService.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
|
|
|
|
|
|
Mockito.doThrow(new UserStoreException("Mocked Exception when obtaining Tenant Realm"))
|
|
|
|
|
.when(mockRealmService).getTenantUserRealm(tenantID);
|
|
|
|
|
RealmService currentRealm = DeviceManagementDataHolder.getInstance().getRealmService();
|
|
|
|
|
DeviceManagementDataHolder.getInstance().setRealmService(mockRealmService);
|
|
|
|
|
try {
|
|
|
|
|
deviceMgtService.getAllDevicesOfRole("admin");
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDataHolder.getInstance().setRealmService(currentRealm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetAllDevicesOfRoleWithNonExistentRole() throws DeviceManagementException {
|
|
|
|
|
List<Device> devices = deviceMgtService.getAllDevicesOfRole("non-existent-role");
|
|
|
|
|
Assert.assertTrue(devices.size() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testGetAllDevicesOfRoleWithNullArgs() throws DeviceManagementException {
|
|
|
|
|
deviceMgtService.getAllDevicesOfRole(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testDeviceByOwner() throws DeviceManagementException {
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
|
|
|
|
@ -279,11 +362,47 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
Assert.assertTrue(device != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testDeviceByOwnerAndNonExistentDeviceID() throws DeviceManagementException {
|
|
|
|
|
String nonExistentDeviceID = "4455";
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier(nonExistentDeviceID,
|
|
|
|
|
DEVICE_TYPE), "admin", true);
|
|
|
|
|
Assert.assertTrue(device == null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testDeviceByOwnerWithNullDeviceID() throws DeviceManagementException {
|
|
|
|
|
deviceMgtService.getDevice(null, "admin", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testDeviceByDate() throws DeviceManagementException, TransactionManagementException, DeviceDetailsMgtDAOException {
|
|
|
|
|
Device initialDevice = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
|
|
|
|
|
DEVICE_TYPE));
|
|
|
|
|
|
|
|
|
|
addDeviceInformation(initialDevice);
|
|
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
|
|
|
|
|
DEVICE_TYPE), yesterday());
|
|
|
|
|
Assert.assertTrue(device != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testDeviceByDateWithNonExistentDevice() throws DeviceManagementException,
|
|
|
|
|
TransactionManagementException, DeviceDetailsMgtDAOException {
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier(ALTERNATE_DEVICE_ID,
|
|
|
|
|
DEVICE_TYPE), yesterday());
|
|
|
|
|
Assert.assertTrue(device == null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testDeviceByDateWithNullDeviceID() throws DeviceManagementException {
|
|
|
|
|
deviceMgtService.getDevice(null, yesterday());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addDeviceInformation(Device initialDevice) throws TransactionManagementException, DeviceDetailsMgtDAOException {
|
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
//Device details table will be reffered when looking for last updated time
|
|
|
|
@ -292,10 +411,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
.generateDummyDeviceInfo());
|
|
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier(DEVICE_ID,
|
|
|
|
|
DEVICE_TYPE), yesterday());
|
|
|
|
|
Assert.assertTrue(device != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testDeviceByDate"})
|
|
|
|
@ -320,10 +435,18 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetAllDevicesPaginated() throws DeviceManagementException {
|
|
|
|
|
PaginationRequest request = new PaginationRequest(0, 100);
|
|
|
|
|
request.setOwnerRole("admin");
|
|
|
|
|
PaginationResult result = deviceMgtService.getAllDevices(request);
|
|
|
|
|
Assert.assertTrue(result.getRecordsTotal() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testGetAllDevicesWithNullRequest() throws DeviceManagementException {
|
|
|
|
|
PaginationRequest request = null;
|
|
|
|
|
deviceMgtService.getAllDevices(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetAllDevicesByName() throws DeviceManagementException {
|
|
|
|
|
PaginationRequest request = new PaginationRequest(0, 100);
|
|
|
|
@ -392,8 +515,15 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
Assert.assertTrue(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testGetDeviesOfUser() throws DeviceManagementException {
|
|
|
|
|
String username = null;
|
|
|
|
|
deviceMgtService.getDevicesOfUser(username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetDeviesOfUserWhileUserNull() throws DeviceManagementException {
|
|
|
|
|
List<Device> devices = deviceMgtService.getDevicesOfUser("admin");
|
|
|
|
|
Assert.assertTrue(!devices.isEmpty());
|
|
|
|
|
}
|
|
|
|
@ -419,6 +549,13 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
Assert.assertTrue(result.getRecordsTotal() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"}, expectedExceptions =
|
|
|
|
|
DeviceManagementException.class)
|
|
|
|
|
public void testGetDeviesOfUserWhileNullOwnerPaginated() throws DeviceManagementException {
|
|
|
|
|
PaginationRequest request = null;
|
|
|
|
|
deviceMgtService.getDevicesOfUser(request, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetDeviesByOwnership() throws DeviceManagementException {
|
|
|
|
|
PaginationRequest request = new PaginationRequest(0, 100);
|
|
|
|
@ -427,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);
|
|
|
|
@ -435,6 +592,25 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
Assert.assertTrue(result.getRecordsTotal() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
|
|
|
|
|
public void testUpdateDevicesStatus() throws DeviceManagementException {
|
|
|
|
|
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",
|
|
|
|
|
EnrolmentInfo.Status.ACTIVE);
|
|
|
|
|
Assert.assertTrue(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
|
|
|
|
|
public void testUpdateDevicesStatusOfNonExistingUser() throws DeviceManagementException {
|
|
|
|
|
boolean status = deviceMgtService.setStatus("random-user", EnrolmentInfo.Status.REMOVED);
|
|
|
|
|
Assert.assertFalse(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetDeviesOfUserAndDeviceType() throws DeviceManagementException {
|
|
|
|
|
List<Device> devices = deviceMgtService.getDevicesOfUser("admin", DEVICE_TYPE, true);
|
|
|
|
@ -451,7 +627,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
props.setProperty("password", "!@#$$$%");
|
|
|
|
|
|
|
|
|
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
|
|
|
|
|
|
|
|
|
deviceMgtService.sendRegistrationEmail(metaInfo);
|
|
|
|
|
Assert.assertTrue(true);
|
|
|
|
|
}
|
|
|
|
|