|
|
|
@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationSe
|
|
|
|
|
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.config.DeviceConfigurationManager;
|
|
|
|
|
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.DeviceManagementServiceComponent;
|
|
|
|
|
import org.wso2.carbon.registry.core.config.RegistryContext;
|
|
|
|
@ -39,12 +40,14 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTest {
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
|
|
|
|
|
private DeviceManagementProviderService providerService;
|
|
|
|
|
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
|
|
|
|
|
private static final String DEVICE_TYPE_2 = "RANDOM_DEVICE_TYPE";
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceMgtService;
|
|
|
|
|
|
|
|
|
@ -75,6 +78,17 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
return context.getEmbeddedRegistryService();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetAvailableDeviceTypes() {
|
|
|
|
|
try {
|
|
|
|
|
List<DeviceType> deviceTypes = deviceMgtService.getDeviceTypes();
|
|
|
|
|
Assert.assertTrue(deviceTypes.size() > 0);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while getting the device types";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testNullDeviceEnrollment() {
|
|
|
|
|
try {
|
|
|
|
@ -85,17 +99,50 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSuccessfullDeviceEnrollment() {
|
|
|
|
|
public void testSuccessfulDeviceEnrollment() {
|
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
|
|
|
|
|
try {
|
|
|
|
|
boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
|
|
|
|
|
Assert.assertTrue(enrollmentStatus);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error Occured while enrolling device";
|
|
|
|
|
String msg = "Error occurred while enrolling device";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = "testSuccessfulDeviceEnrollment")
|
|
|
|
|
public void testIsEnrolled() {
|
|
|
|
|
try {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId(TestDataHolder.initialDeviceIdentifier);
|
|
|
|
|
deviceIdentifier.setType(DEVICE_TYPE);
|
|
|
|
|
boolean enrollmentStatus = deviceMgtService.isEnrolled(deviceIdentifier);
|
|
|
|
|
Assert.assertTrue(enrollmentStatus);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while checking enrollment status.";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIsEnrolledForNonExistingDevice() {
|
|
|
|
|
try {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId("34535235235235235");
|
|
|
|
|
deviceIdentifier.setType(DEVICE_TYPE);
|
|
|
|
|
boolean enrollmentStatus = deviceMgtService.isEnrolled(deviceIdentifier);
|
|
|
|
|
Assert.assertFalse(enrollmentStatus);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while checking enrollment status.";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expectedExceptions = DeviceManagementException.class)
|
|
|
|
|
public void testIsEnrolledForNullDevice() throws DeviceManagementException {
|
|
|
|
|
deviceMgtService.isEnrolled(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testNonExistentDeviceType() {
|
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData("abc");
|
|
|
|
@ -103,13 +150,13 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
boolean enrollmentStatus = deviceMgtService.enrollDevice(device);
|
|
|
|
|
Assert.assertFalse(enrollmentStatus);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error Occured while enrolling device";
|
|
|
|
|
String msg = "Error occurred while enrolling device";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfullDeviceEnrollment"})
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testReEnrollmentofSameDeviceUnderSameUser() {
|
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
|
|
|
|
|
|
|
|
|
@ -118,7 +165,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(enrollment);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error Occured while enrolling device";
|
|
|
|
|
String msg = "Error occurred while enrolling device";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -158,7 +205,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
|
|
|
|
|
public void testDisenrollment() {
|
|
|
|
|
Device device = TestDataHolder.generateDummyDeviceData(DEVICE_TYPE);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
boolean disenrollmentStatus = deviceMgtService.disenrollDevice(new DeviceIdentifier
|
|
|
|
|
(device
|
|
|
|
@ -168,9 +214,111 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(disenrollmentStatus);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error Occured while enrolling device";
|
|
|
|
|
String msg = "Error occurred while enrolling device";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetDeviceCount() {
|
|
|
|
|
try {
|
|
|
|
|
int count = deviceMgtService.getDeviceCount();
|
|
|
|
|
Assert.assertTrue(count > 0);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while getting the device count";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetDeviceCountForUser() {
|
|
|
|
|
try {
|
|
|
|
|
int count = deviceMgtService.getDeviceCount(TestDataHolder.OWNER);
|
|
|
|
|
Assert.assertTrue(count > 0);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while getting the device count";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetDeviceCountForNonExistingUser() {
|
|
|
|
|
try {
|
|
|
|
|
int count = deviceMgtService.getDeviceCount("ABCD");
|
|
|
|
|
Assert.assertEquals(count, 0);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while getting the device count";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expectedExceptions = DeviceManagementException.class)
|
|
|
|
|
public void testGetDeviceCountForNullUser() throws DeviceManagementException {
|
|
|
|
|
deviceMgtService.getDeviceCount(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testIsActive() {
|
|
|
|
|
try {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId(TestDataHolder.initialDeviceIdentifier);
|
|
|
|
|
deviceIdentifier.setType(DEVICE_TYPE);
|
|
|
|
|
Assert.assertTrue(deviceMgtService.isActive(deviceIdentifier));
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while checking the device status";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIsActiveForNonExistingDevice() {
|
|
|
|
|
try {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId("34535235235235235");
|
|
|
|
|
deviceIdentifier.setType("TEST_TYPE");
|
|
|
|
|
Assert.assertFalse(deviceMgtService.isActive(deviceIdentifier));
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while checking the device status";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testSetActive() {
|
|
|
|
|
try {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId(TestDataHolder.initialDeviceIdentifier);
|
|
|
|
|
deviceIdentifier.setType(DEVICE_TYPE);
|
|
|
|
|
Assert.assertFalse(deviceMgtService.setActive(deviceIdentifier, true));
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSetActiveForNonExistingDevice() {
|
|
|
|
|
try {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId("34535235235235235");
|
|
|
|
|
deviceIdentifier.setType("TEST_TYPE");
|
|
|
|
|
Assert.assertFalse(deviceMgtService.setActive(deviceIdentifier, true));
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while updating the device status for non-existing device";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
|
|
|
|
|
public void testGetDeviceEnrolledTenants() {
|
|
|
|
|
try {
|
|
|
|
|
List<Integer> tenants = deviceMgtService.getDeviceEnrolledTenants();
|
|
|
|
|
Assert.assertEquals(tenants.size(), 1);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
String msg = "Error occurred while updating the device status";
|
|
|
|
|
Assert.fail(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|