use of uk.ac.ed.ph.jqtiplus.JqtiExtensionManager in project OpenOLAT by OpenOLAT.
the class SingleChoiceAssessmentItemBuilderTest method createSingleAssessmentItem_allCorrectAnswers.
@Test
public void createSingleAssessmentItem_allCorrectAnswers() throws IOException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "Single choice", qtiSerializer);
itemBuilder.setQuestion("<p>Hello</p>");
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
SimpleChoice choice1 = AssessmentItemFactory.createSimpleChoice(interaction, "One", "sc");
SimpleChoice choice2 = AssessmentItemFactory.createSimpleChoice(interaction, "Two", "sc");
SimpleChoice choice3 = AssessmentItemFactory.createSimpleChoice(interaction, "Three", "sc");
List<SimpleChoice> choiceList = new ArrayList<>();
choiceList.add(choice1);
choiceList.add(choice2);
choiceList.add(choice3);
itemBuilder.setSimpleChoices(choiceList);
itemBuilder.setCorrectAnswer(choice2.getIdentifier());
itemBuilder.setMaxScore(3.0d);
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
itemBuilder.build();
File itemFile = new File(WebappHelper.getTmpDir(), "scAssessmentItem" + UUID.randomUUID() + ".xml");
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(itemBuilder.getAssessmentItem(), out);
} catch (Exception e) {
log.error("", e);
}
{
// correct answers
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice2.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
}
{
// wrong answer
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice3.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(0.0d), score);
}
FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
use of uk.ac.ed.ph.jqtiplus.JqtiExtensionManager 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.JqtiExtensionManager 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();
}
use of uk.ac.ed.ph.jqtiplus.JqtiExtensionManager in project OpenOLAT by OpenOLAT.
the class QTI12To21ConverterTest 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();
if (e != null) {
StringBuilder err = new StringBuilder();
BadRessourceHelper.extractMessage(e, err);
log.error(err.toString());
}
return test.getModelValidationErrors().isEmpty();
}
use of uk.ac.ed.ph.jqtiplus.JqtiExtensionManager in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method findFeedbacks.
@Test
public void findFeedbacks() throws URISyntaxException {
URL itemUrl = AssessmentItemBuilderTest.class.getResource("assessment-item-single-choice-feedbacks.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertTrue(correctFeedback.isCorrectRule());
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertTrue(incorrectFeedback.isIncorrectRule());
}
Aggregations