Search in sources :

Example 6 with KeyTranslator

use of org.olat.test.KeyTranslator in project openolat by klemens.

the class CSVToQuestionConverterTest method importFillInBlanck.

@Test
public void importFillInBlanck() throws IOException, URISyntaxException {
    URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib.txt");
    Assert.assertNotNull(importTxtUrl);
    File importTxt = new File(importTxtUrl.toURI());
    String input = FileUtils.readFileToString(importTxt, "UTF-8");
    Translator translator = new KeyTranslator(Locale.ENGLISH);
    ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
    converter.parse(input);
    List<ItemAndMetadata> items = converter.getItems();
    Assert.assertNotNull(items);
    Assert.assertEquals(1, items.size());
    ItemAndMetadata importedItem = items.get(0);
    Item item = importedItem.getItem();
    Assert.assertNotNull(item);
    Assert.assertEquals(Question.TYPE_FIB, item.getQuestion().getType());
    Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
    FIBQuestion question = (FIBQuestion) item.getQuestion();
    List<Response> responses = question.getResponses();
    Assert.assertNotNull(responses);
    Assert.assertEquals(7, responses.size());
    // check java type
    for (Response response : responses) {
        Assert.assertTrue(response instanceof FIBResponse);
    }
    // check type
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
    Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(2)).getType());
    Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(3)).getType());
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(4)).getType());
    Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(5)).getType());
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(6)).getType());
    // check size
    Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getSize());
    Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getSize());
    Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getSize());
    // check max length
    Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getMaxLength());
    Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getMaxLength());
    Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getMaxLength());
}
Also used : URL(java.net.URL) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) Translator(org.olat.core.gui.translator.Translator) KeyTranslator(org.olat.test.KeyTranslator) KeyTranslator(org.olat.test.KeyTranslator) File(java.io.File) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion) Test(org.junit.Test)

Aggregations

File (java.io.File)6 URL (java.net.URL)6 Test (org.junit.Test)6 Translator (org.olat.core.gui.translator.Translator)6 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)6 Item (org.olat.ims.qti.editor.beecom.objects.Item)6 Response (org.olat.ims.qti.editor.beecom.objects.Response)6 KeyTranslator (org.olat.test.KeyTranslator)6 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)4 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)2 Material (org.olat.ims.qti.editor.beecom.objects.Material)2 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)2 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)2