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

OO-292: optimization in repository manager after upgrade of hibernate + unit tests

parent d725b81a
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -40,6 +40,8 @@ import java.util.UUID; ...@@ -40,6 +40,8 @@ import java.util.UUID;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
...@@ -70,6 +72,7 @@ import org.olat.testutils.codepoints.client.CodepointClientFactory; ...@@ -70,6 +72,7 @@ import org.olat.testutils.codepoints.client.CodepointClientFactory;
import org.olat.testutils.codepoints.client.CodepointRef; import org.olat.testutils.codepoints.client.CodepointRef;
import org.olat.testutils.codepoints.client.CommunicationException; import org.olat.testutils.codepoints.client.CommunicationException;
import org.olat.testutils.codepoints.client.TemporaryPausedThread; import org.olat.testutils.codepoints.client.TemporaryPausedThread;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* Initial Date: Mar 26, 2004 * Initial Date: Mar 26, 2004
...@@ -86,10 +89,16 @@ public class RepositoryManagerTest extends OlatTestCase { ...@@ -86,10 +89,16 @@ public class RepositoryManagerTest extends OlatTestCase {
private static final String FG_TYPE = UUID.randomUUID().toString().replace("_", ""); private static final String FG_TYPE = UUID.randomUUID().toString().replace("_", "");
private static final String CG_TYPE = UUID.randomUUID().toString().replace("-", ""); private static final String CG_TYPE = UUID.randomUUID().toString().replace("-", "");
/**
* @see junit.framework.TestCase#setUp() @Autowired
*/ private DB dbInstance;
@Before public void setup() { @Autowired
private BaseSecurity securityManager;
@Autowired
private RepositoryManager repositoryManager;
@Before
public void setup() {
try { try {
// Setup for code-points // Setup for code-points
JMSCodePointServerJunitHelper.startServer(CODEPOINT_SERVER_ID); JMSCodePointServerJunitHelper.startServer(CODEPOINT_SERVER_ID);
...@@ -97,10 +106,7 @@ public class RepositoryManagerTest extends OlatTestCase { ...@@ -97,10 +106,7 @@ public class RepositoryManagerTest extends OlatTestCase {
log.error("Error while setting up activeMq or Codepointserver", e); log.error("Error while setting up activeMq or Codepointserver", e);
} }
} }
/**
* @see junit.framework.TestCase#tearDown()
*/
@After public void tearDown() { @After public void tearDown() {
try { try {
JMSCodePointServerJunitHelper.stopServer(); JMSCodePointServerJunitHelper.stopServer();
...@@ -138,9 +144,72 @@ public class RepositoryManagerTest extends OlatTestCase { ...@@ -138,9 +144,72 @@ public class RepositoryManagerTest extends OlatTestCase {
} }
} }
/** @Test
*/ public void lookupRepositoryEntryByOLATResourceable() {
@Test public void testQueryReferencableResourcesLimitType() { RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
dbInstance.commitAndCloseSession();
RepositoryEntry loadedRe = repositoryManager.lookupRepositoryEntry(re.getOlatResource(), false);
Assert.assertNotNull(loadedRe);
Assert.assertEquals(re, loadedRe);
}
@Test
public void lookupRepositoryEntryBySoftkey() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
dbInstance.commitAndCloseSession();
RepositoryEntry loadedRe = repositoryManager.lookupRepositoryEntryBySoftkey(re.getSoftkey(), false);
Assert.assertNotNull(loadedRe);
Assert.assertEquals(re, loadedRe);
}
@Test
public void lookupDisplayNameByOLATResourceableId() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
dbInstance.commitAndCloseSession();
String displayName = repositoryManager.lookupDisplayNameByOLATResourceableId(re.getOlatResource().getResourceableId());
Assert.assertNotNull(displayName);
Assert.assertEquals(re.getDisplayname(), displayName);
}
@Test
public void queryByOwnerLimitAccess() {
//create a repository entry with an owner
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-owner-la-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
dbInstance.commitAndCloseSession();
securityManager.addIdentityToSecurityGroup(id, re.getOwnerGroup());
dbInstance.commitAndCloseSession();
List<RepositoryEntry> entries = repositoryManager.queryByOwnerLimitAccess(id, RepositoryEntry.ACC_OWNERS, Boolean.TRUE);
Assert.assertNotNull(entries);
Assert.assertEquals(1, entries.size());
Assert.assertTrue(entries.contains(re));
}
@Test
public void isOwnerOfRepositoryEntry() {
//create a repository entry with an owner and a participant
Identity owner = JunitTestHelper.createAndPersistIdentityAsUser("re-owner-is-" + UUID.randomUUID().toString());
Identity part = JunitTestHelper.createAndPersistIdentityAsUser("re-owner-is-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
dbInstance.commitAndCloseSession();
securityManager.addIdentityToSecurityGroup(owner, re.getOwnerGroup());
securityManager.addIdentityToSecurityGroup(part, re.getParticipantGroup());
dbInstance.commitAndCloseSession();
//check
boolean isOwnerOwner = repositoryManager.isOwnerOfRepositoryEntry(owner, re);
Assert.assertTrue(isOwnerOwner);
boolean isPartOwner = repositoryManager.isOwnerOfRepositoryEntry(part, re);
Assert.assertFalse(isPartOwner);
}
@Test
public void testQueryReferencableResourcesLimitType() {
DB db = DBFactory.getInstance(); DB db = DBFactory.getInstance();
RepositoryManager rm = RepositoryManager.getInstance(); RepositoryManager rm = RepositoryManager.getInstance();
BaseSecurity securityManager = BaseSecurityManager.getInstance(); BaseSecurity securityManager = BaseSecurityManager.getInstance();
...@@ -193,7 +262,7 @@ public class RepositoryManagerTest extends OlatTestCase { ...@@ -193,7 +262,7 @@ public class RepositoryManagerTest extends OlatTestCase {
List<String> typelist = Collections.singletonList(FG_TYPE); List<String> typelist = Collections.singletonList(FG_TYPE);
// finally the search query // finally the search query
long startSearchReferencable = System.currentTimeMillis(); long startSearchReferencable = System.currentTimeMillis();
List results = rm.queryReferencableResourcesLimitType(id1, new Roles(false, false, false, true, false, false, false), typelist, null, null, null); List<RepositoryEntry> results = rm.queryReferencableResourcesLimitType(id1, new Roles(false, false, false, true, false, false, false), typelist, null, null, null);
long endSearchReferencable = System.currentTimeMillis(); long endSearchReferencable = System.currentTimeMillis();
log.debug("found " + results.size() + " repo entries " + (endSearchReferencable - startSearchReferencable) + "ms"); log.debug("found " + results.size() + " repo entries " + (endSearchReferencable - startSearchReferencable) + "ms");
......
...@@ -39,6 +39,7 @@ import org.olat.basesecurity.SecurityGroup; ...@@ -39,6 +39,7 @@ import org.olat.basesecurity.SecurityGroup;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable; import org.olat.core.id.OLATResourceable;
import org.olat.core.id.User; import org.olat.core.id.User;
import org.olat.core.util.CodeHelper;
import org.olat.core.util.Encoder; import org.olat.core.util.Encoder;
import org.olat.core.util.resource.OresHelper; import org.olat.core.util.resource.OresHelper;
import org.olat.course.CourseFactory; import org.olat.course.CourseFactory;
...@@ -136,7 +137,7 @@ public class JunitTestHelper { ...@@ -136,7 +137,7 @@ public class JunitTestHelper {
public static final RepositoryEntry createAndPersistRepositoryEntry() { public static final RepositoryEntry createAndPersistRepositoryEntry() {
OLATResourceManager resourceManager = OLATResourceManager.getInstance(); OLATResourceManager resourceManager = OLATResourceManager.getInstance();
OLATResourceable ores = OresHelper.createOLATResourceableInstance(UUID.randomUUID().toString(), 0l); OLATResourceable ores = OresHelper.createOLATResourceableInstance(UUID.randomUUID().toString(), CodeHelper.getForeverUniqueID());
OLATResource r = resourceManager.createOLATResourceInstance(ores); OLATResource r = resourceManager.createOLATResourceInstance(ores);
resourceManager.saveOLATResource(r); resourceManager.saveOLATResource(r);
......
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