Search in sources :

Example 31 with Localizer

use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.

the class LocalizerTest method testNullArgs.

public void testNullArgs() {
    Localizer l = new Localizer();
    l.addAvailableLocale("test");
    TableLocaleSource table = new TableLocaleSource();
    try {
        l.addAvailableLocale(null);
        fail("addAvailableLocale: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    if (l.hasLocale(null)) {
        fail("Localizer reports it contains null locale");
    }
    try {
        l.registerLocaleResource(null, new TableLocaleSource());
        fail("setLocaleData: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        l.registerLocaleResource("test", null);
        fail("setLocaleData: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    if (l.getLocaleData(null) != null) {
        fail("getLocaleData: Localizer returns mappings for null locale");
    }
    try {
        l.getLocaleMap(null);
        fail("getLocaleMap: Did not get expected exception");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
    try {
        table.setLocaleMapping(null, "text");
        fail("setLocaleMapping: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        table.setLocaleMapping(null, null);
        fail("setLocaleMapping: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        l.hasMapping(null, "textID");
        fail("hasMapping: Did not get expected exception");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
    if (l.hasMapping("test", null)) {
        fail("Localization reports it contains null mapping");
    }
    try {
        l.destroyLocale(null);
        fail("destroyLocale: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
    try {
        l.getText("textID", (String) null);
        fail("getText: Did not get expected exception");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
    try {
        l.getText(null, "test");
        fail("getText: Did not get expected null pointer exception");
    } catch (NullPointerException npe) {
    // expected
    }
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer) UnregisteredLocaleException(org.javarosa.core.util.UnregisteredLocaleException)

Example 32 with Localizer

use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.

the class LocalizerTest method testSetToDefaultNoDefault.

public void testSetToDefaultNoDefault() {
    Localizer l = new Localizer();
    final String TEST_LOCALE = "test";
    l.addAvailableLocale(TEST_LOCALE);
    try {
        l.setToDefault();
        fail("Set current locale to default when no default set");
    } catch (IllegalStateException ise) {
    // expected
    }
}
Also used : Localizer(org.javarosa.core.services.locale.Localizer)

Example 33 with Localizer

use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.

the class LocalizerTest method testFallbacks.

public void testFallbacks() {
    Localizer localizer = new Localizer(true, true);
    localizer.addAvailableLocale("one");
    localizer.addAvailableLocale("two");
    TableLocaleSource firstLocale = new TableLocaleSource();
    firstLocale.setLocaleMapping("data", "val");
    firstLocale.setLocaleMapping("data2", "vald2");
    localizer.registerLocaleResource("one", firstLocale);
    TableLocaleSource secondLocale = new TableLocaleSource();
    firstLocale.setLocaleMapping("data", "val2");
    localizer.registerLocaleResource("two", secondLocale);
    localizer.setDefaultLocale("one");
    localizer.setLocale("two");
    String text = localizer.getText("data2");
    assertEquals("fallback", text, "vald2");
    String shouldBeNull = localizer.getText("noexist");
    assertNull("Localizer didn't return null value", shouldBeNull);
    localizer.setToDefault();
    shouldBeNull = localizer.getText("noexist");
    assertNull("Localizer didn't return null value", shouldBeNull);
    assertNull("Localizer didn't return null value", shouldBeNull);
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer)

Example 34 with Localizer

use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.

the class LocalizerTest method testGetTextNoCurrentLocale.

public void testGetTextNoCurrentLocale() {
    Localizer l = new Localizer();
    TableLocaleSource table = new TableLocaleSource();
    l.addAvailableLocale("test");
    l.setDefaultLocale("test");
    table.setLocaleMapping("textID", "text");
    l.registerLocaleResource("test", table);
    try {
        l.getText("textID");
        fail("Retrieved current locale text when current locale not set");
    } catch (UnregisteredLocaleException nsee) {
    // expected
    }
}
Also used : TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer) UnregisteredLocaleException(org.javarosa.core.util.UnregisteredLocaleException)

Example 35 with Localizer

use of org.javarosa.core.services.locale.Localizer in project javarosa by opendatakit.

the class TextFormTests method testTextForms.

/**
 * Test that the long and short text forms work as expected
 * (fallback to default for example).
 * Test being able to retrieve other exotic forms
 */
public void testTextForms() {
    FormEntryController fec = fpi.getFormEntryController();
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    boolean foundFlag = false;
    Localizer l = fpi.getFormDef().getLocalizer();
    l.setDefaultLocale(l.getAvailableLocales()[0]);
    l.setLocale(l.getAvailableLocales()[0]);
    int state = -99;
    while (state != FormEntryController.EVENT_QUESTION) {
        state = fec.stepToNextEvent();
    }
    fep = fec.getModel().getQuestionPrompt();
    if (!fep.getLongText().equals("Patient ID"))
        fail("getLongText() not returning correct value");
    if (!fep.getShortText().equals("ID"))
        fail("getShortText() not returning correct value");
    if (!fep.getAudioText().equals("jr://audio/hah.mp3"))
        fail("getAudioText() not returning correct value");
    state = -99;
    while (state != FormEntryController.EVENT_QUESTION) {
        state = fec.stepToNextEvent();
    }
    fep = fec.getModel().getQuestionPrompt();
    if (!fep.getShortText().equals("Name"))
        fail("getShortText() not returning correct value");
    if (!fep.getLongText().equals("Full Name"))
        fail("getLongText() not falling back to default text form correctly");
    String v = fep.getSpecialFormQuestionText("long");
    if (fep.getSpecialFormQuestionText("long") != null)
        fail("getSpecialFormQuestionText() returning incorrect value");
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) Localizer(org.javarosa.core.services.locale.Localizer)

Aggregations

Localizer (org.javarosa.core.services.locale.Localizer)37 TableLocaleSource (org.javarosa.core.services.locale.TableLocaleSource)10 UnregisteredLocaleException (org.javarosa.core.util.UnregisteredLocaleException)7 ArrayList (java.util.ArrayList)3 QuestionDef (org.javarosa.core.model.QuestionDef)3 FormEntryController (org.javarosa.form.api.FormEntryController)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 List (java.util.List)1 IDataReference (org.javarosa.core.model.IDataReference)1 IFormElement (org.javarosa.core.model.IFormElement)1 Condition (org.javarosa.core.model.condition.Condition)1 IConditionExpr (org.javarosa.core.model.condition.IConditionExpr)1 Recalculate (org.javarosa.core.model.condition.Recalculate)1 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)1 DataInstance (org.javarosa.core.model.instance.DataInstance)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 DummyFormEntryPrompt (org.javarosa.core.model.test.DummyFormEntryPrompt)1 InvalidReferenceException (org.javarosa.core.reference.InvalidReferenceException)1 Reference (org.javarosa.core.reference.Reference)1 ResourceReferenceFactory (org.javarosa.core.reference.ResourceReferenceFactory)1