Search in sources :

Example 1 with QtiContentPackageSummary

use of uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary in project openolat by klemens.

the class QTI12To21ConverterTest method convert.

@Test
public void convert() throws URISyntaxException, IOException, XmlResourceNotFoundException, ImsManifestException {
    QTIDocument doc = loadDocument("qti12_4questiontypes.xml");
    File exportDir = new File(WebappHelper.getTmpDir(), "qti12to21" + UUID.randomUUID());
    exportDir.mkdirs();
    QTI12To21Converter converter = new QTI12To21Converter(exportDir, Locale.ENGLISH);
    converter.convert(null, doc, null);
    int validAssessmentItems = 0;
    boolean validAssessmentTest = false;
    QtiContentPackageSummary readableManifest = null;
    File[] generatedFiles = exportDir.listFiles();
    for (File generatedFile : generatedFiles) {
        String filename = generatedFile.getName();
        if (filename.equals("imsmanifest.xml")) {
            readableManifest = new QtiContentPackageExtractor(exportDir).parse();
        } else if (filename.startsWith("test")) {
            validAssessmentTest = validateAssessmentTest(generatedFile);
        } else if (filename.endsWith(".xml")) {
            boolean validItem = validateAssessmentItem(generatedFile);
            if (validItem) {
                validAssessmentItems++;
            }
        }
    }
    // delete tmp
    FileUtils.deleteDirsAndFiles(exportDir.toPath());
    Assert.assertTrue(validAssessmentTest);
    Assert.assertEquals(4, validAssessmentItems);
    Assert.assertEquals(1, readableManifest.getTestResources().size());
    Assert.assertEquals(4, readableManifest.getItemResources().size());
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) QtiContentPackageSummary(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary) File(java.io.File) QtiContentPackageExtractor(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageExtractor) Test(org.junit.Test)

Example 2 with QtiContentPackageSummary

use of uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary in project openolat by klemens.

the class QTI21AssessmentTestHandlerTest method readManifest.

private boolean readManifest(File tmpDir) throws ImsManifestException, XmlResourceNotFoundException {
    QtiContentPackageExtractor extractor = new QtiContentPackageExtractor(tmpDir);
    QtiContentPackageSummary summary = extractor.parse();
    List<ContentPackageResource> items = summary.getItemResources();
    List<ContentPackageResource> tests = summary.getTestResources();
    return items.size() == 1 && tests.size() == 1;
}
Also used : QtiContentPackageSummary(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary) ContentPackageResource(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.ContentPackageResource) QtiContentPackageExtractor(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageExtractor)

Example 3 with QtiContentPackageSummary

use of uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentTestHandlerTest method readManifest.

private boolean readManifest(File tmpDir) throws ImsManifestException, XmlResourceNotFoundException {
    QtiContentPackageExtractor extractor = new QtiContentPackageExtractor(tmpDir);
    QtiContentPackageSummary summary = extractor.parse();
    List<ContentPackageResource> items = summary.getItemResources();
    List<ContentPackageResource> tests = summary.getTestResources();
    return items.size() == 1 && tests.size() == 1;
}
Also used : QtiContentPackageSummary(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary) ContentPackageResource(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.ContentPackageResource) QtiContentPackageExtractor(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageExtractor)

Example 4 with QtiContentPackageSummary

use of uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary in project OpenOLAT by OpenOLAT.

the class QTI12To21ConverterTest method convert.

@Test
public void convert() throws URISyntaxException, IOException, XmlResourceNotFoundException, ImsManifestException {
    QTIDocument doc = loadDocument("qti12_4questiontypes.xml");
    File exportDir = new File(WebappHelper.getTmpDir(), "qti12to21" + UUID.randomUUID());
    exportDir.mkdirs();
    QTI12To21Converter converter = new QTI12To21Converter(exportDir, Locale.ENGLISH);
    converter.convert(null, doc, null);
    int validAssessmentItems = 0;
    boolean validAssessmentTest = false;
    QtiContentPackageSummary readableManifest = null;
    File[] generatedFiles = exportDir.listFiles();
    for (File generatedFile : generatedFiles) {
        String filename = generatedFile.getName();
        if (filename.equals("imsmanifest.xml")) {
            readableManifest = new QtiContentPackageExtractor(exportDir).parse();
        } else if (filename.startsWith("test")) {
            validAssessmentTest = validateAssessmentTest(generatedFile);
        } else if (filename.endsWith(".xml")) {
            boolean validItem = validateAssessmentItem(generatedFile);
            if (validItem) {
                validAssessmentItems++;
            }
        }
    }
    // delete tmp
    FileUtils.deleteDirsAndFiles(exportDir.toPath());
    Assert.assertTrue(validAssessmentTest);
    Assert.assertEquals(4, validAssessmentItems);
    Assert.assertEquals(1, readableManifest.getTestResources().size());
    Assert.assertEquals(4, readableManifest.getItemResources().size());
}
Also used : QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) QtiContentPackageSummary(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary) File(java.io.File) QtiContentPackageExtractor(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageExtractor) Test(org.junit.Test)

Example 5 with QtiContentPackageSummary

use of uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary in project OpenOLAT by OpenOLAT.

the class ManifestPackageTest method makeManifest.

@Test
public void makeManifest() throws XmlResourceNotFoundException, ImsManifestException, IOException {
    ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
    String testFilename = manifest.appendAssessmentTest();
    String itemFilename = manifest.appendAssessmentItem();
    Assert.assertNotNull(testFilename);
    Assert.assertNotNull(itemFilename);
    File tmpDir = new File(WebappHelper.getTmpDir(), "itembuilder" + UUID.randomUUID());
    tmpDir.mkdirs();
    File manifestFile = new File(tmpDir, "imsmanifest.xml");
    FileOutputStream out = new FileOutputStream(manifestFile);
    manifest.write(out);
    out.flush();
    out.close();
    QtiContentPackageExtractor extractor = new QtiContentPackageExtractor(tmpDir);
    QtiContentPackageSummary summary = extractor.parse();
    List<ContentPackageResource> items = summary.getItemResources();
    List<ContentPackageResource> tests = summary.getTestResources();
    Assert.assertEquals(1, items.size());
    Assert.assertEquals(1, tests.size());
    ManifestBuilder reloadManifest = ManifestBuilder.read(manifestFile);
    Assert.assertNotNull(reloadManifest);
    FileUtils.deleteDirsAndFiles(tmpDir.toPath());
}
Also used : FileOutputStream(java.io.FileOutputStream) QtiContentPackageSummary(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary) File(java.io.File) ContentPackageResource(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.ContentPackageResource) QtiContentPackageExtractor(uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageExtractor) Test(org.junit.Test)

Aggregations

QtiContentPackageExtractor (uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageExtractor)6 QtiContentPackageSummary (uk.ac.ed.ph.jqtiplus.utils.contentpackaging.QtiContentPackageSummary)6 File (java.io.File)4 Test (org.junit.Test)4 ContentPackageResource (uk.ac.ed.ph.jqtiplus.utils.contentpackaging.ContentPackageResource)4 FileOutputStream (java.io.FileOutputStream)2 QTIDocument (org.olat.ims.qti.editor.beecom.objects.QTIDocument)2