private Person insertPerson() throws DataAccessException { Person p = new Person(); p.setEmail("*****@*****.**"); p.setPassword("asdasd"); p = personDAOLocal.insert(p); Assert.assertTrue(p.getId() != -1); Assert.assertTrue(p.getId() != 0); Log.i("BeerBuddy", p.toString()); return p; }
public void testInsert() throws DataAccessException { Person p = insertPerson(); DrinkingSpot ds = new DrinkingSpot(); ds.setCreator(p); ds.setStartTime(new Date()); ds.setGps("asd"); ds = spotDAOLocal.insert(ds); Assert.assertTrue(ds.getId() != -1); Assert.assertTrue(ds.getId() != 0); Log.i("BeerBuddy", ds.toString()); // select it SQLiteDatabase writableDatabase = db.getWritableDatabase(); Cursor dbCursor = writableDatabase.rawQuery("Select * from person", null); while (dbCursor.moveToNext()) { for (String colname : dbCursor.getColumnNames()) { Log.i("BeerBuddy", colname + ": " + dbCursor.getString(dbCursor.getColumnIndex(colname))); ; } } dbCursor.close(); assertTrue(dbCursor.getCount() > 0); dbCursor = writableDatabase.rawQuery( "Select * from drinkingspot where id = ?", new String[] {ds.getId() + ""}); while (dbCursor.moveToNext()) { for (String colname : dbCursor.getColumnNames()) { Log.i("BeerBuddy", colname + ": " + dbCursor.getString(dbCursor.getColumnIndex(colname))); ; } assertEquals(ds.getId(), dbCursor.getLong(dbCursor.getColumnIndex("id"))); } assertTrue(dbCursor.getCount() > 0); dbCursor.close(); DrinkingSpot byId = spotDAOLocal.getById(ds.getId()); assertNotNull(byId); byId = spotDAOLocal.getActiveByPersonId(p.getId()); assertNotNull(byId); }