diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/migration/MigrationTestExecutionDecider.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/migration/MigrationTestExecutionDecider.java index 78d26d5059..b526870431 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/migration/MigrationTestExecutionDecider.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/migration/MigrationTestExecutionDecider.java @@ -38,7 +38,7 @@ public class MigrationTestExecutionDecider implements TestExecutionDecider { if (migrationTest && migrationAnnotation != null) { String versionFrom = migrationAnnotation.versionFrom(); - if (versionFrom.equals(migratedAuthServerVersion)) { + if (migratedAuthServerVersion.contains(versionFrom)) { return ExecutionDecision.execute(); } else { return ExecutionDecision.dontExecute(method.getName() + "doesn't fit with migration version."); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/MigrationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/MigrationTest.java index 1864324c78..41a3d446f0 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/MigrationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/MigrationTest.java @@ -17,7 +17,6 @@ package org.keycloak.testsuite.migration; import java.util.List; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.keycloak.admin.client.resource.RealmResource; @@ -31,8 +30,7 @@ import org.keycloak.testsuite.arquillian.migration.Migration; */ public class MigrationTest extends AbstractKeycloakTest { - private RealmResource realmResource; - private RealmRepresentation realmRep; + private final String migrationRealmName = "Migration"; @Override public void addTestRealms(List testRealms) { @@ -41,28 +39,31 @@ public class MigrationTest extends AbstractKeycloakTest { @Before public void beforeMigrationTest() { - realmResource = adminClient.realms().realm("Migration"); - realmRep = realmResource.toRepresentation(); + } @Test @Migration(versionFrom = "1.9.8.Final") public void migration198Test() { + //test migrated data + test198(); + + //import realm from previous version and test imported data + MigrationUtil.executeImport(testingClient); + test198(); + } + + private void test198() { + RealmResource realmResource = adminClient.realms().realm(migrationRealmName); + Assert.assertNames(realmResource.roles().list(), "offline_access", "uma_authorization"); Assert.assertNames(realmResource.clients().findAll(), "admin-cli", "realm-management", "security-admin-console", "broker", "account"); - //TODO - } - - /** - * Assumed that there is only one migration test for each version and *remove* - * 'Migration' realm from Keycloak after test to be able to run the rest - * of the testsuite isolated afterward. - */ - @After - public void afterMigrationTest() { + //TODO - add more asserts + + //cleanup + RealmRepresentation realmRep = realmResource.toRepresentation(); log.info("removing '" + realmRep.getRealm() + "' realm"); removeRealm(realmRep); } - } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/MigrationUtil.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/MigrationUtil.java new file mode 100644 index 0000000000..51e8c651b9 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/migration/MigrationUtil.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 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.testsuite.migration; + +import java.io.File; +import org.keycloak.exportimport.ExportImportConfig; +import org.keycloak.exportimport.singlefile.SingleFileExportProviderFactory; +import static org.keycloak.testsuite.arquillian.migration.MigrationTestExecutionDecider.MIGRATED_AUTH_SERVER_VERSION_PROPERTY; +import org.keycloak.testsuite.client.KeycloakTestingClient; + +/** + * @author Vlastislav Ramik + */ +public class MigrationUtil { + + private static final String migratedAuthServerVersion = System.getProperty(MIGRATED_AUTH_SERVER_VERSION_PROPERTY); + + static void executeImport(KeycloakTestingClient testingClient) { + String realmJsonName = "migration-realm-" + migratedAuthServerVersion + ".json"; + + File file = getRealmFilePath(realmJsonName, "src", "test", "resources", "migration-test"); + + testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID); + testingClient.testing().exportImport().setFile(file.getAbsolutePath()); + + // Configure import + testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT); + testingClient.testing().exportImport().runImport(); + } + + private static File getRealmFilePath(String fileName, String... path) { + StringBuilder builder = new StringBuilder(); + for (String dir : path) { + builder.append(dir).append(File.separator); + } + builder.append(fileName); + return new File(builder.toString()); + } +}