Search in sources :

Example 56 with QuestionItem

use of org.olat.modules.qpool.QuestionItem 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 57 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method createQuestion.

@Test
public void createQuestion() {
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    QuestionItem item = questionDao.createAndPersist(null, "Stars", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
    Assert.assertNotNull(item);
    Assert.assertNotNull(item.getKey());
    Assert.assertNotNull(item.getIdentifier());
    Assert.assertNotNull(item.getCreationDate());
    Assert.assertNotNull(item.getLastModified());
    Assert.assertNotNull(item.getType());
    Assert.assertNotNull(item.getQuestionStatus());
    Assert.assertNotNull(item.getQuestionStatusLastModified());
    Assert.assertEquals("Stars", item.getTitle());
    dbInstance.commitAndCloseSession();
}
Also used : QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 58 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method shareItems_businessGroups.

@Test
public void shareItems_businessGroups() {
    // create a group to share 2 items
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-item-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item = questionDao.createAndPersist(id, "Share-Item-Dup-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    dbInstance.commit();
    // share them
    questionDao.share(item, group.getResource());
    questionDao.share(item, group.getResource());
    questionDao.share(item, group.getResource());
    // retrieve them
    List<BusinessGroup> shared = questionDao.getResourcesWithSharedItems(id);
    Assert.assertNotNull(shared);
    Assert.assertEquals(1, shared.size());
    Assert.assertTrue(shared.contains(group));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 59 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method deleteQuestion_alreadyDeletedQuestions.

@Test
public void deleteQuestion_alreadyDeletedQuestions() {
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    QuestionItem item1 = questionDao.createAndPersist(null, "To delete 1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
    QuestionItem item2 = questionDao.createAndPersist(null, "To delete 2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
    dbInstance.commitAndCloseSession();
    // delete item 1
    questionDao.delete(Collections.singletonList(item1));
    dbInstance.commitAndCloseSession();
    List<QuestionItem> itemsToDelete = new ArrayList<>();
    itemsToDelete.add(item1);
    itemsToDelete.add(item2);
    questionDao.delete(itemsToDelete);
    dbInstance.commitAndCloseSession();
    QuestionItem deletedItem1 = questionDao.loadById(item1.getKey());
    Assert.assertNull(deletedItem1);
    QuestionItem deletedItem2 = questionDao.loadById(item2.getKey());
    Assert.assertNull(deletedItem2);
}
Also used : ArrayList(java.util.ArrayList) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 60 with QuestionItem

use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method resetAllStatesToDraft.

@Test
public void resetAllStatesToDraft() {
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItemImpl item1 = questionDao.createAndPersist(null, "RES DRAFT 1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    item1.setQuestionStatus(QuestionStatus.endOfLife);
    questionDao.loadForUpdate(item1);
    QuestionItemImpl item2 = questionDao.createAndPersist(null, "RES DRAFT 2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    item2.setQuestionStatus(QuestionStatus.review);
    questionDao.loadForUpdate(item2);
    QuestionItemImpl item3 = questionDao.createAndPersist(null, "RES DRAFT 3", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    item3.setQuestionStatus(QuestionStatus.revised);
    questionDao.loadForUpdate(item3);
    questionDao.createAndPersist(null, "RES DRAFT 4", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    dbInstance.commitAndCloseSession();
    questionDao.resetAllStatesToDraft();
    dbInstance.commitAndCloseSession();
    List<QuestionItemFull> allItems = questionDao.getAllItems(0, -1);
    for (QuestionItem item : allItems) {
        Assert.assertEquals(QuestionStatus.draft, item.getQuestionStatus());
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Aggregations

QuestionItem (org.olat.modules.qpool.QuestionItem)260 Test (org.junit.Test)160 Identity (org.olat.core.id.Identity)122 QItemType (org.olat.modules.qpool.model.QItemType)82 QuestionItemView (org.olat.modules.qpool.QuestionItemView)76 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)54 ArrayList (java.util.ArrayList)42 File (java.io.File)32 BusinessGroup (org.olat.group.BusinessGroup)32 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)32 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)30 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)28 URL (java.net.URL)24 Pool (org.olat.modules.qpool.Pool)20 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)16 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)16 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12