Skip to content

Commit

Permalink
Add imports for FormsColumns and InstanceColumns (getodk#3458)
Browse files Browse the repository at this point in the history
  • Loading branch information
zestyping authored and lognaturel committed Dec 5, 2019
1 parent ea223c6 commit 4599dfe
Show file tree
Hide file tree
Showing 28 changed files with 311 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import android.content.SharedPreferences;
import android.database.Cursor;
import android.preference.PreferenceManager;
import androidx.test.InstrumentationRegistry;
import androidx.test.rule.GrantPermissionRule;
import androidx.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
Expand All @@ -33,8 +30,8 @@
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.preferences.AdminKeys;
import org.odk.collect.android.preferences.GeneralKeys;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.provider.FormsProviderAPI.FormsColumns;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import org.odk.collect.android.utilities.ResetUtility;
import org.odk.collect.android.utilities.WebCredentialsUtils;
import org.osmdroid.config.Configuration;
Expand All @@ -46,6 +43,10 @@
import java.util.Collections;
import java.util.List;

import androidx.test.InstrumentationRegistry;
import androidx.test.rule.GrantPermissionRule;
import androidx.test.runner.AndroidJUnit4;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -167,28 +168,28 @@ private void setupTestSettings() throws IOException {

private void setupTestFormsDatabase() {
ContentValues values = new ContentValues();
values.put(FormsProviderAPI.FormsColumns.JRCACHE_FILE_PATH, Collect.ODK_ROOT + "/.cache/3a76a386464925b6f3e53422673dfe3c.formdef");
values.put(FormsProviderAPI.FormsColumns.JR_FORM_ID, "jrFormId");
values.put(FormsProviderAPI.FormsColumns.FORM_MEDIA_PATH, Collect.FORMS_PATH + "/testFile1-media");
values.put(FormsProviderAPI.FormsColumns.DATE, "1487077903756");
values.put(FormsProviderAPI.FormsColumns.DISPLAY_NAME, "displayName");
values.put(FormsProviderAPI.FormsColumns.FORM_FILE_PATH, Collect.FORMS_PATH + "/testFile1.xml");
values.put(FormsColumns.JRCACHE_FILE_PATH, Collect.ODK_ROOT + "/.cache/3a76a386464925b6f3e53422673dfe3c.formdef");
values.put(FormsColumns.JR_FORM_ID, "jrFormId");
values.put(FormsColumns.FORM_MEDIA_PATH, Collect.FORMS_PATH + "/testFile1-media");
values.put(FormsColumns.DATE, "1487077903756");
values.put(FormsColumns.DISPLAY_NAME, "displayName");
values.put(FormsColumns.FORM_FILE_PATH, Collect.FORMS_PATH + "/testFile1.xml");
Collect.getInstance().getContentResolver()
.insert(FormsProviderAPI.FormsColumns.CONTENT_URI, values);
.insert(FormsColumns.CONTENT_URI, values);

assertEquals(1, getFormsCount());
}

private void setupTestInstancesDatabase() {
ContentValues values = new ContentValues();
values.put(InstanceProviderAPI.InstanceColumns.INSTANCE_FILE_PATH, Collect.INSTANCES_PATH + "/testDir1/testFile1");
values.put(InstanceProviderAPI.InstanceColumns.SUBMISSION_URI, "submissionUri");
values.put(InstanceProviderAPI.InstanceColumns.DISPLAY_NAME, "displayName");
values.put(InstanceProviderAPI.InstanceColumns.DISPLAY_NAME, "formName");
values.put(InstanceProviderAPI.InstanceColumns.JR_FORM_ID, "jrformid");
values.put(InstanceProviderAPI.InstanceColumns.JR_VERSION, "jrversion");
values.put(InstanceColumns.INSTANCE_FILE_PATH, Collect.INSTANCES_PATH + "/testDir1/testFile1");
values.put(InstanceColumns.SUBMISSION_URI, "submissionUri");
values.put(InstanceColumns.DISPLAY_NAME, "displayName");
values.put(InstanceColumns.DISPLAY_NAME, "formName");
values.put(InstanceColumns.JR_FORM_ID, "jrformid");
values.put(InstanceColumns.JR_VERSION, "jrversion");
Collect.getInstance().getContentResolver()
.insert(InstanceProviderAPI.InstanceColumns.CONTENT_URI, values);
.insert(InstanceColumns.CONTENT_URI, values);

assertEquals(1, getInstancesCount());
}
Expand Down Expand Up @@ -235,8 +236,8 @@ private void saveTestOSMDroidFiles() throws IOException {
private int getFormsCount() {
int forms = 0;
Cursor cursor = Collect.getInstance().getContentResolver().query(
FormsProviderAPI.FormsColumns.CONTENT_URI, null, null, null,
FormsProviderAPI.FormsColumns.DISPLAY_NAME + " ASC");
FormsColumns.CONTENT_URI, null, null, null,
FormsColumns.DISPLAY_NAME + " ASC");
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
Expand All @@ -256,8 +257,8 @@ private int getFormsCount() {
private int getInstancesCount() {
int instances = 0;
Cursor cursor = Collect.getInstance().getContentResolver().query(
InstanceProviderAPI.InstanceColumns.CONTENT_URI, null, null, null,
InstanceProviderAPI.InstanceColumns.DISPLAY_NAME + " ASC");
InstanceColumns.CONTENT_URI, null, null, null,
InstanceColumns.DISPLAY_NAME + " ASC");
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
package org.odk.collect.android.dao;

import android.database.Cursor;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.forms.Form;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.FormsProviderAPI.FormsColumns;
import org.odk.collect.android.utilities.ResetUtility;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -99,7 +100,7 @@ public void getFormsCursorTest() {
assertEquals(sampleForm, forms.get(5));
assertEquals(birds2Form, forms.get(6));

String sortOrder = FormsProviderAPI.FormsColumns.DISPLAY_NAME + " COLLATE NOCASE DESC";
String sortOrder = FormsColumns.DISPLAY_NAME + " COLLATE NOCASE DESC";

cursor = formsDao.getFormsCursor(null, null, null, sortOrder);
forms = formsDao.getFormsFromCursor(cursor);
Expand All @@ -113,7 +114,7 @@ public void getFormsCursorTest() {
assertEquals(sampleForm, forms.get(1));
assertEquals(widgetsForm, forms.get(0));

String selection = FormsProviderAPI.FormsColumns.DISPLAY_NAME + "=?";
String selection = FormsColumns.DISPLAY_NAME + "=?";
String[] selectionArgs = {"Miramare"};

cursor = formsDao.getFormsCursor(null, selection, selectionArgs, null);
Expand Down Expand Up @@ -150,7 +151,7 @@ public void updateInstanceTest() {
.jrCacheFilePath(Collect.ODK_ROOT + "/.cache/0eacc6333449e66826326eb5fcc75749.formdef")
.build();

String where = FormsProviderAPI.FormsColumns.DISPLAY_NAME + "=?";
String where = FormsColumns.DISPLAY_NAME + "=?";
String[] whereArgs = {"Widgets"};
assertEquals(formsDao.updateForm(formsDao.getValuesFromFormObject(widgetsForm), where, whereArgs), 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.instances.Instance;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;

import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import static org.junit.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -92,7 +94,7 @@ public void getSentInstancesCursorTest() {

@Test
public void getSavedInstancesCursorTest() {
Cursor cursor = instancesDao.getSavedInstancesCursor(InstanceProviderAPI.InstanceColumns.DISPLAY_NAME + " ASC");
Cursor cursor = instancesDao.getSavedInstancesCursor(InstanceColumns.DISPLAY_NAME + " ASC");
List<Instance> instances = instancesDao.getInstancesFromCursor(cursor);

assertEquals(5, instances.size());
Expand Down Expand Up @@ -156,7 +158,7 @@ public void updateInstanceTest() {
.lastStatusChangeDate(1487597090653L)
.build();

String where = InstanceProviderAPI.InstanceColumns.INSTANCE_FILE_PATH + "=?";
String where = InstanceColumns.INSTANCE_FILE_PATH + "=?";
String[] whereArgs = {Collect.INSTANCES_PATH + "/Biggest N of Set_2017-02-20_14-24-46/Biggest N of Set_2017-02-20_14-24-46.xml"};

assertEquals(instancesDao.updateInstance(instancesDao.getValuesFromInstanceObject(biggestNOfSet2Instance), where, whereArgs), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import androidx.test.rule.ActivityTestRule;

import org.odk.collect.android.R;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.FormsProviderAPI.FormsColumns;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
Expand Down Expand Up @@ -61,21 +61,21 @@ public FillBlankFormPage checkIsFormSubtextDisplayed() {
}

public FillBlankFormPage checkMapIconDisplayedForForm(String formName) {
onData(allOf(is(instanceOf(Cursor.class)), CursorMatchers.withRowString(FormsProviderAPI.FormsColumns.DISPLAY_NAME, is(formName))))
onData(allOf(is(instanceOf(Cursor.class)), CursorMatchers.withRowString(FormsColumns.DISPLAY_NAME, is(formName))))
.onChildView(withId(R.id.map_button))
.check(matches(isDisplayed()));
return this;
}

public FillBlankFormPage checkMapIconNotDisplayedForForm(String formName) {
onData(allOf(is(instanceOf(Cursor.class)), CursorMatchers.withRowString(FormsProviderAPI.FormsColumns.DISPLAY_NAME, is(formName))))
onData(allOf(is(instanceOf(Cursor.class)), CursorMatchers.withRowString(FormsColumns.DISPLAY_NAME, is(formName))))
.onChildView(withId(R.id.map_button))
.check(matches(not(isDisplayed())));
return this;
}

public FormMapPage clickOnMapIconForForm(String formName) {
onData(allOf(is(instanceOf(Cursor.class)), CursorMatchers.withRowString(FormsProviderAPI.FormsColumns.DISPLAY_NAME, is(formName))))
onData(allOf(is(instanceOf(Cursor.class)), CursorMatchers.withRowString(FormsColumns.DISPLAY_NAME, is(formName))))
.onChildView(withId(R.id.map_button))
.perform(click());
return new FormMapPage(rule).assertOnPage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.odk.collect.android.espressoutils.pages;

import androidx.test.espresso.Espresso;
import androidx.test.rule.ActivityTestRule;

import org.odk.collect.android.R;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.FormsProviderAPI.FormsColumns;
import org.odk.collect.android.support.ActivityHelpers;

import androidx.test.espresso.Espresso;
import androidx.test.rule.ActivityTestRule;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
Expand Down Expand Up @@ -63,7 +63,7 @@ public FillBlankFormPage clickFillBlankForm() {

private void goToBlankForm(String formName) {
onView(withId(R.id.enter_data)).perform(click());
onData(withRowString(FormsProviderAPI.FormsColumns.DISPLAY_NAME, formName)).perform(click());
onData(withRowString(FormsColumns.DISPLAY_NAME, formName)).perform(click());
}

public EditSavedFormPage clickEditSavedForm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.net.Uri;

import androidx.test.rule.GrantPermissionRule;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -12,10 +10,12 @@
import org.odk.collect.android.instances.Instance;
import org.odk.collect.android.http.openrosa.OpenRosaConstants;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import org.odk.collect.android.test.MockedServerTest;

import java.io.File;

import androidx.test.rule.GrantPermissionRule;
import okhttp3.mockwebserver.RecordedRequest;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -94,7 +94,7 @@ private long createStoredInstance() throws Exception {
.build();

Uri contentUri = dao.saveInstance(dao.getValuesFromInstanceObject(i));
return Long.parseLong(contentUri.toString().substring(InstanceProviderAPI.InstanceColumns.CONTENT_URI.toString().length() + 1));
return Long.parseLong(contentUri.toString().substring(InstanceColumns.CONTENT_URI.toString().length() + 1));
}

private String hostAndPort() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.odk.collect.android.activities.FormEntryActivity;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.dao.FormsDao;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.FormsProviderAPI.FormsColumns;
import org.odk.collect.android.tasks.FormLoaderTask;
import org.odk.collect.android.utilities.FileUtils;

Expand Down Expand Up @@ -71,16 +71,16 @@ public static void copyFormToSdCard(String formFilename) throws IOException {
private static void saveFormToDatabase(File outFile) {
Map<String, String> formInfo = FileUtils.getMetadataFromFormDefinition(outFile);
final ContentValues v = new ContentValues();
v.put(FormsProviderAPI.FormsColumns.FORM_FILE_PATH, outFile.getAbsolutePath());
v.put(FormsProviderAPI.FormsColumns.FORM_MEDIA_PATH, FileUtils.constructMediaPath(outFile.getAbsolutePath()));
v.put(FormsProviderAPI.FormsColumns.DISPLAY_NAME, formInfo.get(FileUtils.TITLE));
v.put(FormsProviderAPI.FormsColumns.JR_VERSION, formInfo.get(FileUtils.VERSION));
v.put(FormsProviderAPI.FormsColumns.JR_FORM_ID, formInfo.get(FileUtils.FORMID));
v.put(FormsProviderAPI.FormsColumns.SUBMISSION_URI, formInfo.get(FileUtils.SUBMISSIONURI));
v.put(FormsProviderAPI.FormsColumns.BASE64_RSA_PUBLIC_KEY, formInfo.get(FileUtils.BASE64_RSA_PUBLIC_KEY));
v.put(FormsProviderAPI.FormsColumns.AUTO_DELETE, formInfo.get(FileUtils.AUTO_DELETE));
v.put(FormsProviderAPI.FormsColumns.AUTO_SEND, formInfo.get(FileUtils.AUTO_SEND));
v.put(FormsProviderAPI.FormsColumns.GEOMETRY_XPATH, formInfo.get(FileUtils.GEOMETRY_XPATH));
v.put(FormsColumns.FORM_FILE_PATH, outFile.getAbsolutePath());
v.put(FormsColumns.FORM_MEDIA_PATH, FileUtils.constructMediaPath(outFile.getAbsolutePath()));
v.put(FormsColumns.DISPLAY_NAME, formInfo.get(FileUtils.TITLE));
v.put(FormsColumns.JR_VERSION, formInfo.get(FileUtils.VERSION));
v.put(FormsColumns.JR_FORM_ID, formInfo.get(FileUtils.FORMID));
v.put(FormsColumns.SUBMISSION_URI, formInfo.get(FileUtils.SUBMISSIONURI));
v.put(FormsColumns.BASE64_RSA_PUBLIC_KEY, formInfo.get(FileUtils.BASE64_RSA_PUBLIC_KEY));
v.put(FormsColumns.AUTO_DELETE, formInfo.get(FileUtils.AUTO_DELETE));
v.put(FormsColumns.AUTO_SEND, formInfo.get(FileUtils.AUTO_SEND));
v.put(FormsColumns.GEOMETRY_XPATH, formInfo.get(FileUtils.GEOMETRY_XPATH));

new FormsDao().saveForm(v);
}
Expand All @@ -103,4 +103,4 @@ private static void copyFormMediaFiles(String formFilename, List<String> mediaFi
copyFileFromAssets("media/" + mediaFilename, mediaPathName + mediaFilename);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package org.odk.collect.android.test;

import android.os.Environment;
import androidx.test.espresso.PerformException;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.util.HumanReadables;
import androidx.test.espresso.util.TreeIterables;
import android.view.View;

import org.hamcrest.Matcher;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;

import java.io.Closeable;
import java.io.File;
Expand All @@ -21,6 +16,12 @@
import java.util.Map;
import java.util.concurrent.TimeoutException;

import androidx.test.espresso.PerformException;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.util.HumanReadables;
import androidx.test.espresso.util.TreeIterables;

import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

Expand Down Expand Up @@ -89,7 +90,7 @@ public static void closeSafely(Closeable c) {
}

public static void resetInstancesContentProvider() {
Collect.getInstance().getContentResolver().delete(InstanceProviderAPI.InstanceColumns.CONTENT_URI, null, null);
Collect.getInstance().getContentResolver().delete(InstanceColumns.CONTENT_URI, null, null);
}

public static void assertMatches(String expectedPattern, Object actual) {
Expand Down
Loading

0 comments on commit 4599dfe

Please sign in to comment.