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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations