use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
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);
}
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class QItemQueriesDAOTest method shouldGetItemsFilteredByOnlyAuthor.
@Test
public void shouldGetItemsFilteredByOnlyAuthor() {
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.setOnlyAuthor(owner1);
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 getSharedItemByResource_subset.
@Test
public void getSharedItemByResource_subset() {
// create a group to share 2 items
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-1-" + UUID.randomUUID());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item1 = questionDao.createAndPersist(id, "Share-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
QuestionItem item2 = questionDao.createAndPersist(id, "Share-Item-2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
dbInstance.commit();
// share them
questionDao.share(item1, group.getResource());
questionDao.share(item2, group.getResource());
// retrieve them
List<QuestionItemView> sharedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
List<Long> sharedItemKeys = new ArrayList<>();
for (QuestionItemView sharedItem : sharedItems) {
sharedItemKeys.add(sharedItem.getKey());
}
Assert.assertNotNull(sharedItems);
Assert.assertEquals(2, sharedItems.size());
Assert.assertTrue(sharedItemKeys.contains(item1.getKey()));
Assert.assertTrue(sharedItemKeys.contains(item2.getKey()));
// retrieve limited sub set
List<QuestionItemView> limitedSharedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), Collections.singletonList(item1.getKey()), null, 0, -1);
Assert.assertNotNull(limitedSharedItems);
Assert.assertEquals(1, limitedSharedItems.size());
Assert.assertEquals(item1.getKey(), limitedSharedItems.get(0).getKey());
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method getItemsOfPool.
@Test
public void getItemsOfPool() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
// create a pool
String poolTitle = "NGC-" + UUID.randomUUID().toString();
Pool pool = poolDao.createPool(null, poolTitle, true);
QuestionItem item = questionItemDao.createAndPersist(id, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
poolDao.addItemToPool(item, Collections.singletonList(pool), false);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
params.setPoolKey(pool.getKey());
// retrieve
List<QuestionItemView> items = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
Assert.assertTrue(items.get(0).getKey().equals(item.getKey()));
// count
int numOfItems = poolDao.countItemsInPool(params);
Assert.assertEquals(1, numOfItems);
}
Aggregations