Search in sources :

Example 1 with FileTrace

use of com.axway.ats.common.filesystem.snapshot.equality.FileTrace in project ats-framework by Axway.

the class SnapshotUtils method checkFileSnapshots.

static void checkFileSnapshots(String firstSnapshotName, final Map<String, FileSnapshot> firstFileSnapshots, String secondSnapshotName, final Map<String, FileSnapshot> secondFileSnapshots, EqualityState equality) {
    // compare each FIRST file with its counterpart in SECOND files
    for (Entry<String, FileSnapshot> fileSnapshotEntry : firstFileSnapshots.entrySet()) {
        log.debug("Check file \"" + fileSnapshotEntry.getKey() + "\"");
        FileSnapshot firstFile = fileSnapshotEntry.getValue();
        FileSnapshot secondFile = secondFileSnapshots.get(fileSnapshotEntry.getKey());
        if (secondFile == null) {
            equality.addDifference(new FileTrace(firstSnapshotName, firstFile.getPath(), secondSnapshotName, null));
        } else {
            firstFile.compare(firstSnapshotName, secondSnapshotName, secondFile, equality);
        }
    }
    // if we find such file - it is a problem
    for (Entry<String, FileSnapshot> fileEntry : secondFileSnapshots.entrySet()) {
        FileSnapshot firstFile = firstFileSnapshots.get(fileEntry.getKey());
        FileSnapshot secondFile = fileEntry.getValue();
        if (firstFile == null) {
            equality.addDifference(new FileTrace(firstSnapshotName, null, secondSnapshotName, secondFile.getPath()));
        }
    }
}
Also used : FileTrace(com.axway.ats.common.filesystem.snapshot.equality.FileTrace)

Example 2 with FileTrace

use of com.axway.ats.common.filesystem.snapshot.equality.FileTrace in project ats-framework by Axway.

the class FileSystemSnapshotException method getFilesPresentInOneSnapshotOnly.

/**
     * Get the all files which are present in just one of the snapshots.
     * </br>Note that <b>null</b> is returned if provide a not existing snapshot name.
     *
     * @param snapshot snapshot name
     * @return list of matching files
     */
