keycloakRule.restartServer();
// Delete some realm (and some data in admin realm)
KeycloakSession session = keycloakRule.startSession();
try {
RealmProvider realmProvider = session.realms();
UserProvider userProvider = session.users();
new RealmManager(session).removeRealm(realmProvider.getRealmByName("test"));
Assert.assertEquals(2, realmProvider.getRealms().size());
assertNotAuthenticated(userProvider, realmProvider, "test", "test-user@localhost", "password");
assertNotAuthenticated(userProvider, realmProvider, "test", "user1", "password");
assertNotAuthenticated(userProvider, realmProvider, "test", "user2", "password");
assertNotAuthenticated(userProvider, realmProvider, "test", "user3", "password");
} finally {
keycloakRule.stopSession(session, true);
}
// Configure import
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
// Restart server, which triggers import
keycloakRule.restartServer();
// Ensure data are imported back
session = keycloakRule.startSession();
try {
RealmProvider model = session.realms();
UserProvider userProvider = session.users();
Assert.assertEquals(3, model.getRealms().size());
assertAuthenticated(userProvider, model, "test", "test-user@localhost", "password");
assertAuthenticated(userProvider, model, "test", "user1", "password");
assertAuthenticated(userProvider, model, "test", "user2", "password");
assertAuthenticated(userProvider, model, "test", "user3", "password");
RealmModel testRealmRealm = model.getRealm("test-realm");
ImportTest.assertDataImportedInRealm(session, testRealmRealm);
} finally {
keycloakRule.stopSession(session, true);
}
}