use of org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore in project dhis2-android-sdk by dhis2.
the class DataBaseMigrationShould method have_database_version_3_after_migration_from_database_with_content.
@Test
public void have_database_version_3_after_migration_from_database_with_content() throws IOException {
// given
final String finalEventScheme = "CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL " + "UNIQUE,enrollment TEXT, created TEXT,lastUpdated TEXT,createdAtClient " + "TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude " + "TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit" + " TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state " + "TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, " + "trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program " + "(uid) ON DELETE CASCADE, FOREIGN KEY (programStage) REFERENCES " + "ProgramStage (uid) ON DELETE CASCADE,FOREIGN KEY (enrollment) " + "REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY " + "DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit " + "(uid) ON DELETE CASCADE)";
final String finalTrackedEntityDataValueScheme = "CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event" + " TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT," + "created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY " + "(dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE, FOREIGN" + " KEY (event) REFERENCES Event (uid) ON DELETE CASCADE)";
initCoreDataBase(dbName, 2, realMigrationDir, databaseSqlVersion2_with_data);
EventStore eventStore = new EventStoreImpl(databaseAdapter);
List<Event> eventList = eventStore.queryAll();
TrackedEntityDataValueStore trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter);
Map<String, List<TrackedEntityDataValue>> listOfTrackedEntityDataValues = trackedEntityDataValueStore.queryTrackedEntityDataValues();
// when
initCoreDataBase(dbName, 3, realMigrationDir, "");
eventStore = new EventStoreImpl(databaseAdapter);
trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter);
// then
assertTrue(eventList.equals(eventStore.queryAll()));
assertTrue(eventList.size() == 50);
assertTrue(listOfTrackedEntityDataValues.equals(trackedEntityDataValueStore.queryTrackedEntityDataValues()));
assertTrue(listOfTrackedEntityDataValues.size() == 50);
assertTrue(listOfTrackedEntityDataValues.get(eventList.get(0).uid()).equals(listOfTrackedEntityDataValues.get(eventList.get(0).uid())));
assertTrue(getSqlTableScheme(databaseAdapter, "Event").equals(finalEventScheme));
assertTrue(getSqlTableScheme(databaseAdapter, "TrackedEntityDataValue").equals(finalTrackedEntityDataValueScheme));
}
use of org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore in project dhis2-android-sdk by dhis2.
the class HandlerFactory method createTrackedEntityDataValueHandler.
public static TrackedEntityDataValueHandler createTrackedEntityDataValueHandler(DatabaseAdapter databaseAdapter) {
TrackedEntityDataValueStore trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter);
TrackedEntityDataValueHandler trackedEntityDataValueHandler = new TrackedEntityDataValueHandler(trackedEntityDataValueStore);
return trackedEntityDataValueHandler;
}
Aggregations