use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult in project openolat by klemens.
the class AssessmentItemBuilderTest method buildAssessmentItem_essay.
@Test
public void buildAssessmentItem_essay() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
EssayAssessmentItemBuilder itemBuilder = new EssayAssessmentItemBuilder("Essay", 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 ExtendedTextInteraction);
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult in project openolat by klemens.
the class AssessmentItemBuilderTest method buildAssessmentItem_multipleChoice.
/**
* Check if a bare bone multiple choice created with our builder make a valid assessmentItem.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void buildAssessmentItem_multipleChoice() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", 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 ChoiceInteraction);
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult in project openolat by klemens.
the class AssessmentItemBuilderTest method buildAssessmentItem_kprim.
@Test
public void buildAssessmentItem_kprim() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem singleChoiceItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(singleChoiceItem);
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 MatchInteraction);
MatchInteraction interaction = (MatchInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
Assert.assertEquals(2, interaction.getSimpleMatchSets().size());
SimpleMatchSet matchSet = interaction.getSimpleMatchSets().get(0);
Assert.assertEquals(4, matchSet.getSimpleAssociableChoices().size());
SimpleMatchSet correctWrongSet = interaction.getSimpleMatchSets().get(1);
Assert.assertEquals(2, correctWrongSet.getSimpleAssociableChoices().size());
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult in project OpenOLAT by OpenOLAT.
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));
}
use of uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult in project OpenOLAT by OpenOLAT.
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();
}
Aggregations