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