use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class PoolDAOTest method removeItemFromPool.
@Test
public void removeItemFromPool() {
// create a pool
String poolName = "NGC-" + UUID.randomUUID().toString();
Pool pool = poolDao.createPool(null, poolName, true);
Assert.assertNotNull(pool);
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QuestionItem item = questionItemDao.createAndPersist(null, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
Assert.assertNotNull(item);
dbInstance.commitAndCloseSession();
// get pools
poolDao.addItemToPool(item, Collections.singletonList(pool), false);
dbInstance.commit();
SearchQuestionItemParams params = new SearchQuestionItemParams(null, null);
params.setPoolKey(pool.getKey());
// check
int numOfItems = poolDao.countItemsInPool(params);
Assert.assertEquals(1, numOfItems);
// remove
poolDao.removeFromPool(Collections.<QuestionItemShort>singletonList(item), pool);
dbInstance.commit();
// check empty pool
int numOfStayingItems = poolDao.countItemsInPool(params);
Assert.assertEquals(0, numOfStayingItems);
// but item exists
QuestionItem reloadedItem = questionItemDao.loadById(item.getKey());
Assert.assertNotNull(reloadedItem);
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class PoolDAOTest method getPoolInfos_byItem.
@Test
public void getPoolInfos_byItem() {
// create a pool
String poolName = "NGC-" + UUID.randomUUID().toString();
Pool pool1 = poolDao.createPool(null, poolName, true);
Pool pool2 = poolDao.createPool(null, poolName, true);
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QuestionItem item = questionItemDao.createAndPersist(null, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
List<Pool> pools = new ArrayList<Pool>(2);
pools.add(pool1);
pools.add(pool2);
poolDao.addItemToPool(item, pools, false);
dbInstance.commitAndCloseSession();
// retrieve
List<QuestionItem2Pool> infos = poolDao.getQuestionItem2Pool(item);
Assert.assertNotNull(infos);
Assert.assertEquals(2, infos.size());
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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 OpenOLAT.
the class QuestionItemAuditLogDAOTest method shouldPersistAuditLog.
@Test
public void shouldPersistAuditLog() {
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);
licenseService.loadOrCreateLicense(item);
QuestionItemAuditLog auditLog = qpoolService.createAuditLogBuilder(id, QuestionItemAuditLog.Action.CREATE_QUESTION_ITEM_NEW).withBefore(item).withAfter(item).withMessage("item was created").create();
dbInstance.commitAndCloseSession();
sut.persist(auditLog);
dbInstance.commitAndCloseSession();
List<QuestionItemAuditLog> auditLogs = sut.getAuditLogByQuestionItem(item);
QuestionItemAuditLog loadedAuditLog = auditLogs.get(0);
assertThat(loadedAuditLog.getAuthorKey()).isNotNull();
assertThat(loadedAuditLog.getBefore()).isNotNull();
assertThat(loadedAuditLog.getAfter()).isNotNull();
assertThat(loadedAuditLog.getLicenseBefore()).isNotNull();
assertThat(loadedAuditLog.getLicenseAfter()).isNotNull();
assertThat(loadedAuditLog.getMessage()).isNotNull();
}
Aggregations