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