Search in sources :

Example 1 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

the class PoolDAOTest method isMemberOfPrivatePools_negativeTest.

@Test
public void isMemberOfPrivatePools_negativeTest() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsUser("Pool-owner-" + UUID.randomUUID().toString());
    Identity somebody = JunitTestHelper.createAndPersistIdentityAsUser("Somebody-" + UUID.randomUUID().toString());
    // pool
    Pool pool = poolDao.createPool(owner, "NGC owned", false);
    Assert.assertNotNull(pool);
    // group without item
    BusinessGroup group = businessGroupDao.createAndPersist(owner, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(somebody, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    boolean isMember = poolDao.isMemberOfPrivatePools(somebody);
    Assert.assertFalse(isMember);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 2 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

the class PoolDAOTest method getPools_ofItem.

@Test
public void getPools_ofItem() {
    // create a pool
    String poolName = "NGC-" + UUID.randomUUID().toString();
    Pool pool1 = poolDao.createPool(null, poolName, true);
    Pool pool2 = poolDao.createPool(null, poolName + "-b", true);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item = questionItemDao.createAndPersist(null, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    poolDao.addItemToPool(item, Collections.singletonList(pool1), false);
    poolDao.addItemToPool(item, Collections.singletonList(pool2), true);
    dbInstance.commitAndCloseSession();
    // retrieve the pools
    List<Pool> pools = poolDao.getPools(item);
    Assert.assertNotNull(pools);
    Assert.assertEquals(2, pools.size());
    Assert.assertTrue(pools.contains(pool1));
    Assert.assertTrue(pools.contains(pool2));
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 3 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

the class PoolDAOTest method getPrivatePool.

@Test
public void getPrivatePool() {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsUser("Pool-owner-" + UUID.randomUUID().toString());
    Identity quidam = JunitTestHelper.createAndPersistIdentityAsUser("Pool-quidam-" + UUID.randomUUID().toString());
    Pool pool = poolDao.createPool(owner, "Private pool", false);
    dbInstance.commitAndCloseSession();
    // owner has a private pool and public pools
    List<Pool> ownerPoolList = poolDao.getPools(owner, 0, -1);
    Assert.assertTrue(ownerPoolList.contains(pool));
    // quidam has only public pools
    List<Pool> quidamPoolList = poolDao.getPools(quidam, 0, -1);
    Assert.assertFalse(quidamPoolList.contains(pool));
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 4 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

the class PoolDAOTest method addItemToPool.

@Test
public void addItemToPool() {
    // create a pool
    String poolName = "NGC-" + UUID.randomUUID().toString();
    Pool pool = poolDao.createPool(null, poolName, true);
    Assert.assertNotNull(pool);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item = questionItemDao.createAndPersist(null, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    Assert.assertNotNull(item);
    dbInstance.commitAndCloseSession();
    // get pools
    poolDao.addItemToPool(item, Collections.singletonList(pool), false);
    dbInstance.commit();
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 5 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

the class PoolDAOTest method removeItemFromPool_paranoid.

@Test
public void removeItemFromPool_paranoid() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool
    String name1 = "NGC-" + UUID.randomUUID().toString();
    Pool pool1 = poolDao.createPool(null, name1, true);
    String name2 = "NGC-" + UUID.randomUUID().toString();
    Pool pool2 = poolDao.createPool(null, name2, true);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item1 = questionItemDao.createAndPersist(id, "Cluster of stars", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionItemDao.createAndPersist(id, "Nebula", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    poolDao.addItemToPool(item1, Collections.singletonList(pool1), false);
    poolDao.addItemToPool(item1, Collections.singletonList(pool2), false);
    poolDao.addItemToPool(item2, Collections.singletonList(pool1), false);
    poolDao.addItemToPool(item2, Collections.singletonList(pool2), false);
    dbInstance.commit();
    SearchQuestionItemParams params1 = new SearchQuestionItemParams(id, null);
    params1.setPoolKey(pool1.getKey());
    SearchQuestionItemParams params2 = new SearchQuestionItemParams(id, null);
    params2.setPoolKey(pool2.getKey());
    // check
    int numOfItems_1 = poolDao.countItemsInPool(params1);
    Assert.assertEquals(2, numOfItems_1);
    int numOfItems_2 = poolDao.countItemsInPool(params2);
    Assert.assertEquals(2, numOfItems_2);
    // remove
    poolDao.removeFromPool(Collections.<QuestionItemShort>singletonList(item1), pool2);
    dbInstance.commit();
    // check empty pool
    int numOfStayingItems_1 = poolDao.countItemsInPool(params1);
    Assert.assertEquals(2, numOfStayingItems_1);
    int numOfStayingItems_2 = poolDao.countItemsInPool(params2);
    Assert.assertEquals(1, numOfStayingItems_2);
    // check content
    List<QuestionItemView> items_1 = qItemQueriesDao.getItemsOfPool(params1, null, 0, -1);
    Assert.assertEquals(2, items_1.size());
    List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfPool(params2, null, 0, -1);
    Assert.assertEquals(1, items_2.size());
    Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
    // but item exists
    QuestionItem reloadedItem = questionItemDao.loadById(item1.getKey());
    Assert.assertNotNull(reloadedItem);
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Aggregations

Pool (org.olat.modules.qpool.Pool)52 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)32 Test (org.junit.Test)30 Identity (org.olat.core.id.Identity)22 QuestionItem (org.olat.modules.qpool.QuestionItem)20 QItemType (org.olat.modules.qpool.model.QItemType)12 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)12 QuestionItemView (org.olat.modules.qpool.QuestionItemView)10 BusinessGroup (org.olat.group.BusinessGroup)8 ArrayList (java.util.ArrayList)6 List (java.util.List)4 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)4 PoolItemsSource (org.olat.modules.qpool.ui.datasource.PoolItemsSource)4 Date (java.util.Date)2 Set (java.util.Set)2 StringTokenizer (java.util.StringTokenizer)2 Document (org.apache.lucene.document.Document)2 StringField (org.apache.lucene.document.StringField)2