コード例 #1
0
ファイル: DaapTransactionTest.java プロジェクト: rkapsi/daap
  public void testExtendedCommit() {
    Database database = new Database("Database");
    Playlist playlist = new Playlist("Playlist");

    assertTrue(library.getRevision() == 1);
    assertTrue(library.getDatabaseCount() == 0);
    assertTrue(database.getPlaylistCount() == 1); /* masterPlaylist!!! */

    Transaction txn = library.beginTransaction();
    database.addPlaylist(txn, playlist);
    library.addDatabase(txn, database);
    txn.commit();

    assertTrue(library.getRevision() == 2); /* incremeted with each commit */
    assertTrue(library.getDatabaseCount() == 1);
    assertTrue(database.getPlaylistCount() == 2);

    Transaction txn2 = library.beginTransaction();
    database.setName(txn2, "NewDatabaseName");
    playlist.setName(txn2, "NewPlaylistName");
    library.setName(txn2, "NewLibraryName");
    txn2.commit();

    assertTrue(library.getRevision() == 3);
    assertTrue(library.getDatabaseCount() == 1);
    assertTrue(database.getPlaylistCount() == 2);

    assertEquals(library.getName(), "NewLibraryName");
    assertEquals(database.getName(), "NewDatabaseName");
    assertEquals(playlist.getName(), "NewPlaylistName");

    Song song1 = new Song("Song1");
    Transaction txn3 = library.beginTransaction();
    playlist.addSong(txn3, song1);
    txn3.commit();

    assertTrue(library.getRevision() == 4);
    assertTrue(library.getDatabaseCount() == 1);
    assertTrue(database.getPlaylistCount() == 2);
    assertTrue(playlist.getSongCount() == 1 && playlist.containsSong(song1));
    assertTrue(database.getSongCount() == 1 && database.containsSong(song1));

    Playlist masterPlaylist = database.getMasterPlaylist();
    assertFalse(masterPlaylist.getSongCount() == 1 && masterPlaylist.containsSong(song1));
  }
コード例 #2
0
ファイル: DaapTransactionTest.java プロジェクト: rkapsi/daap
 public void testRollback() {
   assertTrue(library.getRevision() == 1);
   Transaction txn = library.beginTransaction();
   Database database = new Database("Database");
   library.addDatabase(txn, database);
   txn.rollback();
   assertTrue(library.getRevision() == 1);
   assertTrue(library.getDatabaseCount() == 0);
 }