Search in sources :

Example 31 with QuestionItemCollection

use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.

the class QItemQueriesDAOTest method getItemsOfCollection_orderBy.

@Test
public void getItemsOfCollection_orderBy() {
    // create a collection with 2 items
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-3-" + UUID.randomUUID().toString());
    QuestionItemCollection coll = collectionDao.createCollection("NGC collection 3", id);
    QuestionItem item = questionDao.createAndPersist(null, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, qItemType);
    collectionDao.addItemToCollection(item, singletonList(coll));
    // check if it's alright
    dbInstance.commit();
    // test order by
    for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
        SortKey sortAsc = new SortKey(order.name(), true);
        List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1, sortAsc);
        Assert.assertNotNull(ascOrderedItems);
        SortKey sortDesc = new SortKey(order.name(), false);
        List<QuestionItemView> descOrderedItems = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1, sortDesc);
        Assert.assertNotNull(descOrderedItems);
    }
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) SortKey(org.olat.core.commons.persistence.SortKey) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 32 with QuestionItemCollection

use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.

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 33 with QuestionItemCollection

use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.

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 34 with QuestionItemCollection

use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.

the class CollectionDAOTest method countItemsOfCollection.

@Test
public void countItemsOfCollection() {
    // create 2 collections 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 8", 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", QTI21Constants.QTI_21_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);
    int numOfItems_21 = collectionDao.countItemsOfCollection(coll, QTI21Constants.QTI_21_FORMAT);
    Assert.assertEquals(1, numOfItems_21);
}
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 35 with QuestionItemCollection

use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.

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)

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