/**
   * Runs the console installer twice, verifying that a second uninstall key is created.
   *
   * @throws Exception for any error
   */
  @Test
  @InstallFile("samples/windows/install.xml")
  public void testRejectMultipleInstallation() throws Exception {
    Assume.assumeTrue(
        "This test must be run as administrator, or with Windows UAC turned off",
        !skipTests && isAdminUser);

    checkInstall(container, APP_NAME);

    removeLock();

    ConsoleInstallerContainer container2 = new TestConsoleInstallerContainer();
    TestConsoleInstaller installer2 = container2.getComponent(TestConsoleInstaller.class);
    RegistryDefaultHandler handler2 = container2.getComponent(RegistryDefaultHandler.class);
    InstallData installData2 = container2.getComponent(InstallData.class);

    TestConsole console2 = installer2.getConsole();
    console2.addScript("CheckedHelloPanel", "n");

    assertFalse(registryKeyExists(handler2, UNINSTALL_KEY2));
    installer2.run(Installer.CONSOLE_INSTALL, null, new String[0]);

    // verify the installation thinks it was unsuccessful
    assertFalse(installData2.isInstallSuccess());

    // make sure the script has completed
    TestConsole console = installer2.getConsole();
    assertTrue("Script still running panel: " + console.getScriptName(), console.scriptCompleted());

    // verify the second registry key hasn't been created
    assertFalse(registryKeyExists(handler2, UNINSTALL_KEY2));
  }
  /**
   * Runs the console installer against a script with an alternative uninstaller name and path,
   * verifying that the correct uninstall JAR and registry value are created.
   *
   * @throws Exception for any error
   */
  @Test
  @InstallFile("samples/windows/consoleinstall_alt_uninstall.xml")
  public void testNonDefaultUninstaller() throws Exception {
    Assume.assumeTrue(
        "This test must be run as administrator, or with Windows UAC turned off",
        !skipTests && isAdminUser);

    assertFalse(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));

    TestConsole console = installer.getConsole();
    console.addScript("CheckedHelloPanel", "1");
    console.addScript("InfoPanel", "1");
    console.addScript("TargetPanel", "\n", "O", "1");

    // run installer and check that default uninstaller doesn't exist
    InstallData installData = getInstallData();
    checkInstall(installer, installData, false);

    // check that uninstaller exists as specified in install spec
    String installPath = installData.getInstallPath();
    assertTrue(new File(installPath, "/uninstallme.jar").exists());

    // check that the registry key has the correct value
    assertTrue(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));
    String command =
        "\""
            + installData.getVariable("JAVA_HOME")
            + "\\bin\\javaw.exe\" -jar \""
            + installPath
            + "\\uninstallme.jar\"";
    registryValueStringEquals(handler, DEFAULT_UNINSTALL_KEY, UNINSTALL_CMD_VALUE, command);
  }
  /**
   * Runs the console installer twice, verifying that a second uninstall key is created.
   *
   * @throws Exception for any error
   */
  @Test
  @InstallFile("samples/windows/install.xml")
  public void testMultipleInstallation() throws Exception {
    Assume.assumeTrue(
        "This test must be run as administrator, or with Windows UAC turned off",
        !skipTests && isAdminUser);

    // run the install
    checkInstall(container, APP_NAME);

    // remove the lock file to enable second installation
    removeLock();

    // run the installation again
    ConsoleInstallerContainer container2 = new TestConsoleInstallerContainer();
    TestConsoleInstaller installer2 = container2.getComponent(TestConsoleInstaller.class);
    InstallData installData2 = container2.getComponent(InstallData.class);

    // copied from super.setUp()
    // write to temporary folder so the test doesn't need to be run with elevated permissions
    File installPath = new File(temporaryFolder.getRoot(), "izpackTest");
    installData2.setInstallPath(installPath.getAbsolutePath());
    installData2.setDefaultInstallPath(installPath.getAbsolutePath());

    TestConsole console2 = installer2.getConsole();
    console2.addScript("CheckedHelloPanel", "y", "1");
    console2.addScript("TargetPanel", "\n", "y", "1");
    console2.addScript("PacksPanel", "1");

    assertFalse(registryKeyExists(handler, UNINSTALL_KEY2));
    checkInstall(installer2, installData2);

    // verify the UNINSTALL_NAME has been updated
    assertEquals(APP_NAME + "(1)", installData2.getVariable("UNINSTALL_NAME"));

    // verify a second key is created
    assertTrue(registryKeyExists(handler, UNINSTALL_KEY2));
  }
  /**
   * Runs the installation, and verifies the uninstall key is created.
   *
   * @throws NativeLibException for any native library exception
   */
  private void checkInstall(TestConsoleInstallerContainer container, String uninstallName)
      throws NativeLibException {
    // UNINSTALL_NAME should be null prior to display of CheckedHelloPanel
    InstallData installData = container.getComponent(InstallData.class);
    TestConsoleInstaller installer = container.getComponent(TestConsoleInstaller.class);
    RegistryDefaultHandler handler = container.getComponent(RegistryDefaultHandler.class);

    assertNull(installData.getVariable("UNINSTALL_NAME"));

    assertFalse(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));

    TestConsole console = installer.getConsole();
    console.addScript("CheckedHelloPanel", "1");
    console.addScript("TargetPanel", "\n", "O", "1");
    console.addScript("PacksPanel", "1");
    console.addScript("ShortcutPanel", "N");

    checkInstall(installer, installData);

    // UNINSTALL_NAME should now be defined
    assertEquals(uninstallName, installData.getVariable("UNINSTALL_NAME"));

    assertTrue(registryKeyExists(handler, DEFAULT_UNINSTALL_KEY));
  }