Search in sources :

Example 6 with LocalFileSystemOperations

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

the class Test_FileSystemSnapshot method fixFileModificationTimes.

private static void fixFileModificationTimes() {
    // map with all modification times of all files used in the tests
    long now = new Date().getTime();
    Map<Long, String> map = new TreeMap<Long, String>();
    map.put(now, "dir3/sub-dir1/file2.xml");
    map.put(now + 10000, "dir1/file1.xml;dir1_copy/file1.xml;dir3/file1.xml;dir4/file1.xml;dir5/file1.xml");
    map.put(now + 20000, "dir1/file2.xml;dir1_copy/file2.xml;dir3/file2.xml;dir4/file2.xml;dir5/file2.xml");
    map.put(now + 30000, "dir1/sub-dir1/file2.xml;dir1/sub-dir1/sub-dir3/file2.xml;dir1_copy/sub-dir1/file2.xml;dir1_copy/sub-dir1/sub-dir3/file2.xml;dir3/sub-dir1/sub-dir3/file2.xml;dir4/sub-dir1/file2.xml;dir4/sub-dir1/file3.xml;dir4/sub-dir1/file4.xml;dir4/sub-dir1/file5.xml;dir4/sub-dir1/sub-dir3/file2.xml;dir5/sub-dir1/file2.xml;dir5/sub-dir1/sub-dir3/file2.xml;dir5/sub-dir2/file2.xml;modification_time/sub-dir1/file2.xml");
    map.put(now + 40000, "dir2/file1.xml");
    map.put(now + 50000, "dir2/file2.xml");
    map.put(now + 60000, "dir2/file3.xml");
    map.put(now + 70000, "dir2/file4.xml");
    map.put(now + 80000, "modification_time/sub-dir2/file2.xml");
    map.put(now + 90000, "md5/sub-dir1/file3.xml;md5/sub-dir2/file3.xml;missing_file/sub-dir1/file3.xml;missing_file/sub-dir2/file3.xml;modification_time/sub-dir1/file3.xml;modification_time/sub-dir2/file3.xml;size/sub-dir1/file3.xml;size/sub-dir2/file3.xml");
    map.put(now + 100000, "missing_file/sub-dir1/file2.xml;size/sub-dir1/file2.xml;size/sub-dir2/file2.xml");
    map.put(now + 110000, "md5/sub-dir1/file2.xml;md5/sub-dir2/file2.xml");
    for (long time : map.keySet()) {
        // get all the files for one timestamp
        String[] files = map.get(time).split(";");
        for (String file : files) {
            // apply the correct timestamp
            new LocalFileSystemOperations().setFileModificationTime(FILES_ROOT + file, time);
        }
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) TreeMap(java.util.TreeMap) Date(java.util.Date)

Example 7 with LocalFileSystemOperations

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

the class AgentServicePool method createServicePort.

private AgentService createServicePort(String host) throws AgentException {
    try {
        String protocol = AgentConfigurator.getConnectionProtocol(host);
        if (protocol == null) {
            protocol = "http";
        } else {
            SslUtils.trustAllHttpsCertificates();
            SslUtils.trustAllHostnames();
        }
        URL url = this.getClass().getResource("/META-INF/wsdl/" + AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME + ".wsdl");
        Service agentService = Service.create(url, new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME));
        AgentService agentServicePort = agentService.getPort(new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_PORT_NAME), AgentService.class);
        Map<String, Object> ctxt = ((BindingProvider) agentServicePort).getRequestContext();
        // setting ENDPOINT ADDRESS, which defines the web service URL for SOAP communication
        // NOTE: if we specify WSDL URL (...<endpoint_address>?wsdl), the JBoss server returns the WSDL on a SOAP call,
        // but we are expecting a SOAP message response and an exception is thrown.
        // The Jetty server (in ATS agents) is working in both cases.
        ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, protocol + "://" + host + AgentWsDefinitions.AGENT_SERVICE_ENDPOINT_ADDRESS);
        // setting timeouts
        // timeout in milliseconds
        ctxt.put(BindingProviderProperties.CONNECT_TIMEOUT, 10000);
        // check if new unique id must be generated each time
        if (!useNewUuId) {
            // create temp file containing caller working directory and the unique id
            String userWorkingDirectory = AtsSystemProperties.SYSTEM_USER_HOME_DIR;
            String uuiFileLocation = AtsSystemProperties.SYSTEM_USER_TEMP_DIR + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + "\\ats_uid.txt";
            File uuiFile = new File(uuiFileLocation);
            // otherwise add it to the file 
            if (uuiFile.exists()) {
                String uuiFileContent = IoUtils.streamToString(IoUtils.readFile(uuiFileLocation));
                if (uuiFileContent.contains(userWorkingDirectory)) {
                    for (String line : uuiFileContent.split("\n")) {
                        if (line.contains(userWorkingDirectory)) {
                            uniqueId = line.substring(userWorkingDirectory.length()).trim();
                        }
                    }
                } else {
                    generateNewUUID();
                    new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
                }
            } else {
                generateNewUUID();
                try {
                    uuiFile.createNewFile();
                } catch (IOException e) {
                    log.warn("Unable to create file '" + uuiFile.getAbsolutePath() + "'");
                }
                if (uuiFile.exists()) {
                    new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
                }
            }
        } else {
            generateNewUUID();
        }
        // add header with unique session ID
        Map<String, List<String>> requestHeaders = new HashMap<>();
        requestHeaders.put(ApplicationContext.ATS_UID_SESSION_TOKEN, Arrays.asList(uniqueId));
        ctxt.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
        return agentServicePort;
    } catch (Exception e) {
        throw new AgentException("Cannot connect to Agent application on host '" + host + "' check your configuration", e);
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) AgentException(com.axway.ats.agent.core.exceptions.AgentException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) IOException(java.io.IOException) URL(java.net.URL) AgentException(com.axway.ats.agent.core.exceptions.AgentException) IOException(java.io.IOException) List(java.util.List) File(java.io.File)

