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()));
}
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();
}
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));
}
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);
}
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());
}
}
Aggregations