use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class CollectionDAOTest method getItemKeysOfCollection.
@Test
public void getItemKeysOfCollection() {
// 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 4", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 99", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 101", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll));
collectionDao.addItemToCollection(item2, singletonList(coll));
// check if it's alright
dbInstance.commit();
// load the items of the collection
List<Long> items = collectionDao.getItemKeysOfCollection(coll);
Assert.assertNotNull(items);
Assert.assertEquals(2, items.size());
Assert.assertTrue(items.contains(item1.getKey()));
Assert.assertTrue(items.contains(item2.getKey()));
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class CollectionDAOTest method getCollections_myOhMy.
@Test
public void getCollections_myOhMy() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-5-" + UUID.randomUUID().toString());
QuestionItemCollection coll1 = collectionDao.createCollection("NGC collection part. 6", id);
QuestionItemCollection coll2 = collectionDao.createCollection("NGC collection part. 7", id);
// check if it's alright
dbInstance.commit();
// load the items of the collection
List<QuestionItemCollection> items = collectionDao.getCollections(id);
Assert.assertNotNull(items);
Assert.assertEquals(2, items.size());
Assert.assertTrue(items.contains(coll1));
Assert.assertTrue(items.contains(coll2));
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class CollectionDAOTest method loadCollectionById.
@Test
public void loadCollectionById() {
// create an owner and its collection
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-" + UUID.randomUUID());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection", id);
dbInstance.commitAndCloseSession();
// load the collection
QuestionItemCollection loadedColl = collectionDao.loadCollectionById(coll.getKey());
Assert.assertNotNull(loadedColl);
Assert.assertNotNull(loadedColl.getKey());
Assert.assertNotNull(loadedColl.getCreationDate());
Assert.assertNotNull(loadedColl.getLastModified());
Assert.assertEquals(coll, loadedColl);
Assert.assertEquals("NGC collection", loadedColl.getName());
Assert.assertEquals(id, loadedColl.getOwner());
}
use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class CollectionDAOTest method addItemToCollectionById.
@Test
public void addItemToCollectionById() {
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-2-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 2", id);
QuestionItem item = questionDao.createAndPersist(null, "NGC 89", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
dbInstance.commitAndCloseSession();
// add the item to the collection
collectionDao.addItemToCollection(item, singletonList(coll));
// check if it's alright
dbInstance.commit();
}
use of org.olat.modules.qpool.QuestionItemCollection 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());
}
Aggregations