Search in sources :

Example 61 with QItemType

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);
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 62 with QItemType

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());
}
Also used : ArrayList(java.util.ArrayList) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 63 with QItemType

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);
}
Also used : Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemAuditLog(org.olat.modules.qpool.QuestionItemAuditLog) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 64 with QItemType

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);
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 65 with QItemType

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();
}
Also used : Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QuestionItemAuditLog(org.olat.modules.qpool.QuestionItemAuditLog) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Aggregations

QItemType (org.olat.modules.qpool.model.QItemType)118 Test (org.junit.Test)94 QuestionItem (org.olat.modules.qpool.QuestionItem)82 Identity (org.olat.core.id.Identity)58 BusinessGroup (org.olat.group.BusinessGroup)22 QuestionItemView (org.olat.modules.qpool.QuestionItemView)18 Pool (org.olat.modules.qpool.Pool)12 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)12 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)12 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 HttpResponse (org.apache.http.HttpResponse)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)8 QEducationalContext (org.olat.modules.qpool.model.QEducationalContext)8 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)8 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionType (org.olat.modules.qpool.QuestionType)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 InputStream (java.io.InputStream)4