use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody in project OpenOLAT by OpenOLAT.
the class AssessmentHtmlBuilderTest method filter_alt.
@Test
public void filter_alt() {
String content = "<p>Test <textEntryInteraction responseIdentifier=\"RESPONSE_1\"/> </p>";
AssessmentItem item = new AssessmentItem();
ItemBody helper = new ItemBody(item);
new AssessmentHtmlBuilder().appendHtml(helper, content);
List<Interaction> interactions = helper.findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Interaction interaction = interactions.get(0);
Assert.assertTrue(interaction instanceof TextEntryInteraction);
Assert.assertNotNull(interaction.getResponseIdentifier());
Assert.assertEquals("RESPONSE_1", interaction.getResponseIdentifier().toString());
}
use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody in project OpenOLAT by OpenOLAT.
the class AssessmentHtmlBuilderTest method filter.
@Test
public void filter() throws IOException {
String content = "<html><p>Test \u00EA<strong><span><img src='img.jpg'></span></strong></p><p>Test 2</p></html>";
AssessmentItem item = new AssessmentItem();
ItemBody helper = new ItemBody(item);
new AssessmentHtmlBuilder().appendHtml(helper, content);
List<Block> paragraphs = helper.getBlocks();
Assert.assertNotNull(paragraphs);
Assert.assertEquals(2, paragraphs.size());
// The serializer can throw some exceptions if it doens't like the model
// we want to serialize.
StringOutput sb = new StringOutput();
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
String serializedQti = sb.toString();
Assert.assertTrue(serializedQti.contains("img.jpg"));
sb.close();
}
use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody in project OpenOLAT by OpenOLAT.
the class AssessmentHtmlBuilderTest method serializeVideo.
@Test
public void serializeVideo() throws IOException {
String content = "<p><span id=\"olatFlashMovieViewer213060\" class=\"olatFlashMovieViewer\" style=\"display:block;border:solid 1px #000; width:320px; height:240px;\">\n" + "<script src=\"/raw/fx-111111x11/movie/player.js\" type=\"text/javascript\"></script>\n" + "<script type=\"text/javascript\" defer=\"defer\">// <![CDATA[\n" + "BPlayer.insertPlayer(\"demo-video.mp4\",\"olatFlashMovieViewer213060\",320,240,0,0,\"video\",undefined,false,false,true,undefined);\n" + "// ]]></script>\n" + "</span></p>";
AssessmentItem item = new AssessmentItem();
ItemBody helper = new ItemBody(item);
new AssessmentHtmlBuilder().appendHtml(helper, content);
List<Block> paragraphs = helper.getBlocks();
Assert.assertNotNull(paragraphs);
Assert.assertEquals(1, paragraphs.size());
StringOutput sb = new StringOutput();
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
String serializedQti = sb.toString();
Assert.assertNotNull(serializedQti);
Assert.assertTrue(serializedQti.contains("object"));
Assert.assertFalse(serializedQti.contains("span"));
Assert.assertFalse(serializedQti.contains("script"));
sb.close();
}
use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody in project OpenOLAT by OpenOLAT.
the class HotspotAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.hotspot, title);
// define the response
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
Identifier correctResponseId = IdentifierGenerator.newNumberAsIdentifier("hc");
ResponseDeclaration responseDeclaration = createHotspotEntryResponseDeclarationSingle(assessmentItem, responseDeclarationId, correctResponseId);
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
appendHotspotInteraction(itemBody, responseDeclarationId, correctResponseId);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
use of uk.ac.ed.ph.jqtiplus.node.content.ItemBody in project OpenOLAT by OpenOLAT.
the class KPrimAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.kprim, title);
NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
double maxScore = 1.0d;
Identifier responseDeclarationId = Identifier.assumedLegal("KPRIM_RESPONSE_1");
// define correct answer
ResponseDeclaration responseDeclaration = createKPrimResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>(), maxScore);
nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
// the single choice interaction
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
MatchInteraction matchInteraction = appendMatchInteractionForKPrim(itemBody, responseDeclarationId, defaultAnswer);
List<String> cssClasses = new ArrayList<>();
cssClasses.add(QTI21Constants.CSS_MATCH_KPRIM);
matchInteraction.setClassAttr(cssClasses);
SimpleMatchSet matchSet = matchInteraction.getSimpleMatchSets().get(0);
Map<Identifier, Identifier> associations = new HashMap<>();
for (SimpleAssociableChoice choice : matchSet.getSimpleAssociableChoices()) {
associations.put(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
}
appendAssociationKPrimResponseDeclaration(responseDeclaration, associations, 1.0);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
Aggregations