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 3a6bad6ed1..6a4e8afe39 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,37 @@ org.wso2.carbon.device.mgt.extensions.pull.notification test - + + com.h2database.wso2 + h2-database-engine + test + + + commons-dbcp.wso2 + commons-dbcp + test + + + commons-pool.wso2 + commons-pool + test + + + org.wso2.carbon.governance + org.wso2.carbon.governance.registry.extensions + test + + + org.wso2.carbon.registry + org.wso2.carbon.registry.indexing + test + + + org.slf4j + jcl-over-slf4j + + + 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..e705661daa 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 @@ -252,21 +252,24 @@ public class DeviceTypePluginDAOImpl implements PluginDAO { } private void initializeDbQueries() { - selectDBQueryForGetDevice = "SELECT " + getDeviceTableColumnNames() + " FROM " + - deviceDAODefinition.getDeviceTableName() + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; + selectDBQueryForGetDevice = + "SELECT " + getDeviceTableColumnNames() + " FROM " + deviceDAODefinition.getDeviceTableName() + + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; - createDBqueryForAddDevice = "INSERT INTO " + deviceDAODefinition.getDeviceTableName() + "(" - + deviceDAODefinition.getPrimaryKey() + " , " + getDeviceTableColumnNames() + ") VALUES (" - + getPreparedInputString(deviceDAODefinition.getColumnNames().size() + 1) + ")"; + createDBqueryForAddDevice = + "INSERT INTO " + deviceDAODefinition.getDeviceTableName() + "(" + deviceDAODefinition.getPrimaryKey() + + " , " + getDeviceTableColumnNames() + ") VALUES (" + getPreparedInputString( + deviceDAODefinition.getColumnNames().size() + 1) + ")"; updateDBQueryForUpdateDevice = "UPDATE " + deviceDAODefinition.getDeviceTableName() + " SET " - + getDeviceTableColumnNamesForUpdateQuery() + " WHERE " + deviceDAODefinition.getPrimaryKey() - + " = ?"; + + getDeviceTableColumnNamesForUpdateQuery() + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; - deleteDBQueryToRemoveDevicd = "DELETE FROM " + deviceDAODefinition.getDeviceTableName() - + " WHERE " + deviceDAODefinition.getPrimaryKey() + " = ?"; + 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/BaseExtensionsTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java new file mode 100644 index 0000000000..8d69cac776 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java @@ -0,0 +1,84 @@ +/* + * 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.testng.annotations.BeforeSuite; +import org.wso2.carbon.CarbonConstants; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.RegistryType; +import org.wso2.carbon.context.internal.OSGiDataHolder; +import org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionDataHolder; +import org.wso2.carbon.device.mgt.extensions.utils.Utils; +import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration; +import org.wso2.carbon.governance.api.util.GovernanceUtils; +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.wso2.carbon.registry.core.session.UserRegistry; +import org.wso2.carbon.utils.FileUtil; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceArtifactConfiguration; + +/** + * This class handles all the setup that need to be done before starting to run the test cases. + */ +public class BaseExtensionsTest { + + @BeforeSuite + public void init() throws RegistryException, IOException { + ClassLoader classLoader = getClass().getClassLoader(); + URL resourceUrl = classLoader.getResource("license.rxt"); + String rxt = null; + File carbonHome; + if (resourceUrl != null) { + rxt = FileUtil.readFileToString(resourceUrl.getFile()); + } + resourceUrl = classLoader.getResource("carbon-home"); + + if (resourceUrl != null) { + carbonHome = new File(resourceUrl.getFile()); + System.setProperty("carbon.home", carbonHome.getAbsolutePath()); + } + + PrivilegedCarbonContext.getThreadLocalCarbonContext() + .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + RegistryService registryService = Utils.getRegistryService(); + OSGiDataHolder.getInstance().setRegistryService(registryService); + UserRegistry systemRegistry = + registryService.getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME); + + GovernanceArtifactConfiguration configuration = getGovernanceArtifactConfiguration(rxt); + List configurations = new ArrayList<>(); + configurations.add(configuration); + GovernanceUtils.loadGovernanceArtifacts(systemRegistry, configurations); + Registry governanceSystemRegistry = registryService.getConfigSystemRegistry(); + DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService); + PrivilegedCarbonContext.getThreadLocalCarbonContext() + .setRegistry(RegistryType.SYSTEM_CONFIGURATION, governanceSystemRegistry); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java index f261f98374..2e1b1a52ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerServiceTest.java @@ -31,6 +31,8 @@ import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceStatusTaskConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration; @@ -40,6 +42,7 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNot import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException; import org.wso2.carbon.device.mgt.extensions.utils.Utils; +import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.xml.sax.SAXException; import javax.xml.bind.JAXBException; @@ -63,6 +66,8 @@ public class DeviceTypeManagerServiceTest { private DeviceTypeConfiguration androidDeviceConfiguration; private DeviceTypeManagerService rasberrypiDeviceTypeManagerService; private DeviceTypeConfiguration rasberrypiDeviceConfiguration; + private DeviceTypeManagerService arduinoDeviceTypeManagerService; + private DeviceTypeConfiguration arduinoDeviceTypeConfiguration; private Method setProvisioningConfig; private Method setOperationMonitoringConfig; private Method setDeviceStatusTaskPluginConfig; @@ -73,7 +78,9 @@ public class DeviceTypeManagerServiceTest { @BeforeTest public void setup() throws NoSuchMethodException, SAXException, JAXBException, ParserConfigurationException, DeviceTypeConfigurationException, IOException, NoSuchFieldException, IllegalAccessException, - DeviceManagementException { + DeviceManagementException, RegistryException { + ClassLoader classLoader = getClass().getClassLoader(); + setProvisioningConfig = DeviceTypeManagerService.class .getDeclaredMethod("setProvisioningConfig", String.class, DeviceTypeConfiguration.class); setProvisioningConfig.setAccessible(true); @@ -117,7 +124,6 @@ public class DeviceTypeManagerServiceTest { operationMonitoringConfigs.set(rasberrypiDeviceTypeManagerService, new OperationMonitoringTaskConfig()); initialOperationConfig.set(rasberrypiDeviceTypeManagerService, new InitialOperationConfig()); - ClassLoader classLoader = getClass().getClassLoader(); URL resourceUrl = classLoader.getResource("android.xml"); File androidConfiguration = null; @@ -143,14 +149,10 @@ public class DeviceTypeManagerServiceTest { configurationEntries.add(configurationEntry); platformConfiguration.setConfiguration(configurationEntries); - - if (androidConfiguration != null) { - // This is needed for DeviceTypeManager Initialization - System.setProperty("carbon.home", androidConfiguration.getAbsolutePath()); - } DeviceTypeManager deviceTypeManager = Mockito.mock(DeviceTypeManager.class); when(deviceTypeManager.getConfiguration()).thenReturn(platformConfiguration); deviceManager.set(androidDeviceTypeManagerService, deviceTypeManager); + setupArduinoDeviceType(); } @Test(description = "This test cases tests the retrieval of provisioning config after providing the configurations " @@ -164,7 +166,7 @@ public class DeviceTypeManagerServiceTest { ProvisioningConfig provisioningConfig = androidDeviceTypeManagerService.getProvisioningConfig(); Assert.assertEquals(provisioningConfig.isSharedWithAllTenants(), androidDeviceConfiguration.getProvisioningConfig().isSharedWithAllTenants(), - "Provisioning configs " + "are not correctly set as per the configuration file provided"); + "Provisioning configs are not correctly set as per the configuration file provided"); setProvisioningConfig.invoke(rasberrypiDeviceTypeManagerService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, rasberrypiDeviceConfiguration); @@ -273,4 +275,42 @@ public class DeviceTypeManagerServiceTest { rasberrypiDeviceConfiguration.getPullNotificationSubscriberConfig() != null); } + + @Test (description = "This test case tests the addition and retrieval of the license") + public void testGetLicense () throws LicenseManagementException { + License license = arduinoDeviceTypeManagerService.getDeviceManager().getLicense("en_Us"); + Assert.assertEquals(license.getText(), arduinoDeviceTypeConfiguration.getLicense().getText(), + "The retrieved" + " license is different from added license"); + license.setLanguage("eu"); + license.setText("This is a EU License"); + arduinoDeviceTypeManagerService.getDeviceManager().addLicense(license); + License newLicense = arduinoDeviceTypeManagerService.getDeviceManager().getLicense("eu"); + Assert.assertEquals(newLicense.getText(), license.getText(), + "The retrieved license is different from added license"); + Assert.assertNull(arduinoDeviceTypeManagerService.getDeviceManager().getLicense("tn"), + "License is retrieved for a non-existing language code"); + } + + /** + * Setting the Arduino Device Type + * @throws RegistryException Registry Exception + * @throws IOException IO Exception + * @throws SAXException SAX Exception + * @throws ParserConfigurationException Parser Configuration Exception + * @throws DeviceTypeConfigurationException Device Type Configuration Exception + * @throws JAXBException JAXB Exception + */ + private void setupArduinoDeviceType() + throws RegistryException, IOException, SAXException, ParserConfigurationException, + DeviceTypeConfigurationException, JAXBException { + ClassLoader classLoader = getClass().getClassLoader(); + URL resourceUrl = classLoader.getResource("arduino.xml"); + File raspberrypiConfiguration = null; + if (resourceUrl != null) { + raspberrypiConfiguration = new File(resourceUrl.getFile()); + } + arduinoDeviceTypeConfiguration = Utils.getDeviceTypeConfiguration(raspberrypiConfiguration); + arduinoDeviceTypeManagerService = new DeviceTypeManagerService(new + DeviceTypeConfigIdentifier("arduino", "carbon.super"), arduinoDeviceTypeConfiguration); + } } 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..137640f5d8 --- /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,228 @@ +/* + * 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.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.utils.Utils; +import org.wso2.carbon.registry.core.exceptions.RegistryException; +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 { + PlatformConfiguration platformConfiguration = new PlatformConfiguration(); + platformConfiguration.setType(androidDeviceType); + 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/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java new file mode 100644 index 0000000000..461b9d9f72 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest.java @@ -0,0 +1,157 @@ +/* + * 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.testng.Assert; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.wso2.carbon.CarbonConstants; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.RegistryType; +import org.wso2.carbon.context.internal.OSGiDataHolder; +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.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Operation; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException; +import org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionDataHolder; +import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; +import org.wso2.carbon.device.mgt.extensions.utils.Utils; +import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration; +import org.wso2.carbon.governance.api.util.GovernanceUtils; +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.wso2.carbon.registry.core.session.UserRegistry; +import org.wso2.carbon.utils.FileUtil; +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.net.URL; +import java.util.ArrayList; +import java.util.List; + +import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceArtifactConfiguration; + +/** + * This test case contains the tests for {@link HTTPDeviceTypeManagerService} and {@link DeviceTypeGeneratorServiceImpl} + */ +public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { + private DeviceTypeMetaDefinition deviceTypeMetaDefinition; + private HTTPDeviceTypeManagerService httpDeviceTypeManagerService; + private DeviceTypeGeneratorServiceImpl deviceTypeGeneratorService; + private String androidSenseDeviceType = "androidsense"; + private String sampleDeviceType = "sample"; + + @BeforeTest + public void setup() throws RegistryException, IOException, SAXException, ParserConfigurationException, + DeviceTypeConfigurationException, JAXBException { + createSampleDeviceTypeMetaDefinition(); + httpDeviceTypeManagerService = new HTTPDeviceTypeManagerService(androidSenseDeviceType, + deviceTypeMetaDefinition); + deviceTypeGeneratorService = new DeviceTypeGeneratorServiceImpl(); + + } + + @Test(description = "This test case tests the get type method of the device type manager") + public void testGetType() { + Assert.assertEquals(httpDeviceTypeManagerService.getType(), androidSenseDeviceType, + "HttpDeviceTypeManagerService returns" + " a different device type than initially provided"); + } + + @Test(description = "This test case tests the enrollment of newly added device type") + public void testEnrollDevice() throws DeviceManagementException { + String deviceId = "testdevice1"; + Device sampleDevice1 = new Device(deviceId, androidSenseDeviceType, "test", "testdevice", null, null, null); + Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager().enrollDevice(sampleDevice1), + "Enrollment of " + androidSenseDeviceType + " device failed"); + Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager() + .isEnrolled(new DeviceIdentifier(deviceId, androidSenseDeviceType)), + "Enrollment of " + androidSenseDeviceType + " device " + "failed"); + } + + @Test(description = "This test case tests the populate device management service method") + public void testPopulateDeviceManagementService() { + DeviceManagementService deviceManagementService = deviceTypeGeneratorService + .populateDeviceManagementService(sampleDeviceType, deviceTypeMetaDefinition); + Assert.assertEquals(deviceManagementService.getType(), sampleDeviceType, + "DeviceTypeGeneration for the " + "sample device type failed"); + } + + /** + * To create a sample device type meta defintion. + * @throws SAXException SAX Exception. + * @throws JAXBException JAXB Exception. + * @throws ParserConfigurationException ParserConfiguration Exception. + * @throws DeviceTypeConfigurationException DeviceTypeConfiguration Exception. + * @throws IOException IO Exception. + */ + private void createSampleDeviceTypeMetaDefinition() + throws SAXException, JAXBException, ParserConfigurationException, DeviceTypeConfigurationException, + IOException { + ClassLoader classLoader = getClass().getClassLoader(); + URL resourceUrl = classLoader.getResource("android_sense.xml"); + File androidSenseConfiguration = null; + + if (resourceUrl != null) { + androidSenseConfiguration = new File(resourceUrl.getFile()); + } + DeviceTypeConfiguration androidSenseDeviceTypeConfiguration = Utils + .getDeviceTypeConfiguration(androidSenseConfiguration); + PushNotificationProvider pushNotificationProvider = androidSenseDeviceTypeConfiguration + .getPushNotificationProvider(); + PushNotificationConfig pushNotificationConfig = new PushNotificationConfig(pushNotificationProvider.getType(), + pushNotificationProvider.isScheduled(), null); + org.wso2.carbon.device.mgt.extensions.device.type.template.config.License license = + androidSenseDeviceTypeConfiguration.getLicense(); + License androidSenseLicense = new License(); + androidSenseLicense.setText(license.getText()); + androidSenseLicense.setLanguage(license.getLanguage()); + + List configurationFeatues = androidSenseDeviceTypeConfiguration.getFeatures().getFeature(); + List features = new ArrayList<>(); + + for (Feature feature : configurationFeatues) { + org.wso2.carbon.device.mgt.common.Feature commonFeature = new org.wso2.carbon.device.mgt.common.Feature(); + commonFeature.setCode(feature.getCode()); + commonFeature.setDescription(feature.getDescription()); + commonFeature.setName(feature.getName()); + features.add(commonFeature); + } + + deviceTypeMetaDefinition = new DeviceTypeMetaDefinition(); + deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig); + deviceTypeMetaDefinition.setDescription("This is android_sense"); + deviceTypeMetaDefinition.setClaimable(true); + deviceTypeMetaDefinition.setLicense(androidSenseLicense); + deviceTypeMetaDefinition.setFeatures(features); + } +} 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..0e6c37cd1b 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,83 @@ 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/android_sense.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml new file mode 100644 index 0000000000..fbc58a1115 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/android_sense.xml @@ -0,0 +1,50 @@ + + + + + + + Add Keywords + Send keywords to the device + + + Add Threshold + Send Threshold to the device + + + Remove words + Remove Threshold from the device + + + + + true + + + + true + + + + en_US + 1.0.0 + This is license text + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml new file mode 100644 index 0000000000..eb12e9ccb3 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/arduino.xml @@ -0,0 +1,43 @@ + + + + + + + Control Bulb + Control Bulb on Arduino Uno + + + state + + + + + + + true + + + + en_US + 1.0.0 + This is license text + + + 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..31752cf9b4 --- /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..0bb97a7dc9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/registry.xml @@ -0,0 +1,50 @@ + + + + + + + + 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/license.rxt b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/license.rxt new file mode 100644 index 0000000000..3fa9d8b7c9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/license.rxt @@ -0,0 +1,41 @@ + + + /device-mgt/license/@{overview_name}/@{overview_language}/@{overview_version} + overview_name + + + + + + + + + + + + + + +
+ + Name + + + Language + + + Version + + + Validity From + + + Validity To + + + License + +
+ + 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..bad5807be5 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 @@ -23,7 +23,10 @@ + + + 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..bac4fc7667 --- /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 + + diff --git a/pom.xml b/pom.xml index 14a9972c3d..2128358763 100644 --- a/pom.xml +++ b/pom.xml @@ -1538,6 +1538,24 @@ ${power.mock.version} test + + commons-dbcp.wso2 + commons-dbcp + ${commons.dbcp.version} + test + + + org.wso2.carbon.governance + org.wso2.carbon.governance.registry.extensions + ${carbon.governance.version} + test + + + org.slf4j + jcl-over-slf4j + + + @@ -1968,6 +1986,8 @@ 0.7.5.201505241946 1.0b3 1.7.0 + 1.4.0.wso2v1 +