public void testGetDeletedFiles() throws Exception {
    cleanUpDataFolder();
    LocalHistoryTestStore store = createStore();
    LogHandler lh = new LogHandler("copied file", LogHandler.Compare.STARTS_WITH);

    cleanUpDataFolder();
    File folder = dataDir;
    folder.mkdirs();

    // create the files
    File file1 = new File(folder, "file1");
    File file2 = new File(folder, "file2");
    File file3 = new File(folder, "file3");
    File file4 = new File(folder, "file4");

    createFile(store, file1, System.currentTimeMillis(), "data1");
    createFile(store, file2, System.currentTimeMillis(), "data2");
    createFile(store, file3, System.currentTimeMillis(), "data3");
    createFile(store, file4, System.currentTimeMillis(), "data4");

    // touch the files
    lh.reset();
    changeFile(store, file1, System.currentTimeMillis(), "data1.1");
    lh.waitUntilDone();
    lh.reset();
    changeFile(store, file2, System.currentTimeMillis(), "data2.1");
    lh.waitUntilDone();
    lh.reset();
    changeFile(store, file3, System.currentTimeMillis(), "data3.1");
    lh.waitUntilDone();
    lh.reset();
    changeFile(store, file4, System.currentTimeMillis(), "data4.1");
    lh.waitUntilDone();

    // delete one of them
    store.fileDelete(file2, System.currentTimeMillis());
    StoreEntry[] entries = store.getDeletedFiles(folder);
    assertEntries(entries, new File[] {file2}, new String[] {"data2.1"});

    // delete one of them
    store.fileDelete(file3, System.currentTimeMillis());
    entries = store.getDeletedFiles(folder);
    assertEntries(entries, new File[] {file2, file3}, new String[] {"data2.1", "data3.1"});

    // delete without entry - only via .delete()
    file4.delete();
    entries = store.getDeletedFiles(folder);
    assertEntries(
        entries, new File[] {file2, file3, file4}, new String[] {"data2.1", "data3.1", "data4.1"});
  }
  public void testFileDelete() throws Exception {
    cleanUpDataFolder();
    LocalHistoryTestStore store = createStore();
    long ts = System.currentTimeMillis();

    // create file in store
    File file = new File(dataDir, "file1");
    createFile(store, file, ts, "data");

    store.fileDelete(file, ts);
    // check
    File storefile = store.getStoreFile(file, ts, false);
    assertFile(file, store, ts, storefile.lastModified(), 1, 1, "data", DELETED);

    file = new File(dataDir, "file2");
    createFile(store, file, ts, "data");

    store.fileDelete(file, ts);
    // check
    storefile = store.getStoreFile(file, ts, false);
    assertFile(file, store, ts, storefile.lastModified(), 1, 1, "data", DELETED);
  }
  public void testGetFolderState() throws Exception {
    LocalHistoryTestStore store = createStore();

    // check for deleted root folder
    File folder = new File(dataDir, "datafolder");
    setupFirstFolderToRevert(store, folder);

    File[] files = folder.listFiles();

    assertEquals(files.length, 7); //   fileNotInStorage
    //   fileUnchanged
    //   fileChangedAfterRevert
    // X fileDeletedAfterRevert
    //   fileDeletedBeforeRevert
    //   fileUndeletedBeforeRevert
    //   fileCreatedToLate
    //   folderCreatedAfterRevert

    store.fileDelete(folder, System.currentTimeMillis());
    Thread.sleep(1000); // give me some time
    long revertToTS = System.currentTimeMillis();

    StoreEntry[] entries = store.getFolderState(folder, files, revertToTS);
    assertEquals(entries.length, 0); // all are deleted

    store.cleanUp(1);
    cleanUpDataFolder();

    folder = new File(dataDir, "datafolder");
    revertToTS = setupFirstFolderToRevert(store, folder);
    files = folder.listFiles();
    assertEquals(files.length, 7); //   fileNotInStorage
    //   fileUnchanged
    //   fileChangedAfterRevert
    // X fileDeletedAfterRevert
    //   fileDeletedBeforeRevert
    //   fileUndeletedBeforeRevert
    //   fileCreatedToLate

    // X  folderDeletedAfterRevert
    //    folderCreatedAfterRevert

    entries = store.getFolderState(folder, files, revertToTS);

    assertEquals(entries.length, 8);
    //   * returned, X as to be deleted
    //   fileNotInStorage             -
    // *   fileUnchanged                - *
    // *   fileChangedAfterRevert       - * previous revision
    // *   fileDeletedAfterRevert       - *
    // *   fileUndeletedBeforeRevert    - *
    // X fileCreatedAfterRevert       - * X
    // * X fileDeletedBeforeRevert      - * X

    // *   folderDeletedAfterRevert     - *
    //   folderCreatedAfterRevert     - * X

    Map<String, StoreEntry> entriesMap = new HashMap<String, StoreEntry>();
    for (StoreEntry se : entries) {
      entriesMap.put(se.getFile().getName(), se);
    }
    assertNull(entriesMap.get("fileNotInStorage"));

    assertNotNull(entriesMap.get("fileUnchanged"));
    assertNotNull(entriesMap.get("fileChangedAfterRevert"));
    assertNotNull(entriesMap.get("fileDeletedAfterRevert"));
    assertNotNull(entriesMap.get("fileUndeletedBeforeRevert"));
    assertNotNull(entriesMap.get("fileCreatedAfterRevert"));
    assertNotNull(entriesMap.get("fileDeletedBeforeRevert"));
    assertNotNull(entriesMap.get("folderDeletedAfterRevert"));
    assertNotNull(entriesMap.get("folderCreatedAfterRevert"));

    assertNotNull(entriesMap.get("fileUnchanged").getStoreFile());
    assertNotNull(entriesMap.get("fileChangedAfterRevert").getStoreFile());
    assertNotNull(entriesMap.get("fileDeletedAfterRevert").getStoreFile());
    assertNotNull(entriesMap.get("fileUndeletedBeforeRevert").getStoreFile());
    assertNotNull(entriesMap.get("folderDeletedAfterRevert").getStoreFile());
    assertNull(entriesMap.get("fileCreatedAfterRevert").getStoreFile());
    assertNull(entriesMap.get("fileDeletedBeforeRevert").getStoreFile());
    assertNull(entriesMap.get("folderCreatedAfterRevert").getStoreFile());

    String strStore =
        read(entriesMap.get("fileChangedAfterRevert").getStoreFileInputStream(), 1024);
    //        String strFile = read(new
    // FileInputStream(entriesMap.get("fileChangedAfterRevert").getFile()), 1024);
    assertNotSame("BEFORE change", strStore);
  }