From 16ab9dac3bb42fd17c1817f42622295476a0f42c Mon Sep 17 00:00:00 2001 From: megala21 Date: Fri, 29 Sep 2017 15:27:16 +0530 Subject: [PATCH] Moving the device-type and sql file folder as constants --- .../device/type/template/BaseExtensionsTest.java | 2 +- .../type/template/DeviceTypeManagerNegativeTest.java | 10 +++++----- .../type/template/DeviceTypeManagerServiceTest.java | 6 +++--- .../device/type/template/DeviceTypeManagerTest.java | 7 ++++--- ...anagerServiceAndDeviceTypeGeneratorServceTest.java | 2 +- .../carbon/device/mgt/extensions/utils/Utils.java | 11 ++++++----- 6 files changed, 20 insertions(+), 18 deletions(-) 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 index 2b6e945921..3ec819a10b 100644 --- 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 @@ -51,7 +51,7 @@ public class BaseExtensionsTest { @BeforeSuite public void init() throws RegistryException, IOException { ClassLoader classLoader = getClass().getClassLoader(); - URL resourceUrl = classLoader.getResource("device-types/license.rxt"); + URL resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "license.rxt"); String rxt = null; File carbonHome; if (resourceUrl != null) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java index 84bdc16f24..d2d9060d12 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java @@ -50,7 +50,7 @@ public class DeviceTypeManagerNegativeTest { throws SAXException, JAXBException, ParserConfigurationException, DeviceTypeConfigurationException, IOException { ClassLoader classLoader = getClass().getClassLoader(); - URL resourceUrl = classLoader.getResource("device-types/defective-devicetype.xml"); + URL resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "defective-devicetype.xml"); File configurationFile = null; if (resourceUrl != null) { configurationFile = new File(resourceUrl.getFile()); @@ -58,10 +58,10 @@ public class DeviceTypeManagerNegativeTest { if (configurationFile != null) { defectiveDeviceTypeConfiguration1 = Utils.getDeviceTypeConfiguration(configurationFile.getAbsoluteFile()); } - deviceTypeConfigIdentifier = new DeviceTypeConfigIdentifier(DEFECTIVE_DEVICE_TYPE,MultitenantConstants - .SUPER_TENANT_DOMAIN_NAME); + deviceTypeConfigIdentifier = new DeviceTypeConfigIdentifier(DEFECTIVE_DEVICE_TYPE, + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - resourceUrl = classLoader.getResource("device-types/defective-devicetype2.xml"); + resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "defective-devicetype2.xml"); if (resourceUrl != null) { configurationFile = new File(resourceUrl.getFile()); } @@ -69,7 +69,7 @@ public class DeviceTypeManagerNegativeTest { defectiveDeviceTypeConfiguration2 = Utils.getDeviceTypeConfiguration(configurationFile.getAbsoluteFile()); } - resourceUrl = classLoader.getResource("device-types/android.xml"); + resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "android.xml"); if (resourceUrl != null) { configurationFile = new File(resourceUrl.getFile()); } 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 cb0d8e9d57..f90d33bd34 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 @@ -124,7 +124,7 @@ public class DeviceTypeManagerServiceTest { operationMonitoringConfigs.set(rasberrypiDeviceTypeManagerService, new OperationMonitoringTaskConfig()); initialOperationConfig.set(rasberrypiDeviceTypeManagerService, new InitialOperationConfig()); - URL resourceUrl = classLoader.getResource("device-types/android.xml"); + URL resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "android.xml"); File androidConfiguration = null; if (resourceUrl != null) { @@ -132,7 +132,7 @@ public class DeviceTypeManagerServiceTest { } androidDeviceConfiguration = Utils.getDeviceTypeConfiguration(androidConfiguration); - resourceUrl = classLoader.getResource("device-types/raspberrypi.xml"); + resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "raspberrypi.xml"); File raspberrypiConfiguration = null; if (resourceUrl != null) { raspberrypiConfiguration = new File(resourceUrl.getFile()); @@ -304,7 +304,7 @@ public class DeviceTypeManagerServiceTest { throws RegistryException, IOException, SAXException, ParserConfigurationException, DeviceTypeConfigurationException, JAXBException { ClassLoader classLoader = getClass().getClassLoader(); - URL resourceUrl = classLoader.getResource("device-types/arduino.xml"); + URL resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "arduino.xml"); File arduinoConfiguration = null; if (resourceUrl != null) { arduinoConfiguration = new File(resourceUrl.getFile()); 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 index ed3ff2485e..27ebd3f827 100644 --- 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 @@ -71,12 +71,13 @@ public class DeviceTypeManagerTest { private Field deviceTypePluginDAOField; private Field deviceTypeDAOHandlerField; private String[] customDeviceTypeProperties = {"custom_property", "custom_property2"}; + private final String SQL_FOLDER = "sql-files" + File.separator; @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("sql-files/android_h2.sql"); + URL resourceUrl = classLoader.getResource(SQL_FOLDER + "android_h2.sql"); androidDeviceType = "android"; File androidDatabaseScript = null; javax.sql.DataSource dataSource = null; @@ -85,7 +86,7 @@ public class DeviceTypeManagerTest { if (resourceUrl != null) { androidDatabaseScript = new File(resourceUrl.getFile()); } - resourceUrl = classLoader.getResource("device-types/android.xml"); + resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "android.xml"); if (resourceUrl != null) { androidConfiguration = new File(resourceUrl.getFile()); @@ -295,7 +296,7 @@ public class DeviceTypeManagerTest { private DeviceTypePluginDAOManager createPluginBasedDeviceTypeManager() throws IOException, SQLException, NoSuchFieldException, IllegalAccessException { ClassLoader classLoader = getClass().getClassLoader(); - URL resourceUrl = classLoader.getResource("sql-files/h2.sql"); + URL resourceUrl = classLoader.getResource(SQL_FOLDER + "h2.sql"); File cdmDataScript = null; javax.sql.DataSource dataSource = null; if (resourceUrl != null) { 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 index 62b655a218..7c4ff9ec2c 100644 --- 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 @@ -154,7 +154,7 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { throws SAXException, JAXBException, ParserConfigurationException, DeviceTypeConfigurationException, IOException { ClassLoader classLoader = getClass().getClassLoader(); - URL resourceUrl = classLoader.getResource("device-types/android_sense.xml"); + URL resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "android_sense.xml"); File androidSenseConfiguration = null; if (resourceUrl != null) { 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 0e6c37cd1b..d35b8eba93 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 @@ -21,7 +21,6 @@ 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; @@ -56,16 +55,18 @@ import java.util.List; * This class handles the test utility tasks. */ public class Utils { + public static final String DEVICE_TYPE_FOLDER = "device-types" + File.separator; /** * To get the device type configuration based on the configuration file + * * @param configurationFile Relevant configuration file of a device type * @return the DeviceTypeConfiguration object of the relevant Device Type * @throws DeviceTypeConfigurationException DeviceType Configuration Exception - * @throws IOException IO Exception - * @throws SAXException SAX Exception - * @throws ParserConfigurationException Parser Configuration Exception - * @throws JAXBException JAXB Exception + * @throws IOException IO Exception + * @throws SAXException SAX Exception + * @throws ParserConfigurationException Parser Configuration Exception + * @throws JAXBException JAXB Exception */ public static DeviceTypeConfiguration getDeviceTypeConfiguration(File configurationFile) throws DeviceTypeConfigurationException, IOException, SAXException, ParserConfigurationException,