use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method shouldGetItemsFilteredByWithoutAuthor.
@Test
public void shouldGetItemsFilteredByWithoutAuthor() {
QuestionItem item11 = createRandomItem(null);
QuestionItem item12 = createRandomItem(createRandomIdentity());
QuestionItem item21 = createRandomItem(null);
QuestionItem item22 = createRandomItem(createRandomIdentity());
QuestionItem item23 = createRandomItem(createRandomIdentity());
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
params.setWithoutAuthorOnly(true);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(loadedItems).hasSize(2);
assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item21)).doesNotContainAnyElementsOf(keysOf(item12, item22, item23));
int countItems = qItemQueriesDao.countItems(params);
assertThat(countItems).isEqualTo(2);
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QuestionDAOTest method removeFromShare.
@Test
public void removeFromShare() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-rm-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdrm", "gdrm-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commit();
// share them
questionDao.share(item, group.getResource());
// retrieve them as a check
List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
Assert.assertEquals(1, shared.size());
// and remove the items
List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(shared.get(0));
int count = questionDao.removeFromShares(toDelete);
Assert.assertEquals(1, count);
// make sure that changes are committed
dbInstance.commit();
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class CollectionDAOTest method removeFromCollection_paranoid.
@Test
public void removeFromCollection_paranoid() {
// create 2 collections with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
QuestionItemCollection coll1 = collectionDao.createCollection("NGC collection 8", id);
QuestionItemCollection coll2 = collectionDao.createCollection("NGC collection 9", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 103", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 104", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll1));
collectionDao.addItemToCollection(item1, singletonList(coll2));
collectionDao.addItemToCollection(item2, singletonList(coll1));
collectionDao.addItemToCollection(item2, singletonList(coll2));
dbInstance.commit();
// check if it's alright
int numOfItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfItems_1);
int numOfItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(2, numOfItems_2);
// remove
collectionDao.removeItemFromCollection(Collections.<QuestionItemShort>singletonList(item1), coll2);
dbInstance.commitAndCloseSession();
// check if the item has been removed
int numOfStayingItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfStayingItems_1);
int numOfStayingItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(1, numOfStayingItems_2);
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll2, null, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class CollectionDAOTest method removeFromCollections.
@Test
public void removeFromCollections() {
// create a collection with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 10", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 107", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 108", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll));
collectionDao.addItemToCollection(item2, singletonList(coll));
dbInstance.commit();
// check if it's alright
int numOfItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(2, numOfItems);
// remove
collectionDao.deleteItemFromCollections(Collections.<QuestionItemShort>singletonList(item1));
dbInstance.commitAndCloseSession();
// check if the item has been removed
int numOfStayingItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(1, numOfStayingItems);
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class PoolDAOTest method removeItemFromPools.
@Test
public void removeItemFromPools() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
// create a pool with an item
String poolName = "NGC-" + UUID.randomUUID().toString();
Pool pool = poolDao.createPool(null, poolName, true);
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QuestionItem item = questionItemDao.createAndPersist(id, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
poolDao.addItemToPool(item, Collections.singletonList(pool), false);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
params.setPoolKey(pool.getKey());
// check the pool and remove the items
List<QuestionItemView> items = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
Assert.assertEquals(1, items.size());
List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(items.get(0));
int count = poolDao.removeFromPools(toDelete);
Assert.assertEquals(1, count);
dbInstance.commitAndCloseSession();
// check if the pool is empty
List<QuestionItemView> emptyItems = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
Assert.assertTrue(emptyItems.isEmpty());
}
Aggregations