|
|
@ -26,12 +26,16 @@ 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.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.*;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinition;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypeDAOHandler;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.PluginDAO;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.PropertyBasedPluginDAOImpl;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.utils.Utils;
|
|
|
|
import org.wso2.carbon.device.mgt.extensions.utils.Utils;
|
|
|
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
|
|
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
@ -47,6 +51,7 @@ import java.net.URL;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -54,10 +59,18 @@ import java.util.List;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class DeviceTypeManagerTest {
|
|
|
|
public class DeviceTypeManagerTest {
|
|
|
|
private DeviceTypeManager androidDeviceTypeManager;
|
|
|
|
private DeviceTypeManager androidDeviceTypeManager;
|
|
|
|
|
|
|
|
private DeviceTypeManager customDeviceTypeManager;
|
|
|
|
private DeviceIdentifier nonExistingDeviceIdentifier;
|
|
|
|
private DeviceIdentifier nonExistingDeviceIdentifier;
|
|
|
|
private Device sampleDevice1;
|
|
|
|
private Device sampleDevice1;
|
|
|
|
private Device sampleDevice2;
|
|
|
|
private Device sampleDevice2;
|
|
|
|
|
|
|
|
private Device customDevice;
|
|
|
|
private String androidDeviceType;
|
|
|
|
private String androidDeviceType;
|
|
|
|
|
|
|
|
private String customDeviceType = "customDeviceType";
|
|
|
|
|
|
|
|
private Field datasourceField;
|
|
|
|
|
|
|
|
private Field currentConnection;
|
|
|
|
|
|
|
|
private Field deviceTypePluginDAOField;
|
|
|
|
|
|
|
|
private Field deviceTypeDAOHandlerField;
|
|
|
|
|
|
|
|
private String[] customDeviceTypeProperties = {"custom_property", "custom_property2"};
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeTest(description = "Mocking the classes for testing")
|
|
|
|
@BeforeTest(description = "Mocking the classes for testing")
|
|
|
|
public void setup() throws NoSuchFieldException, IllegalAccessException, IOException, SQLException, SAXException,
|
|
|
|
public void setup() throws NoSuchFieldException, IllegalAccessException, IOException, SQLException, SAXException,
|
|
|
@ -67,26 +80,24 @@ public class DeviceTypeManagerTest {
|
|
|
|
androidDeviceType = "android";
|
|
|
|
androidDeviceType = "android";
|
|
|
|
File androidDatabaseScript = null;
|
|
|
|
File androidDatabaseScript = null;
|
|
|
|
javax.sql.DataSource dataSource = null;
|
|
|
|
javax.sql.DataSource dataSource = null;
|
|
|
|
File carbonHome = new File("src/test/resources/carbon-home");
|
|
|
|
File androidConfiguration = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (resourceUrl != null) {
|
|
|
|
if (resourceUrl != null) {
|
|
|
|
androidDatabaseScript = new File(resourceUrl.getFile());
|
|
|
|
androidDatabaseScript = new File(resourceUrl.getFile());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (carbonHome.exists()) {
|
|
|
|
|
|
|
|
System.setProperty("carbon.home", carbonHome.getAbsolutePath());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceUrl = classLoader.getResource("android.xml");
|
|
|
|
resourceUrl = classLoader.getResource("android.xml");
|
|
|
|
File androidConfiguration = null;
|
|
|
|
|
|
|
|
if (resourceUrl != null) {
|
|
|
|
if (resourceUrl != null) {
|
|
|
|
androidConfiguration = new File(resourceUrl.getFile());
|
|
|
|
androidConfiguration = new File(resourceUrl.getFile());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceTypeConfiguration androidDeviceConfiguration = Utils.getDeviceTypeConfiguration(androidConfiguration);
|
|
|
|
DeviceTypeConfiguration androidDeviceConfiguration = Utils.getDeviceTypeConfiguration(androidConfiguration);
|
|
|
|
androidDeviceTypeManager = Mockito.mock(DeviceTypeManager.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
androidDeviceTypeManager = Mockito.mock(DeviceTypeManager.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
|
|
|
|
customDeviceTypeManager = Mockito.mock(DeviceTypeManager.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
|
|
|
|
|
|
|
|
if (androidDatabaseScript != null) {
|
|
|
|
if (androidDatabaseScript != null) {
|
|
|
|
dataSource = Utils.createDataTables("deviceType", androidDatabaseScript.getAbsolutePath());
|
|
|
|
dataSource = Utils.createDataTables("customDeviceType", androidDatabaseScript.getAbsolutePath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceTypePluginDAOManager deviceTypePluginDAOManager = createMockDeviceTypePluginDAOManager(dataSource,
|
|
|
|
DeviceTypePluginDAOManager deviceTypePluginDAOManager = createandroidDeviceTypePluginDAOManager(dataSource,
|
|
|
|
androidDeviceConfiguration);
|
|
|
|
androidDeviceConfiguration);
|
|
|
|
Field deviceTypePluginDAOManagerField = DeviceTypeManager.class.getDeclaredField("deviceTypePluginDAOManager");
|
|
|
|
Field deviceTypePluginDAOManagerField = DeviceTypeManager.class.getDeclaredField("deviceTypePluginDAOManager");
|
|
|
|
deviceTypePluginDAOManagerField.setAccessible(true);
|
|
|
|
deviceTypePluginDAOManagerField.setAccessible(true);
|
|
|
@ -96,9 +107,25 @@ public class DeviceTypeManagerTest {
|
|
|
|
propertiesExist.setAccessible(true);
|
|
|
|
propertiesExist.setAccessible(true);
|
|
|
|
Field deviceType = DeviceTypeManager.class.getDeclaredField("deviceType");
|
|
|
|
Field deviceType = DeviceTypeManager.class.getDeclaredField("deviceType");
|
|
|
|
deviceType.setAccessible(true);
|
|
|
|
deviceType.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datasourceField = DeviceTypeDAOHandler.class.getDeclaredField("dataSource");
|
|
|
|
|
|
|
|
datasourceField.setAccessible(true);
|
|
|
|
|
|
|
|
currentConnection = DeviceTypeDAOHandler.class.getDeclaredField("currentConnection");
|
|
|
|
|
|
|
|
currentConnection.setAccessible(true);
|
|
|
|
|
|
|
|
deviceTypePluginDAOField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypePluginDAO");
|
|
|
|
|
|
|
|
deviceTypePluginDAOField.setAccessible(true);
|
|
|
|
|
|
|
|
deviceTypeDAOHandlerField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypeDAOHandler");
|
|
|
|
|
|
|
|
deviceTypeDAOHandlerField.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
|
|
deviceType.set(androidDeviceTypeManager, androidDeviceType);
|
|
|
|
deviceType.set(androidDeviceTypeManager, androidDeviceType);
|
|
|
|
propertiesExist.set(androidDeviceTypeManager, true);
|
|
|
|
propertiesExist.set(androidDeviceTypeManager, true);
|
|
|
|
createDevice();
|
|
|
|
createAndroidDevice();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceTypePluginDAOManager propertyBasedPluginDAOManager = createPluginBasedDeviceTypeManager();
|
|
|
|
|
|
|
|
deviceTypePluginDAOManagerField.set(customDeviceTypeManager, propertyBasedPluginDAOManager);
|
|
|
|
|
|
|
|
deviceType.set(customDeviceTypeManager, customDeviceType);
|
|
|
|
|
|
|
|
propertiesExist.set(customDeviceTypeManager, true);
|
|
|
|
|
|
|
|
createCustomDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This test case tests IsEnrolled method of the DeviceTypeManager",
|
|
|
|
@Test(description = "This test case tests IsEnrolled method of the DeviceTypeManager",
|
|
|
@ -106,10 +133,17 @@ public class DeviceTypeManagerTest {
|
|
|
|
public void testIsEnrolled() throws DeviceManagementException {
|
|
|
|
public void testIsEnrolled() throws DeviceManagementException {
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
|
|
|
|
sampleDevice2.getType());
|
|
|
|
sampleDevice2.getType());
|
|
|
|
Assert.assertTrue(!androidDeviceTypeManager.isEnrolled(nonExistingDeviceIdentifier),
|
|
|
|
DeviceIdentifier nonExistingCustomDeviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
|
|
|
|
"Device with " + "NON-Existing ID is not enrolled, but this shows as enrolled");
|
|
|
|
customDevice.getType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertFalse(androidDeviceTypeManager.isEnrolled(nonExistingDeviceIdentifier),
|
|
|
|
|
|
|
|
"Device with NON-Existing ID is not enrolled, but this shows as enrolled");
|
|
|
|
Assert.assertTrue(androidDeviceTypeManager.isEnrolled(deviceIdentifier),
|
|
|
|
Assert.assertTrue(androidDeviceTypeManager.isEnrolled(deviceIdentifier),
|
|
|
|
"Enrolled device is shown as un-enrolled");
|
|
|
|
"Enrolled device is shown as un-enrolled");
|
|
|
|
|
|
|
|
Assert.assertFalse(customDeviceTypeManager.isEnrolled(nonExistingCustomDeviceIdentifier),
|
|
|
|
|
|
|
|
"Custom device type manager returns an non-existing device as enrolled");
|
|
|
|
|
|
|
|
Assert.assertTrue(customDeviceTypeManager.isEnrolled(new DeviceIdentifier(customDeviceType, customDeviceType))
|
|
|
|
|
|
|
|
, "Enrolled device is shown as un-enrolled in custom device type manager");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This test case tests the getDevcie method of the DeviceTypeManager", dependsOnMethods =
|
|
|
|
@Test(description = "This test case tests the getDevcie method of the DeviceTypeManager", dependsOnMethods =
|
|
|
@ -120,20 +154,37 @@ public class DeviceTypeManagerTest {
|
|
|
|
Assert.assertNull(androidDeviceTypeManager.getDevice(nonExistingDeviceIdentifier),
|
|
|
|
Assert.assertNull(androidDeviceTypeManager.getDevice(nonExistingDeviceIdentifier),
|
|
|
|
"Non existing sampleDevice was retrieved");
|
|
|
|
"Non existing sampleDevice was retrieved");
|
|
|
|
Assert.assertNotNull(androidDeviceTypeManager.getDevice(existingDeviceIdntifier),
|
|
|
|
Assert.assertNotNull(androidDeviceTypeManager.getDevice(existingDeviceIdntifier),
|
|
|
|
"Existing sampleDevice was retrieved");
|
|
|
|
"Existing sampleDevice was not retrieved");
|
|
|
|
|
|
|
|
Device customDevice1 = customDeviceTypeManager
|
|
|
|
|
|
|
|
.getDevice(new DeviceIdentifier(customDeviceType, customDeviceType));
|
|
|
|
|
|
|
|
Assert.assertEquals(customDevice1.getProperties().size(), 2,
|
|
|
|
|
|
|
|
"GetDevice call" + " failed in custom deviceTypeManager");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This test case tests the enrollment of the device")
|
|
|
|
@Test(description = "This test case tests the enrollment of the device")
|
|
|
|
public void testEnrollDevice() throws DeviceManagementException {
|
|
|
|
public void testEnrollDevice() throws DeviceManagementException {
|
|
|
|
Assert.assertTrue(androidDeviceTypeManager.enrollDevice(sampleDevice1));
|
|
|
|
Assert.assertTrue(androidDeviceTypeManager.enrollDevice(sampleDevice1), "New android device enrollment failed");
|
|
|
|
Assert.assertTrue(!androidDeviceTypeManager.enrollDevice(sampleDevice2));
|
|
|
|
Assert.assertFalse(androidDeviceTypeManager.enrollDevice(sampleDevice2),
|
|
|
|
|
|
|
|
"Modification to existing android " + "device enrollment failed");
|
|
|
|
|
|
|
|
Assert.assertTrue(customDeviceTypeManager.enrollDevice(customDevice), "Custom device type enrollment failed.");
|
|
|
|
|
|
|
|
List<Device.Property> properties = customDevice.getProperties();
|
|
|
|
|
|
|
|
Device.Property property = new Device.Property();
|
|
|
|
|
|
|
|
property.setName("test");
|
|
|
|
|
|
|
|
property.setValue("test");
|
|
|
|
|
|
|
|
properties.add(property);
|
|
|
|
|
|
|
|
customDevice.setProperties(properties);
|
|
|
|
|
|
|
|
Assert.assertFalse(customDeviceTypeManager.enrollDevice(customDevice),
|
|
|
|
|
|
|
|
"Custom device type re-enrollment " + "failed.");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This test case tests the get all devices method of the DeviceTypeManager", dependsOnMethods
|
|
|
|
@Test(description = "This test case tests the get all devices method of the DeviceTypeManager", dependsOnMethods
|
|
|
|
= {"testEnrollDevice"})
|
|
|
|
= {"testEnrollDevice"})
|
|
|
|
public void testGetAllDevices() throws DeviceManagementException {
|
|
|
|
public void testGetAllDevices() throws DeviceManagementException {
|
|
|
|
Assert.assertEquals(androidDeviceTypeManager.getAllDevices().size(), 1,
|
|
|
|
Assert.assertEquals(androidDeviceTypeManager.getAllDevices().size(), 1,
|
|
|
|
"All the added devices are not fetched " + "from the database");
|
|
|
|
"All the added devices are not fetched from the database");
|
|
|
|
|
|
|
|
Assert.assertEquals(customDeviceTypeManager.getAllDevices().size(), 1,
|
|
|
|
|
|
|
|
"All the added devices are not fetched from the database");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(description = "This test case tests the addition of platform configuration and retrieval of the same")
|
|
|
|
@Test(description = "This test case tests the addition of platform configuration and retrieval of the same")
|
|
|
@ -147,6 +198,7 @@ public class DeviceTypeManagerTest {
|
|
|
|
"Platform Configuration saved and retrieved correctly in " + "DeviceType Manager");
|
|
|
|
"Platform Configuration saved and retrieved correctly in " + "DeviceType Manager");
|
|
|
|
Assert.assertEquals(actualPlatformConfiguration.getType(), androidDeviceType,
|
|
|
|
Assert.assertEquals(actualPlatformConfiguration.getType(), androidDeviceType,
|
|
|
|
"Platform Configuration saved and " + "retrieved correctly in DeviceType Manager");
|
|
|
|
"Platform Configuration saved and " + "retrieved correctly in DeviceType Manager");
|
|
|
|
|
|
|
|
Assert.assertNull(customDeviceTypeManager.getConfiguration());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test (description = "This test case tests the getDefaultConfiguration method")
|
|
|
|
@Test (description = "This test case tests the getDefaultConfiguration method")
|
|
|
@ -169,9 +221,9 @@ public class DeviceTypeManagerTest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* To create a sample sampleDevice to add to DAO Layer.
|
|
|
|
* To create sample android devices to add to DAO Layer.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void createDevice() {
|
|
|
|
private void createAndroidDevice() {
|
|
|
|
nonExistingDeviceIdentifier = new DeviceIdentifier("NON-EXISTING", androidDeviceType);
|
|
|
|
nonExistingDeviceIdentifier = new DeviceIdentifier("NON-EXISTING", androidDeviceType);
|
|
|
|
List<Device.Property> list = new ArrayList<>();
|
|
|
|
List<Device.Property> list = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
@ -190,6 +242,21 @@ public class DeviceTypeManagerTest {
|
|
|
|
sampleDevice2 = new Device("testdevice1", androidDeviceType, "test", "testdevice", null, null, list);
|
|
|
|
sampleDevice2 = new Device("testdevice1", androidDeviceType, "test", "testdevice", null, null, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* To create a sample custom device.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void createCustomDevice () {
|
|
|
|
|
|
|
|
List<Device.Property> list = new ArrayList<>();
|
|
|
|
|
|
|
|
for(String customProperty : customDeviceTypeProperties) {
|
|
|
|
|
|
|
|
Device.Property property = new Device.Property();
|
|
|
|
|
|
|
|
property.setName(customProperty);
|
|
|
|
|
|
|
|
property.setValue(customProperty);
|
|
|
|
|
|
|
|
list.add(property);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
customDevice = new Device(customDeviceType, customDeviceType, customDeviceType, customDeviceType, null,
|
|
|
|
|
|
|
|
null, list);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* To create a mock sampleDevice type plugin dao manager.
|
|
|
|
* To create a mock sampleDevice type plugin dao manager.
|
|
|
|
* @param dataSource DataSource for the DAO layer
|
|
|
|
* @param dataSource DataSource for the DAO layer
|
|
|
@ -198,13 +265,8 @@ public class DeviceTypeManagerTest {
|
|
|
|
* @throws NoSuchFieldException No Such Field Exception
|
|
|
|
* @throws NoSuchFieldException No Such Field Exception
|
|
|
|
* @throws IllegalAccessException Illegal Access Exception
|
|
|
|
* @throws IllegalAccessException Illegal Access Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private DeviceTypePluginDAOManager createMockDeviceTypePluginDAOManager(javax.sql.DataSource dataSource,
|
|
|
|
private DeviceTypePluginDAOManager createandroidDeviceTypePluginDAOManager(javax.sql.DataSource dataSource,
|
|
|
|
DeviceTypeConfiguration androidDeviceConfiguration) throws NoSuchFieldException, IllegalAccessException {
|
|
|
|
DeviceTypeConfiguration androidDeviceConfiguration) throws NoSuchFieldException, IllegalAccessException {
|
|
|
|
Field datasourceField = DeviceTypeDAOHandler.class.getDeclaredField("dataSource");
|
|
|
|
|
|
|
|
datasourceField.setAccessible(true);
|
|
|
|
|
|
|
|
Field currentConnection = DeviceTypeDAOHandler.class.getDeclaredField("currentConnection");
|
|
|
|
|
|
|
|
currentConnection.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceTypeDAOHandler deviceTypeDAOHandler = Mockito
|
|
|
|
DeviceTypeDAOHandler deviceTypeDAOHandler = Mockito
|
|
|
|
.mock(DeviceTypeDAOHandler.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
.mock(DeviceTypeDAOHandler.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
datasourceField.set(deviceTypeDAOHandler, dataSource);
|
|
|
|
datasourceField.set(deviceTypeDAOHandler, dataSource);
|
|
|
@ -213,22 +275,25 @@ public class DeviceTypeManagerTest {
|
|
|
|
DeviceDAODefinition deviceDAODefinition = Utils.getDeviceDAODefinition(androidDeviceConfiguration);
|
|
|
|
DeviceDAODefinition deviceDAODefinition = Utils.getDeviceDAODefinition(androidDeviceConfiguration);
|
|
|
|
DeviceTypePluginDAOImpl deviceTypePluginDAO = new DeviceTypePluginDAOImpl(deviceDAODefinition,
|
|
|
|
DeviceTypePluginDAOImpl deviceTypePluginDAO = new DeviceTypePluginDAOImpl(deviceDAODefinition,
|
|
|
|
deviceTypeDAOHandler);
|
|
|
|
deviceTypeDAOHandler);
|
|
|
|
|
|
|
|
|
|
|
|
DeviceTypePluginDAOManager deviceTypePluginDAOManager = Mockito
|
|
|
|
DeviceTypePluginDAOManager deviceTypePluginDAOManager = Mockito
|
|
|
|
.mock(DeviceTypePluginDAOManager.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
.mock(DeviceTypePluginDAOManager.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
Field deviceTypePluginDAOField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypePluginDAO");
|
|
|
|
|
|
|
|
deviceTypePluginDAOField.setAccessible(true);
|
|
|
|
|
|
|
|
Field deviceTypeDAOHandlerField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypeDAOHandler");
|
|
|
|
|
|
|
|
deviceTypeDAOHandlerField.setAccessible(true);
|
|
|
|
|
|
|
|
deviceTypePluginDAOField.set(deviceTypePluginDAOManager, deviceTypePluginDAO);
|
|
|
|
deviceTypePluginDAOField.set(deviceTypePluginDAOManager, deviceTypePluginDAO);
|
|
|
|
deviceTypeDAOHandlerField.set(deviceTypePluginDAOManager, deviceTypeDAOHandler);
|
|
|
|
deviceTypeDAOHandlerField.set(deviceTypePluginDAOManager, deviceTypeDAOHandler);
|
|
|
|
|
|
|
|
|
|
|
|
return deviceTypePluginDAOManager;
|
|
|
|
return deviceTypePluginDAOManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void createPluginBasedDeviceTypeManager()
|
|
|
|
/**
|
|
|
|
|
|
|
|
* To create a plugin based device type manager.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return Plugin based device type manager.
|
|
|
|
|
|
|
|
* @throws IOException IO Exception.
|
|
|
|
|
|
|
|
* @throws SQLException SQL Exception
|
|
|
|
|
|
|
|
* @throws NoSuchFieldException No Such File Exception.
|
|
|
|
|
|
|
|
* @throws IllegalAccessException Illegal Access Exception.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private DeviceTypePluginDAOManager createPluginBasedDeviceTypeManager()
|
|
|
|
throws IOException, SQLException, NoSuchFieldException, IllegalAccessException {
|
|
|
|
throws IOException, SQLException, NoSuchFieldException, IllegalAccessException {
|
|
|
|
String deviceType = "new_property_device_type";
|
|
|
|
|
|
|
|
ClassLoader classLoader = getClass().getClassLoader();
|
|
|
|
ClassLoader classLoader = getClass().getClassLoader();
|
|
|
|
URL resourceUrl = classLoader.getResource("h2.sql");
|
|
|
|
URL resourceUrl = classLoader.getResource("h2.sql");
|
|
|
|
File cdmDataScript = null;
|
|
|
|
File cdmDataScript = null;
|
|
|
@ -237,37 +302,28 @@ public class DeviceTypeManagerTest {
|
|
|
|
cdmDataScript = new File(resourceUrl.getFile());
|
|
|
|
cdmDataScript = new File(resourceUrl.getFile());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cdmDataScript != null) {
|
|
|
|
if (cdmDataScript != null) {
|
|
|
|
dataSource = Utils.createDataTables("deviceType", cdmDataScript.getAbsolutePath());
|
|
|
|
dataSource = Utils.createDataTables(customDeviceType, cdmDataScript.getAbsolutePath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Field datasourceField = DeviceTypeDAOHandler.class.getDeclaredField("dataSource");
|
|
|
|
|
|
|
|
datasourceField.setAccessible(true);
|
|
|
|
|
|
|
|
Field currentConnection = DeviceTypeDAOHandler.class.getDeclaredField("currentConnection");
|
|
|
|
|
|
|
|
currentConnection.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceDetails deviceDetails = new DeviceDetails();
|
|
|
|
DeviceDetails deviceDetails = new DeviceDetails();
|
|
|
|
|
|
|
|
|
|
|
|
List<String> propertyList = new ArrayList<>();
|
|
|
|
List<String> propertyList = new ArrayList<>();
|
|
|
|
propertyList.add("custom_property");
|
|
|
|
propertyList.addAll(Arrays.asList(customDeviceTypeProperties));
|
|
|
|
propertyList.add("custom_property");
|
|
|
|
|
|
|
|
Properties properties = new Properties();
|
|
|
|
Properties properties = new Properties();
|
|
|
|
|
|
|
|
properties.addProperties(propertyList);
|
|
|
|
|
|
|
|
deviceDetails.setProperties(properties);
|
|
|
|
|
|
|
|
|
|
|
|
DeviceTypeDAOHandler deviceTypeDAOHandler = Mockito
|
|
|
|
DeviceTypeDAOHandler deviceTypeDAOHandler = Mockito
|
|
|
|
.mock(DeviceTypeDAOHandler.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
.mock(DeviceTypeDAOHandler.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
datasourceField.set(deviceTypeDAOHandler, dataSource);
|
|
|
|
datasourceField.set(deviceTypeDAOHandler, dataSource);
|
|
|
|
currentConnection.set(deviceTypeDAOHandler, new ThreadLocal<Connection>());
|
|
|
|
currentConnection.set(deviceTypeDAOHandler, new ThreadLocal<Connection>());
|
|
|
|
|
|
|
|
PluginDAO deviceTypePluginDAO = new PropertyBasedPluginDAOImpl(deviceDetails, deviceTypeDAOHandler,
|
|
|
|
PluginDAO deviceTypePluginDAO = new PropertyBasedPluginDAOImpl(deviceDetails, deviceTypeDAOHandler, deviceType);
|
|
|
|
customDeviceType);
|
|
|
|
|
|
|
|
|
|
|
|
DeviceTypePluginDAOManager deviceTypePluginDAOManager = Mockito
|
|
|
|
DeviceTypePluginDAOManager deviceTypePluginDAOManager = Mockito
|
|
|
|
.mock(DeviceTypePluginDAOManager.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
.mock(DeviceTypePluginDAOManager.class, Mockito.CALLS_REAL_METHODS);
|
|
|
|
Field deviceTypePluginDAOField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypePluginDAO");
|
|
|
|
|
|
|
|
deviceTypePluginDAOField.setAccessible(true);
|
|
|
|
|
|
|
|
Field deviceTypeDAOHandlerField = DeviceTypePluginDAOManager.class.getDeclaredField("deviceTypeDAOHandler");
|
|
|
|
|
|
|
|
deviceTypeDAOHandlerField.setAccessible(true);
|
|
|
|
|
|
|
|
deviceTypePluginDAOField.set(deviceTypePluginDAOManager, deviceTypePluginDAO);
|
|
|
|
deviceTypePluginDAOField.set(deviceTypePluginDAOManager, deviceTypePluginDAO);
|
|
|
|
deviceTypeDAOHandlerField.set(deviceTypePluginDAOManager, deviceTypeDAOHandler);
|
|
|
|
deviceTypeDAOHandlerField.set(deviceTypePluginDAOManager, deviceTypeDAOHandler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return deviceTypePluginDAOManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|