use of com.axway.ats.common.filesystem.snapshot.equality.EqualityState in project ats-framework by Axway.
the class LocalFileSystemSnapshot method loadFromFile.
@Override
public void loadFromFile(String sourceFile) throws FileSystemSnapshotException {
log.info("Load snapshot from file " + sourceFile + " - START");
// first clean up the current instance, in case some snapshot was taken before
this.dirSnapshots.clear();
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(sourceFile));
doc.getDocumentElement().normalize();
} catch (Exception e) {
throw new FileSystemSnapshotException("Error reading backup file " + sourceFile);
}
Element fileSystemNode = doc.getDocumentElement();
if (!NODE_FILE_SYSTEM.equals(fileSystemNode.getNodeName())) {
throw new FileSystemSnapshotException("Bad backup file. Root node name is expeced to be '" + NODE_FILE_SYSTEM + "', but it is '" + fileSystemNode.getNodeName() + "'");
}
// the file system snapshot
log.info("Loading snapshot with name [" + this.name + "]");
this.snapshotTimestamp = SnapshotUtils.stringToDate(fileSystemNode.getAttribute("time"));
// the root directories
List<Element> dirNodes = SnapshotUtils.getChildrenByTagName(fileSystemNode, NODE_DIRECTORY);
for (Element dirNode : dirNodes) {
String dirAlias = dirNode.getAttributes().getNamedItem("alias").getNodeValue();
this.dirSnapshots.put(dirAlias, DirectorySnapshot.fromFile(dirNode, new EqualityState(this.name, null)));
}
// sub-dir snapshots are deleted, and then added according to those Rules
for (DirectorySnapshot topLevelDirSnapshot : this.dirSnapshots.values()) {
for (DirectorySnapshot subDirSnapshot : topLevelDirSnapshot.getDirSnapshots().values()) {
for (String fileName : subDirSnapshot.getFileRules().keySet()) {
String fileAbsPath = fileName;
if (!fileAbsPath.startsWith(subDirSnapshot.getPath())) {
fileAbsPath = subDirSnapshot.getPath() + fileName;
}
topLevelDirSnapshot.addFindRules(fileAbsPath, subDirSnapshot.getFileRules().get(fileName).getRules());
}
for (String skippedSubDir : subDirSnapshot.getSkippedSubDirectories()) {
topLevelDirSnapshot.skipSubDirectory(skippedSubDir);
}
}
}
log.info("Load snapshot from file " + sourceFile + " - END");
}
use of com.axway.ats.common.filesystem.snapshot.equality.EqualityState in project ats-framework by Axway.
the class LocalFileSystemSnapshot method compare.
public void compare(LocalFileSystemSnapshot that) {
if (that == null) {
throw new FileSystemSnapshotException("Snapshot to compare is null");
}
if (this.name.equals(that.name)) {
throw new FileSystemSnapshotException("You are trying to compare snapshots with same name: " + this.name);
}
if (this.snapshotTimestamp == -1) {
throw new FileSystemSnapshotException("You are trying to compare snapshots but [" + this.name + "] snapshot is still not created");
}
if (that.snapshotTimestamp == -1) {
throw new FileSystemSnapshotException("You are trying to compare snapshots but [" + that.name + "] snapshot is still not created");
}
log.debug("Comparing snapshots [" + this.name + "] taken on " + SnapshotUtils.dateToString(this.snapshotTimestamp) + " and [" + that.name + "] taken on " + SnapshotUtils.dateToString(that.snapshotTimestamp));
this.equality = new EqualityState(this.name, that.name);
SnapshotUtils.checkDirSnapshotsTopLevel(this.name, this.dirSnapshots, that.name, that.dirSnapshots, equality);
if (equality.getDifferences().size() > 0) {
// there are some unexpected differences
throw new FileSystemSnapshotException(equality);
} else {
log.debug("Successful verification");
}
}
Aggregations