use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult 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();
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult 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();
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult in project openolat by klemens.
the class AssessmentItemBuilderTest method buildAssessmentItem_gap.
@Test
public void buildAssessmentItem_gap() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(assessmentItem);
AssessmentItem reloadedItem = itemResult.getResolvedAssessmentItem().getItemLookup().extractIfSuccessful();
List<Interaction> interactions = reloadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof TextEntryInteraction);
TextEntryInteraction interaction = (TextEntryInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult in project openolat by klemens.
the class AssessmentItemBuilderTest method buildAssessmentItem_hotspot.
@Test
public void buildAssessmentItem_hotspot() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
HotspotAssessmentItemBuilder itemBuilder = new HotspotAssessmentItemBuilder("Hotspot", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(assessmentItem);
AssessmentItem reloadedItem = itemResult.getResolvedAssessmentItem().getItemLookup().extractIfSuccessful();
List<Interaction> interactions = reloadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HotspotInteraction);
HotspotInteraction interaction = (HotspotInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult 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;
}
Aggregations