use of org.olat.modules.qpool.model.QItemType 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);
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class QuestionItemAuditLogDAOTest method shouldFindAuditLogByQuestionItem.
@Test
public void shouldFindAuditLogByQuestionItem() {
QItemType qItemType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("qitem-audit-log");
QuestionItem item = questionDao.createAndPersist(id, "NGC 55", QTI21Constants.QTI_21_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
QuestionItemAuditLog auditLog = qpoolService.createAuditLogBuilder(id, QuestionItemAuditLog.Action.CREATE_QUESTION_ITEM_NEW).withBefore(item).create();
sut.persist(auditLog);
auditLog = qpoolService.createAuditLogBuilder(id, QuestionItemAuditLog.Action.UPDATE_QUESTION).withBefore(item).create();
sut.persist(auditLog);
auditLog = qpoolService.createAuditLogBuilder(id, QuestionItemAuditLog.Action.UPDATE_QUESTION_ITEM_METADATA).withBefore(item).create();
sut.persist(auditLog);
QuestionItem otherItem = questionDao.createAndPersist(id, "NGC 55", QTI21Constants.QTI_21_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
auditLog = qpoolService.createAuditLogBuilder(id, QuestionItemAuditLog.Action.UPDATE_QUESTION_ITEM_METADATA).withBefore(otherItem).create();
sut.persist(auditLog);
dbInstance.commitAndCloseSession();
List<QuestionItemAuditLog> auditLogs = sut.getAuditLogByQuestionItem(item);
assertThat(auditLogs).hasSize(3);
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class QuestionItemAuditLogDAOTest method shouldConvertToXMLAndBack.
@Test
public void shouldConvertToXMLAndBack() {
QItemType qItemType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("qitem-audit-log");
String title = "NGC 55";
String format = QTI21Constants.QTI_21_FORMAT;
String language = Locale.ENGLISH.getLanguage();
QuestionItemImpl item = questionDao.createAndPersist(id, title, format, language, null, null, null, qItemType);
String xml = sut.toXml(item);
QuestionItem itemFromXml = sut.questionItemFromXml(xml);
assertThat(itemFromXml.getTitle()).isEqualTo(title);
assertThat(itemFromXml.getFormat()).isEqualTo(format);
assertThat(itemFromXml.getLanguage()).isEqualTo(language);
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class CollectionDAOTest method addItemToCollectionById.
@Test
public void addItemToCollectionById() {
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-2-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 2", id);
QuestionItem item = questionDao.createAndPersist(null, "NGC 89", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
dbInstance.commitAndCloseSession();
// add the item to the collection
collectionDao.addItemToCollection(item, singletonList(coll));
// check if it's alright
dbInstance.commit();
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class CollectionDAOTest method removeFromCollection_paranoid.
@Test
public void removeFromCollection_paranoid() {
// create 2 collections with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
QuestionItemCollection coll1 = collectionDao.createCollection("NGC collection 8", id);
QuestionItemCollection coll2 = collectionDao.createCollection("NGC collection 9", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 103", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 104", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll1));
collectionDao.addItemToCollection(item1, singletonList(coll2));
collectionDao.addItemToCollection(item2, singletonList(coll1));
collectionDao.addItemToCollection(item2, singletonList(coll2));
dbInstance.commit();
// check if it's alright
int numOfItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfItems_1);
int numOfItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(2, numOfItems_2);
// remove
collectionDao.removeItemFromCollection(Collections.<QuestionItemShort>singletonList(item1), coll2);
dbInstance.commitAndCloseSession();
// check if the item has been removed
int numOfStayingItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfStayingItems_1);
int numOfStayingItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(1, numOfStayingItems_2);
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll2, null, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
Aggregations