Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
d0eb26b8bb
3 changed files with 71 additions and 17 deletions
|
@ -38,7 +38,7 @@ public class MigrationTestExecutionDecider implements TestExecutionDecider {
|
||||||
if (migrationTest && migrationAnnotation != null) {
|
if (migrationTest && migrationAnnotation != null) {
|
||||||
String versionFrom = migrationAnnotation.versionFrom();
|
String versionFrom = migrationAnnotation.versionFrom();
|
||||||
|
|
||||||
if (versionFrom.equals(migratedAuthServerVersion)) {
|
if (migratedAuthServerVersion.contains(versionFrom)) {
|
||||||
return ExecutionDecision.execute();
|
return ExecutionDecision.execute();
|
||||||
} else {
|
} else {
|
||||||
return ExecutionDecision.dontExecute(method.getName() + "doesn't fit with migration version.");
|
return ExecutionDecision.dontExecute(method.getName() + "doesn't fit with migration version.");
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.keycloak.testsuite.migration;
|
package org.keycloak.testsuite.migration;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.keycloak.admin.client.resource.RealmResource;
|
import org.keycloak.admin.client.resource.RealmResource;
|
||||||
|
@ -31,8 +30,7 @@ import org.keycloak.testsuite.arquillian.migration.Migration;
|
||||||
*/
|
*/
|
||||||
public class MigrationTest extends AbstractKeycloakTest {
|
public class MigrationTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
private RealmResource realmResource;
|
private final String migrationRealmName = "Migration";
|
||||||
private RealmRepresentation realmRep;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||||
|
@ -41,28 +39,31 @@ public class MigrationTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void beforeMigrationTest() {
|
public void beforeMigrationTest() {
|
||||||
realmResource = adminClient.realms().realm("Migration");
|
|
||||||
realmRep = realmResource.toRepresentation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Migration(versionFrom = "1.9.8.Final")
|
@Migration(versionFrom = "1.9.8.Final")
|
||||||
public void migration198Test() {
|
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.roles().list(), "offline_access", "uma_authorization");
|
||||||
Assert.assertNames(realmResource.clients().findAll(), "admin-cli", "realm-management", "security-admin-console", "broker", "account");
|
Assert.assertNames(realmResource.clients().findAll(), "admin-cli", "realm-management", "security-admin-console", "broker", "account");
|
||||||
|
|
||||||
//TODO
|
//TODO - add more asserts
|
||||||
}
|
|
||||||
|
//cleanup
|
||||||
/**
|
RealmRepresentation realmRep = realmResource.toRepresentation();
|
||||||
* 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() {
|
|
||||||
log.info("removing '" + realmRep.getRealm() + "' realm");
|
log.info("removing '" + realmRep.getRealm() + "' realm");
|
||||||
removeRealm(realmRep);
|
removeRealm(realmRep);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue