Merge pull request #2007 from mposolda/master

Fix DB tests. Cleanup after AddUserTest
This commit is contained in:
Marek Posolda 2016-01-11 18:56:56 +01:00
commit bc3222ab67
4 changed files with 6 additions and 3 deletions

View file

@ -66,7 +66,7 @@ public class ApplianceBootstrap {
return true; return true;
} }
public void createMasterRealmUser(KeycloakSession session, String username, String password) { public void createMasterRealmUser(String username, String password) {
RealmModel realm = session.realms().getRealm(Config.getAdminRealm()); RealmModel realm = session.realms().getRealm(Config.getAdminRealm());
if (session.users().getUsersCount(realm) > 0) { if (session.users().getUsersCount(realm) > 0) {
throw new IllegalStateException("Can't create initial user as users already exists"); throw new IllegalStateException("Can't create initial user as users already exists");

View file

@ -92,7 +92,7 @@ public class WelcomeResource {
ApplianceBootstrap applianceBootstrap = new ApplianceBootstrap(session); ApplianceBootstrap applianceBootstrap = new ApplianceBootstrap(session);
if (applianceBootstrap.isNoMasterUser()) { if (applianceBootstrap.isNoMasterUser()) {
bootstrap = false; bootstrap = false;
applianceBootstrap.createMasterRealmUser(session, username, password); applianceBootstrap.createMasterRealmUser(username, password);
logger.infov("Created initial admin user with username {0}", username); logger.infov("Created initial admin user with username {0}", username);
return createWelcomePage("User created", null); return createWelcomePage("User created", null);

View file

@ -278,7 +278,7 @@ public class KeycloakServer {
try { try {
session.getTransaction().begin(); session.getTransaction().begin();
if (new ApplianceBootstrap(session).isNoMasterUser()) { if (new ApplianceBootstrap(session).isNoMasterUser()) {
new ApplianceBootstrap(session).createMasterRealmUser(session, "admin", "admin"); new ApplianceBootstrap(session).createMasterRealmUser("admin", "admin");
} }
session.getTransaction().commit(); session.getTransaction().commit();
} finally { } finally {

View file

@ -105,6 +105,9 @@ public class AddUserTest {
assertRoles(accountRoles, "view-profile", "manage-account"); assertRoles(accountRoles, "view-profile", "manage-account");
// User needs to delete himself as other tests rely on "admin" user
userResource.remove();
keycloak.close(); keycloak.close();
assertEquals(0, dir.listFiles().length); assertEquals(0, dir.listFiles().length);