diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractExportImportCommand.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractExportImportCommand.java index 170936c64e..136f0bf09e 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractExportImportCommand.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractExportImportCommand.java @@ -22,7 +22,7 @@ import org.keycloak.quarkus.runtime.Environment; import picocli.CommandLine; import picocli.CommandLine.Option; -public abstract class AbstractExportImportCommand extends AbstractCommand implements Runnable { +public abstract class AbstractExportImportCommand extends AbstractStartCommand implements Runnable { private final String action; @@ -50,7 +50,6 @@ public abstract class AbstractExportImportCommand extends AbstractCommand implem @Override public void run() { - doBeforeRun(); System.setProperty("keycloak.migration.action", action); if (toDir != null) { @@ -69,10 +68,6 @@ public abstract class AbstractExportImportCommand extends AbstractCommand implem Environment.setProfile(Environment.IMPORT_EXPORT_MODE); - new CommandLine(new Main()).execute("start"); - } - - protected void doBeforeRun() { - + super.run(); } } diff --git a/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/CLIResult.java b/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/CLIResult.java index bd61aadeed..b7aefd8f6d 100644 --- a/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/CLIResult.java +++ b/quarkus/tests/integration/src/main/java/org/keycloak/it/junit5/extension/CLIResult.java @@ -73,4 +73,8 @@ public interface CLIResult extends LaunchResult { throw new RuntimeException("Failed to assert help", cause); } } + + default void assertMessage(String message) { + assertTrue(getOutput().contains(message)); + } } diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/ExportDistTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/ExportDistTest.java new file mode 100644 index 0000000000..9a1178636c --- /dev/null +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/ExportDistTest.java @@ -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."); + } +} diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/ImportDistTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/ImportDistTest.java new file mode 100644 index 0000000000..37f8884e80 --- /dev/null +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/ImportDistTest.java @@ -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"); + } +}