|
|
@ -23,11 +23,16 @@ import org.testng.annotations.Test;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
|
|
@ -40,6 +45,8 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
|
|
|
|
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
|
|
|
@ -47,7 +54,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
|
|
|
|
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
|
|
|
|
private DeviceManagementProviderService providerService;
|
|
|
|
private DeviceManagementProviderService providerService;
|
|
|
|
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
|
|
|
|
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
|
|
|
|
private static final String DEVICE_TYPE_2 = "RANDOM_DEVICE_TYPE";
|
|
|
|
private DeviceDetailsDAO deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceMgtService;
|
|
|
|
DeviceManagementProviderService deviceMgtService;
|
|
|
|
|
|
|
|
|
|
|
@ -65,7 +72,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
|
|
|
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
|
|
|
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private RegistryService getRegistryService() throws RegistryException {
|
|
|
|
private RegistryService getRegistryService() throws RegistryException {
|
|
|
@ -170,39 +176,39 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
|
|
|
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
|
|
|
|
// public void testReEnrollmentofSameDeviceWithOtherUser() {
|
|
|
|
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);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
public void testDisenrollment() {
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -320,5 +326,114 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
|
|
|
public void testGetDevice() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",DEVICE_TYPE));
|
|
|
|
|
|
|
|
Assert.assertTrue(device.getDeviceIdentifier().equalsIgnoreCase("12345"));
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
|
|
|
public void testGetDeviceWithInfo() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE)
|
|
|
|
|
|
|
|
, true);
|
|
|
|
|
|
|
|
Assert.assertTrue(device.getDeviceInfo() != null);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
|
|
|
public void testGetDeviceWithOutInfo() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345", DEVICE_TYPE)
|
|
|
|
|
|
|
|
, false);
|
|
|
|
|
|
|
|
Assert.assertTrue(device.getDeviceInfo() == null);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
|
|
|
public void testGetAllDevicesOfRole() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<Device> devices = deviceMgtService.getAllDevicesOfRole("admin");
|
|
|
|
|
|
|
|
Assert.assertTrue(devices.size() > 0);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
|
|
|
public void testDeviceByOwner() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",
|
|
|
|
|
|
|
|
DEVICE_TYPE), "admin", true);
|
|
|
|
|
|
|
|
Assert.assertTrue(device != null);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
|
|
|
public void testDeviceByDate() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Device initialDevice = deviceMgtService.getDevice(new DeviceIdentifier("12345",
|
|
|
|
|
|
|
|
DEVICE_TYPE));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Device details table will be reffered when looking for last updated time
|
|
|
|
|
|
|
|
//This dao entry is to mimic a device info operation
|
|
|
|
|
|
|
|
deviceDetailsDAO.addDeviceInformation(initialDevice.getId(), TestDataHolder
|
|
|
|
|
|
|
|
.generateDummyDeviceInfo());
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (DeviceDetailsMgtDAOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",
|
|
|
|
|
|
|
|
DEVICE_TYPE), yesterday());
|
|
|
|
|
|
|
|
Assert.assertTrue(device != null);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testDeviceByDate"})
|
|
|
|
|
|
|
|
public void testDeviceByDateAndOwner() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Device device = deviceMgtService.getDevice(new DeviceIdentifier("12345",
|
|
|
|
|
|
|
|
DEVICE_TYPE), "admin", yesterday(), true);
|
|
|
|
|
|
|
|
Assert.assertTrue(device != null);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Date yesterday() {
|
|
|
|
|
|
|
|
final Calendar cal = Calendar.getInstance();
|
|
|
|
|
|
|
|
cal.add(Calendar.DATE, -1);
|
|
|
|
|
|
|
|
return cal.getTime();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|