Merge pull request #3261 from vramik/KEYCLOAK-3609

KEYCLOAK-3609 Export/Import migration testing
This commit is contained in:
Pavel Drozd 2016-09-27 07:39:00 +02:00 committed by GitHub
commit fc6d6ff7f7
3 changed files with 71 additions and 17 deletions

View file

@ -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.");

View file

@ -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<RealmRepresentation> 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);
}
}

View file

@ -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 <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*/
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());
}
}