Search in sources :

Example 1 with Reference

use of org.javarosa.core.reference.Reference in project javarosa by opendatakit.

the class QuestionDefTest method testReferences.

@Test
public void testReferences() {
    QuestionDef q = fpi.getFirstQuestionDef();
    FormEntryPrompt fep = fpi.getFormEntryModel().getQuestionPrompt();
    Localizer l = fpi.getFormDef().getLocalizer();
    l.setDefaultLocale(l.getAvailableLocales()[0]);
    l.setLocale(l.getAvailableLocales()[0]);
    String audioURI = fep.getAudioText();
    String ref;
    ReferenceManager.instance().addReferenceFactory(new ResourceReferenceFactory());
    ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://audio/", "jr://resource/"));
    try {
        Reference r = ReferenceManager.instance().DeriveReference(audioURI);
        ref = r.getURI();
        if (!ref.equals("jr://resource/hah.mp3")) {
            fail("Root translation failed.");
        }
    } catch (InvalidReferenceException ire) {
        fail("There was an Invalid Reference Exception:" + ire.getMessage());
        ire.printStackTrace();
    }
    ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://images/", "jr://resource/"));
    q = fpi.getNextQuestion();
    fep = fpi.getFormEntryModel().getQuestionPrompt();
    String imURI = fep.getImageText();
    try {
        Reference r = ReferenceManager.instance().DeriveReference(imURI);
        ref = r.getURI();
        if (!ref.equals("jr://resource/four.gif")) {
            fail("Root translation failed.");
        }
    } catch (InvalidReferenceException ire) {
        fail("There was an Invalid Reference Exception:" + ire.getMessage());
        ire.printStackTrace();
    }
}
Also used : ResourceReferenceFactory(org.javarosa.core.reference.ResourceReferenceFactory) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Reference(org.javarosa.core.reference.Reference) IDataReference(org.javarosa.core.model.IDataReference) QuestionDef(org.javarosa.core.model.QuestionDef) Localizer(org.javarosa.core.services.locale.Localizer) RootTranslator(org.javarosa.core.reference.RootTranslator) InvalidReferenceException(org.javarosa.core.reference.InvalidReferenceException) Test(org.junit.Test)

Example 2 with Reference

use of org.javarosa.core.reference.Reference in project collect by opendatakit.

the class ChoicesRecyclerViewTest method setUpReferenceManager.

private void setUpReferenceManager() throws InvalidReferenceException {
    referenceManager = mock(ReferenceManager.class);
    Reference reference = mock(Reference.class);
    when(reference.getLocalURI()).thenReturn("");
    when(referenceManager.deriveReference(any())).thenReturn(reference);
}
Also used : Reference(org.javarosa.core.reference.Reference) ReferenceManager(org.javarosa.core.reference.ReferenceManager)

Example 3 with Reference

use of org.javarosa.core.reference.Reference in project collect by opendatakit.

the class CollectHelpers method createFakeReference.

private static String createFakeReference(ReferenceManager referenceManager, String referenceURI, String localURI) throws InvalidReferenceException {
    Reference reference = mock(Reference.class);
    when(reference.getLocalURI()).thenReturn(localURI);
    when(referenceManager.deriveReference(referenceURI)).thenReturn(reference);
    return localURI;
}
Also used : Reference(org.javarosa.core.reference.Reference)

Aggregations

Reference (org.javarosa.core.reference.Reference)3 IDataReference (org.javarosa.core.model.IDataReference)1 QuestionDef (org.javarosa.core.model.QuestionDef)1 InvalidReferenceException (org.javarosa.core.reference.InvalidReferenceException)1 ReferenceManager (org.javarosa.core.reference.ReferenceManager)1 ResourceReferenceFactory (org.javarosa.core.reference.ResourceReferenceFactory)1 RootTranslator (org.javarosa.core.reference.RootTranslator)1 Localizer (org.javarosa.core.services.locale.Localizer)1 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)1 Test (org.junit.Test)1