use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method shouldGetAllItems.
@Test
public void shouldGetAllItems() {
Identity owner1 = createRandomIdentity();
QuestionItem item11 = createRandomItem(owner1);
QuestionItem item12 = createRandomItem(owner1);
QuestionItem item13 = createRandomItem(owner1);
Identity owner2 = createRandomIdentity();
QuestionItem item21 = createRandomItem(owner2);
QuestionItem item22 = createRandomItem(owner2);
QuestionItem item23 = createRandomItem(owner2);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(loadedItems).hasSize(6);
assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item11, item12, item13, item21, item22, item23));
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
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 klemens.
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 klemens.
the class QItemQueriesDAOTest method shouldGetItemsIsRater.
@Test
public void shouldGetItemsIsRater() {
Identity owner1 = createRandomIdentity();
QuestionItem item11 = createRandomItem(owner1);
QuestionItem item12 = createRandomItem(owner1);
commentAndRatingService.createRating(owner1, item11, null, 2);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(filterByKey(loadedItems, item11).isRater()).isTrue();
assertThat(filterByKey(loadedItems, item12).isRater()).isFalse();
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method getSharedItemByResource_orderBy.
@Test
public void getSharedItemByResource_orderBy() {
// create a group to share 1 item
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-2-" + UUID.randomUUID());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao-3", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-Item-3", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
dbInstance.commit();
// share them
List<OLATResource> resources = new ArrayList<>();
resources.add(group.getResource());
questionDao.share(item, resources, false);
dbInstance.commitAndCloseSession();
// test order by
for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
SortKey sortAsc = new SortKey(order.name(), true);
List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1, sortAsc);
Assert.assertNotNull(ascOrderedItems);
SortKey sortDesc = new SortKey(order.name(), false);
List<QuestionItemView> descOrderedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1, sortDesc);
Assert.assertNotNull(descOrderedItems);
}
}
Aggregations