Skip to content
Snippets Groups Projects
Commit a2abeb2b authored by srosse's avatar srosse
Browse files

OO-2667: add a unit test to simulate the case

parent 7e953c04
No related branches found
No related tags found
No related merge requests found
...@@ -825,7 +825,6 @@ public class RepositoryManager { ...@@ -825,7 +825,6 @@ public class RepositoryManager {
updatedRe.getStatistics().getLaunchCounter(); updatedRe.getStatistics().getLaunchCounter();
if(updatedRe.getLifecycle() != null) { if(updatedRe.getLifecycle() != null) {
updatedRe.getLifecycle().getKey(); updatedRe.getLifecycle().getKey();
System.out.println(updatedRe.getLifecycle().getValidTo());
} }
dbInstance.commit(); dbInstance.commit();
......
...@@ -38,6 +38,7 @@ import java.util.List; ...@@ -38,6 +38,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.hibernate.LazyInitializationException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurity;
...@@ -1327,6 +1328,36 @@ public class RepositoryManagerTest extends OlatTestCase { ...@@ -1327,6 +1328,36 @@ public class RepositoryManagerTest extends OlatTestCase {
boolean group2CoachRole = businessGroupRelationDao.hasRole(owner, group2, GroupRoles.coach.name()); boolean group2CoachRole = businessGroupRelationDao.hasRole(owner, group2, GroupRoles.coach.name());
Assert.assertTrue(group2CoachRole); Assert.assertTrue(group2CoachRole);
} }
/**
* This is a simulation of OO-2667 to make sure that the LazyInitializationException don't
* set the transaction on rollback.
*/
@Test
public void lazyLoadingCheck() {
RepositoryEntry re = repositoryService.create("Rei Ayanami", "-", "Repository entry DAO Test 5", "", null);
dbInstance.commitAndCloseSession();
RepositoryEntryLifecycle cycle = lifecycleDao.create("New cycle 1", "New cycle soft 1", false, new Date(), new Date());
re = repositoryManager.setDescriptionAndName(re, "Updated repo entry", null, null, "", null, null, null, null, null, null, cycle);
dbInstance.commitAndCloseSession();
RepositoryEntry lazyRe = repositoryManager.setAccess(re, 2, false);
dbInstance.commitAndCloseSession();
try {// produce the exception
lazyRe.getLifecycle().getValidFrom();
Assert.fail();
} catch (LazyInitializationException e) {
//
}
//load a fresh entry
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(lazyRe.getKey());
Date validFrom = entry.getLifecycle().getValidFrom();
Assert.assertNotNull(validFrom);
dbInstance.commitAndCloseSession();
}
private RepositoryEntry createRepositoryEntry(final String type, Identity owner, long i) { private RepositoryEntry createRepositoryEntry(final String type, Identity owner, long i) {
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance(type, new Long(i)); OLATResourceable resourceable = OresHelper.createOLATResourceableInstance(type, new Long(i));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment