Search in sources :

Example 6 with InstancesRepository

use of org.odk.collect.forms.instances.InstancesRepository 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 7 with InstancesRepository

use of org.odk.collect.forms.instances.InstancesRepository 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 8 with InstancesRepository

use of org.odk.collect.forms.instances.InstancesRepository 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 9 with InstancesRepository

use of org.odk.collect.forms.instances.InstancesRepository 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)

Example 10 with InstancesRepository

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

the class InstancesRepositoryTest method save_returnsInstanceWithId.

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

Aggregations

InstancesRepository (org.odk.collect.forms.instances.InstancesRepository)25 Instance (org.odk.collect.forms.instances.Instance)23 Test (org.junit.Test)19 File (java.io.File)4 InstancesRepositoryProvider (org.odk.collect.android.utilities.InstancesRepositoryProvider)3 ContentValues (android.content.ContentValues)2 FormInstance (org.javarosa.core.model.instance.FormInstance)2 FormController (org.odk.collect.android.javarosawrapper.FormController)2 FormsRepository (org.odk.collect.forms.FormsRepository)2 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)2 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 RandomAccessFile (java.io.RandomAccessFile)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 ByteArrayPayload (org.javarosa.core.services.transport.payload.ByteArrayPayload)1 Collect (org.odk.collect.android.application.Collect)1 DatabaseObjectMapper.getValuesFromInstance (org.odk.collect.android.database.DatabaseObjectMapper.getValuesFromInstance)1