/**
   * @native(docker) Scenario: Configure a job with over ssh publishing Given I have installed the
   *     "publish-over-ssh" plugin And a docker fixture "sshd" And a job When I configure docker
   *     fixture as SSH site And I configure the job to use a unsecure keyfile with passphrase And I
   *     copy resource "scp_plugin/lorem-ipsum-scp.txt" into workspace And I publish
   *     "lorem-ipsum-scp.txt" with SSH plugin And I save the job And I build the job Then the build
   *     should succeed And SSH plugin should have published "lorem-ipsum-scp.txt" on docker fixture
   *     And SSH plugin should have create with exec "testecho" on docker fixture
   */
  @Test
  public void ssh_key_path_and_key_password_and_exec_publishing()
      throws IOException, InterruptedException {
    SshdContainer sshd = docker.start(SshdContainer.class);
    Resource cp_file = resource(resourceFilePath);
    File sshFile = sshd.getEncryptedPrivateKey();

    FreeStyleJob j = jenkins.jobs.create();

    jenkins.configure();
    this.commonConfigKeyFileAndPassword(sshFile, false);
    InstanceSite is = this.instanceConfig(sshd);
    this.advancedConfigAllowExec(is, sshd);
    jenkins.save();
    this.configureJobWithExec(j, cp_file);
    j.save();
    j.startBuild().shouldSucceed();

    sshd.cp(tempCopyFile, tempPath);
    sshd.cp(tempCopyFileEcho, tempPath);
    assertThat(
        FileUtils.readFileToString(new File(tempCopyFile)), CoreMatchers.is(cp_file.asText()));
    assertThat(
        FileUtils.readFileToString(new File(tempCopyFileEcho)), CoreMatchers.is("i was here\n"));
  }
  /**
   * @native(docker) Scenario: Configure a job with over ssh publishing Given I have installed the
   *     "publish-over-ssh" plugin And a docker fixture "sshd" And a job When I configure docker
   *     fixture as SSH site And I configure the job to use a unsecure keyfile without passphrase
   *     And I copy resource "scp_plugin/lorem-ipsum-scp.txt" into workspace And I publish
   *     "lorem-ipsum-scp.txt" with SSH plugin And I save the job And I build the job Then the build
   *     should succeed And SSH plugin should have published "lorem-ipsum-scp.txt" on docker fixture
   */
  @Test
  public void ssh_key_path_and_no_password_publishing() throws IOException, InterruptedException {
    SshdContainer sshd = docker.start(SshdContainer.class);
    Resource cp_file = resource(resourceFilePath);
    File sshFile = sshd.getPrivateKey();

    FreeStyleJob j = jenkins.jobs.create();
    jenkins.configure();
    this.commonConfigKeyFile(sshFile, false);
    InstanceSite is = this.instanceConfig(sshd);
    this.advancedConfigAllowExec(is, sshd);
    // delete button
    // is.delete.click();

    // validate input
    // is.validate.click();
    jenkins.save();
    this.configureJobNoExec(j, cp_file);
    j.save();
    j.startBuild().shouldSucceed();

    sshd.cp(tempCopyFile, tempPath);
    assertThat(
        FileUtils.readFileToString(new File(tempCopyFile)), CoreMatchers.is(cp_file.asText()));
  }
 /*helper method for creating a advanced config*/
 private void advancedConfigAllowExec(InstanceSite is, SshdContainer sshd) {
   AdvancedConfig ac = is.addAdvancedConfig();
   {
     ac.port.set(sshd.port(22));
     ac.timeout.set(timeout);
   }
 }
 /*helper method for creating a ssh server config*/
 private InstanceSite instanceConfig(SshdContainer sshd) {
   InstanceSite is = new PublishOverSSHGlobalConfig(jenkins).addInstanceSite();
   {
     is.name.set(serverName);
     is.hostname.set(sshd.ipBound(22));
     is.username.set(userName);
     is.remoteRootDir.set(rootDir);
   }
   return is;
 }
  /*helper method for creating a advanced config no exec*/
  private void advancedConfigNoExec(InstanceSite is, SshdContainer sshd) {
    AdvancedConfig ac = is.addAdvancedConfig();
    {
      ac.port.set(sshd.port(22));
      ac.timeout.set(timeout);

      // for disabling exec per instance
      ac.disableAllExecInstance.check();
    }
  }