Search in sources :

Example 41 with QItemType

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

Example 42 with QItemType

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);
}
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 43 with QItemType

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);
}
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 44 with QItemType

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

Example 45 with QItemType

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());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) 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