|
|
@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.search;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.powermock.api.mockito.PowerMockito;
|
|
|
|
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
@ -31,7 +30,6 @@ import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
|
|
|
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.dao.DeviceManagementDAOFactory;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
|
|
|
@ -43,18 +41,13 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This class holds unit test cases for org.wso2.carbon.device.mgt.core.search.mgt.impl.ProcessorImpl
|
|
|
|
* This class holds unit test cases for org.wso2.carbon.device.mgt.core.search.mgt.impl.ProcessorImpl
|
|
|
|
* */
|
|
|
|
*/
|
|
|
|
public class ProcessorImplTest extends BaseDeviceManagementTest {
|
|
|
|
public class ProcessorImplTest extends BaseDeviceManagementTest {
|
|
|
|
|
|
|
|
|
|
|
|
private DeviceAccessAuthorizationService deviceAccessAuthorizationService;
|
|
|
|
private DeviceAccessAuthorizationService deviceAccessAuthorizationService;
|
|
|
@ -67,7 +60,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
|
|
|
public void init() throws Exception {
|
|
|
|
public void init() throws Exception {
|
|
|
|
deviceAccessAuthorizationService = DeviceManagementDataHolder.getInstance()
|
|
|
|
deviceAccessAuthorizationService = DeviceManagementDataHolder.getInstance()
|
|
|
|
.getDeviceAccessAuthorizationService();
|
|
|
|
.getDeviceAccessAuthorizationService();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
deviceIdentifiers.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
|
|
|
deviceIdentifiers.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -76,7 +68,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
|
|
|
|
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
|
|
|
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> devices = TestDataHolder.generateDummyDeviceData(deviceIdentifiers);
|
|
|
|
List<Device> devices = TestDataHolder.generateDummyDeviceData(deviceIdentifiers);
|
|
|
|
for (Device device : devices) {
|
|
|
|
for (Device device : devices) {
|
|
|
|
device.setDeviceInfo(Utils.getDeviceInfo());
|
|
|
|
device.setDeviceInfo(Utils.getDeviceInfo());
|
|
|
@ -91,27 +82,23 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Test the Search Processor")
|
|
|
|
@Test(description = "Test the Search Processor")
|
|
|
|
public void testWithNoDeviceAccessAuthorization() throws Exception {
|
|
|
|
public void testWithNoDeviceAccessAuthorization() throws NoSuchFieldException, IllegalAccessException,
|
|
|
|
|
|
|
|
SearchMgtException {
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
Condition cond = new Condition();
|
|
|
|
Condition cond = new Condition();
|
|
|
|
cond.setKey("batteryLevel");
|
|
|
|
cond.setKey("batteryLevel");
|
|
|
|
cond.setOperator("=");
|
|
|
|
cond.setOperator("=");
|
|
|
|
cond.setValue("40");
|
|
|
|
cond.setValue("40");
|
|
|
|
cond.setState(Condition.State.AND);
|
|
|
|
cond.setState(Condition.State.AND);
|
|
|
|
conditions.add(cond);
|
|
|
|
conditions.add(cond);
|
|
|
|
|
|
|
|
|
|
|
|
context.setConditions(conditions);
|
|
|
|
context.setConditions(conditions);
|
|
|
|
|
|
|
|
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
Field deviceAccessAuthorizationServiceField = ProcessorImpl.class.getDeclaredField
|
|
|
|
Field deviceAccessAuthorizationServiceField = ProcessorImpl.class.getDeclaredField
|
|
|
|
("deviceAccessAuthorizationService");
|
|
|
|
("deviceAccessAuthorizationService");
|
|
|
|
deviceAccessAuthorizationServiceField.setAccessible(true);
|
|
|
|
deviceAccessAuthorizationServiceField.setAccessible(true);
|
|
|
|
deviceAccessAuthorizationServiceField.set(processor, null);
|
|
|
|
deviceAccessAuthorizationServiceField.set(processor, null);
|
|
|
|
|
|
|
|
|
|
|
|
List<Device> searchedDevices = processor.execute(context);
|
|
|
|
List<Device> searchedDevices = processor.execute(context);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(0, searchedDevices.size());
|
|
|
|
Assert.assertEquals(0, searchedDevices.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -120,9 +107,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
|
|
|
public void testInvalidState() throws SearchMgtException {
|
|
|
|
public void testInvalidState() throws SearchMgtException {
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
ChangeEnumValues.addEnum(Condition.State.class, "BLA");
|
|
|
|
ChangeEnumValues.addEnum(Condition.State.class, "BLA");
|
|
|
|
|
|
|
|
|
|
|
|
Condition.State state = Condition.State.valueOf("BLA");
|
|
|
|
Condition.State state = Condition.State.valueOf("BLA");
|
|
|
|
|
|
|
|
|
|
|
|
Condition cond = new Condition();
|
|
|
|
Condition cond = new Condition();
|
|
|
@ -147,7 +132,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
|
|
|
conditions.add(cond3);
|
|
|
|
conditions.add(cond3);
|
|
|
|
|
|
|
|
|
|
|
|
context.setConditions(conditions);
|
|
|
|
context.setConditions(conditions);
|
|
|
|
|
|
|
|
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
processor.execute(context);
|
|
|
|
processor.execute(context);
|
|
|
@ -161,13 +145,11 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
|
|
|
@Test(description = "Test when Device Access Authorization is null", expectedExceptions = {IllegalStateException
|
|
|
|
@Test(description = "Test when Device Access Authorization is null", expectedExceptions = {IllegalStateException
|
|
|
|
.class}, dependsOnMethods = {"testWithNoDeviceAccessAuthorization", "testInvalidState"})
|
|
|
|
.class}, dependsOnMethods = {"testWithNoDeviceAccessAuthorization", "testInvalidState"})
|
|
|
|
public void testProcessorInitializationError() throws ClassNotFoundException, NoSuchMethodException,
|
|
|
|
public void testProcessorInitializationError() throws ClassNotFoundException, NoSuchMethodException,
|
|
|
|
NoSuchFieldException,
|
|
|
|
NoSuchFieldException, IllegalAccessException, SearchMgtException {
|
|
|
|
IllegalAccessException, SearchMgtException {
|
|
|
|
|
|
|
|
DeviceManagementDataHolder deviceManagementDataHolder = DeviceManagementDataHolder.getInstance();
|
|
|
|
DeviceManagementDataHolder deviceManagementDataHolder = DeviceManagementDataHolder.getInstance();
|
|
|
|
Field field = DeviceManagementDataHolder.class.getDeclaredField("deviceAccessAuthorizationService");
|
|
|
|
Field field = DeviceManagementDataHolder.class.getDeclaredField("deviceAccessAuthorizationService");
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(deviceManagementDataHolder, null);
|
|
|
|
field.set(deviceManagementDataHolder, null);
|
|
|
|
|
|
|
|
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
processor.execute(null);
|
|
|
|
processor.execute(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|