Search in sources :

Example 11 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project openolat by klemens.

the class OpenOLATAssessementItemsTest method ourItem.

@Test
public void ourItem() throws IOException, XMLStreamException, SAXException, ParserConfigurationException, URISyntaxException {
    URL xmlUrl = OpenOLATAssessementItemsTest.class.getResource("resources/openolat/" + xmlFilename);
    File xmlFile = new File(xmlUrl.toURI());
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(xmlFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(xmlFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    Assert.assertFalse(xmlFilename + " has errors", (itemResult.getModelValidationErrors().size() > 0));
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) File(java.io.File) URL(java.net.URL) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult) Test(org.junit.Test)

Example 12 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project openolat by klemens.

the class QTI12To21ConverterTest method validateAssessmentItem.

private boolean validateAssessmentItem(File assessmentItemFile) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentItemFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(assessmentItemFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    return itemResult.getModelValidationErrors().isEmpty();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)

Example 13 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project openolat by klemens.

the class QTI21AssessmentTestHandlerTest method validateAssessmentItem.

private boolean validateAssessmentItem(File assessmentItemFile) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentItemFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(assessmentItemFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    return itemResult.getModelValidationErrors().isEmpty();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)

Example 14 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project openolat by klemens.

the class QTI21AssessmentTestHandlerTest method validateAssessmentTest.

private boolean validateAssessmentTest(File assessmentTestFile) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentTestFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    TestValidationResult test = assessmentObjectXmlLoader.loadResolveAndValidateTest(assessmentTestFile.toURI());
    for (Notification notification : test.getModelValidationErrors()) {
        log.error(notification.getQtiNode() + " : " + notification.getMessage());
    }
    BadResourceException e = test.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
    StringBuilder err = new StringBuilder();
    BadRessourceHelper.extractMessage(e, err);
    log.error(err.toString());
    return test.getModelValidationErrors().isEmpty();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) TestValidationResult(uk.ac.ed.ph.jqtiplus.validation.TestValidationResult) Notification(uk.ac.ed.ph.jqtiplus.notification.Notification) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)

Example 15 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project openolat by klemens.

the class AssessmentItemBuilderTest method serializeAndReload.

/**
 * The method serialize as xml the assessmentItem, load it, validate it and return the itemResult.
 *
 * @param assessmentItem
 * @return
 * @throws IOException
 */
private ItemValidationResult serializeAndReload(AssessmentItem assessmentItem) throws IOException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    File tmpDir = new File(WebappHelper.getTmpDir(), "itembuilder" + UUID.randomUUID());
    tmpDir.mkdirs();
    File outputFile = new File(tmpDir, "sc_item.xml");
    try (FileOutputStream out = new FileOutputStream(outputFile)) {
        qtiSerializer.serializeJqtiObject(assessmentItem, out);
    } catch (Exception e) {
        log.error("", e);
    }
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(outputFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(outputFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    FileUtils.deleteDirsAndFiles(tmpDir.toPath());
    Assert.assertFalse("Has errors", (itemResult.getModelValidationErrors().size() > 0));
    return itemResult;
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) FileOutputStream(java.io.FileOutputStream) File(java.io.File) URISyntaxException(java.net.URISyntaxException) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) IOException(java.io.IOException) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)

Aggregations

BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)26 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)20 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)20 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)20 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)20 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)20 ItemValidationResult (uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)14 File (java.io.File)10 URISyntaxException (java.net.URISyntaxException)10 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)10 IOException (java.io.IOException)8 URL (java.net.URL)8 Test (org.junit.Test)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 TestValidationResult (uk.ac.ed.ph.jqtiplus.validation.TestValidationResult)8 InputStream (java.io.InputStream)6 Writer (java.io.Writer)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 SAXParser (javax.xml.parsers.SAXParser)6 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)6