8000 Test migration util - Migrate runOnServer by vaceksimon · Pull Request #49170 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,48 @@

public class RunOnServerRewrite extends TestRewrite {

private static final String REGEX = "testingClient\\.server\\([a-zA-Z\"_-]*\\)";
private static final String REPLACEMENT = "runOnServer";
private static final String TESTING_CLIENT_REGEX = "testingClient\\.server\\([a-zA-Z\"_-]*\\)";
private static final String RUN_ON_SERVER_VAR = "runOnServer";
private static final String RUN_ON_SERVER_MASTER_VAR = RUN_ON_SERVER_VAR + "Master";

@Override
public void rewrite() {
int runOnServerLine = findLine(".*testingClient.server(.*)[.].*");
if (runOnServerLine >= 0) {
int managedRealm = findLine(" ManagedRealm managedRealm;");
int testingClientLine = findLine(".*testingClient.server(.*)[.].*");
boolean hasTestingClientLine = testingClientLine > -1;
boolean hasRunOnServerLine = findLine(".*runOnServer\\..*") > -1;
boolean hasRunOnServerMasterLine = findLine(".*runOnServerMaster\\..*") > -1;

content.add(managedRealm + 1, "");
content.add(managedRealm + 2, " @InjectRunOnServer");
content.add(managedRealm + 3, " RunOnServerClient " + REPLACEMENT + ";");
info(managedRealm + 2, "Injecting: RunOnServerClient");
if (!hasTestingClientLine && !hasRunOnServerLine && !hasRunOnServerMasterLine) {
return;
}

addImport("org.keycloak.testframework.remote.runonserver.InjectRunOnServer");
addImport("org.keycloak.testframework.remote.runonserver.RunOnServerClient");

addImport("org.keycloak.testframework.remote.runonserver.InjectRunOnServer");
addImport("org.keycloak.testframework.remote.runonserver.RunOnServerClient");
int insertionPoint = findLine(" ManagedRealm managedRealm;");
if (hasRunOnServerMasterLine) {
content.add(++insertionPoint, "");
content.add(++insertionPoint, " @InjectRealm(ref=\"master\", attachTo=\"master\")");
content.add(++insertionPoint, " ManagedRealm managedMasterRealm;");
content.add(++insertionPoint, "");
content.add(++insertionPoint, " @InjectRunOnServer(ref=\"master\", realmRef=\"master\")");
content.add(++insertionPoint, " RunOnServerClient " + RUN_ON_SERVER_MASTER_VAR + ";");
info(insertionPoint, "Injecting: RunOnServerClient");
}
if (hasRunOnServerLine || hasTestingClientLine) {
content.add(++insertionPoint, "");
content.add(++insertionPoint, " @InjectRunOnServer");
content.add(++insertionPoint, " RunOnServerClient " + RUN_ON_SERVER_VAR + ";");
info(insertionPoint, "Injecting: RunOnServerClient");
}

int startingLine = findClassDeclaration();
for (int i = startingLine; i < content.size(); i++) {
String l = content.get(i);
if (l.trim().contains("testingClient.server")) {
replaceLine(i, l.replaceAll(REGEX, REPLACEMENT));
info(i, "Statement rewritten: '" + REGEX + "' --> '" + REPLACEMENT + "'");
if (hasTestingClientLine) {
for (int i = testingClientLine; i < content.size(); i++) {
String l = content.get(i);
if (l.trim().contains("testingClient.server")) {
replaceLine(i, l.replaceAll(TESTING_CLIENT_REGEX, RUN_ON_SERVER_VAR));
info(i, "Statement rewritten: '" + TESTING_CLIENT_REGEX + "' --> '" + RUN_ON_SERVER_VAR + "'");
}
}
}
}
Expand Down
Loading
0