Merge pull request #5210 from vramik/KEYCLOAK-6991-fix-test-not-to-affect-other-tests

KEYCLOAK-6991 fixed ExportImportTest not to affect other tests
This commit is contained in:
Martin Kanis 2018-05-17 12:08:45 +02:00 committed by GitHub
commit 28040109ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -133,6 +133,10 @@ public final class TestContext {
this.testRealmReps = testRealmReps;
}
public void addTestRealmToTestRealmReps(RealmRepresentation testRealmRep) {
this.testRealmReps.add(testRealmRep);
}
public boolean isInitialized() {
return initialized;
}

View file

@ -174,20 +174,35 @@ public class ExportImportTest extends AbstractKeycloakTest {
// import a realm with clients without roles
importRealmFromFile("/import/partial-import.json");
Assert.assertTrue("Imported realm hasn't been found!", isRealmPresent("partial-import"));
addTestRealmToTestRealmReps("partial-import");
// import a realm with clients without roles
importRealmFromFile("/import/import-without-roles.json");
Assert.assertTrue("Imported realm hasn't been found!", isRealmPresent("import-without-roles"));
addTestRealmToTestRealmReps("import-without-roles");
// import a realm with roles without clients
importRealmFromFile("/import/import-without-clients.json");
Assert.assertTrue("Imported realm hasn't been found!", isRealmPresent("import-without-clients"));
addTestRealmToTestRealmReps("import-without-clients");
}
private boolean isRealmPresent(String realmId) {
return adminClient.realms().findAll().stream().filter(realm -> realmId.equals(realm.getId())).findFirst().isPresent();
}
/*
* non-JavaDoc
*
* Adds a testTealm to TestContext.testRealmReps (which are after testClass removed)
*
* It prevents from affecting other tests. (auth-server-undertow)
*
*/
private void addTestRealmToTestRealmReps(String realm) {
testContext.addTestRealmToTestRealmReps(adminClient.realms().realm(realm).toRepresentation());
}
private void testFullExportImport() throws LifecycleException {
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
testingClient.testing().exportImport().setRealmName("");
@ -311,7 +326,7 @@ public class ExportImportTest extends AbstractKeycloakTest {
private void clearExportImportProperties() {
// Clear export/import properties after test
Properties systemProps = System.getProperties();
Set<String> propsToRemove = new HashSet<String>();
Set<String> propsToRemove = new HashSet<>();
for (Object key : systemProps.keySet()) {
if (key.toString().startsWith(ExportImportConfig.PREFIX)) {