Search in sources :

Example 71 with SearchQuestionItemParams

use of org.olat.modules.qpool.model.SearchQuestionItemParams 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)

Example 72 with SearchQuestionItemParams

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

the class QuestionPoolServiceTest method createCollection.

@Test
public void createCollection() {
    // create an user with 2 items
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Owner-3-" + UUID.randomUUID().toString());
    QuestionItem item1 = questionDao.createAndPersist(id, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    QuestionItem item2 = questionDao.createAndPersist(id, "NGC 97", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    dbInstance.commit();
    // load the items of the collection
    List<QuestionItemShort> items = new ArrayList<>();
    items.add(item1);
    items.add(item2);
    QuestionItemCollection newColl = qpoolService.createCollection(id, "My private collection", items);
    Assert.assertNotNull(newColl);
    Assert.assertEquals("My private collection", newColl.getName());
    // check if it's alright
    dbInstance.commit();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    // retrieve the list of items in the collection
    int numOfItemsInCollection = qpoolService.countItemsOfCollection(newColl, params);
    Assert.assertEquals(2, numOfItemsInCollection);
    ResultInfos<QuestionItemView> itemsOfCollection = qpoolService.getItemsOfCollection(newColl, params, 0, -1);
    Assert.assertNotNull(itemsOfCollection);
    Assert.assertEquals(2, itemsOfCollection.getObjects().size());
    List<Long> itemKeys = new ArrayList<>();
    for (QuestionItemView item : itemsOfCollection.getObjects()) {
        itemKeys.add(item.getKey());
    }
    Assert.assertTrue(itemKeys.contains(item1.getKey()));
    Assert.assertTrue(itemKeys.contains(item2.getKey()));
}
Also used : ArrayList(java.util.ArrayList) QItemType(org.olat.modules.qpool.model.QItemType) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) 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)

Aggregations

SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)72 QuestionItemView (org.olat.modules.qpool.QuestionItemView)62 Test (org.junit.Test)60 QuestionItem (org.olat.modules.qpool.QuestionItem)54 Identity (org.olat.core.id.Identity)50 Pool (org.olat.modules.qpool.Pool)12 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 QItemType (org.olat.modules.qpool.model.QItemType)8 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)8 ArrayList (java.util.ArrayList)6 SortKey (org.olat.core.commons.persistence.SortKey)6 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)6 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)4 BusinessGroup (org.olat.group.BusinessGroup)2 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)2 QuestionStatus (org.olat.modules.qpool.QuestionStatus)2 OLATResource (org.olat.resource.OLATResource)2