use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method shouldGetItemsFilteredByLikeTaxonomyLevel.
@Test
public void shouldGetItemsFilteredByLikeTaxonomyLevel() {
Taxonomy taxonomy = taxonomyDao.createTaxonomy("QPool", "QPool", "", null);
TaxonomyLevel taxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, null, null, taxonomy);
TaxonomyLevel taxonomySubLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, taxonomyLevel, null, taxonomy);
TaxonomyLevel otherTaxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QPool", "QPool", "QPool", null, null, null, null, taxonomy);
QuestionItemImpl item11 = createRandomItem(createRandomIdentity());
item11.setTaxonomyLevel(taxonomyLevel);
QuestionItemImpl item12 = createRandomItem(createRandomIdentity());
item12.setTaxonomyLevel(taxonomySubLevel);
QuestionItemImpl item21 = createRandomItem(createRandomIdentity());
item21.setTaxonomyLevel(otherTaxonomyLevel);
QuestionItem item22 = createRandomItem(createRandomIdentity());
QuestionItem item23 = createRandomItem(createRandomIdentity());
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
params.setLikeTaxonomyLevel(taxonomyLevel);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(loadedItems).hasSize(2);
assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item12)).doesNotContainAnyElementsOf(keysOf(item21, item22, item23));
int countItems = qItemQueriesDao.countItems(params);
assertThat(countItems).isEqualTo(2);
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method shouldGetItemsNumberOfRating.
@Test
public void shouldGetItemsNumberOfRating() {
Identity owner1 = createRandomIdentity();
QuestionItem item11 = createRandomItem(owner1);
commentAndRatingService.createRating(createRandomIdentity(), item11, null, 2);
commentAndRatingService.createRating(createRandomIdentity(), item11, null, 3);
commentAndRatingService.createRating(createRandomIdentity(), item11, null, 4);
commentAndRatingService.createRating(createRandomIdentity(), item11, null, 4);
QuestionItem item12 = createRandomItem(owner1);
commentAndRatingService.createRating(createRandomIdentity(), item12, null, 4);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(filterByKey(loadedItems, item11).getNumberOfRatings()).isEqualTo(4);
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method shouldGetItemsFilteredByExcludeRater.
@Test
public void shouldGetItemsFilteredByExcludeRater() {
QuestionItem item11 = createRandomItem(createRandomIdentity());
QuestionItem item12 = createRandomItem(createRandomIdentity());
QuestionItem item21 = createRandomItem(createRandomIdentity());
QuestionItem item22 = createRandomItem(createRandomIdentity());
QuestionItem item23 = createRandomItem(createRandomIdentity());
Identity rater1 = createRandomIdentity();
commentAndRatingService.createRating(createRandomIdentity(), item21, null, 2);
commentAndRatingService.createRating(rater1, item21, null, 2);
commentAndRatingService.createRating(rater1, item22, null, 2);
commentAndRatingService.createRating(rater1, item23, null, 2);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
params.setExcludeRated(rater1);
;
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(loadedItems).hasSize(2);
assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item12)).doesNotContainAnyElementsOf(keysOf(item21, item22, item23));
int countItems = qItemQueriesDao.countItems(params);
assertThat(countItems).isEqualTo(2);
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method shouldGetAllItemsByFormat.
@Test
public void shouldGetAllItemsByFormat() {
Identity owner1 = createRandomIdentity();
QuestionItem item11 = questionDao.createAndPersist(owner1, "QPool 1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
QuestionItem item12 = questionDao.createAndPersist(owner1, "QPool 2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
QuestionItem item13 = createRandomItem(owner1);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
params.setFormat(QTIConstants.QTI_12_FORMAT);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(loadedItems).hasSize(2);
assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item12)).doesNotContainAnyElementsOf(keysOf(item13));
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method getFavoritItems_orderBy.
@Test
public void getFavoritItems_orderBy() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fav-item-" + UUID.randomUUID().toString());
QuestionItem item1 = questionDao.createAndPersist(id, "NGC 55", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
QuestionItem item2 = questionDao.createAndPersist(id, "NGC 253", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
markManager.setMark(item1, id, null, "[QuestionItem:" + item1 + "]");
markManager.setMark(item2, id, null, "[QuestionItem:" + item2 + "]");
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
// test order by
for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
SortKey sortAsc = new SortKey(order.name(), true);
List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getFavoritItems(params, null, 0, -1, sortAsc);
Assert.assertNotNull(ascOrderedItems);
SortKey sortDesc = new SortKey(order.name(), false);
List<QuestionItemView> descOrderedItems = qItemQueriesDao.getFavoritItems(params, null, 0, -1, sortDesc);
Assert.assertNotNull(descOrderedItems);
}
}
Aggregations