/**
   * cleanup with obsolete profiles.
   *
   * @throws Exception if failed
   */
  @SuppressWarnings("deprecation")
  @Test
  public void cleanup_obsolete_profiles() throws Exception {
    String target =
        new File(getAsakusaHome(), ProcessHadoopScriptHandler.PATH_EXECUTE).getAbsolutePath();
    File shell = putScript("arguments.sh", new File(target));

    HadoopScriptHandler handler =
        handler(
            "env.ASAKUSA_HOME",
            getAsakusaHome().getAbsolutePath(),
            ProcessHadoopScriptHandler.KEY_CLEANUP,
            "true",
            ProcessHadoopScriptHandler.KEY_WORKING_DIRECTORY,
            "OBSOLETE",
            ProcessUtil.PREFIX_CLEANUP + "1",
            "OBSOLETE");

    ExecutionContext context =
        new ExecutionContext("tbatch", "tflow", "texec", ExecutionPhase.CLEANUP, map());

    handler.cleanUp(ExecutionMonitor.NULL, context);

    List<String> results = getOutput(shell);
    assertThat(
        results.subList(0, 5),
        is(
            Arrays.asList(
                ProcessHadoopScriptHandler.CLEANUP_STAGE_CLASS,
                "tbatch",
                "tflow",
                "texec",
                context.getArgumentsAsString())));
  }
  /**
   * Invoke setup.
   *
   * @throws Exception if failed
   */
  @Test
  public void setup() throws Exception {
    HadoopScriptHandler handler = handler("env.ASAKUSA_HOME", getAsakusaHome().getAbsolutePath());

    ExecutionContext context =
        new ExecutionContext("tbatch", "tflow", "texec", ExecutionPhase.SETUP, map());
    handler.setUp(ExecutionMonitor.NULL, context);
  }
  /**
   * Script is missing.
   *
   * @throws Exception if failed
   */
  @Test(expected = IOException.class)
  public void script_missing() throws Exception {
    HadoopScript script = new HadoopScript("testing", set(), "com.example.Client", map(), map());

    HadoopScriptHandler handler = handler("env.ASAKUSA_HOME", getAsakusaHome().getAbsolutePath());
    ExecutionContext context =
        new ExecutionContext("tbatch", "tflow", "texec", ExecutionPhase.MAIN, map());
    handler.execute(ExecutionMonitor.NULL, context, script);
  }
  /**
   * Asakusa home is missing.
   *
   * @throws Exception if failed
   */
  @Test(expected = IOException.class)
  public void home_missing() throws Exception {
    String target =
        new File(getAsakusaHome(), ProcessHadoopScriptHandler.PATH_EXECUTE).getAbsolutePath();
    putScript("arguments.sh", new File(target));

    HadoopScript script = new HadoopScript("testing", set(), "com.example.Client", map(), map());

    HadoopScriptHandler handler = handler();
    ExecutionContext context =
        new ExecutionContext("tbatch", "tflow", "texec", ExecutionPhase.MAIN, map());
    handler.execute(ExecutionMonitor.NULL, context, script);
  }
  /**
   * cleanup.
   *
   * @throws Exception if failed
   */
  @Test
  public void cleanup_skip() throws Exception {
    String target =
        new File(getAsakusaHome(), ProcessHadoopScriptHandler.PATH_EXECUTE).getAbsolutePath();
    File shell = putScript("arguments.sh", new File(target));

    HadoopScriptHandler handler =
        handler(
            "env.ASAKUSA_HOME",
            getAsakusaHome().getAbsolutePath(),
            ProcessHadoopScriptHandler.KEY_CLEANUP,
            "false");
    ExecutionContext context =
        new ExecutionContext("tbatch", "tflow", "texec", ExecutionPhase.CLEANUP, map());

    handler.cleanUp(ExecutionMonitor.NULL, context);

    try {
      getOutput(shell);
      fail();
    } catch (IOException e) {
      // ok,
    }
  }