From 4d1b9ea03df2383d5ac53993f6844a2cb47d3449 Mon Sep 17 00:00:00 2001 From: megala21 Date: Tue, 10 Oct 2017 20:37:30 +0530 Subject: [PATCH] Refactoring --- .../template/DeviceTypeManagerNegativeTest.java | 10 +++++----- .../type/template/DeviceTypeManagerTest.java | 8 ++++---- ...ServiceAndDeviceTypeGeneratorServceTest.java | 11 ++++++----- .../device/mgt/extensions/utils/Utils.java | 1 + .../device/mgt/extensions/utils/UtilsTest.java | 17 +++++++++-------- 5 files changed, 25 insertions(+), 22 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/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 7d8de52148..06c0a3a0fb 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 @@ -111,24 +111,24 @@ public class DeviceTypeManagerNegativeTest { } createDefectiveDeviceTypeManager(); deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId("test"); + deviceIdentifier.setId(Utils.TEST_STRING); deviceIdentifier.setType(ANDROID_DEVICE_TYPE); DeviceDetails deviceDetails = new DeviceDetails(); Properties properties = new Properties(); List propertyList = new ArrayList<>(); - propertyList.add("test"); + propertyList.add(Utils.TEST_STRING); properties.addProperties(propertyList); deviceDetails.setProperties(properties); propertyBasedPluginDAO = new PropertyBasedPluginDAOImpl(deviceDetails, deviceTypeDAOHandler, ANDROID_DEVICE_TYPE); sampleDevice = new Device(); - sampleDevice.setDeviceIdentifier("test"); + sampleDevice.setDeviceIdentifier(Utils.TEST_STRING); List deviceProperties = new ArrayList<>(); Device.Property property = new Device.Property(); - property.setName("test"); - property.setValue("test"); + property.setName(Utils.TEST_STRING); + property.setValue(Utils.TEST_STRING); deviceProperties.add(property); sampleDevice.setProperties(deviceProperties); } 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 27ebd3f827..d6f732cf13 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 @@ -170,8 +170,8 @@ public class DeviceTypeManagerTest { Assert.assertTrue(customDeviceTypeManager.enrollDevice(customDevice), "Custom device type enrollment failed."); List properties = customDevice.getProperties(); Device.Property property = new Device.Property(); - property.setName("test"); - property.setValue("test"); + property.setName(Utils.TEST_STRING); + property.setValue(Utils.TEST_STRING); properties.add(property); customDevice.setProperties(properties); Assert.assertFalse(customDeviceTypeManager.enrollDevice(customDevice), @@ -239,8 +239,8 @@ public class DeviceTypeManagerTest { list.add(property); } - sampleDevice1 = new Device("testdevice", androidDeviceType, "test", "testdevice", null, null, list); - sampleDevice2 = new Device("testdevice1", androidDeviceType, "test", "testdevice", null, null, list); + sampleDevice1 = new Device("testdevice", androidDeviceType, Utils.TEST_STRING, "testdevice", null, null, list); + sampleDevice2 = new Device("testdevice1", androidDeviceType, Utils.TEST_STRING, "testdevice", null, null, list); } /** 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 d34ed73a3b..b6beda3c2c 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 @@ -79,7 +79,8 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { @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); + Device sampleDevice1 = new Device(deviceId, androidSenseDeviceType, Utils.TEST_STRING, "testdevice", null, null, + null); Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager().enrollDevice(sampleDevice1), "Enrollment of " + androidSenseDeviceType + " device failed"); Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager() @@ -112,7 +113,7 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { ConfigurationEntry configurationEntry = configurationEntries.get(0); - Assert.assertEquals(configurationEntry.getName(), "test", + Assert.assertEquals(configurationEntry.getName(), Utils.TEST_STRING, "Platform Configuration for device type " + "sample is not saved correctly"); String contentType = configurationEntry.getContentType(); @@ -154,10 +155,10 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { .getDeclaredMethod("getDeviceTypeConfiguration", String.class, DeviceTypeMetaDefinition.class); getDeviceTypeConfiguration.setAccessible(true); List properties = new ArrayList<>(); - properties.add("test"); + properties.add(Utils.TEST_STRING); deviceTypeMetaDefinition.setProperties(properties); Map mapProperties = new HashMap<>(); - mapProperties.put("test", "test"); + mapProperties.put(Utils.TEST_STRING, Utils.TEST_STRING); PushNotificationConfig pushNotificationConfig = new PushNotificationConfig("push", true, mapProperties); deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig); DeviceTypeConfiguration deviceTypeConfiguration = (DeviceTypeConfiguration) getDeviceTypeConfiguration @@ -209,7 +210,7 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest { org.wso2.carbon.device.mgt.common.Feature.MetadataEntry metadataEntry = new org.wso2.carbon.device.mgt .common.Feature.MetadataEntry(); metadataEntry.setId(1); - metadataEntry.setValue("test"); + metadataEntry.setValue(Utils.TEST_STRING); List metadataEntries = new ArrayList<>(); metadataEntries.add(metadataEntry); commonFeature.setMetadataEntries(metadataEntries); 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 d35b8eba93..8a2634d0f8 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 @@ -56,6 +56,7 @@ import java.util.List; */ public class Utils { public static final String DEVICE_TYPE_FOLDER = "device-types" + File.separator; + public static final String TEST_STRING = "test"; /** * To get the device type configuration based on the configuration file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java index a682ab99bb..c5a6f419cd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/utils/UtilsTest.java @@ -68,7 +68,7 @@ public class UtilsTest { @Test(description = "This test case tests the getLicense method of the FileBasedLicenseManager") public void testFileBasedLicenseManagerGetLicense() throws LicenseManagementException { - License fileBasedLicense = fileSystemBasedLicenseManager.getLicense("test","en_US"); + License fileBasedLicense = fileSystemBasedLicenseManager.getLicense(Utils.TEST_STRING,"en_US"); Assert.assertEquals(fileBasedLicense.getText(), "This is a file based license", "FileBased License cannot " + "be retrieved by FileBasedLicenseManager"); } @@ -84,7 +84,7 @@ public class UtilsTest { + "file system", expectedExceptions = {UnsupportedOperationException.class}, expectedExceptionsMessageRegExp = "'addLicense' method is not supported in FileSystemBasedLicenseManager") public void testFileBasedLicenseManagerAddLicense() throws LicenseManagementException { - fileSystemBasedLicenseManager.addLicense("test", null); + fileSystemBasedLicenseManager.addLicense(Utils.TEST_STRING, null); } @Test(description = "This test case tests the DeviceTypeConfigIdentifier equals method") @@ -102,15 +102,16 @@ public class UtilsTest { @Test(description = "This test cases tests the registry based license addition") public void testAddRegistryBasedLicense() throws LicenseManagementException { String newLicenseString = "New License"; - License fileBasedLicense = fileSystemBasedLicenseManager.getLicense("test", "en_US"); + License fileBasedLicense = fileSystemBasedLicenseManager.getLicense(Utils.TEST_STRING, "en_US"); RegistryBasedLicenseManager registryBasedLicenseManager = new RegistryBasedLicenseManager(); - registryBasedLicenseManager.addLicense("test", fileBasedLicense); + registryBasedLicenseManager.addLicense(Utils.TEST_STRING, fileBasedLicense); Assert.assertEquals(fileBasedLicense.getText(), - registryBasedLicenseManager.getLicense("test", "en_US").getText(), "Registry license addition failed"); + registryBasedLicenseManager.getLicense(Utils.TEST_STRING, "en_US").getText(), + "Registry license addition failed"); fileBasedLicense.setText(newLicenseString); - registryBasedLicenseManager.addLicense("test", fileBasedLicense); - Assert.assertEquals(registryBasedLicenseManager.getLicense("test", "en_US").getText(), newLicenseString, - "Registry license update failed"); + registryBasedLicenseManager.addLicense(Utils.TEST_STRING, fileBasedLicense); + Assert.assertEquals(registryBasedLicenseManager.getLicense(Utils.TEST_STRING, "en_US").getText(), + newLicenseString, "Registry license update failed"); } @Test(description = "This test case tests the GetConfigurationRegistry method when the registry service is "