Search in sources :

Example 46 with Pool

use of org.olat.modules.qpool.Pool in project openolat by klemens.

the class PoolDAOTest method getPoolsAndGetNumOfPools.

@Test
public void getPoolsAndGetNumOfPools() {
    // create a pool
    String poolName = "NGC-" + UUID.randomUUID().toString();
    Pool pool = poolDao.createPool(null, poolName, true);
    Assert.assertNotNull(pool);
    Assert.assertNotNull(pool.getKey());
    Assert.assertEquals(poolName, pool.getName());
    Assert.assertTrue(pool.isPublicPool());
    dbInstance.commitAndCloseSession();
    // get pools
    List<Pool> pools = poolDao.getPools(0, -1);
    Assert.assertNotNull(pools);
    Assert.assertTrue(pools.size() >= 1);
    // count
    int numOfPools = poolDao.countPools();
    Assert.assertEquals(pools.size(), numOfPools);
    // retrieve our pool
    boolean foundIt = false;
    for (Pool retrievedPool : pools) {
        if (poolName.equals(retrievedPool.getName())) {
            foundIt = true;
        }
    }
    Assert.assertTrue(foundIt);
    dbInstance.commitAndCloseSession();
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Test(org.junit.Test)

Example 47 with Pool

use of org.olat.modules.qpool.Pool in project openolat by klemens.

the class QItemQueriesDAOTest method shouldGetItemsIsEditableInAPool.

@Test
public void shouldGetItemsIsEditableInAPool() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    QuestionItem item12 = createRandomItem(owner1);
    QuestionItem item13 = createRandomItem(owner1);
    Pool pool = poolDao.createPool(null, "Pool", true);
    poolDao.addItemToPool(item11, Collections.singletonList(pool), true);
    poolDao.addItemToPool(item12, Collections.singletonList(pool), false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isEditableInPool()).isTrue();
    assertThat(filterByKey(loadedItems, item12).isEditableInPool()).isFalse();
    assertThat(filterByKey(loadedItems, item13).isEditableInPool()).isFalse();
}
Also used : 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) Test(org.junit.Test)

Example 48 with Pool

use of org.olat.modules.qpool.Pool in project openolat by klemens.

the class QItemQueriesDAOTest method getItemsOfPool_orderBy.

@Test
public void getItemsOfPool_orderBy() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool
    String poolTitle = "NGC-" + UUID.randomUUID().toString();
    Pool pool = poolDao.createPool(null, poolTitle, true);
    QuestionItem item = questionItemDao.createAndPersist(id, "Mega cluster of galaxies", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    poolDao.addItemToPool(item, Collections.singletonList(pool), false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setPoolKey(pool.getKey());
    // test order by
    for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
        SortKey sortAsc = new SortKey(order.name(), true);
        List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getItemsOfPool(params, null, 0, -1, sortAsc);
        Assert.assertNotNull(ascOrderedItems);
        SortKey sortDesc = new SortKey(order.name(), false);
        List<QuestionItemView> descOrderedItems = qItemQueriesDao.getItemsOfPool(params, null, 0, -1, sortDesc);
        Assert.assertNotNull(descOrderedItems);
    }
}
Also used : Pool(org.olat.modules.qpool.Pool) SortKey(org.olat.core.commons.persistence.SortKey) 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) Test(org.junit.Test)

Example 49 with Pool

use of org.olat.modules.qpool.Pool in project openolat by klemens.

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 50 with Pool

use of org.olat.modules.qpool.Pool in project openolat by klemens.

the class PoolDAOTest method removeItemFromPool.

@Test
public void removeItemFromPool() {
    // 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();
    SearchQuestionItemParams params = new SearchQuestionItemParams(null, null);
    params.setPoolKey(pool.getKey());
    // check
    int numOfItems = poolDao.countItemsInPool(params);
    Assert.assertEquals(1, numOfItems);
    // remove
    poolDao.removeFromPool(Collections.<QuestionItemShort>singletonList(item), pool);
    dbInstance.commit();
    // check empty pool
    int numOfStayingItems = poolDao.countItemsInPool(params);
    Assert.assertEquals(0, numOfStayingItems);
    // but item exists
    QuestionItem reloadedItem = questionItemDao.loadById(item.getKey());
    Assert.assertNotNull(reloadedItem);
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) 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