Beispiel #1
0
  /*
     This test uses the database directly to insert and then uses the ContentProvider to
     read out the data.  Uncomment this test to see if your location queries are
     performing correctly.
  */
  public void testBasicLocationQueries() {
    // insert our test records into the database
    WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    ContentValues testValues = TestUtilities.createNorthPoleLocationValues();
    long locationRowId = TestUtilities.insertNorthPoleLocationValues(mContext);

    // Test the basic content provider query
    Cursor locationCursor =
        mContext.getContentResolver().query(LocationEntry.CONTENT_URI, null, null, null, null);

    // Make sure we get the correct cursor out of the database
    TestUtilities.validateCursor(
        "testBasicLocationQueries, location query", locationCursor, testValues);

    // Has the NotificationUri been set correctly? --- we can only test this easily against API
    // level 19 or greater because getNotificationUri was added in API level 19.
    if (Build.VERSION.SDK_INT >= 19) {
      assertEquals(
          "Error: Location Query did not properly set NotificationUri",
          locationCursor.getNotificationUri(),
          LocationEntry.CONTENT_URI);
    }
  }
Beispiel #2
0
  /*
    This helper function deletes all records from both database tables using the database
    functions only.  This is designed to be used to reset the state of the database until the
    delete functionality is available in the ContentProvider.
  */
  public void deleteAllRecordsFromDB() {
    WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    db.delete(WeatherEntry.TABLE_NAME, null, null);
    db.delete(LocationEntry.TABLE_NAME, null, null);
    db.close();
  }
Beispiel #3
0
  /*
     This test uses the database directly to insert and then uses the ContentProvider to
     read out the data.  Uncomment this test to see if the basic weather query functionality
     given in the ContentProvider is working correctly.
  */
  public void testBasicWeatherQuery() {
    // insert our test records into the database
    WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    ContentValues testValues = TestUtilities.createNorthPoleLocationValues();
    long locationRowId = TestUtilities.insertNorthPoleLocationValues(mContext);

    // Fantastic.  Now that we have a location, add some weather!
    ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);

    long weatherRowId = db.insert(WeatherEntry.TABLE_NAME, null, weatherValues);
    assertTrue("Unable to Insert WeatherEntry into the Database", weatherRowId != -1);

    db.close();

    // Test the basic content provider query
    Cursor weatherCursor =
        mContext.getContentResolver().query(WeatherEntry.CONTENT_URI, null, null, null, null);

    // Make sure we get the correct cursor out of the database
    TestUtilities.validateCursor("testBasicWeatherQuery", weatherCursor, weatherValues);
  }