use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
the class QuestionDAOTest method shareItems_countSharedItemByResource.
@Test
public void shareItems_countSharedItemByResource() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
BusinessGroup group = businessGroupDao.createAndPersist(null, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item1 = questionDao.createAndPersist(null, "Count-shared-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item2 = questionDao.createAndPersist(null, "Count-shared-Item-2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item3 = questionDao.createAndPersist(null, "Count-shared-Item-3", QTIConstants.QTI_12_FORMAT, Locale.FRENCH.getLanguage(), null, null, null, fibType);
dbInstance.commit();
// share them
questionDao.share(item1, group.getResource());
questionDao.share(item2, group.getResource());
questionDao.share(item3, group.getResource());
dbInstance.commitAndCloseSession();
// retrieve them
int sharedItems = questionDao.countSharedItemByResource(group.getResource(), null);
Assert.assertEquals(3, sharedItems);
}
use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
the class QuestionDAOTest method shareInfos_byItems.
@Test
public void shareInfos_byItems() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-item-" + UUID.randomUUID().toString());
BusinessGroup group1 = businessGroupDao.createAndPersist(id, "gdap", "gdao-desc", -1, -1, false, false, false, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(id, "gdaq", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-Item-Dup-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
questionDao.share(item, group1.getResource());
questionDao.share(item, group2.getResource());
dbInstance.commit();
// retrieve them
List<QuestionItem2Resource> shared = questionDao.getSharedResourceInfos(item);
Assert.assertNotNull(shared);
Assert.assertEquals(2, shared.size());
}
use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
the class QuestionDAOTest method removeFromShare.
@Test
public void removeFromShare() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-rm-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdrm", "gdrm-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commit();
// share them
questionDao.share(item, group.getResource());
// retrieve them as a check
List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
Assert.assertEquals(1, shared.size());
// and remove the items
List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(shared.get(0));
int count = questionDao.removeFromShares(toDelete);
Assert.assertEquals(1, count);
// make sure that changes are committed
dbInstance.commit();
}
use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
the class QuestionDAOTest method createQuestion.
@Test
public void createQuestion() {
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
QuestionItem item = questionDao.createAndPersist(null, "Stars", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
Assert.assertNotNull(item);
Assert.assertNotNull(item.getKey());
Assert.assertNotNull(item.getIdentifier());
Assert.assertNotNull(item.getCreationDate());
Assert.assertNotNull(item.getLastModified());
Assert.assertNotNull(item.getType());
Assert.assertNotNull(item.getQuestionStatus());
Assert.assertNotNull(item.getQuestionStatusLastModified());
Assert.assertEquals("Stars", item.getTitle());
dbInstance.commitAndCloseSession();
}
use of org.olat.modules.qpool.QuestionItem in project openolat by klemens.
the class QuestionDAOTest method shareItems_countSharedItemByResource_format.
@Test
public void shareItems_countSharedItemByResource_format() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
BusinessGroup group = businessGroupDao.createAndPersist(null, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item1 = questionDao.createAndPersist(null, "Count-shared-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item2 = questionDao.createAndPersist(null, "Count-shared-Item-2", QTI21Constants.QTI_21_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item3 = questionDao.createAndPersist(null, "Count-shared-Item-3", QTIConstants.QTI_12_FORMAT, Locale.FRENCH.getLanguage(), null, null, null, fibType);
dbInstance.commit();
// share them
questionDao.share(item1, group.getResource());
questionDao.share(item2, group.getResource());
questionDao.share(item3, group.getResource());
dbInstance.commitAndCloseSession();
// retrieve them
int sharedItems = questionDao.countSharedItemByResource(group.getResource(), QTI21Constants.QTI_21_FORMAT);
Assert.assertEquals(1, sharedItems);
}
Aggregations