diff --git a/libreplan-business/src/main/java/org/libreplan/business/users/bootstrap/PredefinedProfiles.java b/libreplan-business/src/main/java/org/libreplan/business/users/bootstrap/PredefinedProfiles.java index 45190b904..a4691e255 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/users/bootstrap/PredefinedProfiles.java +++ b/libreplan-business/src/main/java/org/libreplan/business/users/bootstrap/PredefinedProfiles.java @@ -131,7 +131,7 @@ public enum PredefinedProfiles { public Profile getFromDB() { try { - return Registry.getProfileDAO().findByProfileName(name); + return Registry.getProfileDAO().findByProfileNameLoadingRoles(name); } catch (InstanceNotFoundException e) { return null; } diff --git a/libreplan-business/src/main/java/org/libreplan/business/users/daos/IProfileDAO.java b/libreplan-business/src/main/java/org/libreplan/business/users/daos/IProfileDAO.java index ace7d1eec..ab5b5f8fc 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/users/daos/IProfileDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/users/daos/IProfileDAO.java @@ -51,4 +51,7 @@ public interface IProfileDAO extends IGenericDAO{ List getOrderAuthorizationsByProfile(Profile profile); + Profile findByProfileNameLoadingRoles(String profileName) + throws InstanceNotFoundException; + } diff --git a/libreplan-business/src/main/java/org/libreplan/business/users/daos/ProfileDAO.java b/libreplan-business/src/main/java/org/libreplan/business/users/daos/ProfileDAO.java index c6afe7c42..22e835dcf 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/users/daos/ProfileDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/users/daos/ProfileDAO.java @@ -112,4 +112,13 @@ public class ProfileDAO extends GenericDAOHibernate implements } } + @Override + @Transactional(readOnly = true) + public Profile findByProfileNameLoadingRoles(String profileName) + throws InstanceNotFoundException { + Profile profile = findByProfileName(profileName); + profile.getRoles().size(); + return profile; + } + } diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/bootstrap/UsersBootstrapInDBTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/bootstrap/UsersBootstrapInDBTest.java index e465119b8..b9f7d8f71 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/bootstrap/UsersBootstrapInDBTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/bootstrap/UsersBootstrapInDBTest.java @@ -66,18 +66,18 @@ public class UsersBootstrapInDBTest { @Test @Rollback(false) - public void testMandatoryUsersCreated() throws InstanceNotFoundException { + public void testLoadProfiles() { profileBootstrap.loadRequiredData(); - - checkLoadRequiredData(); - - // Load data again to verify that a second load does not cause problems - checkLoadRequiredData(); } - private void checkLoadRequiredData() throws InstanceNotFoundException { - + @Test + @Rollback(false) + public void testLoadUsers() { usersBootstrap.loadRequiredData(); + } + + @Test + public void testMandatoryUsersCreated() throws InstanceNotFoundException { for (PredefinedUsers u : PredefinedUsers.values()) { @@ -85,7 +85,6 @@ public class UsersBootstrapInDBTest { assertEquals(u.getLoginName(), user.getLoginName()); assertEquals(u.getInitialRoles(), user.getRoles()); - assertEquals(u.getInitialProfiles(), user.getProfiles()); } diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java index 617de9a14..bcef66a9b 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java @@ -37,6 +37,7 @@ import org.junit.runner.RunWith; import org.libreplan.business.common.IAdHocTransactionService; import org.libreplan.business.common.IOnTransaction; import org.libreplan.business.scenarios.bootstrap.IScenariosBootstrap; +import org.libreplan.business.users.daos.IProfileDAO; import org.libreplan.business.users.entities.Profile; import org.libreplan.business.users.entities.UserRole; import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB; @@ -73,6 +74,9 @@ public class DBUserDetailsServiceTest { @Autowired private IAdHocTransactionService transactionService; + @Autowired + private IProfileDAO profileDAO; + @Before public void loadScenariosBootsrap() { /*