Skip to content

Commit

Permalink
Merge pull request #761 from spyrkob/760-feature_pack_test_framework
Browse files Browse the repository at this point in the history
Test utility classes introducing tools to generate and install a feature pack with modules artifacts
  • Loading branch information
spyrkob authored Sep 13, 2024
2 parents aaeb2b6 + 26b2ff5 commit c5a8e85
Show file tree
Hide file tree
Showing 4 changed files with 495 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import static org.junit.Assert.fail;

public class DirectoryComparator {
private static final BinaryDiff BINARY_DIFF = new BinaryDiff();

private static class FileChange {

final Path expected;
final Path actual;

public FileChange(Path expected, Path actual) {
this.expected = expected;
this.actual = actual;
}
}

public static void assertNoChanges(Path originalServer, Path targetDir) throws IOException {
}
public static void assertNoChanges(Path originalServer, Path targetDir, Path... exceptions) throws IOException {
final List<FileChange> changes = new ArrayList<>();

// get a list of files present only in the expected server or ones present in both but with different content
Files.walkFileTree(originalServer, listAddedAndModifiedFiles(originalServer, targetDir, changes));
Files.walkFileTree(originalServer, listAddedAndModifiedFiles(originalServer, targetDir, changes, Set.of(exceptions)));

// get a list of files present only in the actual server
Files.walkFileTree(targetDir, listRemovedFiles(originalServer, targetDir, changes));
Files.walkFileTree(targetDir, listRemovedFiles(originalServer, targetDir, changes, Set.of(exceptions)));

if (!changes.isEmpty()) {
fail(describeChanges(originalServer, targetDir, changes));
Expand Down Expand Up @@ -68,11 +69,14 @@ private static String describeChanges(Path originalServer, Path targetDir, List<
return sb.toString();
}

private static SimpleFileVisitor<Path> listRemovedFiles(Path originalServer, Path targetDir, List<FileChange> changes) {
private static SimpleFileVisitor<Path> listRemovedFiles(Path originalServer, Path targetDir, List<FileChange> changes, Set<Path> exceptions) {
return new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
final Path relative = targetDir.relativize(file);
if (exceptions.contains(relative)) {
return FileVisitResult.CONTINUE;
}
final Path expectedFile = originalServer.resolve(relative);
if (!Files.exists(expectedFile)) {
changes.add(new FileChange(null, file));
Expand All @@ -89,14 +93,27 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
final Path relative = targetDir.relativize(dir);
if (exceptions.contains(relative)) {
return FileVisitResult.SKIP_SUBTREE;
} else {
return FileVisitResult.CONTINUE;
}
}
};
}

private static SimpleFileVisitor<Path> listAddedAndModifiedFiles(Path originalServer, Path targetDir, List<FileChange> changes) {
private static SimpleFileVisitor<Path> listAddedAndModifiedFiles(Path originalServer, Path targetDir, List<FileChange> changes, Set<Path> exceptions) {
return new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
final Path relative = originalServer.relativize(file);
if (exceptions.contains(relative)) {
return FileVisitResult.CONTINUE;
}
final Path actualFile = targetDir.resolve(relative);
if (!Files.exists(actualFile)) {
changes.add(new FileChange(file, null));
Expand All @@ -115,6 +132,16 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
final Path relative = originalServer.relativize(dir);
if (exceptions.contains(relative)) {
return FileVisitResult.SKIP_SUBTREE;
} else {
return FileVisitResult.CONTINUE;
}
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.prospero.test;

import java.io.IOException;
import java.util.Properties;

/**
* Access to the Maven build properties
*/
public class BuildProperties {

private static final Properties properties;

static {
properties = new Properties();
try {
properties.load(BuildProperties.class.getClassLoader().getResourceAsStream("properties-from-pom.properties"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static String getProperty(String name) {
return properties.getProperty(name);
}
}
Loading

0 comments on commit c5a8e85

Please sign in to comment.