@Test
  public void shouldExitCleanlyIfDatabaseMissingSoThatDatabaseCreationIsLeftToMainProcess()
      throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    PreStartupStoreUpgrader upgrader =
        new PreStartupStoreUpgrader(buildProperties(true), new PrintStream(outputStream));

    int exit = upgrader.run();

    assertEquals(0, exit);

    assertEquals("", new String(outputStream.toByteArray()));
  }
  @Test
  public void shouldUpgradeDatabase() throws IOException {
    Properties systemProperties = buildProperties(true);
    prepareSampleLegacyDatabase(new File(STORE_DIRECTORY));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    PreStartupStoreUpgrader upgrader =
        new PreStartupStoreUpgrader(systemProperties, new PrintStream(outputStream));

    int exit = upgrader.run();

    assertEquals(0, exit);

    String[] lines = new String(outputStream.toByteArray()).split("\\r?\\n");
    assertEquals("Starting upgrade of database store files", lines[0]);
    assertEquals(dots(100), lines[1]);
    assertEquals("Finished upgrade of database store files", lines[2]);
  }
  @Test
  public void shouldExitImmediatelyIfStoreIsAlreadyAtLatestVersion() throws IOException {
    Properties systemProperties = buildProperties(false);
    new GraphDatabaseFactory()
        .newEmbeddedDatabaseBuilder(STORE_DIRECTORY)
        .newGraphDatabase()
        .shutdown();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    PreStartupStoreUpgrader upgrader =
        new PreStartupStoreUpgrader(systemProperties, new PrintStream(outputStream));

    int exit = upgrader.run();

    assertEquals(0, exit);

    assertEquals("", new String(outputStream.toByteArray()));
  }
  @Test
  public void shouldGiveHelpfulMessageIfAutoUpgradeParameterNotSet() throws IOException {
    Properties systemProperties = buildProperties(false);
    prepareSampleLegacyDatabase(new File(STORE_DIRECTORY));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    PreStartupStoreUpgrader upgrader =
        new PreStartupStoreUpgrader(systemProperties, new PrintStream(outputStream));

    int exit = upgrader.run();

    assertEquals(1, exit);

    String[] lines = new String(outputStream.toByteArray()).split("\\r?\\n");
    assertTrue(
        lines[0].contains(
            "To enable automatic upgrade, please set configuration parameter "
                + "\"allow_store_upgrade=true\""));
  }