Search in sources :

Example 1 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class SelectOneWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }

        @Override
        public SoftKeyboardController provideSoftKeyboardController() {
            return mock(SoftKeyboardController.class);
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) SoftKeyboardController(org.odk.collect.android.utilities.SoftKeyboardController) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager)

Example 2 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class SelectMultiWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }

        @Override
        public SoftKeyboardController provideSoftKeyboardController() {
            return mock(SoftKeyboardController.class);
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) SoftKeyboardController(org.odk.collect.android.utilities.SoftKeyboardController) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager)

Example 3 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class ServerFormDownloaderTest method whenDownloadingFormWithVersion_andId_butNotHashOnDevice_logsAnalytics.

// endregion
// region Form update analytics
@Test
public void whenDownloadingFormWithVersion_andId_butNotHashOnDevice_logsAnalytics() throws Exception {
    String xform = FormUtils.createXFormBody("form", "version", "A title");
    Form form = buildForm("form", "version", getFormFilesPath(), xform).build();
    formsRepository.save(form);
    String xform2 = FormUtils.createXFormBody("form2", "version", "A different title");
    Form form2 = buildForm("form", "version", getFormFilesPath(), xform2).build();
    ServerFormDetails serverFormDetails = new ServerFormDetails(form2.getDisplayName(), "http://downloadUrl", form2.getFormId(), form2.getVersion(), Md5.getMd5Hash(new ByteArrayInputStream(xform2.getBytes())), true, false, null);
    FormSource formSource = mock(FormSource.class);
    when(formSource.fetchForm("http://downloadUrl")).thenReturn(new ByteArrayInputStream(xform2.getBytes()));
    Analytics mockAnalytics = mock(Analytics.class);
    ServerFormDownloader downloader = new ServerFormDownloader(formSource, formsRepository, cacheDir, formsDir.getAbsolutePath(), new FormMetadataParser(), mockAnalytics);
    downloader.downloadForm(serverFormDetails, null, null);
    String formIdentifier = form.getDisplayName() + " " + form.getFormId();
    String formIdHash = Md5.getMd5Hash(new ByteArrayInputStream(formIdentifier.getBytes()));
    verify(mockAnalytics).logEventWithParam(DOWNLOAD_SAME_FORMID_VERSION_DIFFERENT_HASH, "form", formIdHash);
}
Also used : Form(org.odk.collect.forms.Form) FormUtils.buildForm(org.odk.collect.formstest.FormUtils.buildForm) ByteArrayInputStream(java.io.ByteArrayInputStream) FormSource(org.odk.collect.forms.FormSource) Analytics(org.odk.collect.analytics.Analytics) Test(org.junit.Test)

Example 4 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class ServerFormDownloaderTest method whenDownloadingFormWithVersion_andId_andHashOnDevice_doesNotLogAnalytics.

@Test
public void whenDownloadingFormWithVersion_andId_andHashOnDevice_doesNotLogAnalytics() throws Exception {
    String xform = FormUtils.createXFormBody("form", "version", "A title");
    Form form = buildForm("form", "version", getFormFilesPath(), xform).build();
    formsRepository.save(form);
    String xform2 = FormUtils.createXFormBody("form2", "version", "A different title");
    Form form2 = buildForm("form", "version", getFormFilesPath(), xform2).build();
    formsRepository.save(form2);
    ServerFormDetails serverFormDetails = new ServerFormDetails(form.getDisplayName(), "http://downloadUrl", form.getFormId(), form.getVersion(), Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), true, false, null);
    FormSource formSource = mock(FormSource.class);
    when(formSource.fetchForm("http://downloadUrl")).thenReturn(new ByteArrayInputStream(xform.getBytes()));
    Analytics mockAnalytics = mock(Analytics.class);
    ServerFormDownloader downloader = new ServerFormDownloader(formSource, formsRepository, cacheDir, formsDir.getAbsolutePath(), new FormMetadataParser(), mockAnalytics);
    downloader.downloadForm(serverFormDetails, null, null);
    verifyNoInteractions(mockAnalytics);
}
Also used : Form(org.odk.collect.forms.Form) FormUtils.buildForm(org.odk.collect.formstest.FormUtils.buildForm) ByteArrayInputStream(java.io.ByteArrayInputStream) FormSource(org.odk.collect.forms.FormSource) Analytics(org.odk.collect.analytics.Analytics) Test(org.junit.Test)

Example 5 with Analytics

use of org.odk.collect.analytics.Analytics in project collect by opendatakit.

the class QuestionWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(asList(new Pair<>("ref", "blah.mp3")));
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager) Pair(androidx.core.util.Pair)

Aggregations

Analytics (org.odk.collect.analytics.Analytics)9 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)5 Application (android.app.Application)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ReferenceManager (org.javarosa.core.reference.ReferenceManager)3 Before (org.junit.Before)3 Test (org.junit.Test)3 AudioHelperFactory (org.odk.collect.android.formentry.media.AudioHelperFactory)3 CollectHelpers.setupFakeReferenceManager (org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager)3 Scheduler (org.odk.collect.async.Scheduler)3 AudioRecorder (org.odk.collect.audiorecorder.recording.AudioRecorder)3 Form (org.odk.collect.forms.Form)3 FormSource (org.odk.collect.forms.FormSource)3 FormUtils.buildForm (org.odk.collect.formstest.FormUtils.buildForm)3 NonNull (androidx.annotation.NonNull)2 SoftKeyboardController (org.odk.collect.android.utilities.SoftKeyboardController)2 PermissionsChecker (org.odk.collect.permissions.PermissionsChecker)2 SettingsProvider (org.odk.collect.settings.SettingsProvider)2 Pair (androidx.core.util.Pair)1 File (java.io.File)1