Example 8 with LocalFileSystemOperations

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

the class AtsDbLoggerUtilities method checkFileSizeIsNotTooLarge.

private boolean checkFileSizeIsNotTooLarge(String fileLocation) {
    long fileSize = new LocalFileSystemOperations().getFileSize(fileLocation);
    boolean goodSize = fileSize <= MAX_FILE_SIZE;
    if (!goodSize) {
        logger.warn(ERR_MSG_PREFIX + "as its size of \"" + fileSize + "\" bytes is larger than the allowed 10MB");
    }
    return goodSize;
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations)

Example 9 with LocalFileSystemOperations

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

the class XmlUtilities method verifyResponseFile.

private void verifyResponseFile(ActionResponseObject expectedHttpResponseNode, Node actualHttpResponseNode) throws XmlUtilitiesException {
    String expectedResponseFile = expectedHttpResponseNode.getResourceFile();
    Node actualResponseFileNode = getFirstChildNode(actualHttpResponseNode, TOKEN_HTTP_RESOURCE_FILE);
    if (expectedResponseFile == null && actualResponseFileNode == null) {
    // no file is expected and no file was received
    } else if (expectedResponseFile != null && actualResponseFileNode != null) {
        if (matchFilesBySize || matchFilesByContent) /* pre-check before MD5 sum */
        {
            String expectedFileSize = expectedHttpResponseNode.getResourceFileSize();
            String actualFileSize = getNodeAttribute(actualResponseFileNode, "size");
            if ((actualFileSize == null && expectedFileSize != null) || (actualFileSize != null && expectedFileSize == null) || (actualFileSize != null && !actualFileSize.equals(expectedFileSize))) {
                throw new XmlUtilitiesException("The expected response file '" + expectedResponseFile + "' has the length of " + expectedFileSize + " while the actual has the length of " + actualFileSize);
            }
        }
        if (matchFilesByContent) {
            // compare both files using MD5 sums
            String actualResponseFile = expectedResponseFile.substring(0, expectedResponseFile.lastIndexOf(AtsSystemProperties.SYSTEM_FILE_SEPARATOR)) + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + "actual" + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + Thread.currentThread().getName() + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + actualResponseFileNode.getTextContent();
            String expectedFileMD5Sum;
            String actualFileMD5Sum;
            LocalFileSystemOperations localFileOperations = new LocalFileSystemOperations();
            try {
                expectedFileMD5Sum = localFileOperations.computeMd5Sum(expectedResponseFile, Md5SumMode.BINARY);
            } catch (Exception e) {
                throw new XmlUtilitiesException("Error calculating MD5 sum for " + expectedResponseFile, e);
            }
            try {
                actualFileMD5Sum = localFileOperations.computeMd5Sum(actualResponseFile, Md5SumMode.BINARY);
            } catch (Exception e) {
                throw new XmlUtilitiesException("Error calculating MD5 sum for " + actualResponseFile, e);
            }
            if (!expectedFileMD5Sum.equalsIgnoreCase(actualFileMD5Sum)) {
                throw new XmlUtilitiesException("The expected response file '" + expectedResponseFile + "' is not the same as the actual '" + actualResponseFile + "'");
            }
        }
    } else {
        throw new XmlUtilitiesException("Expected to " + (expectedResponseFile != null ? "receive the " + expectedResponseFile + " file" : "not receive a response file") + ", but " + (actualResponseFileNode != null ? "received the " + actualResponseFileNode.getTextContent() + " file" : "did not receive a response file"));
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) XmlUtilitiesException(com.axway.ats.agent.core.templateactions.exceptions.XmlUtilitiesException) Node(org.w3c.dom.Node) XmlUtilitiesException(com.axway.ats.agent.core.templateactions.exceptions.XmlUtilitiesException) InvalidMatcherException(com.axway.ats.agent.core.templateactions.exceptions.InvalidMatcherException) TransformerException(javax.xml.transform.TransformerException)

Example 10 with LocalFileSystemOperations

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

the class FileSystemOperations method copyRemoteFile.

/**
     * Copies the contents of a file from one remote host to another remote host
     *
     * @param fromHost the address of the ATS agent on the source host.<br /> 
     * If you provide null then local host will be used. In such case it is recommended to use 
     * {@link #copyFileTo(String, String)} method after FileSytemOperations is constructed with target agent (toHost) 
     * @param fromFile the source file to copy
     * @param toHost the address of the ATS agent on the destination host.<br /> 
     * If you provide null then local host will be used. In such case it is recommended to use 
     * {@link #copyFileFrom(String, String)} method after FileSytemOperations is constructed with target agent (fromHost)
     * @param toFile the destination file to copy to
     */
@PublicAtsApi
public void copyRemoteFile(@Validate(name = "fromHost", type = ValidationType.STRING_SERVER_WITH_PORT) String fromHost, @Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toHost", type = ValidationType.STRING_SERVER_WITH_PORT) String toHost, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
    // 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, fromFile, toHost, toFile });
    // execute action
    IFileSystemOperations fromHostOperations = getOperationsImplementationFor(fromHost);
    if (fromHostOperations instanceof LocalFileSystemOperations) {
        IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
        if (toHostOperations instanceof LocalFileSystemOperations) {
            ((LocalFileSystemOperations) toHostOperations).copyFile(fromFile, toFile, this.failOnError);
            log.info("Successfully copied " + fromFile + " to " + toFile);
        } else {
            ((RemoteFileSystemOperations) toHostOperations).copyFile(fromFile, toFile, this.failOnError);
            log.info("Successfully copied " + fromFile + " from local host to file " + toFile + " on " + toHost);
        }
    } else {
        IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
        if (toHostOperations instanceof LocalFileSystemOperations) {
            ((RemoteFileSystemOperations) fromHostOperations).copyFileFrom(fromFile, toFile, this.failOnError);
            log.info("Successfully copied " + fromFile + " from " + fromHost + " to file " + toFile + " on the localhost");
        } else {
            if (fromHost.equalsIgnoreCase(toHost)) {
                // source and target hosts are remote, but they are same host indeed
                ((RemoteFileSystemOperations) fromHostOperations).copyFileLocally(fromFile, toFile, this.failOnError);
            } else {
                ((RemoteFileSystemOperations) fromHostOperations).copyFileTo(fromFile, toHost, toFile, this.failOnError);
            }
            log.info("Successfully copied " + fromFile + " from " + fromHost + " to file " + toFile + " 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)

Aggregations

LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)13 PublicAtsApi (com.axway.ats.common.PublicAtsApi)7 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)6 Validator (com.axway.ats.core.validation.Validator)6 File (java.io.File)2 BaseTest (com.axway.ats.action.BaseTest)1 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 InvalidMatcherException (com.axway.ats.agent.core.templateactions.exceptions.InvalidMatcherException)1 XmlUtilitiesException (com.axway.ats.agent.core.templateactions.exceptions.XmlUtilitiesException)1 FileSystemOperationException (com.axway.ats.common.filesystem.FileSystemOperationException)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 IOException (java.io.IOException)1 URL (java.net.URL)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1