Search in sources :

Example 21 with Instance

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

the class InstancesRepositoryTest method save_whenInstanceHasDeletedDate_doesNotUpdateLastChangesStatusDate.

@Test
public void save_whenInstanceHasDeletedDate_doesNotUpdateLastChangesStatusDate() {
    Supplier<Long> clock = mock(Supplier.class);
    when(clock.get()).thenReturn(123L);
    InstancesRepository instancesRepository = buildSubject(clock);
    Instance originalInstance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    Long originalInstanceDbId = originalInstance.getDbId();
    when(clock.get()).thenReturn(456L);
    instancesRepository.deleteWithLogging(originalInstanceDbId);
    instancesRepository.save(instancesRepository.get(originalInstanceDbId));
    assertThat(instancesRepository.get(originalInstanceDbId).getLastStatusChangeDate(), is(123L));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 22 with Instance

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

the class InstancesRepositoryTest method getAllByFormId_includesAllVersionsForFormId.

@Test
public void getAllByFormId_includesAllVersionsForFormId() {
    InstancesRepository instancesRepository = buildSubject();
    instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    instancesRepository.save(InstanceUtils.buildInstance("formid", "2", "display", Instance.STATUS_COMPLETE, null, getInstancesDir()).build());
    instancesRepository.save(InstanceUtils.buildInstance("formid", "3", getInstancesDir()).build());
    instancesRepository.save(InstanceUtils.buildInstance("formid", "4", "display", Instance.STATUS_COMPLETE, System.currentTimeMillis(), getInstancesDir()).build());
    instancesRepository.save(InstanceUtils.buildInstance("formid2", "1", "display", Instance.STATUS_COMPLETE, null, getInstancesDir()).build());
    List<Instance> instances = instancesRepository.getAllByFormId("formid");
    assertThat(instances.size(), is(4));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 23 with Instance

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

the class InstancesRepositoryTest method delete_deletesInstance.

@Test
public void delete_deletesInstance() {
    InstancesRepository instancesRepository = buildSubject();
    Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    instancesRepository.delete(instance.getDbId());
    assertThat(instancesRepository.getAll().size(), is(0));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 24 with Instance

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

the class InstancesRepositoryTest method save_whenInstanceHasId_updatesLastStatusChangeDate.

@Test
public void save_whenInstanceHasId_updatesLastStatusChangeDate() {
    Supplier<Long> clock = mock(Supplier.class);
    when(clock.get()).thenReturn(123L);
    InstancesRepository instancesRepository = buildSubject(clock);
    Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    instancesRepository.save(instance);
    assertThat(instancesRepository.get(instance.getDbId()).getLastStatusChangeDate(), is(123L));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstancesRepository(org.odk.collect.forms.instances.InstancesRepository) Test(org.junit.Test)

Example 25 with Instance

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

the class InstancesRepositoryTest method delete_deletesInstanceDir.

@Test
public void delete_deletesInstanceDir() {
    InstancesRepository instancesRepository = buildSubject();
    Instance instance = instancesRepository.save(InstanceUtils.buildInstance("formid", "1", getInstancesDir()).build());
    // The repo assumes the parent of the file also contains other instance files
    File instanceDir = new File(instance.getInstanceFilePath()).getParentFile();
    assertThat(instanceDir.exists(), is(true));
    assertThat(instanceDir.isDirectory(), is(true));
    instancesRepository.delete(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