[fixes #9089] - Fixing export and import commands

This commit is contained in:
Pedro Igor 2021-12-13 18:12:35 -03:00
parent f2abfecca1
commit 9b243cebeb
4 changed files with 105 additions and 7 deletions

View file

@ -22,7 +22,7 @@ import org.keycloak.quarkus.runtime.Environment;
import picocli.CommandLine; import picocli.CommandLine;
import picocli.CommandLine.Option; import picocli.CommandLine.Option;
public abstract class AbstractExportImportCommand extends AbstractCommand implements Runnable { public abstract class AbstractExportImportCommand extends AbstractStartCommand implements Runnable {
private final String action; private final String action;
@ -50,7 +50,6 @@ public abstract class AbstractExportImportCommand extends AbstractCommand implem
@Override @Override
public void run() { public void run() {
doBeforeRun();
System.setProperty("keycloak.migration.action", action); System.setProperty("keycloak.migration.action", action);
if (toDir != null) { if (toDir != null) {
@ -69,10 +68,6 @@ public abstract class AbstractExportImportCommand extends AbstractCommand implem
Environment.setProfile(Environment.IMPORT_EXPORT_MODE); Environment.setProfile(Environment.IMPORT_EXPORT_MODE);
new CommandLine(new Main()).execute("start"); super.run();
}
protected void doBeforeRun() {
} }
} }

View file

@ -73,4 +73,8 @@ public interface CLIResult extends LaunchResult {
throw new RuntimeException("Failed to assert help", cause); throw new RuntimeException("Failed to assert help", cause);
} }
} }
default void assertMessage(String message) {
assertTrue(getOutput().contains(message));
}
} }

View file

@ -0,0 +1,46 @@
/*
* Copyright 2021 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.keycloak.it.cli.dist;
import org.junit.jupiter.api.Test;
import org.keycloak.it.junit5.extension.CLIResult;
import org.keycloak.it.junit5.extension.DistributionTest;
import org.keycloak.it.junit5.extension.RawDistOnly;
import io.quarkus.test.junit.main.Launch;
import io.quarkus.test.junit.main.LaunchResult;
@RawDistOnly(reason = "Containers are immutable")
@DistributionTest
public class ExportDistTest {
@Test
@Launch({"export", "--realm=master", "--dir=."})
void testExport(LaunchResult result) {
CLIResult cliResult = (CLIResult) result;
cliResult.assertMessage("Export of realm 'master' requested.");
cliResult.assertMessage("Export finished successfully");
}
@Test
@Launch({"export", "--realm=master" })
void testMissingDir(LaunchResult result) {
CLIResult cliResult = (CLIResult) result;
cliResult.assertError("Must specify either --dir or --file options.");
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright 2021 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.keycloak.it.cli.dist;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.keycloak.it.junit5.extension.CLIResult;
import org.keycloak.it.junit5.extension.DistributionTest;
import org.keycloak.it.junit5.extension.RawDistOnly;
import io.quarkus.test.junit.main.Launch;
import io.quarkus.test.junit.main.LaunchResult;
@DistributionTest
@RawDistOnly(reason = "Containers are immutable")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class ImportDistTest {
@Test
@Order(1)
@Launch({"export", "--realm=master", "--dir=."})
void testExport(LaunchResult result) {
CLIResult cliResult = (CLIResult) result;
cliResult.assertMessage("Export of realm 'master' requested.");
cliResult.assertMessage("Export finished successfully");
}
@Test
@Order(2)
@Launch({"import", "--dir=." })
void testMissingDir(LaunchResult result) {
CLIResult cliResult = (CLIResult) result;
cliResult.assertMessage("Realm 'master' imported");
cliResult.assertMessage("Import finished successfully");
}
}