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