Search in sources :

Example 1 with LocalFileSystemOperations

use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method copyDirectoryTo.

/**
 * Copies the contents of a directory to a new one
 *
 * @param fromDirName the source file to copy
 * @param toDirName the destination file to copy to
 * @param isRecursive whether to copy recursively or not
 */
@PublicAtsApi
public void copyDirectoryTo(@Validate(name = "fromDirName", type = ValidationType.STRING_NOT_EMPTY) String fromDirName, @Validate(name = "toDirName", type = ValidationType.STRING_NOT_EMPTY) String toDirName, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { fromDirName, toDirName, isRecursive });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(this.atsAgent);
    if (operations instanceof LocalFileSystemOperations) {
        ((LocalFileSystemOperations) operations).copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
        log.info("Successfully copied directory " + fromDirName + " to " + toDirName);
    } else {
        RemoteFileSystemOperations rfso = (RemoteFileSystemOperations) operations;
        rfso.setCopyInPassiveMode(copyInPassiveMode);
        rfso.copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
        log.info("Successfully copied directory " + fromDirName + " from local host to " + toDirName + " on " + this.atsAgent);
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 2 with LocalFileSystemOperations

use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method copyRemoteDirectory.

/**
 * Copies the contents of a directory located on a remote host to another remote host
 *
 * @param fromHost the address of the ATS agent on the source host
 * @param fromDirectory the source file to copy
 * @param toHost the address of the  ATS agent on the destination host
 * @param toDirectory the destination file to copy to
 * @param isRecursive whether to copy recursively or not
 */
@PublicAtsApi
public void copyRemoteDirectory(@Validate(name = "fromHost", type = ValidationType.STRING_SERVER_WITH_PORT) String fromHost, @Validate(name = "fromDirectory", type = ValidationType.STRING_NOT_EMPTY) String fromDirectory, @Validate(name = "toHost", type = ValidationType.STRING_SERVER_WITH_PORT) String toHost, @Validate(name = "toDirectory", type = ValidationType.STRING_NOT_EMPTY) String toDirectory, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
    // replace to pass validation
    if (fromHost == null) {
        fromHost = LOCAL_HOST_NAME_AND_PORT;
    }
    if (toHost == null) {
        toHost = LOCAL_HOST_NAME_AND_PORT;
    }
    // validate input parameters
    fromHost = HostUtils.getAtsAgentIpAndPort(fromHost);
    toHost = HostUtils.getAtsAgentIpAndPort(toHost);
    new Validator().validateMethodParameters(new Object[] { fromHost, fromDirectory, toHost, toDirectory, isRecursive });
    // execute action
    IFileSystemOperations fromHostOperations = getOperationsImplementationFor(fromHost);
    if (fromHostOperations instanceof LocalFileSystemOperations) {
        IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
        if (toHostOperations instanceof LocalFileSystemOperations) {
            ((LocalFileSystemOperations) toHostOperations).copyDirectory(fromDirectory, toDirectory, isRecursive, this.failOnError);
            log.info("Successfully copied directory " + fromDirectory + " to " + toDirectory);
        } else {
            ((RemoteFileSystemOperations) toHostOperations).copyDirectory(fromDirectory, toDirectory, isRecursive, this.failOnError);
            log.info("Successfully copied directory " + fromDirectory + " from local host to " + toDirectory + " on " + toHost);
        }
    } else {
        IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
        if (toHostOperations instanceof LocalFileSystemOperations) {
            ((RemoteFileSystemOperations) fromHostOperations).copyDirectoryFrom(fromDirectory, toDirectory, isRecursive, this.failOnError);
            log.info("Successfully copied directory " + fromDirectory + " from " + fromHost + " to " + toDirectory + " on the local host");
        } else {
            if (fromHost.equalsIgnoreCase(toHost)) {
                // source and target hosts are remote, but they are same host indeed
                ((RemoteFileSystemOperations) fromHostOperations).copyDirectoryLocally(fromDirectory, toDirectory, isRecursive, this.failOnError);
            } else {
                ((RemoteFileSystemOperations) fromHostOperations).copyDirectoryTo(fromDirectory, toHost, toDirectory, isRecursive, this.failOnError);
            }
            log.info("Successfully copied directory " + fromDirectory + " from " + fromHost + " to " + toDirectory + " on " + toHost);
        }
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with LocalFileSystemOperations

use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method copyDirectoryFrom.

/**
 * Copies the contents of a directory <code>fromDirName</code> in atsAgent host to a new one on the local host. <br>
 * <b>Note:</b> If no atsAgent is used or it is local, then the source directory is searched on the local host.
 *
 * @param fromDirName the source directory to be copied
 * @param toDirName the destination directory
 * @param isRecursive whether to copy recursively or not
 */
@PublicAtsApi
public void copyDirectoryFrom(@Validate(name = "fromDirName", type = ValidationType.STRING_NOT_EMPTY) String fromDirName, @Validate(name = "toDirName", type = ValidationType.STRING_NOT_EMPTY) String toDirName, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { fromDirName, toDirName, isRecursive });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(this.atsAgent);
    if (operations instanceof LocalFileSystemOperations) {
        ((LocalFileSystemOperations) operations).copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
        log.info("Successfully copied directory " + fromDirName + " to " + toDirName);
    } else {
        ((RemoteFileSystemOperations) operations).copyDirectoryFrom(fromDirName, toDirName, isRecursive, this.failOnError);
        log.info("Successfully copied directory " + fromDirName + " from " + this.atsAgent + " to " + toDirName + " on the local host");
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with LocalFileSystemOperations

use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method copyFileTo.

/**
 * Copies the contents of a file from the local host (Test Executor) to a new file on the atsAgent host
 *
 * @param fromFile the source file to copy
 * @param toFile the destination file name path (not just the directory) to copy to. Absolute path is expected
 */
@PublicAtsApi
public void copyFileTo(@Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { fromFile, toFile });
    try {
        checkIfFileExistsAndIsFile(fromFile);
    } catch (Exception e) {
        throw new FileSystemOperationException("Unable to copy '" + fromFile + "' to '" + toFile + "'", e);
    }
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    if (operations instanceof LocalFileSystemOperations) {
        ((LocalFileSystemOperations) operations).copyFile(fromFile, toFile, this.failOnError);
        log.info("Successfully copied " + fromFile + " to " + toFile);
    } else {
        RemoteFileSystemOperations rfso = (RemoteFileSystemOperations) operations;
        rfso.setCopyInPassiveMode(copyInPassiveMode);
        rfso.copyFile(fromFile, toFile, this.failOnError);
        log.info("Successfully copied " + fromFile + " from local host to file " + toFile + " on " + atsAgent);
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException) IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) FileNotFoundException(java.io.FileNotFoundException) FileSystemOperationException(com.axway.ats.common.filesystem.FileSystemOperationException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with LocalFileSystemOperations

use of com.axway.ats.core.filesystem.LocalFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method copyFileFrom.

/**
 * Copies the contents of a file <strong>from</strong> atsAgent host to a new file on the local host (Test Executor).
 * <br>
 * <b>Note:</b> If no atsAgent is specified in constructor or it is local, then the source files is searched on the
 * local host.
 *
 * @param fromFile the source file located on the ATS Agent
 * @param toFile the local destination file
 */
@PublicAtsApi
public void copyFileFrom(@Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { fromFile, toFile });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    if (operations instanceof LocalFileSystemOperations) {
        ((LocalFileSystemOperations) operations).copyFile(fromFile, toFile, this.failOnError);
        log.info("Successfully copied " + fromFile + " to " + toFile);
    } else {
        ((RemoteFileSystemOperations) operations).copyFileFrom(fromFile, toFile, this.failOnError);
        log.info("Successfully copied " + fromFile + " from " + atsAgent + " to file " + toFile + " on the localhost");
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)14 PublicAtsApi (com.axway.ats.common.PublicAtsApi)7 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)6 Validator (com.axway.ats.core.validation.Validator)6 FileSystemOperationException (com.axway.ats.common.filesystem.FileSystemOperationException)3 File (java.io.File)2 BaseTest (com.axway.ats.action.BaseTest)1 InvalidMatcherException (com.axway.ats.agent.core.templateactions.exceptions.InvalidMatcherException)1 XmlUtilitiesException (com.axway.ats.agent.core.templateactions.exceptions.XmlUtilitiesException)1 FileSystemSnapshotException (com.axway.ats.common.filesystem.snapshot.FileSystemSnapshotException)1 LocalSystemOperations (com.axway.ats.core.system.LocalSystemOperations)1 AbstractRealBrowserDriver (com.axway.ats.uiengine.AbstractRealBrowserDriver)1 MobileDriver (com.axway.ats.uiengine.MobileDriver)1 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 TreeMap (java.util.TreeMap)1 TransformerException (javax.xml.transform.TransformerException)1