|
|
@ -17,14 +17,11 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.wso2.carbon.device.mgt.core.search;
|
|
|
|
package org.wso2.carbon.device.mgt.core.search;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
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;
|
|
|
|
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.authorization.DeviceAccessAuthorizationService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.Condition;
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.Condition;
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
|
|
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;
|
|
|
@ -41,7 +38,6 @@ 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 java.lang.reflect.Field;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
@ -50,16 +46,12 @@ import java.util.List;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class ProcessorImplTest extends BaseDeviceManagementTest {
|
|
|
|
public class ProcessorImplTest extends BaseDeviceManagementTest {
|
|
|
|
|
|
|
|
|
|
|
|
private DeviceAccessAuthorizationService deviceAccessAuthorizationService;
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(SearchManagementServiceTest.class);
|
|
|
|
|
|
|
|
private static List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
private static List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
private static final String DEVICE_ID_PREFIX = "SEARCH-DEVICE-ID-";
|
|
|
|
private static final String DEVICE_ID_PREFIX = "SEARCH-DEVICE-ID-";
|
|
|
|
private static final String DEVICE_TYPE = "SEARCH_TYPE";
|
|
|
|
private static final String DEVICE_TYPE = "SEARCH_TYPE";
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
@BeforeClass
|
|
|
|
public void init() throws Exception {
|
|
|
|
public void init() throws Exception {
|
|
|
|
deviceAccessAuthorizationService = DeviceManagementDataHolder.getInstance()
|
|
|
|
|
|
|
|
.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));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -81,27 +73,59 @@ public class ProcessorImplTest extends BaseDeviceManagementTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Test the Search Processor")
|
|
|
|
@Test (description = "Search for device with and condition")
|
|
|
|
public void testWithNoDeviceAccessAuthorization() throws NoSuchFieldException, IllegalAccessException,
|
|
|
|
public void testSearchDevicesWIthAndCondition() throws SearchMgtException {
|
|
|
|
SearchMgtException {
|
|
|
|
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
Condition cond = new Condition();
|
|
|
|
|
|
|
|
cond.setKey("batteryLevel");
|
|
|
|
Condition condition = new Condition();
|
|
|
|
cond.setOperator("=");
|
|
|
|
condition.setKey("IMEI");
|
|
|
|
cond.setValue("40");
|
|
|
|
condition.setOperator("=");
|
|
|
|
cond.setState(Condition.State.AND);
|
|
|
|
condition.setValue("e6f236ac82537a8e");
|
|
|
|
conditions.add(cond);
|
|
|
|
condition.setState(Condition.State.AND);
|
|
|
|
|
|
|
|
conditions.add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.setConditions(conditions);
|
|
|
|
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
|
|
|
|
List<Device> devices = processor.execute(context);
|
|
|
|
|
|
|
|
Assert.assertEquals(5, devices.size(), "There should be exactly 5 devices with matching search criteria");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test (description = "Search for device with or condition")
|
|
|
|
|
|
|
|
public void testSearchDevicesWIthORCondition() throws SearchMgtException {
|
|
|
|
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Condition condition = new Condition();
|
|
|
|
|
|
|
|
condition.setKey("IMSI");
|
|
|
|
|
|
|
|
condition.setOperator("=");
|
|
|
|
|
|
|
|
condition.setValue("432659632123654845");
|
|
|
|
|
|
|
|
condition.setState(Condition.State.OR);
|
|
|
|
|
|
|
|
conditions.add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
context.setConditions(conditions);
|
|
|
|
context.setConditions(conditions);
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
Field deviceAccessAuthorizationServiceField = ProcessorImpl.class.getDeclaredField
|
|
|
|
List<Device> devices = processor.execute(context);
|
|
|
|
("deviceAccessAuthorizationService");
|
|
|
|
Assert.assertEquals(5, devices.size(), "There should be exactly 5 devices with matching search criteria");
|
|
|
|
deviceAccessAuthorizationServiceField.setAccessible(true);
|
|
|
|
|
|
|
|
deviceAccessAuthorizationServiceField.set(processor, null);
|
|
|
|
|
|
|
|
List<Device> searchedDevices = processor.execute(context);
|
|
|
|
|
|
|
|
Assert.assertEquals(0, searchedDevices.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test (description = "Search for device with wrong condition")
|
|
|
|
|
|
|
|
public void testSearchDevicesWIthWrongCondition() throws SearchMgtException {
|
|
|
|
|
|
|
|
SearchContext context = new SearchContext();
|
|
|
|
|
|
|
|
List<Condition> conditions = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Condition condition = new Condition();
|
|
|
|
|
|
|
|
condition.setKey("IMSI");
|
|
|
|
|
|
|
|
condition.setOperator("=");
|
|
|
|
|
|
|
|
condition.setValue("43265963212378466");
|
|
|
|
|
|
|
|
condition.setState(Condition.State.OR);
|
|
|
|
|
|
|
|
conditions.add(condition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.setConditions(conditions);
|
|
|
|
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
|
|
|
|
List<Device> devices = processor.execute(context);
|
|
|
|
|
|
|
|
Assert.assertEquals(0, devices.size(), "There should be no devices with matching search criteria");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Test for invalid state")
|
|
|
|
@Test(description = "Test for invalid state")
|
|
|
|
public void testInvalidState() throws SearchMgtException {
|
|
|
|
public void testInvalidState() throws SearchMgtException {
|
|
|
@ -141,16 +165,4 @@ public class ProcessorImplTest extends BaseDeviceManagementTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "Test when Device Access Authorization is null", expectedExceptions = {IllegalStateException
|
|
|
|
|
|
|
|
.class}, dependsOnMethods = {"testWithNoDeviceAccessAuthorization", "testInvalidState"})
|
|
|
|
|
|
|
|
public void testProcessorInitializationError() throws ClassNotFoundException, NoSuchMethodException,
|
|
|
|
|
|
|
|
NoSuchFieldException, IllegalAccessException, SearchMgtException {
|
|
|
|
|
|
|
|
DeviceManagementDataHolder deviceManagementDataHolder = DeviceManagementDataHolder.getInstance();
|
|
|
|
|
|
|
|
Field field = DeviceManagementDataHolder.class.getDeclaredField("deviceAccessAuthorizationService");
|
|
|
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
|
|
|
field.set(deviceManagementDataHolder, null);
|
|
|
|
|
|
|
|
ProcessorImpl processor = new ProcessorImpl();
|
|
|
|
|
|
|
|
processor.execute(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|