Search in sources :

Example 66 with QuestionItem

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

the class QuestionDAOTest method createQuestion_withOwner.

@Test
public void createQuestion_withOwner() {
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-1-" + UUID.randomUUID().toString());
    QuestionItem item = questionDao.createAndPersist(id, "My fav. stars", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
    Assert.assertNotNull(item);
    Assert.assertNotNull(item.getKey());
    Assert.assertNotNull(item.getCreationDate());
    Assert.assertNotNull(item.getLastModified());
    Assert.assertNotNull(item.getType());
    Assert.assertNotNull(item.getQuestionStatus());
    Assert.assertEquals("My fav. stars", item.getTitle());
    dbInstance.commitAndCloseSession();
}
Also used : Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 67 with QuestionItem

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

the class QuestionDAOTest method shareItems_countSharedItemByResource.

@Test
public void shareItems_countSharedItemByResource() {
    // create a group to share 2 items
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    BusinessGroup group = businessGroupDao.createAndPersist(null, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item1 = questionDao.createAndPersist(null, "Count-shared-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionDao.createAndPersist(null, "Count-shared-Item-2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item3 = questionDao.createAndPersist(null, "Count-shared-Item-3", QTIConstants.QTI_12_FORMAT, Locale.FRENCH.getLanguage(), null, null, null, fibType);
    dbInstance.commit();
    // share them
    questionDao.share(item1, group.getResource());
    questionDao.share(item2, group.getResource());
    questionDao.share(item3, group.getResource());
    dbInstance.commitAndCloseSession();
    // retrieve them
    int sharedItems = questionDao.countSharedItemByResource(group.getResource(), null);
    Assert.assertEquals(3, sharedItems);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 68 with QuestionItem

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

the class QuestionDAOTest method shareItems_countSharedItemByResource_format.

@Test
public void shareItems_countSharedItemByResource_format() {
    // create a group to share 2 items
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    BusinessGroup group = businessGroupDao.createAndPersist(null, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item1 = questionDao.createAndPersist(null, "Count-shared-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionDao.createAndPersist(null, "Count-shared-Item-2", QTI21Constants.QTI_21_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item3 = questionDao.createAndPersist(null, "Count-shared-Item-3", QTIConstants.QTI_12_FORMAT, Locale.FRENCH.getLanguage(), null, null, null, fibType);
    dbInstance.commit();
    // share them
    questionDao.share(item1, group.getResource());
    questionDao.share(item2, group.getResource());
    questionDao.share(item3, group.getResource());
    dbInstance.commitAndCloseSession();
    // retrieve them
    int sharedItems = questionDao.countSharedItemByResource(group.getResource(), QTI21Constants.QTI_21_FORMAT);
    Assert.assertEquals(1, sharedItems);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 69 with QuestionItem

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

the class QuestionDAOTest method removeFromShare.

@Test
public void removeFromShare() {
    // create a group to share 2 items
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-rm-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupDao.createAndPersist(id, "gdrm", "gdrm-desc", -1, -1, false, false, false, false, false);
    QuestionItem item = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    dbInstance.commit();
    // share them
    questionDao.share(item, group.getResource());
    // retrieve them as a check
    List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
    Assert.assertEquals(1, shared.size());
    // and remove the items
    List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(shared.get(0));
    int count = questionDao.removeFromShares(toDelete);
    Assert.assertEquals(1, count);
    // make sure that changes are committed
    dbInstance.commit();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) 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)

Example 70 with QuestionItem

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

the class QTI21QPoolServiceProviderTest method importArchive_openolatTest.

@Test
public void importArchive_openolatTest() throws URISyntaxException {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsUser("imp-pool-2");
    String filename = "QTI_21_test_sc_mc.zip";
    URL fileUrl = QTI21QPoolServiceProviderTest.class.getResource(filename);
    File questionFile = new File(fileUrl.toURI());
    List<QuestionItem> items = poolServiceProvider.importItems(owner, Locale.ENGLISH, filename, questionFile);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(items);
    Assert.assertEquals(2, items.size());
    int sc = 0;
    int mc = 0;
    for (QuestionItem item : items) {
        if (item.getType() != null) {
            if ("sc".equals(item.getType().getType())) {
                sc++;
            } else if ("mc".equals(item.getType().getType())) {
                mc++;
            }
        }
    }
    Assert.assertEquals(1, sc);
    Assert.assertEquals(1, mc);
}
Also used : Identity(org.olat.core.id.Identity) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem) URL(java.net.URL) 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