mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing code formatting issues in SearchManagementTestCases.
This commit is contained in:
parent
a9f2a0a228
commit
46555cfe3a
@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.search;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
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.common.BaseDeviceManagementTest;
|
||||
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.DeviceManagementServiceComponent;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
|
||||
@ -43,19 +41,14 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
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.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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 static final Log log = LogFactory.getLog(SearchManagementServiceTest.class);
|
||||
@ -67,7 +60,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
||||
public void init() throws Exception {
|
||||
deviceAccessAuthorizationService = DeviceManagementDataHolder.getInstance()
|
||||
.getDeviceAccessAuthorizationService();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
deviceIdentifiers.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||
}
|
||||
@ -76,7 +68,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
||||
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService);
|
||||
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||
|
||||
List<Device> devices = TestDataHolder.generateDummyDeviceData(deviceIdentifiers);
|
||||
for (Device device : devices) {
|
||||
device.setDeviceInfo(Utils.getDeviceInfo());
|
||||
@ -91,27 +82,23 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
||||
}
|
||||
|
||||
@Test(description = "Test the Search Processor")
|
||||
public void testWithNoDeviceAccessAuthorization() throws Exception {
|
||||
public void testWithNoDeviceAccessAuthorization() throws NoSuchFieldException, IllegalAccessException,
|
||||
SearchMgtException {
|
||||
SearchContext context = new SearchContext();
|
||||
List<Condition> conditions = new ArrayList<>();
|
||||
|
||||
Condition cond = new Condition();
|
||||
cond.setKey("batteryLevel");
|
||||
cond.setOperator("=");
|
||||
cond.setValue("40");
|
||||
cond.setState(Condition.State.AND);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
ProcessorImpl processor = new ProcessorImpl();
|
||||
Field deviceAccessAuthorizationServiceField = ProcessorImpl.class.getDeclaredField
|
||||
("deviceAccessAuthorizationService");
|
||||
deviceAccessAuthorizationServiceField.setAccessible(true);
|
||||
deviceAccessAuthorizationServiceField.set(processor, null);
|
||||
|
||||
List<Device> searchedDevices = processor.execute(context);
|
||||
|
||||
Assert.assertEquals(0, searchedDevices.size());
|
||||
}
|
||||
|
||||
@ -120,9 +107,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
||||
public void testInvalidState() throws SearchMgtException {
|
||||
SearchContext context = new SearchContext();
|
||||
List<Condition> conditions = new ArrayList<>();
|
||||
|
||||
ChangeEnumValues.addEnum(Condition.State.class, "BLA");
|
||||
|
||||
Condition.State state = Condition.State.valueOf("BLA");
|
||||
|
||||
Condition cond = new Condition();
|
||||
@ -147,7 +132,6 @@ public class ProcessorImplTest extends BaseDeviceManagementTest{
|
||||
conditions.add(cond3);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
ProcessorImpl processor = new ProcessorImpl();
|
||||
try {
|
||||
processor.execute(context);
|
||||
@ -161,13 +145,11 @@ 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 {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -72,8 +72,8 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||
DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl();
|
||||
|
||||
List<Device> devices = TestDataHolder.generateDummyDeviceData(deviceIdentifiers);
|
||||
|
||||
for (Device device : devices) {
|
||||
deviceMgtService.enrollDevice(device);
|
||||
}
|
||||
@ -90,6 +90,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
}
|
||||
|
||||
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE, true);
|
||||
|
||||
for (Device device : returnedDevices) {
|
||||
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||
@ -108,9 +109,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
cond.setValue("40");
|
||||
cond.setState(Condition.State.OR);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
Assert.assertTrue(devices != null);
|
||||
@ -127,9 +126,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
cond.setValue("Karandeniya");
|
||||
cond.setState(Condition.State.AND);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
Assert.assertTrue(devices != null);
|
||||
@ -146,9 +143,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
cond.setValue("Colombo");
|
||||
cond.setState(Condition.State.AND);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
Assert.assertTrue(devices.size() == 0);
|
||||
@ -165,12 +160,9 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
cond.setValue("SM-T520");
|
||||
cond.setState(Condition.State.AND);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
|
||||
Assert.assertTrue(devices != null);
|
||||
}
|
||||
|
||||
@ -185,12 +177,9 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
cond.setValue("3.56");
|
||||
cond.setState(Condition.State.AND);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
|
||||
Assert.assertTrue(devices != null);
|
||||
}
|
||||
|
||||
@ -205,12 +194,9 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
cond.setValue("SM-T520");
|
||||
cond.setState(Condition.State.OR);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
|
||||
Assert.assertTrue(devices != null);
|
||||
}
|
||||
|
||||
@ -232,9 +218,7 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
cond.setValue("bbb");
|
||||
cond.setState(Condition.State.OR);
|
||||
conditions.add(cond);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
try {
|
||||
service.search(context);
|
||||
@ -293,7 +277,6 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
conditions.add(cond6);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
Assert.assertTrue(devices != null);
|
||||
@ -333,7 +316,6 @@ public class SearchManagementServiceTest extends BaseDeviceManagementTest {
|
||||
conditions.add(condition4);
|
||||
|
||||
context.setConditions(conditions);
|
||||
|
||||
SearchManagerService service = new SearchManagerServiceImpl();
|
||||
List<Device> devices = service.search(context);
|
||||
Assert.assertTrue(devices != null);
|
||||
|
||||
@ -66,7 +66,6 @@ public class SearchMgtUtilTest {
|
||||
public void testConvertStringToList() {
|
||||
List<String> stringList = Utils.convertStringToList("some string");
|
||||
List<String> expected = this.getStringList();
|
||||
|
||||
Assert.assertEquals(stringList, expected);
|
||||
}
|
||||
|
||||
|
||||
@ -41,16 +41,12 @@ public class ChangeEnumValues {
|
||||
|
||||
private static void setFailSafeFieldValue(Field field, Object target, Object value) throws NoSuchFieldException,
|
||||
IllegalAccessException {
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
int modifiers = modifiersField.getInt(field);
|
||||
|
||||
modifiers &= ~Modifier.FINAL;
|
||||
modifiersField.setInt(field, modifiers);
|
||||
|
||||
FieldAccessor fa = reflectionFactory.newFieldAccessor(field, false);
|
||||
fa.set(target, value);
|
||||
}
|
||||
@ -115,15 +111,10 @@ public class ChangeEnumValues {
|
||||
try {
|
||||
T[] previousValues = (T[]) valuesField.get(enumType);
|
||||
List<T> values = new ArrayList<T>(Arrays.asList(previousValues));
|
||||
|
||||
T newValue = (T) makeEnum(enumType, enumName, values.size(), new Class<?>[]{}, new Object[]{});
|
||||
|
||||
values.add(newValue);
|
||||
|
||||
setFailSafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0)));
|
||||
|
||||
cleanEnumCache(enumType);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@ -51,7 +51,6 @@ public class Utils {
|
||||
deviceInfo.setLocation(getSampleDeviceLocation());
|
||||
|
||||
Map<String, String> propertyMap = new HashMap<>();
|
||||
|
||||
propertyMap.put("BATTERY_VOLTAGE", "40");
|
||||
propertyMap.put("BATTERY_HEALTH", "Good");
|
||||
propertyMap.put("BATTERY_STATUS", "SWElLED");
|
||||
@ -61,14 +60,11 @@ public class Utils {
|
||||
propertyMap.put("CPU_IRQ", "1");
|
||||
propertyMap.put("IMEI", "e6f236ac82537a8e");
|
||||
propertyMap.put("IMSI", "432659632123654845");
|
||||
|
||||
deviceInfo.setDeviceDetailsMap(propertyMap);
|
||||
|
||||
return deviceInfo;
|
||||
}
|
||||
|
||||
|
||||
private static DeviceLocation getSampleDeviceLocation(){
|
||||
public static DeviceLocation getSampleDeviceLocation(){
|
||||
DeviceLocation deviceLocation = new DeviceLocation();
|
||||
deviceLocation.setDeviceIdentifier(Utils.getDeviceIdentifier());
|
||||
deviceLocation.setLatitude(76.2422);
|
||||
@ -80,7 +76,6 @@ public class Utils {
|
||||
deviceLocation.setZip("80360");
|
||||
deviceLocation.setCountry("Sri Lanka");
|
||||
deviceLocation.setDeviceId(1);
|
||||
|
||||
return deviceLocation;
|
||||
}
|
||||
|
||||
@ -88,11 +83,6 @@ public class Utils {
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setType(TestDataHolder.TEST_DEVICE_TYPE);
|
||||
deviceIdentifier.setId("12345");
|
||||
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user