@PublicAtsApi
public List<String> getFilesPresentInOneSnapshotOnly(String snapshot) {
    DifferenceType searchedDiffType;
    if (equality.getFirstSnapshotName().equals(snapshot)) {
        searchedDiffType = DifferenceType.FILE_PRESENT_IN_FIRST_SNAPSHOT_ONLY;
    } else if (equality.getSecondSnapshotName().equals(snapshot)) {
        searchedDiffType = DifferenceType.FILE_PRESENT_IN_SECOND_SNAPSHOT_ONLY;
    } else {
        return null;
    }
    List<String> files = new ArrayList<String>();
    for (FileTrace diff : equality.getDifferences()) {
        if (diff.getDifferenceType() == searchedDiffType) {
            files.add(diff.toString());
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) FileTrace(com.axway.ats.common.filesystem.snapshot.equality.FileTrace) DifferenceType(com.axway.ats.common.filesystem.snapshot.equality.DifferenceType) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with FileTrace

use of com.axway.ats.common.filesystem.snapshot.equality.FileTrace in project ats-framework by Axway.

the class FileSystemSnapshotException method getDirectoriesPresentInOneSnapshotOnly.

/**
     * Get the all directories which are present in just one of the snapshots.
     * </br>Note that <b>null</b> is returned if provide a not existing snapshot name.
     *
     * @param snapshot snapshot name
     * @return list of matching directories
     */
@PublicAtsApi
public List<String> getDirectoriesPresentInOneSnapshotOnly(String snapshot) {
    DifferenceType searchedDiffType;
    if (equality.getFirstSnapshotName().equals(snapshot)) {
        searchedDiffType = DifferenceType.DIR_PRESENT_IN_FIRST_SNAPSHOT_ONLY;
    } else if (equality.getSecondSnapshotName().equals(snapshot)) {
        searchedDiffType = DifferenceType.DIR_PRESENT_IN_SECOND_SNAPSHOT_ONLY;
    } else {
        return null;
    }
    List<String> dirs = new ArrayList<String>();
    for (FileTrace diff : equality.getDifferences()) {
        if (diff.getDifferenceType() == searchedDiffType) {
            dirs.add(diff.toString());
        }
    }
    return dirs;
}
Also used : ArrayList(java.util.ArrayList) FileTrace(com.axway.ats.common.filesystem.snapshot.equality.FileTrace) DifferenceType(com.axway.ats.common.filesystem.snapshot.equality.DifferenceType) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with FileTrace

use of com.axway.ats.common.filesystem.snapshot.equality.FileTrace in project ats-framework by Axway.

the class FileSystemSnapshotException method getMessage.

@Override
@PublicAtsApi
public String getMessage() {
    if (equality == null) {
        // got a generic exception, not directly concerning the comparision
        return super.getMessage();
    } else {
        StringBuilder msg = new StringBuilder();
        msg.append("Comparing [");
        msg.append(equality.getFirstSnapshotName());
        msg.append("] and [");
        msg.append(equality.getSecondSnapshotName());
        msg.append("] produced the following unexpected differences:");
        // tell all differences sorted by their type
        DifferenceType diffType = null;
        DifferenceType nextDiffType;
        for (FileTrace diff : equality.getDifferences()) {
            nextDiffType = diff.getDifferenceType();
            if (nextDiffType != diffType) {
                // add new difference type
                msg.append("\n\n");
                msg.append(nextDiffType.getDescription(diff.getFirstSnapshot(), diff.getSecondSnapshot()));
                diffType = nextDiffType;
            }
            // add new difference
            msg.append("\n");
            msg.append(diff.toString());
        }
        msg.append("\n");
        return msg.toString();
    }
}
Also used : FileTrace(com.axway.ats.common.filesystem.snapshot.equality.FileTrace) DifferenceType(com.axway.ats.common.filesystem.snapshot.equality.DifferenceType) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with FileTrace

use of com.axway.ats.common.filesystem.snapshot.equality.FileTrace in project ats-framework by Axway.

the class SnapshotUtils method checkDirSnapshotsInternal.

private static void checkDirSnapshotsInternal(String firstSnapshotName, Map<String, DirectorySnapshot> firstDirSnapshots, String secondSnapshotName, Map<String, DirectorySnapshot> secondDirSnapshots, boolean checkDirName, EqualityState equality, boolean areSnapshotsReversed) {
    Set<String> firstDirAliases = firstDirSnapshots.keySet();
    Set<String> secondDirAliases = secondDirSnapshots.keySet();
    Set<String> processedDirAliases = new HashSet<String>();
    // search for FIRST dirs in SECOND dirs
    for (String dirAlias : firstDirAliases) {
        log.debug("Check directories with alias \"" + dirAlias + "\"");
        DirectorySnapshot firstDir = firstDirSnapshots.get(dirAlias);
        DirectorySnapshot secondDir = secondDirSnapshots.get(dirAlias);
        if (secondDir == null) {
            // Second snapshot does not have a directory to match
            if (!areSnapshotsReversed) {
                equality.addDifference(new FileTrace(firstSnapshotName, firstDir.getPath(), secondSnapshotName, null, false));
            } else {
                equality.addDifference(new FileTrace(secondSnapshotName, null, firstSnapshotName, firstDir.getPath(), false));
            }
        } else {
            log.debug("Compare [" + firstSnapshotName + "] " + firstDir.getPath() + " and [" + secondSnapshotName + "] " + secondDir.getPath());
            if (!areSnapshotsReversed) {
                firstDir.compare(firstSnapshotName, secondSnapshotName, secondDir, checkDirName, equality);
            } else {
                firstDir.compare(secondSnapshotName, firstSnapshotName, secondDir, checkDirName, equality);
            }
        }
        processedDirAliases.add(dirAlias);
    }
    // remove the processed dirs from the internal lists, we do not want to deal with them anymore
    for (String checkedDirAlias : processedDirAliases) {
        firstDirAliases.remove(checkedDirAlias);
        secondDirAliases.remove(checkedDirAlias);
    }
}
Also used : FileTrace(com.axway.ats.common.filesystem.snapshot.equality.FileTrace) HashSet(java.util.HashSet)

Aggregations

FileTrace (com.axway.ats.common.filesystem.snapshot.equality.FileTrace)5 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 DifferenceType (com.axway.ats.common.filesystem.snapshot.equality.DifferenceType)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1