mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-09 23:12:06 -03:30
Updates to test migration tool - Adding @Before rewrite, ability to define diff command, and specify test by class name (#37277)
Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
parent
59acbb8f67
commit
fc6ef8ddd0
@ -0,0 +1,25 @@
|
||||
package org.keycloak.test.migration;
|
||||
|
||||
public class BeforeRewrite extends TestRewrite {
|
||||
|
||||
@Override
|
||||
public void rewrite() {
|
||||
int beforeLine = findLine("import org\\.junit\\.Before;");
|
||||
if (beforeLine >= 0) {
|
||||
String current = content.get(beforeLine);
|
||||
String migrateTo = "import org.junit.jupiter.api.BeforeEach;";
|
||||
replaceLine(beforeLine, migrateTo);
|
||||
info(beforeLine, "Import rewritten: '" + current + "' --> '" + migrateTo + "'");
|
||||
|
||||
for (int i = 0; i < content.size(); i++) {
|
||||
String n = content.get(i);
|
||||
if (n.trim().equals("@Before")) {
|
||||
content.remove(i);
|
||||
content.add(i, n.replace("@Before", "@BeforeEach"));
|
||||
info(i, "@Before rewritten to @BeforeEach");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -12,13 +12,16 @@ import java.util.List;
|
||||
|
||||
public class MigrateTest {
|
||||
|
||||
private static final String DIFF_COMMAND = System.getenv("DIFFTOOL");
|
||||
|
||||
final List<Class<? extends TestRewrite>> MIGRATORS = List.of(
|
||||
AddKeycloakIntegrationTestRewrite.class,
|
||||
ChangePackageRewrite.class,
|
||||
RenameImportsRewrite.class,
|
||||
UpdateAssertsRewrite.class,
|
||||
AddManagedResourcesRewrite.class,
|
||||
AdminEventAssertRewrite.class);
|
||||
AdminEventAssertRewrite.class,
|
||||
BeforeRewrite.class);
|
||||
|
||||
Path rootPath = getRootPath();
|
||||
Path oldTestsuitePath = rootPath.resolve("testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite").toAbsolutePath();
|
||||
@ -31,8 +34,14 @@ public class MigrateTest {
|
||||
}
|
||||
|
||||
public void migrate(String test) throws Exception {
|
||||
Path testPath = Path.of(test).normalize().toAbsolutePath();
|
||||
if (test.indexOf('.') != -1) {
|
||||
test = rootPath.toString() +
|
||||
"/testsuite/integration-arquillian/tests/base/src/test/java/" +
|
||||
test.replace('.', '/') +
|
||||
".java";
|
||||
}
|
||||
|
||||
Path testPath = Path.of(test).normalize().toAbsolutePath();
|
||||
if (!Files.isRegularFile(testPath)) {
|
||||
testPath = oldTestsuitePath.resolve(test);
|
||||
}
|
||||
@ -51,6 +60,12 @@ public class MigrateTest {
|
||||
throw new RuntimeException("Can only migrate tests from " + oldTestsuitePath);
|
||||
}
|
||||
|
||||
if (!Files.isRegularFile(testPath)) {
|
||||
throw new RuntimeException("Test file not found");
|
||||
}
|
||||
|
||||
System.exit(1);
|
||||
|
||||
List<String> content = readFileToList(testPath);
|
||||
|
||||
for (Class<? extends TestRewrite> clazz : MIGRATORS) {
|
||||
@ -61,9 +76,11 @@ public class MigrateTest {
|
||||
|
||||
writeFile(content, destinationPath);
|
||||
|
||||
// ProcessBuilder pb = new ProcessBuilder();
|
||||
// pb.command("meld", testPath.toString(), destinationPath.toString());
|
||||
// pb.start();
|
||||
if (DIFF_COMMAND != null && !DIFF_COMMAND.isEmpty()) {
|
||||
ProcessBuilder pb = new ProcessBuilder();
|
||||
pb.command(DIFF_COMMAND, testPath.toString(), destinationPath.toString());
|
||||
pb.start();
|
||||
}
|
||||
}
|
||||
|
||||
private Path getDestination(Path testPath) {
|
||||
|
||||
@ -7,7 +7,8 @@ public class RenameImportsRewrite extends TestRewrite {
|
||||
Map<String, String> IMPORTS = Map.of(
|
||||
"org.junit.Assert", "org.junit.jupiter.api.Assertions",
|
||||
"org.junit.Test", "org.junit.jupiter.api.Test",
|
||||
"org.keycloak.testsuite.util.AdminEventPaths", "org.keycloak.tests.utils.admin.AdminEventPaths"
|
||||
"org.keycloak.testsuite.util.AdminEventPaths", "org.keycloak.tests.utils.admin.AdminEventPaths",
|
||||
"org.keycloak.testsuite.admin.ApiUtil", "org.keycloak.testframework.util.ApiUtil"
|
||||
);
|
||||
|
||||
@Override
|
||||
|
||||
@ -38,4 +38,13 @@
|
||||
<module>custom-providers</module>
|
||||
</modules>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>test-migration-util</id>
|
||||
<modules>
|
||||
<module>migration-util</module>
|
||||
</modules>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user