Search in sources :

Example 6 with QuestionItemCollection

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()));
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 7 with QuestionItemCollection

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));
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 8 with QuestionItemCollection

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());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 9 with QuestionItemCollection

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();
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 10 with QuestionItemCollection

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());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Aggregations

QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)38 Test (org.junit.Test)20 Identity (org.olat.core.id.Identity)20 QuestionItem (org.olat.modules.qpool.QuestionItem)16 QItemType (org.olat.modules.qpool.model.QItemType)12 QuestionItemView (org.olat.modules.qpool.QuestionItemView)10 ArrayList (java.util.ArrayList)6 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 CollectionOfItemsSource (org.olat.modules.qpool.ui.datasource.CollectionOfItemsSource)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 SortKey (org.olat.core.commons.persistence.SortKey)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)2 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 BusinessGroup (org.olat.group.BusinessGroup)2 Pool (org.olat.modules.qpool.Pool)2 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)2