use of org.olat.modules.qpool.QuestionItem 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());
}
use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
the class QItemQueriesDAOTest method shouldGetItemsRating.
@Test
public void shouldGetItemsRating() {
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);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(filterByKey(loadedItems, item11).getRating()).isEqualTo(3);
}
use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
the class QItemQueriesDAOTest method shouldGetItemsIsAuthor.
@Test
public void shouldGetItemsIsAuthor() {
Identity owner1 = createRandomIdentity();
QuestionItem item11 = createRandomItem(owner1);
Identity owner2 = createRandomIdentity();
QuestionItem item21 = createRandomItem(owner2);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(filterByKey(loadedItems, item11).isAuthor()).isTrue();
assertThat(filterByKey(loadedItems, item21).isAuthor()).isFalse();
}
use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
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.QuestionItem in project openolat by klemens.
the class QItemQueriesDAOTest method shouldGetItemsIsMarked.
@Test
public void shouldGetItemsIsMarked() {
Identity owner1 = createRandomIdentity();
QuestionItem item11 = createRandomItem(owner1);
QuestionItem item12 = createRandomItem(owner1);
markManager.setMark(item11, owner1, null, "[QuestionItem:" + item11 + "]");
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null);
List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
assertThat(filterByKey(loadedItems, item11).isMarked()).isTrue();
assertThat(filterByKey(loadedItems, item12).isMarked()).isFalse();
}
Aggregations