Search in sources :

Example 31 with Instance

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

the class FormMapActivityTest method tappingOnEditableInstance_showsSubmissionSummaryWithAppropriateMessage.

@Test
public void tappingOnEditableInstance_showsSubmissionSummaryWithAppropriateMessage() {
    Pair<Instance, MapPoint> editableAndFinalized = new Pair<>(testInstances[1], new MapPoint(10.1, 125.6));
    Pair<Instance, MapPoint> unfinalized = new Pair<>(testInstances[2], new MapPoint(10.1, 126.6));
    Pair<Instance, MapPoint> failedToSend = new Pair<>(testInstances[4], new MapPoint(10.3, 125.6));
    activity.onFeatureClicked(map.getFeatureIdFor(editableAndFinalized.second));
    assertSubmissionSummaryContent(editableAndFinalized.first.getDisplayName(), editableAndFinalized.first.getStatus(), new Date(editableAndFinalized.first.getLastStatusChangeDate()), OPEN_EDIT);
    activity.onFeatureClicked(map.getFeatureIdFor(unfinalized.second));
    assertSubmissionSummaryContent(unfinalized.first.getDisplayName(), unfinalized.first.getStatus(), new Date(unfinalized.first.getLastStatusChangeDate()), OPEN_EDIT);
    activity.onFeatureClicked(map.getFeatureIdFor(failedToSend.second));
    assertSubmissionSummaryContent(failedToSend.first.getDisplayName(), failedToSend.first.getStatus(), new Date(failedToSend.first.getLastStatusChangeDate()), OPEN_READ_ONLY);
}
Also used : Instance(org.odk.collect.forms.instances.Instance) MapPoint(org.odk.collect.geo.maps.MapPoint) Date(java.util.Date) Pair(android.util.Pair) Test(org.junit.Test)

Example 32 with Instance

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

the class FormMapActivityTest method tappingOnFailedSubmission_showsSubmissionSummaryWithAppropriateMessage.

@Test
public void tappingOnFailedSubmission_showsSubmissionSummaryWithAppropriateMessage() {
    Pair<Instance, MapPoint> submissionFailedCantEditWhenFinalized = new Pair<>(testInstances[6], new MapPoint(10.4, 125.6));
    int featureId = map.getFeatureIdFor(submissionFailedCantEditWhenFinalized.second);
    activity.onFeatureClicked(featureId);
    assertSubmissionSummaryContent(submissionFailedCantEditWhenFinalized.first.getDisplayName(), submissionFailedCantEditWhenFinalized.first.getStatus(), new Date(submissionFailedCantEditWhenFinalized.first.getLastStatusChangeDate()), NOT_VIEWABLE_TOAST);
}
Also used : Instance(org.odk.collect.forms.instances.Instance) MapPoint(org.odk.collect.geo.maps.MapPoint) MapPoint(org.odk.collect.geo.maps.MapPoint) Date(java.util.Date) Pair(android.util.Pair) Test(org.junit.Test)

Example 33 with Instance

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

the class InstanceDeleterTest method whenFormForInstanceIsNotSoftDeleted_andThereAreNoOtherInstances_doesNotDeleteForm.

@Test
public void whenFormForInstanceIsNotSoftDeleted_andThereAreNoOtherInstances_doesNotDeleteForm() {
    formsRepository.save(new Form.Builder().formId("1").version("version").deleted(false).formFilePath(FormUtils.createXFormFile("1", "version").getAbsolutePath()).build());
    Instance instanceToDelete = instancesRepository.save(new Instance.Builder().formId("1").formVersion("version").instanceFilePath(TempFiles.createTempDir().getAbsolutePath()).build());
    instanceDeleter.delete(instanceToDelete.getDbId());
    assertThat(formsRepository.getAll().size(), is(1));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstanceUtils.buildInstance(org.odk.collect.formstest.InstanceUtils.buildInstance) Test(org.junit.Test)

Example 34 with Instance

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

the class InstanceDeleterTest method whenFormVersionForInstanceIsNotSoftDeleted_andThereAreNoOtherInstances_doesNotDeleteForm.

@Test
public void whenFormVersionForInstanceIsNotSoftDeleted_andThereAreNoOtherInstances_doesNotDeleteForm() {
    formsRepository.save(new Form.Builder().formId("1").version("1").deleted(true).formFilePath(FormUtils.createXFormFile("1", "1").getAbsolutePath()).build());
    formsRepository.save(new Form.Builder().formId("1").version("2").deleted(false).formFilePath(FormUtils.createXFormFile("1", "2").getAbsolutePath()).build());
    Instance instanceToDelete = instancesRepository.save(new Instance.Builder().formId("1").formVersion("2").instanceFilePath(TempFiles.createTempDir().getAbsolutePath()).build());
    instanceDeleter.delete(instanceToDelete.getDbId());
    assertThat(formsRepository.getAll().size(), is(2));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstanceUtils.buildInstance(org.odk.collect.formstest.InstanceUtils.buildInstance) Test(org.junit.Test)

Example 35 with Instance

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

the class InstanceDeleterTest method whenFormForInstanceIsSoftDeleted_andThereAreNoOtherInstancesForThisVersion_deletesForm.

@Test
public void whenFormForInstanceIsSoftDeleted_andThereAreNoOtherInstancesForThisVersion_deletesForm() {
    formsRepository.save(new Form.Builder().formId("1").version("1").deleted(true).formFilePath(FormUtils.createXFormFile("1", "1").getAbsolutePath()).build());
    formsRepository.save(new Form.Builder().formId("1").version("2").formFilePath(FormUtils.createXFormFile("1", "2").getAbsolutePath()).deleted(true).build());
    Instance instanceToDelete = instancesRepository.save(new Instance.Builder().formId("1").formVersion("1").instanceFilePath(TempFiles.createTempDir().getAbsolutePath()).build());
    instancesRepository.save(new Instance.Builder().formId("1").formVersion("2").instanceFilePath(TempFiles.createTempDir().getAbsolutePath()).build());
    instanceDeleter.delete(instanceToDelete.getDbId());
    assertThat(formsRepository.getAll().size(), is(1));
    assertThat(formsRepository.getAll().get(0).getVersion(), is("2"));
}
Also used : Instance(org.odk.collect.forms.instances.Instance) InstanceUtils.buildInstance(org.odk.collect.formstest.InstanceUtils.buildInstance) 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