Search in sources :

Example 46 with QItemType

use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.

the class CollectionDAOTest method removeFromCollections.

@Test
public void removeFromCollections() {
    // create a collection with 2 items
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
    QuestionItemCollection coll = collectionDao.createCollection("NGC collection 10", id);
    QuestionItem item1 = questionDao.createAndPersist(null, "NGC 107", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    QuestionItem item2 = questionDao.createAndPersist(null, "NGC 108", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
    collectionDao.addItemToCollection(item1, singletonList(coll));
    collectionDao.addItemToCollection(item2, singletonList(coll));
    dbInstance.commit();
    // check if it's alright
    int numOfItems = collectionDao.countItemsOfCollection(coll, null);
    Assert.assertEquals(2, numOfItems);
    // remove
    collectionDao.deleteItemFromCollections(Collections.<QuestionItemShort>singletonList(item1));
    dbInstance.commitAndCloseSession();
    // check if the item has been removed
    int numOfStayingItems = collectionDao.countItemsOfCollection(coll, null);
    Assert.assertEquals(1, numOfStayingItems);
    List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll, 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)

Example 47 with QItemType

use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.

the class MetadataConverterHelperTest method serializeQuestionItem.

@Test
public void serializeQuestionItem() {
    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);
}
Also used : QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 48 with QItemType

use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.

the class PoolDAOTest method removeItemFromPools.

@Test
public void removeItemFromPools() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool with an item
    String poolName = "NGC-" + UUID.randomUUID().toString();
    Pool pool = poolDao.createPool(null, poolName, true);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item = questionItemDao.createAndPersist(id, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    poolDao.addItemToPool(item, Collections.singletonList(pool), false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setPoolKey(pool.getKey());
    // check the pool and remove the items
    List<QuestionItemView> items = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
    Assert.assertEquals(1, items.size());
    List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(items.get(0));
    int count = poolDao.removeFromPools(toDelete);
    Assert.assertEquals(1, count);
    dbInstance.commitAndCloseSession();
    // check if the pool is empty
    List<QuestionItemView> emptyItems = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
    Assert.assertTrue(emptyItems.isEmpty());
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 49 with QItemType

use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.

the class PoolDAOTest method removeItemFromPool_paranoid.

@Test
public void removeItemFromPool_paranoid() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool
    String name1 = "NGC-" + UUID.randomUUID().toString();
    Pool pool1 = poolDao.createPool(null, name1, true);
    String name2 = "NGC-" + UUID.randomUUID().toString();
    Pool pool2 = poolDao.createPool(null, name2, true);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item1 = questionItemDao.createAndPersist(id, "Cluster of stars", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionItemDao.createAndPersist(id, "Nebula", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    poolDao.addItemToPool(item1, Collections.singletonList(pool1), false);
    poolDao.addItemToPool(item1, Collections.singletonList(pool2), false);
    poolDao.addItemToPool(item2, Collections.singletonList(pool1), false);
    poolDao.addItemToPool(item2, Collections.singletonList(pool2), false);
    dbInstance.commit();
    SearchQuestionItemParams params1 = new SearchQuestionItemParams(id, null);
    params1.setPoolKey(pool1.getKey());
    SearchQuestionItemParams params2 = new SearchQuestionItemParams(id, null);
    params2.setPoolKey(pool2.getKey());
    // check
    int numOfItems_1 = poolDao.countItemsInPool(params1);
    Assert.assertEquals(2, numOfItems_1);
    int numOfItems_2 = poolDao.countItemsInPool(params2);
    Assert.assertEquals(2, numOfItems_2);
    // remove
    poolDao.removeFromPool(Collections.<QuestionItemShort>singletonList(item1), pool2);
    dbInstance.commit();
    // check empty pool
    int numOfStayingItems_1 = poolDao.countItemsInPool(params1);
    Assert.assertEquals(2, numOfStayingItems_1);
    int numOfStayingItems_2 = poolDao.countItemsInPool(params2);
    Assert.assertEquals(1, numOfStayingItems_2);
    // check content
    List<QuestionItemView> items_1 = qItemQueriesDao.getItemsOfPool(params1, null, 0, -1);
    Assert.assertEquals(2, items_1.size());
    List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfPool(params2, null, 0, -1);
    Assert.assertEquals(1, items_2.size());
    Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
    // but item exists
    QuestionItem reloadedItem = questionItemDao.loadById(item1.getKey());
    Assert.assertNotNull(reloadedItem);
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 50 with QItemType

use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.

the class PoolDAOTest method addItemToPool.

@Test
public void addItemToPool() {
    // 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();
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) 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