Search in sources :

Example 1 with OperatingSystemType

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);
    }
}
Also used : InputStream(java.io.InputStream) OperatingSystemType(com.axway.ats.common.system.OperatingSystemType) Test(org.junit.Test)

Example 2 with OperatingSystemType

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);
    }
}
Also used : InputStream(java.io.InputStream) OperatingSystemType(com.axway.ats.common.system.OperatingSystemType) Test(org.junit.Test)

Example 3 with OperatingSystemType

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);
    }
}
Also used : SystemOperationException(com.axway.ats.common.system.SystemOperationException) Calendar(java.util.Calendar) OperatingSystemType(com.axway.ats.common.system.OperatingSystemType) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException) SystemOperationException(com.axway.ats.common.system.SystemOperationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AWTException(java.awt.AWTException)

Example 4 with OperatingSystemType

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);
    }
}
Also used : InputStream(java.io.InputStream) OperatingSystemType(com.axway.ats.common.system.OperatingSystemType) Test(org.junit.Test)

Example 5 with OperatingSystemType

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);
    }
}
Also used : InputStream(java.io.InputStream) OperatingSystemType(com.axway.ats.common.system.OperatingSystemType) Test(org.junit.Test)

Aggregations

OperatingSystemType (com.axway.ats.common.system.OperatingSystemType)7 InputStream (java.io.InputStream)6 Test (org.junit.Test)6 SystemOperationException (com.axway.ats.common.system.SystemOperationException)1 AWTException (java.awt.AWTException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1