use of com.axway.ats.common.system.OperatingSystemType in project ats-framework by Axway.
the class Test_ConfigurationParser method testBackupFolder_forWindows.
@Test
public void testBackupFolder_forWindows() throws Exception {
OperatingSystemType currentOs = OperatingSystemType.getCurrentOsType();
simulateOS(OperatingSystemType.WINDOWS);
try {
InputStream _descriptorFileStream = Test_ConfigurationParser.class.getClassLoader().getResourceAsStream("test_descriptors/test_agent_descriptor_windows_backup_folder.xml");
ConfigurationParser configParser = new ConfigurationParser();
configParser.parse(_descriptorFileStream, jarFileAbsolutePath);
String backupFileName = getBackupFileName((FileEnvironmentUnit) configParser.getEnvironments().get(0).getEnvironmentUnits().get(0));
assertEquals(IoUtils.normalizeFilePath("C:/agent_backup_dir/backup_test.txt"), backupFileName);
} finally {
simulateOS(currentOs);
}
}
use of com.axway.ats.common.system.OperatingSystemType in project ats-framework by Axway.
the class Test_ConfigurationParser method testBackupFolder_forWindows_ifIsMissingInTheXml.
@Test
public void testBackupFolder_forWindows_ifIsMissingInTheXml() throws Exception {
OperatingSystemType currentOs = OperatingSystemType.getCurrentOsType();
simulateOS(OperatingSystemType.WINDOWS);
try {
InputStream _descriptorFileStream = Test_ConfigurationParser.class.getClassLoader().getResourceAsStream("test_descriptors/test_agent_descriptor_unix_backup_folder.xml");
ConfigurationParser configParser = new ConfigurationParser();
configParser.parse(_descriptorFileStream, jarFileAbsolutePath);
assertEquals(1, configParser.getEnvironments().get(0).getEnvironmentUnits().size());
String backupFileName = getBackupFileName((FileEnvironmentUnit) configParser.getEnvironments().get(0).getEnvironmentUnits().get(0));
String tempDir = IoUtils.normalizeDirPath(IoUtils.normalizeDirPath(AtsSystemProperties.SYSTEM_USER_TEMP_DIR) + "agent_components_backup");
assertEquals(IoUtils.normalizeDirPath(tempDir) + "backup_test.txt", backupFileName);
} finally {
simulateOS(currentOs);
}
}
use of com.axway.ats.common.system.OperatingSystemType in project ats-framework by Axway.
the class LocalSystemOperations method setTime.
/**
* Set the system time
*
* @param timestamp the timestamp
* @param inMilliseconds whether the timestamp is in milliseconds or a formatted date string
*/
public void setTime(String timestamp, boolean inMilliseconds) {
Calendar calendar = Calendar.getInstance();
// parse the date
if (inMilliseconds) {
try {
calendar.setTimeInMillis(Long.parseLong(timestamp));
} catch (NumberFormatException e) {
throw new SystemOperationException("Could not convert timestamp '" + timestamp + "' to long");
}
} else {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
try {
Date date = dateFormat.parse(timestamp);
calendar.setTime(date);
} catch (ParseException e) {
throw new SystemOperationException("Could not parse timestamp '" + timestamp + "' to format " + DATE_FORMAT);
}
}
try {
OperatingSystemType osType = getOperatingSystemType();
if (osType == OperatingSystemType.WINDOWS) {
setWindowsTime(calendar);
} else {
setUnixTime(calendar);
}
} catch (Exception e) {
throw new SystemOperationException("Could not set time", e);
}
}
use of com.axway.ats.common.system.OperatingSystemType in project ats-framework by Axway.
the class Test_ConfigurationParser method testBackupDirectory_withBackupName_forWindows.
@Test
public void testBackupDirectory_withBackupName_forWindows() throws Exception {
OperatingSystemType currentOs = OperatingSystemType.getCurrentOsType();
simulateOS(OperatingSystemType.WINDOWS);
try {
InputStream _descriptorFileStream = Test_ConfigurationParser.class.getClassLoader().getResourceAsStream("test_descriptors/test_agent_descriptor_windows_backup_folder.xml");
ConfigurationParser configParser = new ConfigurationParser();
configParser.parse(_descriptorFileStream, jarFileAbsolutePath);
String backupFileName = getBackupDirName((DirectoryEnvironmentUnit) configParser.getEnvironments().get(0).getEnvironmentUnits().get(1));
if (currentOs.isWindows()) {
assertEquals(IoUtils.normalizeDirPath("C:/agent_backup_dir/backup dir/"), backupFileName);
} else {
// due to file canonicalization path is interpreted as relative and gets like this:
// /home/user/workspace/.../C:/agent_backup_dir/original dir2/
backupFileName.endsWith(IoUtils.normalizeDirPath("C:/agent_backup_dir/backup dir/"));
}
} finally {
simulateOS(currentOs);
}
}
use of com.axway.ats.common.system.OperatingSystemType in project ats-framework by Axway.
the class Test_ConfigurationParser method testBackupFolder_forUnix_ifIsMissingInTheXml.
@Test
public void testBackupFolder_forUnix_ifIsMissingInTheXml() throws Exception {
OperatingSystemType currentOs = OperatingSystemType.getCurrentOsType();
simulateOS(OperatingSystemType.LINUX);
try {
InputStream _descriptorFileStream = Test_ConfigurationParser.class.getClassLoader().getResourceAsStream("test_descriptors/test_agent_descriptor_windows_backup_folder.xml");
ConfigurationParser configParser = new ConfigurationParser();
configParser.parse(_descriptorFileStream, jarFileAbsolutePath);
assertEquals(1, configParser.getEnvironments().size());
String backupFileName = getBackupFileName((FileEnvironmentUnit) configParser.getEnvironments().get(0).getEnvironmentUnits().get(0));
String tempDir = IoUtils.normalizeDirPath(AtsSystemProperties.SYSTEM_USER_TEMP_DIR) + "agent_components_backup/";
assertEquals(IoUtils.normalizeDirPath(tempDir) + "backup_test.txt", backupFileName);
} finally {
simulateOS(currentOs);
}
}
Aggregations