use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method getItemsWithOneAuthor.
@Test
public void getItemsWithOneAuthor() {
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-all-" + UUID.randomUUID().toString());
QuestionItem item1 = questionDao.createAndPersist(id, "NGC all", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(id, "NGC all", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
QuestionItem item3 = questionDao.createAndPersist(id, "NGC all", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-all-" + UUID.randomUUID().toString());
questionDao.addAuthors(Collections.singletonList(id2), item3);
dbInstance.commitAndCloseSession();
List<QuestionItem> itemsWithOneAuthor = questionDao.getItemsWithOneAuthor(id);
Assert.assertNotNull(itemsWithOneAuthor);
Assert.assertTrue(itemsWithOneAuthor.size() == 2);
Assert.assertTrue(itemsWithOneAuthor.contains(item1));
Assert.assertTrue(itemsWithOneAuthor.contains(item2));
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method copyQuestion.
@Test
public void copyQuestion() {
// create an item and fill it
Taxonomy taxonomy = taxonomyDao.createTaxonomy("ID-QP", "QPool taxonomy", null, null);
TaxonomyLevel taxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QP-L-1", "QLevel 1", "For testing only", null, null, null, null, taxonomy);
QEducationalContext eduContext = qEduContextDao.create("primary.school", true);
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
QItemType essayType = qItemTypeDao.loadByType(QuestionType.ESSAY.name());
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("QClone-1-" + UUID.randomUUID().toString());
Identity cloner = JunitTestHelper.createAndPersistIdentityAsUser("QClone-2-" + UUID.randomUUID().toString());
QuestionItemImpl original = questionDao.createAndPersist(author, "To copy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), taxonomyLevel, null, "root.xml", fibType);
dbInstance.commit();
Assert.assertNotNull(original);
Assert.assertNotNull(original.getIdentifier());
Assert.assertNull(original.getMasterIdentifier());
// general
original.setTitle("Original");
original.setTopic("Topic");
original.setDescription("Original description");
original.setKeywords("original copy to");
original.setCoverage("New coverage");
original.setAdditionalInformations("Additional informations before copy");
original.setLanguage("en");
// educational
original.setEducationalContext(eduContext);
original.setEducationalLearningTime("PT1H30M");
// question
original.setType(essayType);
original.setDifficulty(new BigDecimal("0.1"));
original.setStdevDifficulty(new BigDecimal("0.2"));
original.setDifferentiation(new BigDecimal("-0.5"));
original.setNumOfAnswerAlternatives(4);
original.setUsage(5);
original.setAssessmentType("formative");
// lifecycle
original.setItemVersion("1.0");
original.setStatus(QuestionStatus.review.name());
// technical
original.setEditor("OpenOLAT");
original.setEditorVersion("9.0a");
original = questionDao.merge(original);
dbInstance.commitAndCloseSession();
// clone it
QuestionItemImpl clone = questionDao.copy(original);
questionDao.persist(cloner, clone);
// compare
Assert.assertEquals(1, questionDao.countItems(cloner));
// general
Assert.assertNotNull(clone.getIdentifier());
Assert.assertFalse(clone.getIdentifier().equals(original.getIdentifier()));
Assert.assertEquals(original.getIdentifier(), clone.getMasterIdentifier());
Assert.assertNotNull(clone.getTitle());
Assert.assertEquals("(Copy) " + original.getTitle(), clone.getTitle());
Assert.assertEquals(original.getTopic(), clone.getTopic());
Assert.assertEquals(original.getDescription(), clone.getDescription());
Assert.assertEquals(original.getKeywords(), clone.getKeywords());
Assert.assertEquals(original.getCoverage(), clone.getCoverage());
Assert.assertEquals(original.getAdditionalInformations(), clone.getAdditionalInformations());
Assert.assertEquals(original.getLanguage(), clone.getLanguage());
// classification
Assert.assertEquals(original.getTaxonomyLevelName(), clone.getTaxonomyLevelName());
// educational
Assert.assertEquals(original.getEducationalContext(), clone.getEducationalContext());
Assert.assertEquals(original.getEducationalLearningTime(), clone.getEducationalLearningTime());
// question
Assert.assertEquals(original.getType(), clone.getType());
Assert.assertNotNull(clone.getDifficulty());
Assert.assertEquals(original.getDifficulty().doubleValue(), clone.getDifficulty().doubleValue(), 0.000001);
Assert.assertNotNull(clone.getStdevDifficulty());
Assert.assertEquals(original.getStdevDifficulty().doubleValue(), clone.getStdevDifficulty().doubleValue(), 0.000001);
Assert.assertNotNull(clone.getDifferentiation());
Assert.assertEquals(original.getDifferentiation().doubleValue(), clone.getDifferentiation().doubleValue(), 0.000001);
Assert.assertEquals(original.getNumOfAnswerAlternatives(), clone.getNumOfAnswerAlternatives());
Assert.assertEquals(0, clone.getUsage());
Assert.assertEquals(original.getAssessmentType(), clone.getAssessmentType());
// lifecycle
Assert.assertEquals(QuestionStatus.draft.name(), clone.getStatus());
Assert.assertNotNull(clone.getQuestionStatusLastModified());
Assert.assertEquals(original.getItemVersion(), clone.getItemVersion());
// technical
Assert.assertEquals(original.getEditor(), clone.getEditor());
Assert.assertEquals(original.getEditorVersion(), clone.getEditorVersion());
Assert.assertEquals(original.getFormat(), clone.getFormat());
Assert.assertNotNull(clone.getCreationDate());
Assert.assertNotNull(clone.getLastModified());
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method getItems_all.
@Test
public void getItems_all() {
// create an author with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-all-" + UUID.randomUUID().toString());
QuestionItem item = questionDao.createAndPersist(id, "NGC all", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
dbInstance.commitAndCloseSession();
// retrieve all items
List<QuestionItemFull> items = questionDao.getAllItems(0, -1);
Assert.assertNotNull(items);
Assert.assertTrue(items.size() >= 1);
Assert.assertTrue(items.contains(item));
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method getFavoritItemKeys.
@Test
public void getFavoritItemKeys() {
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fav-item-" + UUID.randomUUID().toString());
QuestionItem item1 = questionDao.createAndPersist(id, "NGC 331", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item2 = questionDao.createAndPersist(id, "NGC 332", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item3 = questionDao.createAndPersist(id, "NGC 333", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
markManager.setMark(item1, id, null, "[QuestionItem:" + item1.getKey() + "]");
markManager.setMark(item2, id, null, "[QuestionItem:" + item2.getKey() + "]");
dbInstance.commitAndCloseSession();
List<Long> favoritKeys = questionDao.getFavoritKeys(id);
Assert.assertNotNull(favoritKeys);
Assert.assertEquals(2, favoritKeys.size());
Assert.assertTrue(favoritKeys.contains(item1.getKey()));
Assert.assertTrue(favoritKeys.contains(item2.getKey()));
Assert.assertFalse(favoritKeys.contains(item3.getKey()));
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method getSharedResources.
@Test
public void getSharedResources() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-item-" + UUID.randomUUID().toString());
BusinessGroup group1 = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
BusinessGroup group2 = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-Item-Dup-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commit();
// share them
questionDao.share(item, group1.getResource());
questionDao.share(item, group2.getResource());
dbInstance.commitAndCloseSession();
// retrieve them
List<OLATResource> shared = questionDao.getSharedResources(item);
Assert.assertNotNull(shared);
Assert.assertEquals(2, shared.size());
Assert.assertTrue(shared.contains(group1.getResource()));
Assert.assertTrue(shared.contains(group2.getResource()));
}
Aggregations