Search in sources :

Example 41 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InstancesRepositoryTest method getAllByStatus_withMultipleStatus_returnsMatchingInstances.

@Test
public void getAllByStatus_withMultipleStatus_returnsMatchingInstances() {
    InstancesRepository instancesRepository = buildSubject();
    instancesRepository.save(InstanceUtils.buildInstance("incomplete", "1", getInstancesDir()).status(Instance.STATUS_INCOMPLETE).build());
    instancesRepository.save(InstanceUtils.buildInstance("incomplete", "1", getInstancesDir()).status(Instance.STATUS_INCOMPLETE).build());
    instancesRepository.save(InstanceUtils.buildInstance("complete", "1", getInstancesDir()).status(Instance.STATUS_COMPLETE).build());
    instancesRepository.save(InstanceUtils.buildInstance("complete", "1", getInstancesDir()).status(Instance.STATUS_COMPLETE).build());
    instancesRepository.save(InstanceUtils.buildInstance("submitted", "1", getInstancesDir()).status(Instance.STATUS_SUBMITTED).build());
    instancesRepository.save(InstanceUtils.buildInstance("submitted", "1", getInstancesDir()).status(Instance.STATUS_SUBMITTED).build());
    List<Instance> incomplete = instancesRepository.getAllByStatus(Instance.STATUS_INCOMPLETE, Instance.STATUS_SUBMITTED);
    assertThat(incomplete.size(), is(4));
    assertThat(incomplete.get(0).getFormId(), is(not("complete")));
    assertThat(incomplete.get(1).getFormId(), is(not("complete")));
    assertThat(incomplete.get(2).getFormId(), is(not("complete")));
    assertThat(incomplete.get(3).getStatus(), is(not("complete")));
    // Check corresponding count method is also correct
    assertThat(instancesRepository.getCountByStatus(Instance.STATUS_INCOMPLETE, Instance.STATUS_SUBMITTED), is(4));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 42 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InstancesRepositoryTest method deleteAll_deletesInstanceFiles.

@Test
public void deleteAll_deletesInstanceFiles() {
    InstancesRepository instancesRepository = buildSubject();
    Instance instance1 = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    Instance instance2 = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    instancesRepository.deleteAll();
    assertThat(new File(instance1.getInstanceFilePath()).exists(), is(false));
    assertThat(new File(instance2.getInstanceFilePath()).exists(), is(false));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) File(java.io.File) Test(org.junit.Test)

Example 43 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InstancesRepositoryTest method deleteWithLogging_clearsGeometryData.

@Test
public void deleteWithLogging_clearsGeometryData() {
    InstancesRepository instancesRepository = buildSubject();
    Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).geometry("blah").geometryType("blah").build());
    instancesRepository.deleteWithLogging(instance.getDbId());
    assertThat(instancesRepository.get(instance.getDbId()).getGeometry(), is(nullValue()));
    assertThat(instancesRepository.get(instance.getDbId()).getGeometryType(), is(nullValue()));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 44 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InstancesRepositoryTest method deleteWithLogging_setsDeletedDate.

@Test
public void deleteWithLogging_setsDeletedDate() {
    InstancesRepository instancesRepository = buildSubject();
    Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    instancesRepository.deleteWithLogging(instance.getDbId());
    assertThat(instancesRepository.get(instance.getDbId()).getDeletedDate(), is(notNullValue()));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 45 with Instance

use of org.odk.collect.forms.instances.Instance in project collect by opendatakit.

the class InstancesRepositoryTest method deleteWithLogging_deletesInstanceDir.

@Test
public void deleteWithLogging_deletesInstanceDir() {
    InstancesRepository instancesRepository = buildSubject();
    Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    File instanceDir = new File(instance.getInstanceFilePath()).getParentFile();
    assertThat(instanceDir.exists(), is(true));
    assertThat(instanceDir.isDirectory(), is(true));
    instancesRepository.deleteWithLogging(instance.getDbId());
    assertThat(instanceDir.exists(), is(false));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) File(java.io.File) Test(org.junit.Test)

Aggregations

Instance (org.odk.collect.forms.instances.Instance)62 Test (org.junit.Test)28 InstancesRepository (org.odk.collect.forms.instances.InstancesRepository)23 InstancesRepositoryProvider (org.odk.collect.android.utilities.InstancesRepositoryProvider)10 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)9 File (java.io.File)7 DatabaseObjectMapper.getValuesFromInstance (org.odk.collect.android.database.DatabaseObjectMapper.getValuesFromInstance)7 Uri (android.net.Uri)6 Form (org.odk.collect.forms.Form)6 InstanceUtils.buildInstance (org.odk.collect.formstest.InstanceUtils.buildInstance)6 Pair (android.util.Pair)5 ArrayList (java.util.ArrayList)5 FormsRepositoryProvider (org.odk.collect.android.utilities.FormsRepositoryProvider)5 Date (java.util.Date)4 FormController (org.odk.collect.android.javarosawrapper.FormController)4 MapPoint (org.odk.collect.geo.maps.MapPoint)4 ContentValues (android.content.ContentValues)3 Intent (android.content.Intent)3 Cursor (android.database.Cursor)3 AsyncTask (android.os.AsyncTask)2