use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method getItemsByAuthor_orderBy.
@Test
public void getItemsByAuthor_orderBy() {
// create an author with 2 items
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-2-" + UUID.randomUUID().toString());
QuestionItem item1 = questionDao.createAndPersist(id, "NGC 2171", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
QuestionItem item2 = questionDao.createAndPersist(id, "NGC 2172", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(item1);
Assert.assertNotNull(item2);
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
params.setAuthor(id);
// test order by
for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
SortKey sortAsc = new SortKey(order.name(), true);
List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getItemsByAuthor(params, null, 0, -1, sortAsc);
Assert.assertNotNull(ascOrderedItems);
SortKey sortDesc = new SortKey(order.name(), false);
List<QuestionItemView> descOrderedItems = qItemQueriesDao.getItemsByAuthor(params, null, 0, -1, sortDesc);
Assert.assertNotNull(descOrderedItems);
}
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method shouldGetItemsFilteredByExcludAuthor.
@Test
public void shouldGetItemsFilteredByExcludAuthor() {
Identity owner1 = createRandomIdentity();
QuestionItem item11 = createRandomItem(owner1);
QuestionItem item12 = createRandomItem(owner1);
QuestionItem item21 = createRandomItem(createRandomIdentity());
QuestionItem item22 = createRandomItem(createRandomIdentity());
QuestionItem item23 = createRandomItem(createRandomIdentity());
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
params.setExcludeAuthor(owner1);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(loadedItems).hasSize(3);
assertThat(keysOf(loadedItems)).containsOnlyElementsOf(keysOf(item21, item22, item23)).doesNotContainAnyElementsOf(keysOf(item11, item12));
int countItems = qItemQueriesDao.countItems(params);
assertThat(countItems).isEqualTo(3);
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method shouldGetLimitedItems.
@Test
public void shouldGetLimitedItems() {
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();
List<Long> inKeys = Arrays.asList(item12.getKey(), item21.getKey());
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, inKeys, 0, -1);
assertThat(loadedItems).hasSize(inKeys.size());
assertThat(keysOf(loadedItems)).containsOnlyElementsOf(inKeys).doesNotContainAnyElementsOf(keysOf(item11, item13, item22, item23));
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method getFavoritItems.
@Test
public void getFavoritItems() {
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);
QuestionItem item3 = questionDao.createAndPersist(id, "NGC 292", 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);
List<QuestionItemView> favorits = qItemQueriesDao.getFavoritItems(params, null, 0, -1);
List<Long> favoritKeys = new ArrayList<>();
for (QuestionItemView favorit : favorits) {
favoritKeys.add(favorit.getKey());
}
Assert.assertNotNull(favorits);
Assert.assertEquals(2, favorits.size());
Assert.assertTrue(favoritKeys.contains(item1.getKey()));
Assert.assertTrue(favoritKeys.contains(item2.getKey()));
Assert.assertFalse(favoritKeys.contains(item3.getKey()));
// limit to the first favorit
List<QuestionItemView> limitedFavorits = qItemQueriesDao.getFavoritItems(params, Collections.singletonList(item1.getKey()), 0, -1);
Assert.assertNotNull(limitedFavorits);
Assert.assertEquals(1, limitedFavorits.size());
Assert.assertEquals(item1.getKey(), limitedFavorits.get(0).getKey());
// check the count
int numOfFavorits = qItemQueriesDao.countFavoritItems(params);
Assert.assertEquals(2, numOfFavorits);
}
use of org.olat.modules.qpool.QuestionItemView in project openolat by klemens.
the class QItemQueriesDAOTest method getSharedItemByResource.
@Test
public void getSharedItemByResource() {
// create a group to share 2 items
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-2-" + UUID.randomUUID());
BusinessGroup group1 = businessGroupDao.createAndPersist(id, "gdao-1", "gdao-desc", -1, -1, false, false, false, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(id, "gdao-2", "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(group1.getResource());
resources.add(group2.getResource());
questionDao.share(item, resources, false);
// retrieve them
List<QuestionItemView> sharedItems1 = qItemQueriesDao.getSharedItemByResource(id, group1.getResource(), null, null, 0, -1);
Assert.assertNotNull(sharedItems1);
Assert.assertEquals(1, sharedItems1.size());
Assert.assertEquals(item.getKey(), sharedItems1.get(0).getKey());
List<QuestionItemView> sharedItems2 = qItemQueriesDao.getSharedItemByResource(id, group2.getResource(), null, null, 0, -1);
Assert.assertNotNull(sharedItems2);
Assert.assertEquals(1, sharedItems2.size());
Assert.assertEquals(item.getKey(), sharedItems2.get(0).getKey());
}
Aggregations