Refactoring

revert-70aa11f8
megala21 7 years ago
parent 845749df14
commit 4d1b9ea03d

@ -111,24 +111,24 @@ public class DeviceTypeManagerNegativeTest {
} }
createDefectiveDeviceTypeManager(); createDefectiveDeviceTypeManager();
deviceIdentifier = new DeviceIdentifier(); deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId("test"); deviceIdentifier.setId(Utils.TEST_STRING);
deviceIdentifier.setType(ANDROID_DEVICE_TYPE); deviceIdentifier.setType(ANDROID_DEVICE_TYPE);
DeviceDetails deviceDetails = new DeviceDetails(); DeviceDetails deviceDetails = new DeviceDetails();
Properties properties = new Properties(); Properties properties = new Properties();
List<String> propertyList = new ArrayList<>(); List<String> propertyList = new ArrayList<>();
propertyList.add("test"); propertyList.add(Utils.TEST_STRING);
properties.addProperties(propertyList); properties.addProperties(propertyList);
deviceDetails.setProperties(properties); deviceDetails.setProperties(properties);
propertyBasedPluginDAO = new PropertyBasedPluginDAOImpl(deviceDetails, propertyBasedPluginDAO = new PropertyBasedPluginDAOImpl(deviceDetails,
deviceTypeDAOHandler, ANDROID_DEVICE_TYPE); deviceTypeDAOHandler, ANDROID_DEVICE_TYPE);
sampleDevice = new Device(); sampleDevice = new Device();
sampleDevice.setDeviceIdentifier("test"); sampleDevice.setDeviceIdentifier(Utils.TEST_STRING);
List<Device.Property> deviceProperties = new ArrayList<>(); List<Device.Property> deviceProperties = new ArrayList<>();
Device.Property property = new Device.Property(); Device.Property property = new Device.Property();
property.setName("test"); property.setName(Utils.TEST_STRING);
property.setValue("test"); property.setValue(Utils.TEST_STRING);
deviceProperties.add(property); deviceProperties.add(property);
sampleDevice.setProperties(deviceProperties); sampleDevice.setProperties(deviceProperties);
} }

