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);
}
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()));
}
Aggregations