From a2abeb2be1007ef8cda1f18897db56d813e1917f Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Fri, 31 Mar 2017 10:40:08 +0200 Subject: [PATCH] OO-2667: add a unit test to simulate the case --- .../olat/repository/RepositoryManager.java | 1 - .../repository/RepositoryManagerTest.java | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/olat/repository/RepositoryManager.java b/src/main/java/org/olat/repository/RepositoryManager.java index b5224b9141a..9173a930807 100644 --- a/src/main/java/org/olat/repository/RepositoryManager.java +++ b/src/main/java/org/olat/repository/RepositoryManager.java @@ -825,7 +825,6 @@ public class RepositoryManager { updatedRe.getStatistics().getLaunchCounter(); if(updatedRe.getLifecycle() != null) { updatedRe.getLifecycle().getKey(); - System.out.println(updatedRe.getLifecycle().getValidTo()); } dbInstance.commit(); diff --git a/src/test/java/org/olat/repository/RepositoryManagerTest.java b/src/test/java/org/olat/repository/RepositoryManagerTest.java index 3f97a66e0a0..6227719b090 100644 --- a/src/test/java/org/olat/repository/RepositoryManagerTest.java +++ b/src/test/java/org/olat/repository/RepositoryManagerTest.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.Set; import java.util.UUID; +import org.hibernate.LazyInitializationException; import org.junit.Assert; import org.junit.Test; import org.olat.basesecurity.BaseSecurity; @@ -1327,6 +1328,36 @@ public class RepositoryManagerTest extends OlatTestCase { boolean group2CoachRole = businessGroupRelationDao.hasRole(owner, group2, GroupRoles.coach.name()); 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) { OLATResourceable resourceable = OresHelper.createOLATResourceableInstance(type, new Long(i)); -- GitLab