@Test
  public void shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldHaltUpgradeIfUpgradeConfigurationVetoesTheProcess");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    UpgradeConfiguration vetoingUpgradeConfiguration =
        new UpgradeConfiguration() {
          public void checkConfigurationAllowsAutomaticUpgrade() {
            throw new UpgradeNotAllowedByConfigurationException("vetoed");
          }
        };

    try {
      newUpgrader(
              vetoingUpgradeConfiguration,
              new StoreMigrator(new SilentMigrationProgressMonitor()),
              new DatabaseFiles())
          .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());
      fail("Should throw exception");
    } catch (UpgradeNotAllowedByConfigurationException e) {
      // expected
    }
  }
  @Test
  public void shouldRefuseToUpgradeIfAllOfTheStoresWeNotShutDownCleanly() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldRefuseToUpgradeIfAllOfTheStoresWeNotShutDownCleanly");
    File comparisonDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldRefuseToUpgradeIfAllOfTheStoresWeNotShutDownCleanly-comparison");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    truncateAllFiles(workingDirectory);
    deleteRecursively(comparisonDirectory);
    copyRecursively(workingDirectory, comparisonDirectory);

    try {
      newUpgrader(
              alwaysAllowed(),
              new StoreMigrator(new SilentMigrationProgressMonitor()),
              new DatabaseFiles())
          .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());
      fail("Should throw exception");
    } catch (StoreUpgrader.UnableToUpgradeException e) {
      // expected
    }

    verifyFilesHaveSameContent(comparisonDirectory, workingDirectory);
  }
  @Test
  public void shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound");
    File comparisonDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldLeaveAllFilesUntouchedIfWrongVersionNumberFound-comparison");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    changeVersionNumber(new File(workingDirectory, "neostore.nodestore.db"), "v0.9.5");
    deleteRecursively(comparisonDirectory);
    copyRecursively(workingDirectory, comparisonDirectory);

    try {
      newUpgrader(
              alwaysAllowed(),
              new StoreMigrator(new SilentMigrationProgressMonitor()),
              new DatabaseFiles())
          .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());
      fail("Should throw exception");
    } catch (StoreUpgrader.UnableToUpgradeException e) {
      // expected
    }

    verifyFilesHaveSameContent(comparisonDirectory, workingDirectory);
  }
  @Test
  public void shouldLeaveACopyOfOriginalStoreFilesInBackupDirectory() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldLeaveACopyOfOriginalStoreFilesInBackupDirectory");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    newUpgrader(
            alwaysAllowed(),
            new StoreMigrator(new SilentMigrationProgressMonitor()),
            new DatabaseFiles())
        .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());

    verifyFilesHaveSameContent(
        MigrationTestUtils.findOldFormatStoreDirectory(),
        new File(workingDirectory, "upgrade_backup"));
  }
  @Test
  public void shouldUpgradeAnOldFormatStore() throws IOException {
    File workingDirectory =
        new File(
            "target/"
                + StoreUpgraderTestIT.class.getSimpleName()
                + "shouldUpgradeAnOldFormatStore");
    MigrationTestUtils.prepareSampleLegacyDatabase(workingDirectory);

    assertTrue(allStoreFilesHaveVersion(workingDirectory, "v0.9.9"));

    newUpgrader(
            alwaysAllowed(),
            new StoreMigrator(new SilentMigrationProgressMonitor()),
            new DatabaseFiles())
        .attemptUpgrade(new File(workingDirectory, NeoStore.DEFAULT_NAME).getPath());

    assertTrue(allStoreFilesHaveVersion(workingDirectory, ALL_STORES_VERSION));
  }