@ -170,8 +170,8 @@ public class DeviceTypeManagerTest {
Assert.assertTrue(customDeviceTypeManager.enrollDevice(customDevice), "Custom device type enrollment failed."); Assert.assertTrue(customDeviceTypeManager.enrollDevice(customDevice), "Custom device type enrollment failed.");
List<Device.Property> properties = customDevice.getProperties(); List<Device.Property> properties = customDevice.getProperties();
Device.Property property = new Device.Property(); Device.Property property = new Device.Property();
property.setName("test"); property.setName(Utils.TEST_STRING);
property.setValue("test"); property.setValue(Utils.TEST_STRING);
properties.add(property); properties.add(property);
customDevice.setProperties(properties); customDevice.setProperties(properties);
Assert.assertFalse(customDeviceTypeManager.enrollDevice(customDevice), Assert.assertFalse(customDeviceTypeManager.enrollDevice(customDevice),
@ -239,8 +239,8 @@ public class DeviceTypeManagerTest {
list.add(property); list.add(property);
} }
sampleDevice1 = new Device("testdevice", androidDeviceType, "test", "testdevice", null, null, list); sampleDevice1 = new Device("testdevice", androidDeviceType, Utils.TEST_STRING, "testdevice", null, null, list);
sampleDevice2 = new Device("testdevice1", androidDeviceType, "test", "testdevice", null, null, list); sampleDevice2 = new Device("testdevice1", androidDeviceType, Utils.TEST_STRING, "testdevice", null, null, list);
} }
/** /**

@ -79,7 +79,8 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest {
@Test(description = "This test case tests the enrollment of newly added device type") @Test(description = "This test case tests the enrollment of newly added device type")
public void testEnrollDevice() throws DeviceManagementException { public void testEnrollDevice() throws DeviceManagementException {
String deviceId = "testdevice1"; 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), Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager().enrollDevice(sampleDevice1),
"Enrollment of " + androidSenseDeviceType + " device failed"); "Enrollment of " + androidSenseDeviceType + " device failed");
Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager() Assert.assertTrue(httpDeviceTypeManagerService.getDeviceManager()
@ -112,7 +113,7 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest {
ConfigurationEntry configurationEntry = configurationEntries.get(0); 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"); "Platform Configuration for device type " + "sample is not saved correctly");
String contentType = configurationEntry.getContentType(); String contentType = configurationEntry.getContentType();
@ -154,10 +155,10 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest {
.getDeclaredMethod("getDeviceTypeConfiguration", String.class, DeviceTypeMetaDefinition.class); .getDeclaredMethod("getDeviceTypeConfiguration", String.class, DeviceTypeMetaDefinition.class);
getDeviceTypeConfiguration.setAccessible(true); getDeviceTypeConfiguration.setAccessible(true);
List<String> properties = new ArrayList<>(); List<String> properties = new ArrayList<>();
properties.add("test"); properties.add(Utils.TEST_STRING);
deviceTypeMetaDefinition.setProperties(properties); deviceTypeMetaDefinition.setProperties(properties);
Map<String, String> mapProperties = new HashMap<>(); Map<String, String> mapProperties = new HashMap<>();
mapProperties.put("test", "test"); mapProperties.put(Utils.TEST_STRING, Utils.TEST_STRING);
PushNotificationConfig pushNotificationConfig = new PushNotificationConfig("push", true, mapProperties); PushNotificationConfig pushNotificationConfig = new PushNotificationConfig("push", true, mapProperties);
deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig); deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig);
DeviceTypeConfiguration deviceTypeConfiguration = (DeviceTypeConfiguration) getDeviceTypeConfiguration 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 org.wso2.carbon.device.mgt.common.Feature.MetadataEntry metadataEntry = new org.wso2.carbon.device.mgt
.common.Feature.MetadataEntry(); .common.Feature.MetadataEntry();
metadataEntry.setId(1); metadataEntry.setId(1);
metadataEntry.setValue("test"); metadataEntry.setValue(Utils.TEST_STRING);
List<org.wso2.carbon.device.mgt.common.Feature.MetadataEntry> metadataEntries = new ArrayList<>(); List<org.wso2.carbon.device.mgt.common.Feature.MetadataEntry> metadataEntries = new ArrayList<>();
metadataEntries.add(metadataEntry); metadataEntries.add(metadataEntry);
commonFeature.setMetadataEntries(metadataEntries); commonFeature.setMetadataEntries(metadataEntries);

@ -56,6 +56,7 @@ import java.util.List;
*/ */
public class Utils { public class Utils {
public static final String DEVICE_TYPE_FOLDER = "device-types" + File.separator; 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 * To get the device type configuration based on the configuration file

@ -68,7 +68,7 @@ public class UtilsTest {
@Test(description = "This test case tests the getLicense method of the FileBasedLicenseManager") @Test(description = "This test case tests the getLicense method of the FileBasedLicenseManager")
public void testFileBasedLicenseManagerGetLicense() throws LicenseManagementException { 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", Assert.assertEquals(fileBasedLicense.getText(), "This is a file based license",
"FileBased License cannot " + "be retrieved by FileBasedLicenseManager"); "FileBased License cannot " + "be retrieved by FileBasedLicenseManager");
} }
@ -84,7 +84,7 @@ public class UtilsTest {
+ "file system", expectedExceptions = {UnsupportedOperationException.class}, + "file system", expectedExceptions = {UnsupportedOperationException.class},
expectedExceptionsMessageRegExp = "'addLicense' method is not supported in FileSystemBasedLicenseManager") expectedExceptionsMessageRegExp = "'addLicense' method is not supported in FileSystemBasedLicenseManager")
public void testFileBasedLicenseManagerAddLicense() throws LicenseManagementException { 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") @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") @Test(description = "This test cases tests the registry based license addition")
public void testAddRegistryBasedLicense() throws LicenseManagementException { public void testAddRegistryBasedLicense() throws LicenseManagementException {
String newLicenseString = "New License"; 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 registryBasedLicenseManager = new RegistryBasedLicenseManager();
registryBasedLicenseManager.addLicense("test", fileBasedLicense); registryBasedLicenseManager.addLicense(Utils.TEST_STRING, fileBasedLicense);
Assert.assertEquals(fileBasedLicense.getText(), 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); fileBasedLicense.setText(newLicenseString);
registryBasedLicenseManager.addLicense("test", fileBasedLicense); registryBasedLicenseManager.addLicense(Utils.TEST_STRING, fileBasedLicense);
Assert.assertEquals(registryBasedLicenseManager.getLicense("test", "en_US").getText(), newLicenseString, Assert.assertEquals(registryBasedLicenseManager.getLicense(Utils.TEST_STRING, "en_US").getText(),
"Registry license update failed"); newLicenseString, "Registry license update failed");
} }
@Test(description = "This test case tests the GetConfigurationRegistry method when the registry service is " @Test(description = "This test case tests the GetConfigurationRegistry method when the registry service is "

Loading…
Cancel
Save