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());
}
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;
}
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;
}
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());
}
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());
}
Aggregations