Search in sources :

Example 16 with QItemType

use of org.olat.modules.qpool.model.QItemType 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 17 with QItemType

use of org.olat.modules.qpool.model.QItemType 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 18 with QItemType

use of org.olat.modules.qpool.model.QItemType 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)

Example 19 with QItemType

use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method deleteQuestion.

@Test
public void deleteQuestion() {
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    QuestionItem item = questionDao.createAndPersist(null, "To delete 1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
    dbInstance.commitAndCloseSession();
    List<QuestionItem> itemsToDelete = Collections.singletonList(item);
    questionDao.delete(itemsToDelete);
    dbInstance.commitAndCloseSession();
    QuestionItem deletedItem = questionDao.loadById(item.getKey());
    Assert.assertNull(deletedItem);
}
Also used : QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 20 with QItemType

use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method shareItems_removeFromBusinessGroups_paranoid.

@Test
public void shareItems_removeFromBusinessGroups_paranoid() {
    // create a group to share 2 items
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-item-" + UUID.randomUUID().toString());
    BusinessGroup group1 = businessGroupDao.createAndPersist(id, "gdao-b", "gdao-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id, "gdao-c", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item1 = questionDao.createAndPersist(id, "Share-Item-Dup-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionDao.createAndPersist(id, "Share-Item-Dup-1", QTI21Constants.QTI_21_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    questionDao.share(item1, group1.getResource());
    questionDao.share(item1, group2.getResource());
    questionDao.share(item2, group1.getResource());
    questionDao.share(item2, group2.getResource());
    dbInstance.commit();
    // check them
    int numOfItems_1 = questionDao.countSharedItemByResource(group1.getResource(), null);
    Assert.assertEquals(2, numOfItems_1);
    int numOfItems_2 = questionDao.countSharedItemByResource(group2.getResource(), null);
    Assert.assertEquals(2, numOfItems_2);
    // remove
    questionDao.removeFromShare(Collections.<QuestionItemShort>singletonList(item2), group1.getResource());
    dbInstance.commitAndCloseSession();
    // check
    int numOfStayingItems_1 = questionDao.countSharedItemByResource(group1.getResource(), null);
    Assert.assertEquals(1, numOfStayingItems_1);
    int numOfStayingItems_2 = questionDao.countSharedItemByResource(group2.getResource(), null);
    Assert.assertEquals(2, numOfStayingItems_2);
    List<QuestionItemView> items_1 = qItemQueriesDao.getSharedItemByResource(id, group1.getResource(), null, null, 0, -1);
    Assert.assertEquals(1, items_1.size());
    Assert.assertEquals(item1.getKey(), items_1.get(0).getKey());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) 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

QItemType (org.olat.modules.qpool.model.QItemType)118 Test (org.junit.Test)94 QuestionItem (org.olat.modules.qpool.QuestionItem)82 Identity (org.olat.core.id.Identity)58 BusinessGroup (org.olat.group.BusinessGroup)22 QuestionItemView (org.olat.modules.qpool.QuestionItemView)18 Pool (org.olat.modules.qpool.Pool)12 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)12 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)12 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 HttpResponse (org.apache.http.HttpResponse)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)8 QEducationalContext (org.olat.modules.qpool.model.QEducationalContext)8 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)8 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionType (org.olat.modules.qpool.QuestionType)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 InputStream (java.io.InputStream)4