Search in sources :

Example 6 with ItemInfos

use of org.olat.ims.qti.qpool.QTIImportProcessor.ItemInfos in project openolat by klemens.

the class QTIImportProcessorTest method testImport_SC.

/**
 * This test check every methods of the import process in details
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void testImport_SC() throws IOException, URISyntaxException {
    URL itemUrl = QTIImportProcessorTest.class.getResource("mchc_i_002.xml");
    Assert.assertNotNull(itemUrl);
    File itemFile = new File(itemUrl.toURI());
    // get the document informations
    QTIImportProcessor proc = new QTIImportProcessor(owner, Locale.ENGLISH, itemFile.getName(), itemFile);
    List<DocInfos> docInfoList = proc.getDocInfos();
    Assert.assertNotNull(docInfoList);
    Assert.assertEquals(1, docInfoList.size());
    DocInfos docInfos = docInfoList.get(0);
    Assert.assertNotNull(docInfos);
    Assert.assertNotNull(docInfos.getFilename());
    Assert.assertNotNull(docInfos.getDocument());
    Assert.assertEquals("mchc_i_002.xml", docInfos.getFilename());
    // get the question DOM's
    List<ItemInfos> itemInfos = proc.getItemList(docInfos);
    Assert.assertNotNull(itemInfos);
    Assert.assertEquals(1, itemInfos.size());
    // process item, files...
    QuestionItemImpl item = proc.processItem(docInfos, itemInfos.get(0), null);
    Assert.assertNotNull(item);
    dbInstance.commitAndCloseSession();
    proc.processFiles(item, itemInfos.get(0), null);
    // reload and check what is saved
    QuestionItemFull reloadItem = questionItemDao.loadById(item.getKey());
    Assert.assertNotNull(reloadItem);
    Assert.assertNotNull(reloadItem.getCreationDate());
    Assert.assertNotNull(reloadItem.getLastModified());
    Assert.assertEquals(QuestionStatus.draft, reloadItem.getQuestionStatus());
    Assert.assertEquals(QTIConstants.QTI_12_FORMAT, reloadItem.getFormat());
    // title
    Assert.assertEquals("Standard Multiple Choice with Images Item", reloadItem.getTitle());
    // description -> qticomment
    Assert.assertEquals("This is a multiple-choice example with image content. The rendering is a standard radio button style. No response processing is incorporated.", reloadItem.getDescription());
    // question type
    Assert.assertNotNull(reloadItem.getType());
    Assert.assertEquals(QuestionType.SC.name().toLowerCase(), reloadItem.getType().getType());
    // check that the file is storead
    VFSContainer itemDir = qpoolFileStorage.getContainer(reloadItem.getDirectory());
    Assert.assertNotNull(itemDir);
    VFSItem qtiLeaf = itemDir.resolve(reloadItem.getRootFilename());
    Assert.assertNotNull(qtiLeaf);
    Assert.assertTrue(qtiLeaf instanceof VFSLeaf);
    Assert.assertTrue(qtiLeaf.exists());
    Assert.assertEquals(itemFile.length(), ((VFSLeaf) qtiLeaf).getSize());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) DocInfos(org.olat.ims.qti.qpool.QTIImportProcessor.DocInfos) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) ItemInfos(org.olat.ims.qti.qpool.QTIImportProcessor.ItemInfos) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

File (java.io.File)6 URL (java.net.URL)6 Test (org.junit.Test)6 DocInfos (org.olat.ims.qti.qpool.QTIImportProcessor.DocInfos)6 ItemInfos (org.olat.ims.qti.qpool.QTIImportProcessor.ItemInfos)6 Element (org.dom4j.Element)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 QuestionItem (org.olat.modules.qpool.QuestionItem)2 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)2 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)2