Search in sources :

Example 91 with QuestionItem

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

the class QItemQueriesDAOTest method shouldGetItemsFilteredByWithoutAuthor.

@Test
public void shouldGetItemsFilteredByWithoutAuthor() {
    QuestionItem item11 = createRandomItem(null);
    QuestionItem item12 = createRandomItem(createRandomIdentity());
    QuestionItem item21 = createRandomItem(null);
    QuestionItem item22 = createRandomItem(createRandomIdentity());
    QuestionItem item23 = createRandomItem(createRandomIdentity());
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    params.setWithoutAuthorOnly(true);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(loadedItems).hasSize(2);
    assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item21)).doesNotContainAnyElementsOf(keysOf(item12, item22, item23));
    int countItems = qItemQueriesDao.countItems(params);
    assertThat(countItems).isEqualTo(2);
}
Also used : SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 92 with QuestionItem

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

the class QuestionDAOTest method getFavoritItemKeys.

@Test
public void getFavoritItemKeys() {
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fav-item-" + UUID.randomUUID().toString());
    QuestionItem item1 = questionDao.createAndPersist(id, "NGC 331", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionDao.createAndPersist(id, "NGC 332", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item3 = questionDao.createAndPersist(id, "NGC 333", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    markManager.setMark(item1, id, null, "[QuestionItem:" + item1.getKey() + "]");
    markManager.setMark(item2, id, null, "[QuestionItem:" + item2.getKey() + "]");
    dbInstance.commitAndCloseSession();
    List<Long> favoritKeys = questionDao.getFavoritKeys(id);
    Assert.assertNotNull(favoritKeys);
    Assert.assertEquals(2, favoritKeys.size());
    Assert.assertTrue(favoritKeys.contains(item1.getKey()));
    Assert.assertTrue(favoritKeys.contains(item2.getKey()));
    Assert.assertFalse(favoritKeys.contains(item3.getKey()));
}
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 93 with QuestionItem

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

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 94 with QuestionItem

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

the class QuestionDAOTest method getSharedResources.

@Test
public void getSharedResources() {
    // 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", "gdao-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group2 = 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, group1.getResource());
    questionDao.share(item, group2.getResource());
    dbInstance.commitAndCloseSession();
    // retrieve them
    List<OLATResource> shared = questionDao.getSharedResources(item);
    Assert.assertNotNull(shared);
    Assert.assertEquals(2, shared.size());
    Assert.assertTrue(shared.contains(group1.getResource()));
    Assert.assertTrue(shared.contains(group2.getResource()));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 95 with QuestionItem

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

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)

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