diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
index 98b5295724..c028609c86 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml
@@ -77,7 +77,21 @@
org.wso2.carbon.device.mgt.extensions.pull.notification
test
-
+
+ com.h2database.wso2
+ h2-database-engine
+ test
+
+
+ commons-dbcp.wso2
+ commons-dbcp
+ 1.4.0.wso2v1
+
+
+ commons-pool.wso2
+ commons-pool
+ 1.5.6.wso2v1
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
index 8bf15732a0..b0c4f8312e 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java
@@ -433,8 +433,11 @@ public class DeviceTypeManager implements DeviceManager {
if (propertiesExist) {
boolean status;
Device existingDevice = this.getDevice(deviceIdentifier);
- existingDevice.setProperties(device.getProperties());
+ if (existingDevice == null) {
+ return false;
+ }
+ existingDevice.setProperties(device.getProperties());
try {
if (log.isDebugEnabled()) {
log.debug(
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
index a8f9141904..a71d8c0185 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/dao/DeviceTypePluginDAOImpl.java
@@ -266,7 +266,7 @@ public class DeviceTypePluginDAOImpl implements PluginDAO {
deleteDBQueryToRemoveDevicd = "DELETE FROM " + deviceDAODefinition.getDeviceTableName()
+ " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?";
- selectDBQueryToGetAllDevice = "SELECT " + getDeviceTableColumnNames() + " FROM "
- + deviceDAODefinition.getDeviceTableName();
+ selectDBQueryToGetAllDevice = "SELECT " + getDeviceTableColumnNames() + "," + deviceDAODefinition.getPrimaryKey() +
+ " FROM " + deviceDAODefinition.getDeviceTableName();
}
}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java
new file mode 100644
index 0000000000..930a4dc4a9
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerTest.java
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.carbon.device.mgt.extensions.device.type.template;
+
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.context.RegistryType;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
+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.internal.DeviceTypeExtensionDataHolder;
+import org.wso2.carbon.device.mgt.extensions.utils.Utils;
+import org.wso2.carbon.registry.core.Registry;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.xml.sax.SAXException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class tests the {@link DeviceTypeManager}
+ */
+public class DeviceTypeManagerTest {
+ private DeviceTypeManager androidDeviceTypeManager;
+ private DeviceIdentifier nonExistingDeviceIdentifier;
+ private Device sampleDevice1;
+ private Device sampleDevice2;
+ private String androidDeviceType;
+
+ @BeforeTest(description = "Mocking the classes for testing")
+ public void setup() throws NoSuchFieldException, IllegalAccessException, IOException, SQLException, SAXException,
+ ParserConfigurationException, DeviceTypeConfigurationException, JAXBException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ URL resourceUrl = classLoader.getResource("android_h2.sql");
+ androidDeviceType = "android";
+ File androidDatabaseScript = null;
+ javax.sql.DataSource dataSource = null;
+ File carbonHome = new File("src/test/resources/carbon-home");
+
+ if (resourceUrl != null) {
+ androidDatabaseScript = new File(resourceUrl.getFile());
+ }
+ if (carbonHome.exists()) {
+ System.setProperty("carbon.home", carbonHome.getAbsolutePath());
+ }
+ resourceUrl = classLoader.getResource("android.xml");
+ File androidConfiguration = null;
+ if (resourceUrl != null) {
+ androidConfiguration = new File(resourceUrl.getFile());
+ }
+ DeviceTypeConfiguration androidDeviceConfiguration = Utils.getDeviceTypeConfiguration(androidConfiguration);
+ androidDeviceTypeManager = Mockito.mock(DeviceTypeManager.class, Mockito.CALLS_REAL_METHODS);
+
+ if (androidDatabaseScript != null) {
+ dataSource = Utils.createDataTables("deviceType", androidDatabaseScript.getAbsolutePath());
+ }
+ DeviceTypePluginDAOManager deviceTypePluginDAOManager = createMockDeviceTypePluginDAOManager(dataSource,
+ androidDeviceConfiguration);
+ Field deviceTypePluginDAOManagerField = DeviceTypeManager.class.getDeclaredField("deviceTypePluginDAOManager");
+ deviceTypePluginDAOManagerField.setAccessible(true);
+ deviceTypePluginDAOManagerField.set(androidDeviceTypeManager, deviceTypePluginDAOManager);
+
+ Field propertiesExist = DeviceTypeManager.class.getDeclaredField("propertiesExist");
+ propertiesExist.setAccessible(true);
+ Field deviceType = DeviceTypeManager.class.getDeclaredField("deviceType");
+ deviceType.setAccessible(true);
+ deviceType.set(androidDeviceTypeManager, androidDeviceType);
+ propertiesExist.set(androidDeviceTypeManager, true);
+ createDevice();
+ }
+
+ @Test(description = "This test case tests IsEnrolled method of the DeviceTypeManager",
+ dependsOnMethods = {"testEnrollDevice"})
+ public void testIsEnrolled() throws DeviceManagementException {
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
+ sampleDevice2.getType());
+ Assert.assertTrue(!androidDeviceTypeManager.isEnrolled(nonExistingDeviceIdentifier),
+ "Device with " + "NON-Existing ID is not enrolled, but this shows as enrolled");
+ Assert.assertTrue(androidDeviceTypeManager.isEnrolled(deviceIdentifier),
+ "Enrolled device is shown as un-enrolled");
+ }
+
+ @Test(description = "This test case tests the getDevcie method of the DeviceTypeManager", dependsOnMethods =
+ {"testEnrollDevice"})
+ public void testGetDevice() throws DeviceManagementException {
+ DeviceIdentifier existingDeviceIdntifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
+ androidDeviceType);
+ Assert.assertNull(androidDeviceTypeManager.getDevice(nonExistingDeviceIdentifier),
+ "Non existing sampleDevice was retrieved");
+ Assert.assertNotNull(androidDeviceTypeManager.getDevice(existingDeviceIdntifier),
+ "Existing sampleDevice was retrieved");
+ }
+
+ @Test(description = "This test case tests the enrollment of the device")
+ public void testEnrollDevice() throws DeviceManagementException {
+ Assert.assertTrue(androidDeviceTypeManager.enrollDevice(sampleDevice1));
+ Assert.assertTrue(!androidDeviceTypeManager.enrollDevice(sampleDevice2));
+ }
+
+ @Test(description = "This test case tests the get all devices method of the DeviceTypeManager", dependsOnMethods
+ = {"testEnrollDevice"})
+ public void testGetAllDevices() throws DeviceManagementException {
+ Assert.assertEquals(androidDeviceTypeManager.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")
+ public void testAddPlatformConfiguration() throws RegistryException, DeviceManagementException {
+ PrivilegedCarbonContext.getThreadLocalCarbonContext()
+ .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ PlatformConfiguration platformConfiguration = new PlatformConfiguration();
+ platformConfiguration.setType(androidDeviceType);
+ RegistryService registryService = Utils.getRegistryService();
+ Registry governanceSystemRegistry = registryService.getConfigSystemRegistry();
+ DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService);
+ PrivilegedCarbonContext.getThreadLocalCarbonContext()
+ .setRegistry(RegistryType.SYSTEM_CONFIGURATION, governanceSystemRegistry);
+ androidDeviceTypeManager.saveConfiguration(platformConfiguration);
+ androidDeviceTypeManager.getConfiguration();
+ PlatformConfiguration actualPlatformConfiguration = androidDeviceTypeManager.getConfiguration();
+ Assert.assertNotNull(actualPlatformConfiguration,
+ "Platform Configuration saved and retrieved correctly in " + "DeviceType Manager");
+ Assert.assertEquals(actualPlatformConfiguration.getType(), androidDeviceType,
+ "Platform Configuration saved and " + "retrieved correctly in DeviceType Manager");
+ }
+
+ @Test (description = "This test case tests the getDefaultConfiguration method")
+ public void testGetDefaultConfiguration()
+ throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Method getDefaultConfiguration = DeviceTypeManager.class.getDeclaredMethod("getDefaultConfiguration");
+ getDefaultConfiguration.setAccessible(true);
+ Assert.assertNull(getDefaultConfiguration.invoke(androidDeviceTypeManager), "Default configuration file "
+ + "retrieved even without adding the configuration for the device type android");
+ }
+
+ @Test (description = "This test case tests the updateDeviceInfo method")
+ public void testUpdateDeviceInfo() throws DeviceManagementException {
+ DeviceIdentifier existingDeviceIdentifier = new DeviceIdentifier(sampleDevice2.getDeviceIdentifier(),
+ androidDeviceType);
+ Assert.assertFalse(androidDeviceTypeManager.updateDeviceInfo(nonExistingDeviceIdentifier, sampleDevice1),
+ "Non-existing device was updated");
+ Assert.assertTrue(androidDeviceTypeManager.updateDeviceInfo(existingDeviceIdentifier, sampleDevice1),
+ "Existing device update failed");
+ }
+
+ /**
+ * To create a sample sampleDevice to add to DAO Layer.
+ */
+ private void createDevice() {
+ nonExistingDeviceIdentifier = new DeviceIdentifier("NON-EXISTING", androidDeviceType);
+ List list = new ArrayList<>();
+
+ String[] deviceTypeAttributes = { "FCM_TOKEN", "DEVICE_INFO", "IMEI", "IMSI", "OS_VERSION", "DEVICE_MODEL",
+ "VENDOR", "LATITUDE", "LONGITUDE", "SERIAL", "MAC_ADDRESS", "DEVICE_NAME", "DEVICE_NAME",
+ "OS_BUILD_DATE" };
+
+ for (String deviceTypeAttribute : deviceTypeAttributes) {
+ Device.Property property = new Device.Property();
+ property.setName(deviceTypeAttribute);
+ property.setValue(deviceTypeAttribute + "T");
+ list.add(property);
+ }
+
+ sampleDevice1 = new Device("testdevice", androidDeviceType, "test", "testdevice", null, null, list);
+ sampleDevice2 = new Device("testdevice1", androidDeviceType, "test", "testdevice", null, null, list);
+ }
+
+ /*
+ * To create a mock sampleDevice type plugin dao manager.
+ * @param dataSource DataSource for the DAO layer
+ * @param androidDeviceConfiguration Android Device Configuration
+ * @return Mock Device Type Plugin DAO Manager
+ * @throws NoSuchFieldException No Such Field Exception
+ * @throws IllegalAccessException Illegal Access Exception
+ */
+ private DeviceTypePluginDAOManager createMockDeviceTypePluginDAOManager(javax.sql.DataSource dataSource,
+ 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
+ .mock(DeviceTypeDAOHandler.class, Mockito.CALLS_REAL_METHODS);
+ datasourceField.set(deviceTypeDAOHandler, dataSource);
+ currentConnection.set(deviceTypeDAOHandler, new ThreadLocal());
+
+ DeviceDAODefinition deviceDAODefinition = Utils.getDeviceDAODefinition(androidDeviceConfiguration);
+ DeviceTypePluginDAOImpl deviceTypePluginDAO = new DeviceTypePluginDAOImpl(deviceDAODefinition,
+ deviceTypeDAOHandler);
+
+ DeviceTypePluginDAOManager deviceTypePluginDAOManager = Mockito
+ .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);
+ deviceTypeDAOHandlerField.set(deviceTypePluginDAOManager, deviceTypeDAOHandler);
+
+ return deviceTypePluginDAOManager;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java
index f19049015b..732110f0e4 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/Utils.java
@@ -19,12 +19,24 @@
package org.wso2.carbon.device.mgt.extensions.utils;
+import org.h2.jdbcx.JdbcDataSource;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
+import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
+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.Table;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
+import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinition;
+import org.wso2.carbon.registry.core.config.RegistryContext;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
+import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
import org.xml.sax.SAXException;
+import javax.sql.DataSource;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -34,6 +46,11 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
/**
* This class handles the test utility tasks.
@@ -73,4 +90,84 @@ public class Utils {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file);
}
+
+ /**
+ * To create the database tables for the particular device-type based on the scripts
+ *
+ * @param databaseName Name of the Database
+ * @param scriptFilePath Path of the SQL script File
+ * @throws IOException IO Exception
+ * @throws SQLException SQL Exception.
+ */
+ public static DataSource createDataTables(String databaseName, String scriptFilePath) throws IOException,
+ SQLException {
+ JdbcDataSource dataSource = new JdbcDataSource();
+ dataSource.setURL("jdbc:h2:mem:" + databaseName + ";DB_CLOSE_DELAY=-1");
+ dataSource.setUser("sa");
+ dataSource.setPassword("sa");
+
+ File file = new File(scriptFilePath);
+
+ final String LOAD_DATA_QUERY = "RUNSCRIPT FROM '" + file.getCanonicalPath() + "'";
+
+ Connection connection = null;
+ try {
+ connection = dataSource.getConnection();
+ Statement statement = connection.createStatement();
+ statement.execute(LOAD_DATA_QUERY);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+ return dataSource;
+ }
+
+ /**
+ * To get the DeviceDAO Definition from the DeviceTypeConfiguration.
+ *
+ * @param deviceTypeConfiguration Device Type Configuration which we need the DeviceDAO Definition
+ * @return DeviceDAO Definition of the particular devicetype
+ */
+ public static DeviceDAODefinition getDeviceDAODefinition(DeviceTypeConfiguration deviceTypeConfiguration) {
+ DeviceDetails deviceDetails = deviceTypeConfiguration.getDeviceDetails();
+ DeviceDAODefinition deviceDAODefinition = null;
+
+ if (deviceDetails != null) {
+ String tableName = deviceTypeConfiguration.getDeviceDetails().getTableId();
+ if (tableName != null && !tableName.isEmpty()) {
+ List tables = deviceTypeConfiguration.getDataSource().getTableConfig().getTable();
+ Table deviceDefinitionTable = null;
+ for (Table table : tables) {
+ if (tableName.equals(table.getName())) {
+ deviceDefinitionTable = table;
+ break;
+ }
+ }
+ if (deviceDefinitionTable != null) {
+ deviceDAODefinition = new DeviceDAODefinition(deviceDefinitionTable);
+ }
+ }
+
+ }
+ return deviceDAODefinition;
+ }
+
+ /**
+ * To get the registry service.
+ * @return RegistryService
+ * @throws RegistryException Registry Exception
+ */
+ public static RegistryService getRegistryService() throws RegistryException {
+ RealmService realmService = new InMemoryRealmService();
+ RegistryDataHolder.getInstance().setRealmService(realmService);
+ DeviceManagementDataHolder.getInstance().setRealmService(realmService);
+ InputStream is = Utils.class.getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml");
+ RegistryContext context = RegistryContext.getBaseInstance(is, realmService);
+ context.setSetup(true);
+ return context.getEmbeddedRegistryService();
+ }
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_h2.sql
new file mode 100644
index 0000000000..9eed9b2d5e
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_h2.sql
@@ -0,0 +1,31 @@
+
+-- -----------------------------------------------------
+-- Table `AD_DEVICE`
+-- -----------------------------------------------------
+CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
+ `DEVICE_ID` VARCHAR(45) NOT NULL,
+ `FCM_TOKEN` VARCHAR(1000) NULL DEFAULT NULL,
+ `DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL,
+ `IMEI` VARCHAR(45) NULL DEFAULT NULL,
+ `IMSI` VARCHAR(45) NULL DEFAULT NULL,
+ `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
+ `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
+ `VENDOR` VARCHAR(45) NULL DEFAULT NULL,
+ `LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
+ `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
+ `SERIAL` VARCHAR(45) NULL DEFAULT NULL,
+ `MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
+ `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
+ `OS_BUILD_DATE` VARCHAR(100) NULL DEFAULT NULL,
+ PRIMARY KEY (`DEVICE_ID`));
+
+-- -----------------------------------------------------
+-- Table `AD_FEATURE`
+-- -----------------------------------------------------
+CREATE TABLE IF NOT EXISTS `AD_FEATURE` (
+ `ID` INT NOT NULL AUTO_INCREMENT,
+ `CODE` VARCHAR(45) NOT NULL,
+ `NAME` VARCHAR(100) NULL,
+ `DESCRIPTION` VARCHAR(200) NULL,
+ PRIMARY KEY (`ID`));
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/dbscripts/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/dbscripts/h2.sql
new file mode 100644
index 0000000000..f6b31c78d9
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/dbscripts/h2.sql
@@ -0,0 +1,429 @@
+CREATE TABLE IF NOT EXISTS REG_CLUSTER_LOCK (
+ REG_LOCK_NAME VARCHAR (20),
+ REG_LOCK_STATUS VARCHAR (20),
+ REG_LOCKED_TIME TIMESTAMP,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (REG_LOCK_NAME)
+);
+
+CREATE TABLE IF NOT EXISTS REG_LOG (
+ REG_LOG_ID INTEGER AUTO_INCREMENT,
+ REG_PATH VARCHAR (2000),
+ REG_USER_ID VARCHAR (31) NOT NULL,
+ REG_LOGGED_TIME TIMESTAMP NOT NULL,
+ REG_ACTION INTEGER NOT NULL,
+ REG_ACTION_DATA VARCHAR (500),
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (REG_LOG_ID, REG_TENANT_ID)
+);
+
+CREATE INDEX IF NOT EXISTS REG_LOG_IND_BY_REG_LOGTIME ON REG_LOG(REG_LOGGED_TIME, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_PATH(
+ REG_PATH_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_PATH_VALUE VARCHAR(2000) NOT NULL,
+ REG_PATH_PARENT_ID INT,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_PATH PRIMARY KEY(REG_PATH_ID, REG_TENANT_ID)
+);
+CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_NAME ON REG_PATH(REG_PATH_VALUE, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_PARENT_ID ON REG_PATH(REG_PATH_PARENT_ID, REG_TENANT_ID);
+
+
+CREATE TABLE IF NOT EXISTS REG_CONTENT (
+ REG_CONTENT_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_CONTENT_DATA LONGBLOB,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_CONTENT PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_CONTENT_HISTORY (
+ REG_CONTENT_ID INTEGER NOT NULL,
+ REG_CONTENT_DATA LONGBLOB,
+ REG_DELETED SMALLINT,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_CONTENT_HISTORY PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE (
+ REG_PATH_ID INTEGER NOT NULL,
+ REG_NAME VARCHAR(256),
+ REG_VERSION INTEGER NOT NULL AUTO_INCREMENT,
+ REG_MEDIA_TYPE VARCHAR(500),
+ REG_CREATOR VARCHAR(31) NOT NULL,
+ REG_CREATED_TIME TIMESTAMP NOT NULL,
+ REG_LAST_UPDATOR VARCHAR(31),
+ REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL,
+ REG_DESCRIPTION VARCHAR(1000),
+ REG_CONTENT_ID INTEGER,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ REG_UUID VARCHAR(100) NOT NULL,
+ CONSTRAINT PK_REG_RESOURCE PRIMARY KEY(REG_VERSION, REG_TENANT_ID)
+);
+
+ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT (REG_CONTENT_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_NAME ON REG_RESOURCE(REG_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_UUID ON REG_RESOURCE(REG_UUID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TENANT ON REG_RESOURCE(REG_TENANT_ID, REG_UUID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TYPE ON REG_RESOURCE(REG_TENANT_ID, REG_MEDIA_TYPE);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_HISTORY (
+ REG_PATH_ID INTEGER NOT NULL,
+ REG_NAME VARCHAR(256),
+ REG_VERSION INTEGER NOT NULL,
+ REG_MEDIA_TYPE VARCHAR(500),
+ REG_CREATOR VARCHAR(31) NOT NULL,
+ REG_CREATED_TIME TIMESTAMP NOT NULL,
+ REG_LAST_UPDATOR VARCHAR(31),
+ REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL,
+ REG_DESCRIPTION VARCHAR(1000),
+ REG_CONTENT_ID INTEGER,
+ REG_DELETED SMALLINT,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ REG_UUID VARCHAR(100) NOT NULL,
+ CONSTRAINT PK_REG_RESOURCE_HISTORY PRIMARY KEY(REG_VERSION, REG_TENANT_ID)
+);
+
+ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_PATHID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT_HISTORY (REG_CONTENT_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_NAME ON REG_RESOURCE_HISTORY(REG_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_COMMENT (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_COMMENT_TEXT VARCHAR(500) NOT NULL,
+ REG_USER_ID VARCHAR(31) NOT NULL,
+ REG_COMMENTED_TIME TIMESTAMP NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_COMMENT PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_COMMENT (
+ REG_COMMENT_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_COMMENT_ID FOREIGN KEY (REG_COMMENT_ID, REG_TENANT_ID) REFERENCES REG_COMMENT (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_COMMENT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_VERSION ON REG_RESOURCE_COMMENT(REG_VERSION, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_RATING (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_RATING INTEGER NOT NULL,
+ REG_USER_ID VARCHAR(31) NOT NULL,
+ REG_RATED_TIME TIMESTAMP NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_RATING PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_RATING (
+ REG_RATING_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_RATING_ID FOREIGN KEY (REG_RATING_ID, REG_TENANT_ID) REFERENCES REG_RATING (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_RATING(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_VERSION ON REG_RESOURCE_RATING(REG_VERSION, REG_TENANT_ID);
+
+
+CREATE TABLE IF NOT EXISTS REG_TAG (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_TAG_NAME VARCHAR(500) NOT NULL,
+ REG_USER_ID VARCHAR(31) NOT NULL,
+ REG_TAGGED_TIME TIMESTAMP NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_TAG PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_TAG (
+ REG_TAG_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_TAG_ID FOREIGN KEY (REG_TAG_ID, REG_TENANT_ID) REFERENCES REG_TAG (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_TAG(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_VERSION ON REG_RESOURCE_TAG(REG_VERSION, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_PROPERTY (
+ REG_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_NAME VARCHAR(100) NOT NULL,
+ REG_VALUE VARCHAR(1000),
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_PROPERTY PRIMARY KEY(REG_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_RESOURCE_PROPERTY (
+ REG_PROPERTY_ID INTEGER NOT NULL,
+ REG_VERSION INTEGER,
+ REG_PATH_ID INTEGER,
+ REG_RESOURCE_NAME VARCHAR(256),
+ REG_TENANT_ID INTEGER DEFAULT 0
+);
+
+ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_TAG_ID FOREIGN KEY (REG_PROPERTY_ID, REG_TENANT_ID) REFERENCES REG_PROPERTY (REG_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_PROPERTY(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_VERSION ON REG_RESOURCE_PROPERTY(REG_VERSION, REG_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS REG_ASSOCIATION (
+ REG_ASSOCIATION_ID INTEGER AUTO_INCREMENT,
+ REG_SOURCEPATH VARCHAR (2000) NOT NULL,
+ REG_TARGETPATH VARCHAR (2000) NOT NULL,
+ REG_ASSOCIATION_TYPE VARCHAR (2000) NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (REG_ASSOCIATION_ID, REG_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS REG_SNAPSHOT (
+ REG_SNAPSHOT_ID INTEGER NOT NULL AUTO_INCREMENT,
+ REG_PATH_ID INTEGER NOT NULL,
+ REG_RESOURCE_NAME VARCHAR (256),
+ REG_RESOURCE_VIDS LONGBLOB NOT NULL,
+ REG_TENANT_ID INTEGER DEFAULT 0,
+ CONSTRAINT PK_REG_SNAPSHOT PRIMARY KEY(REG_SNAPSHOT_ID, REG_TENANT_ID)
+);
+
+ALTER TABLE REG_SNAPSHOT ADD CONSTRAINT IF NOT EXISTS REG_SNAPSHOT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID);
+CREATE INDEX IF NOT EXISTS REG_SNAPSHOT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_SNAPSHOT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID);
+
+-- ################################
+-- USER MANAGER TABLES
+-- ################################
+
+CREATE TABLE IF NOT EXISTS UM_TENANT (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DOMAIN_NAME VARCHAR(255) NOT NULL,
+ UM_EMAIL VARCHAR(255),
+ UM_ACTIVE BOOLEAN DEFAULT FALSE,
+ UM_CREATED_DATE TIMESTAMP NOT NULL,
+ UM_USER_CONFIG LONGBLOB NOT NULL,
+ PRIMARY KEY (UM_ID),
+ UNIQUE(UM_DOMAIN_NAME));
+
+CREATE TABLE IF NOT EXISTS UM_DOMAIN(
+ UM_DOMAIN_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DOMAIN_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_DOMAIN_ID, UM_TENANT_ID)
+);
+
+CREATE INDEX IF NOT EXISTS INDEX_UM_TENANT_UM_DOMAIN_NAME ON UM_TENANT (UM_DOMAIN_NAME);
+
+CREATE TABLE IF NOT EXISTS UM_USER (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_USER_PASSWORD VARCHAR(255) NOT NULL,
+ UM_SALT_VALUE VARCHAR(31),
+ UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE,
+ UM_CHANGED_TIME TIMESTAMP NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ UNIQUE(UM_USER_NAME, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_USER_PASSWORD VARCHAR(255) NOT NULL,
+ UM_SALT_VALUE VARCHAR(31),
+ UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE,
+ UM_CHANGED_TIME TIMESTAMP NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ UNIQUE(UM_USER_NAME, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_USER_ATTRIBUTE (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ATTR_NAME VARCHAR(255) NOT NULL,
+ UM_ATTR_VALUE VARCHAR(1024),
+ UM_PROFILE_ID VARCHAR(255),
+ UM_USER_ID INTEGER,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID));
+
+CREATE INDEX IF NOT EXISTS UM_USER_ID_INDEX ON UM_USER_ATTRIBUTE(UM_USER_ID);
+
+CREATE TABLE IF NOT EXISTS UM_ROLE (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_NAME VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_SHARED_ROLE BOOLEAN DEFAULT FALSE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID),
+ UNIQUE(UM_ROLE_NAME, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_MODULE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_MODULE_NAME VARCHAR(100),
+ UNIQUE(UM_MODULE_NAME),
+ PRIMARY KEY(UM_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_MODULE_ACTIONS(
+ UM_ACTION VARCHAR(255) NOT NULL,
+ UM_MODULE_ID INTEGER NOT NULL,
+ PRIMARY KEY(UM_ACTION, UM_MODULE_ID),
+ FOREIGN KEY (UM_MODULE_ID) REFERENCES UM_MODULE(UM_ID) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS UM_PERMISSION (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_RESOURCE_ID VARCHAR(255) NOT NULL,
+ UM_ACTION VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_MODULE_ID INTEGER DEFAULT 0,
+ UNIQUE(UM_RESOURCE_ID,UM_ACTION, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+CREATE INDEX IF NOT EXISTS INDEX_UM_PERMISSION_UM_RESOURCE_ID_UM_ACTION ON UM_PERMISSION (UM_RESOURCE_ID, UM_ACTION, UM_TENANT_ID);
+
+CREATE TABLE IF NOT EXISTS UM_ROLE_PERMISSION (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_PERMISSION_ID INTEGER NOT NULL,
+ UM_ROLE_NAME VARCHAR(255) NOT NULL,
+ UM_IS_ALLOWED SMALLINT NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_DOMAIN_ID INTEGER,
+ FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_USER_PERMISSION (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_PERMISSION_ID INTEGER NOT NULL,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_IS_ALLOWED SMALLINT NOT NULL,
+ UNIQUE (UM_PERMISSION_ID, UM_USER_NAME, UM_TENANT_ID),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+CREATE TABLE IF NOT EXISTS UM_USER_ROLE (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_USER_ID INTEGER NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_ROLE(UM_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID));
+
+
+CREATE TABLE IF NOT EXISTS UM_SHARED_USER_ROLE(
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_USER_ID INTEGER NOT NULL,
+ UM_USER_TENANT_ID INTEGER NOT NULL,
+ UM_ROLE_TENANT_ID INTEGER NOT NULL,
+ UNIQUE(UM_USER_ID,UM_ROLE_ID,UM_USER_TENANT_ID, UM_ROLE_TENANT_ID),
+ FOREIGN KEY(UM_ROLE_ID,UM_ROLE_TENANT_ID) REFERENCES UM_ROLE(UM_ID,UM_TENANT_ID) ON DELETE CASCADE ,
+ FOREIGN KEY(UM_USER_ID,UM_USER_TENANT_ID) REFERENCES UM_USER(UM_ID,UM_TENANT_ID) ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS UM_ACCOUNT_MAPPING(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER NOT NULL,
+ UM_USER_STORE_DOMAIN VARCHAR(100),
+ UM_ACC_LINK_ID INTEGER NOT NULL,
+ UNIQUE(UM_USER_NAME, UM_TENANT_ID, UM_USER_STORE_DOMAIN, UM_ACC_LINK_ID),
+ FOREIGN KEY (UM_TENANT_ID) REFERENCES UM_TENANT(UM_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID)
+);
+
+
+CREATE TABLE IF NOT EXISTS UM_DIALECT(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DIALECT_URI VARCHAR(255) NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE(UM_DIALECT_URI, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+
+CREATE TABLE IF NOT EXISTS UM_CLAIM(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DIALECT_ID INTEGER NOT NULL,
+ UM_CLAIM_URI VARCHAR(255) NOT NULL,
+ UM_DISPLAY_TAG VARCHAR(255),
+ UM_DESCRIPTION VARCHAR(255),
+ UM_MAPPED_ATTRIBUTE_DOMAIN VARCHAR(255),
+ UM_MAPPED_ATTRIBUTE VARCHAR(255),
+ UM_REG_EX VARCHAR(255),
+ UM_SUPPORTED SMALLINT,
+ UM_REQUIRED SMALLINT,
+ UM_DISPLAY_ORDER INTEGER,
+ UM_CHECKED_ATTRIBUTE SMALLINT,
+ UM_READ_ONLY SMALLINT,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE(UM_DIALECT_ID, UM_CLAIM_URI,UM_MAPPED_ATTRIBUTE_DOMAIN, UM_TENANT_ID),
+ FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_PROFILE_CONFIG(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_DIALECT_ID INTEGER,
+ UM_PROFILE_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+
+CREATE TABLE IF NOT EXISTS UM_HYBRID_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_HYBRID_USER_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255),
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UM_DOMAIN_ID INTEGER,
+ UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID,UM_DOMAIN_ID),
+ FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_HYBRID_ROLE(UM_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_HYBRID_REMEMBER_ME (
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255) NOT NULL,
+ UM_COOKIE_VALUE VARCHAR(1024),
+ UM_CREATED_TIME TIMESTAMP,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_SYSTEM_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_ROLE_NAME VARCHAR(255),
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
+
+CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER_ROLE(
+ UM_ID INTEGER NOT NULL AUTO_INCREMENT,
+ UM_USER_NAME VARCHAR(255),
+ UM_ROLE_ID INTEGER NOT NULL,
+ UM_TENANT_ID INTEGER DEFAULT 0,
+ UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID),
+ FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_SYSTEM_ROLE(UM_ID, UM_TENANT_ID),
+ PRIMARY KEY (UM_ID, UM_TENANT_ID)
+);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml
new file mode 100644
index 0000000000..f24ee57be2
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/carbon.xml
@@ -0,0 +1,656 @@
+
+
+
+
+
+
+
+
+ ${product.name}
+
+
+ ${product.key}
+
+
+ ${product.version}
+
+
+
+
+
+
+
+
+ local:/${carbon.context}/services/
+
+
+
+
+
+
+ ${default.server.role}
+
+
+
+
+
+
+ org.wso2.carbon
+
+
+ /
+
+
+
+
+
+
+
+
+ 15
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+ 9999
+
+ 11111
+
+
+
+
+
+ 10389
+
+ 8000
+
+
+
+
+
+ 10500
+
+
+
+
+
+
+ org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory
+
+
+
+
+
+
+
+
+ java
+
+
+
+
+
+
+
+
+
+ false
+
+
+ false
+
+
+ 600
+
+
+
+ false
+
+
+
+
+
+
+
+ 30
+
+
+
+
+
+
+
+
+ 15
+
+
+
+
+
+ ${carbon.home}/repository/deployment/server/
+
+
+ 15
+
+
+ ${carbon.home}/repository/conf/axis2/axis2.xml
+
+
+ 30000
+
+
+ ${carbon.home}/repository/deployment/client/
+
+ ${carbon.home}/repository/conf/axis2/axis2_client.xml
+
+ true
+
+
+
+
+
+
+
+
+
+ admin
+ Default Administrator Role
+
+
+ user
+ Default User Role
+
+
+
+
+
+
+
+
+
+
+
+ ${carbon.home}/repository/resources/security/wso2carbon.jks
+
+ JKS
+
+ wso2carbon
+
+ wso2carbon
+
+ wso2carbon
+
+
+
+
+
+ ${carbon.home}/repository/resources/security/client-truststore.jks
+
+ JKS
+
+ wso2carbon
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UserManager
+
+
+ false
+
+
+
+
+
+
+ ${carbon.home}/tmp/work
+
+
+
+
+
+ true
+
+
+ 10
+
+
+ 30
+
+
+
+
+
+ 100
+
+
+
+ keystore
+ certificate
+ *
+
+ org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor
+
+
+
+
+ jarZip
+
+ org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor
+
+
+
+ dbs
+
+ org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor
+
+
+
+ tools
+
+ org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor
+
+
+
+ toolsAny
+
+ org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor
+
+
+
+
+
+
+ - info
+ org.wso2.carbon.core.transports.util.InfoProcessor
+
+
+ - wsdl
+ org.wso2.carbon.core.transports.util.Wsdl11Processor
+
+
+ - wsdl2
+ org.wso2.carbon.core.transports.util.Wsdl20Processor
+
+
+ - xsd
+ org.wso2.carbon.core.transports.util.XsdProcessor
+
+
+
+
+
+ false
+ false
+ true
+ svn
+ http://svnrepo.example.com/repos/
+ username
+ password
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${require.carbon.servlet}
+
+
+
+
+ true
+
+
+
+
+
+
+ default repository
+ ${p2.repo.url}
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+ true
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/registry.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/registry.xml
new file mode 100644
index 0000000000..85d422c704
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/registry.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+
+ wso2registry
+ false
+ true
+ /
+
+
+ jdbc:h2:./target/databasetest/CARBON_TEST
+
+ org.h2.Driver
+ 80
+ 60000
+ 5
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+ true
+ true
+ true
+ true
+
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml
index 026b63df9a..ae7dbfaea6 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/testng.xml
@@ -24,6 +24,7 @@
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/user-test/user-mgt-registry-test.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/user-test/user-mgt-registry-test.xml
new file mode 100644
index 0000000000..ebc6ed4cfc
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/user-test/user-mgt-registry-test.xml
@@ -0,0 +1,80 @@
+
+
+
+
+ true
+ admin
+
+ admin
+ admin
+
+ everyone
+ false
+ 500
+ jdbc:h2:target/databasetest/CARBON_TEST
+ org.h2.Driver
+ 50
+ 60000
+ 5
+
+
+ org.wso2.carbon.user.core.tenant.JDBCTenantManager
+ false
+ 100
+ false
+ default
+ SHA-256
+ true
+ true
+ true
+ false
+ ^[\S]{5,30}$
+ Password length should be between 5 to 30 characters
+
+ ^[\S]{5,30}$
+ [a-zA-Z0-9._-|//]{3,30}$
+ ^[\S]{3,30}$
+ ^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$
+ ^[\S]{3,30}$
+ true
+ 100
+ 100
+ false
+ false
+ true
+ ,
+ true
+
+
+ true
+
+
+
+ login
+ manage-configuration
+ manage-security
+ upload-services
+ manage-services
+ manage-lc-configuration
+ manage-mediation
+ monitor-system
+ delegate-identity
+
+