|
|
@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestUtils;
|
|
|
|
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.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.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
@ -52,7 +53,10 @@ import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
public class DeviceTaskManagerTest {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This is a test class to test the functionality in {@link DeviceTaskManager}.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class DeviceTaskManagerTest extends BaseDeviceManagementTest {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(DeviceTaskManagerTest.class);
|
|
|
|
private static final Log log = LogFactory.getLog(DeviceTaskManagerTest.class);
|
|
|
|
private static final String NEW_DEVICE_TYPE = "NEW-DEVICE-TYPE";
|
|
|
|
private static final String NEW_DEVICE_TYPE = "NEW-DEVICE-TYPE";
|
|
|
@ -65,7 +69,6 @@ public class DeviceTaskManagerTest {
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
@BeforeClass
|
|
|
|
public void init() throws DeviceManagementException, RegistryException {
|
|
|
|
public void init() throws DeviceManagementException, RegistryException {
|
|
|
|
DeviceConfigurationManager.getInstance().initConfig();
|
|
|
|
|
|
|
|
log.info("Initializing Device Task Manager Test Suite");
|
|
|
|
log.info("Initializing Device Task Manager Test Suite");
|
|
|
|
this.deviceIds = new ArrayList<>();
|
|
|
|
this.deviceIds = new ArrayList<>();
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
@ -73,14 +76,13 @@ public class DeviceTaskManagerTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
|
|
|
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
|
|
|
this.deviceMgtProviderService = new DeviceManagementProviderServiceImpl();
|
|
|
|
this.deviceMgtProviderService = new DeviceManagementProviderServiceImpl();
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementServiceComponent.notifyStartupListeners();
|
|
|
|
DeviceManagementServiceComponent.notifyStartupListeners();
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(this.deviceMgtProviderService);
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(this.deviceMgtProviderService);
|
|
|
|
DeviceManagementDataHolder.getInstance()
|
|
|
|
DeviceManagementDataHolder.getInstance()
|
|
|
|
.setRegistryService(TestUtils.getRegistryService(DeviceTaskManagerTest.class));
|
|
|
|
.setRegistryService(TestUtils.getRegistryService(DeviceTaskManagerTest.class));
|
|
|
|
DeviceManagementDataHolder.getInstance()
|
|
|
|
DeviceManagementDataHolder.getInstance()
|
|
|
|
.setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
|
|
|
|
.setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl());
|
|
|
|
DeviceManagementDataHolder.getInstance()
|
|
|
|
|
|
|
|
.setGroupManagementProviderService(new GroupManagementProviderServiceImpl());
|
|
|
|
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
|
|
|
|
NotificationStrategy notificationStrategy = new TestNotificationStrategy();
|
|
|
|
NotificationStrategy notificationStrategy = new TestNotificationStrategy();
|
|
|
|
this.operationManager = new OperationManagerImpl(TestDataHolder.TEST_DEVICE_TYPE, notificationStrategy);
|
|
|
|
this.operationManager = new OperationManagerImpl(TestDataHolder.TEST_DEVICE_TYPE, notificationStrategy);
|
|
|
@ -93,113 +95,84 @@ public class DeviceTaskManagerTest {
|
|
|
|
TestDataHolder.generateMonitoringTaskConfig(true, 60000, 3));
|
|
|
|
TestDataHolder.generateMonitoringTaskConfig(true, 60000, 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = "Device Task Manager Test Group")
|
|
|
|
@Test(groups = "Device Task Manager Test Group", description = "Getting the task frequency from the scheduler")
|
|
|
|
public void testGetTaskFrequency() {
|
|
|
|
public void testGetTaskFrequency() throws DeviceMgtTaskException {
|
|
|
|
log.debug("Attempting to retrieve task frequency.");
|
|
|
|
log.info("Attempting to retrieve task frequency.");
|
|
|
|
try {
|
|
|
|
|
|
|
|
Assert.assertEquals(this.deviceTaskManager.getTaskFrequency(), 60000);
|
|
|
|
Assert.assertEquals(this.deviceTaskManager.getTaskFrequency(), 60000);
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
log.info("Successfully retrieved task frequency.");
|
|
|
|
Assert.fail("Exception occurred when obtaining task frequency.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.debug("Successfully retrieved task frequency.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = "Device Task Manager Test Group")
|
|
|
|
@Test(groups = "Device Task Manager Test Group", description = "Testing if the task is enabled")
|
|
|
|
public void testIsTaskEnabled() {
|
|
|
|
public void testIsTaskEnabled() throws DeviceMgtTaskException {
|
|
|
|
log.debug("Attempting to retrieve task status.");
|
|
|
|
log.info("Attempting to retrieve task status.");
|
|
|
|
try {
|
|
|
|
|
|
|
|
Assert.assertTrue(this.deviceTaskManager.isTaskEnabled());
|
|
|
|
Assert.assertTrue(this.deviceTaskManager.isTaskEnabled());
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
log.info("Successfully retrieved task status.");
|
|
|
|
Assert.fail("Exception occurred when checking whether the task is enabled.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.debug("Successfully retrieved task status.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = "Device Task Manager Test Group")
|
|
|
|
@Test(groups = "Device Task Manager Test Group", description = "Testing adding operations to devices.")
|
|
|
|
public void testAddOperation() {
|
|
|
|
public void testAddOperation() throws DeviceMgtTaskException, OperationManagementException {
|
|
|
|
log.debug("Attempting to add operations for devices.");
|
|
|
|
log.info("Attempting to add operations for devices.");
|
|
|
|
try {
|
|
|
|
|
|
|
|
this.deviceTaskManager.addOperations();
|
|
|
|
this.deviceTaskManager.addOperations();
|
|
|
|
for (DeviceIdentifier deviceId : deviceIds) {
|
|
|
|
for (DeviceIdentifier deviceId : deviceIds) {
|
|
|
|
List<? extends Operation> operationList = this.operationManager.getOperations(deviceId);
|
|
|
|
List<? extends Operation> operationList = this.operationManager.getOperations(deviceId);
|
|
|
|
Assert.assertNotNull(operationList);
|
|
|
|
Assert.assertNotNull(operationList);
|
|
|
|
Assert.assertEquals(operationList.size(), 3);
|
|
|
|
Assert.assertEquals(operationList.size(), 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
log.info("Successfully added operations for devices.");
|
|
|
|
Assert.fail("Exception occurred when adding operations to available devices.", e);
|
|
|
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
|
|
|
Assert.fail("Exception occurred when retrieving operations.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.debug("Successfully added operations for devices.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = "Device Task Manager Test Group")
|
|
|
|
@Test(groups = "Device Task Manager Test Group",
|
|
|
|
public void testAddOperationsWithoutDevices() {
|
|
|
|
description = "Testing adding operations when no devices are available")
|
|
|
|
try {
|
|
|
|
public void testAddOperationsWithoutDevices() throws DeviceManagementException, DeviceMgtTaskException {
|
|
|
|
this.deviceMgtProviderService.registerDeviceType(
|
|
|
|
this.deviceMgtProviderService.registerDeviceType(
|
|
|
|
new TestDeviceManagementService(NEW_DEVICE_TYPE, TestDataHolder.SUPER_TENANT_DOMAIN));
|
|
|
|
new TestDeviceManagementService(NEW_DEVICE_TYPE, TestDataHolder.SUPER_TENANT_DOMAIN));
|
|
|
|
DeviceTaskManager taskManager = new DeviceTaskManagerImpl(NEW_DEVICE_TYPE,
|
|
|
|
DeviceTaskManager taskManager = new DeviceTaskManagerImpl(NEW_DEVICE_TYPE,
|
|
|
|
TestDataHolder.generateMonitoringTaskConfig(true, 50000, 3));
|
|
|
|
TestDataHolder.generateMonitoringTaskConfig(true, 50000, 3));
|
|
|
|
taskManager.addOperations();
|
|
|
|
taskManager.addOperations();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
Assert.fail("Unexpected exception occurred", e);
|
|
|
|
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
|
|
|
|
Assert.fail("Exception occurred when adding operations for the devices", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = "Device Task Manager Test Group", dependsOnMethods = "testAddOperationsWithoutDevices")
|
|
|
|
@Test(groups = "Device Task Manager Test Group", dependsOnMethods = "testAddOperationsWithoutDevices",
|
|
|
|
public void testAddOperationsWithoutOperations() {
|
|
|
|
description = "Testing adding operations when no operations are scheduled")
|
|
|
|
|
|
|
|
public void testAddOperationsWithoutOperations() throws DeviceMgtTaskException {
|
|
|
|
DeviceTaskManager taskManager = new DeviceTaskManagerImpl(NEW_DEVICE_TYPE,
|
|
|
|
DeviceTaskManager taskManager = new DeviceTaskManagerImpl(NEW_DEVICE_TYPE,
|
|
|
|
TestDataHolder.generateMonitoringTaskConfig(true, 50000, 3));
|
|
|
|
TestDataHolder.generateMonitoringTaskConfig(true, 50000, 3));
|
|
|
|
try {
|
|
|
|
|
|
|
|
taskManager.addOperations();
|
|
|
|
taskManager.addOperations();
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
|
|
|
|
Assert.fail("Exception occurred when adding operations for the devices", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = "Device Task Manager Test Group")
|
|
|
|
@Test(groups = "Device Task Manager Test Group", description = "Testing device detail retriever task execution")
|
|
|
|
public void testDeviceDetailRetrieverTaskExecute() {
|
|
|
|
public void testDeviceDetailRetrieverTaskExecute() throws OperationManagementException {
|
|
|
|
DeviceDetailsRetrieverTask deviceDetailsRetrieverTask = new DeviceDetailsRetrieverTask();
|
|
|
|
DeviceDetailsRetrieverTask deviceDetailsRetrieverTask = new DeviceDetailsRetrieverTask();
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
map.put("DEVICE_TYPE", TestDataHolder.TEST_DEVICE_TYPE);
|
|
|
|
map.put("DEVICE_TYPE", TestDataHolder.TEST_DEVICE_TYPE);
|
|
|
|
map.put("OPPCONFIG", DEVICE_DETAIL_RETRIEVER_OPPCONFIG);
|
|
|
|
map.put("OPPCONFIG", DEVICE_DETAIL_RETRIEVER_OPPCONFIG);
|
|
|
|
try {
|
|
|
|
|
|
|
|
deviceDetailsRetrieverTask.setProperties(map);
|
|
|
|
deviceDetailsRetrieverTask.setProperties(map);
|
|
|
|
deviceDetailsRetrieverTask.execute();
|
|
|
|
deviceDetailsRetrieverTask.execute();
|
|
|
|
for (DeviceIdentifier deviceId : deviceIds) {
|
|
|
|
for (DeviceIdentifier deviceId : deviceIds) {
|
|
|
|
List<? extends Operation> operationList = this.operationManager.getOperations(deviceId);
|
|
|
|
List<? extends Operation> operationList = this.operationManager.getOperations(deviceId);
|
|
|
|
Assert.assertNotNull(operationList);
|
|
|
|
Assert.assertNotNull(operationList);
|
|
|
|
Assert.assertEquals(operationList.size(), 4, "Expected number of operations is 4 " +
|
|
|
|
Assert.assertEquals(operationList.size(), 4,
|
|
|
|
"after adding the device detail retriever operation");
|
|
|
|
"Expected number of operations is 4 after adding the device detail retriever operation");
|
|
|
|
Assert.assertEquals(operationList.get(0).getCode(), "DEVICE_INFO", "Operation code of " +
|
|
|
|
Assert.assertEquals(operationList.get(0).getCode(), "DEVICE_INFO",
|
|
|
|
"the device detail retriever task should be DEVICE_LOCATION");
|
|
|
|
"Operation code of the device detail retriever task should be DEVICE_LOCATION");
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Assert.fail("Exception occurred when adding operations for the devices", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(groups = "Device Task Manager Test Group")
|
|
|
|
@Test(groups = "Device Task Manager Test Group",
|
|
|
|
public void testDeviceDetailRetrieverTaskExecuteForAllTenants() {
|
|
|
|
description = "Testing device detail retriever task execution for tenants")
|
|
|
|
|
|
|
|
public void testDeviceDetailRetrieverTaskExecuteForAllTenants() throws OperationManagementException {
|
|
|
|
DeviceDetailsRetrieverTask deviceDetailsRetrieverTask = new DeviceDetailsRetrieverTask();
|
|
|
|
DeviceDetailsRetrieverTask deviceDetailsRetrieverTask = new DeviceDetailsRetrieverTask();
|
|
|
|
System.setProperty("is.cloud", "true");
|
|
|
|
System.setProperty("is.cloud", "true");
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
map.put("DEVICE_TYPE", TestDataHolder.TEST_DEVICE_TYPE);
|
|
|
|
map.put("DEVICE_TYPE", TestDataHolder.TEST_DEVICE_TYPE);
|
|
|
|
map.put("OPPCONFIG", DEVICE_DETAIL_RETRIEVER_OPPCONFIG);
|
|
|
|
map.put("OPPCONFIG", DEVICE_DETAIL_RETRIEVER_OPPCONFIG);
|
|
|
|
try {
|
|
|
|
|
|
|
|
deviceDetailsRetrieverTask.setProperties(map);
|
|
|
|
deviceDetailsRetrieverTask.setProperties(map);
|
|
|
|
deviceDetailsRetrieverTask.execute();
|
|
|
|
deviceDetailsRetrieverTask.execute();
|
|
|
|
for (DeviceIdentifier deviceId : deviceIds) {
|
|
|
|
for (DeviceIdentifier deviceId : deviceIds) {
|
|
|
|
List<? extends Operation> operationList = this.operationManager.getOperations(deviceId);
|
|
|
|
List<? extends Operation> operationList = this.operationManager.getOperations(deviceId);
|
|
|
|
Assert.assertNotNull(operationList);
|
|
|
|
Assert.assertNotNull(operationList);
|
|
|
|
Assert.assertEquals(operationList.size(), 4);
|
|
|
|
Assert.assertEquals(operationList.size(), 4);
|
|
|
|
Assert.assertEquals(operationList.get(0).getCode(), "DEVICE_INFO", "Operation code of " +
|
|
|
|
Assert.assertEquals(operationList.get(0).getCode(), "DEVICE_INFO",
|
|
|
|
"the device detail retriever task should be DEVICE_LOCATION");
|
|
|
|
"Operation code of the device detail retriever task should be DEVICE_LOCATION");
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
Assert.fail("Exception occurred when adding operations for the devices", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -209,5 +182,4 @@ public class DeviceTaskManagerTest {
|
|
|
|
this.deviceMgtProviderService.disenrollDevice(deviceId);
|
|
|
|
this.deviceMgtProviderService.disenrollDevice(deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|