private Build buildJob(String jobPath)
      throws Exception, UnsupportedEncodingException, InterruptedException {
    Job job = null;
    AbstractNode result = client.execute(config.getUrl() + "/job/" + jobPath + "/build?delay=0sec");
    assertTrue(result instanceof ResetNode);
    for (int retryCount = 0;
        !(job = client.getJob(jobPath)).isBuilding() && retryCount < TEST_RETRY_COUNT;
        retryCount++) {
      Thread.sleep(TEST_RETRY_SLEEP);
    }

    return job.builds.get(0);
  }
  private Job getJobNotBuilding() throws Exception {
    Job job = null;
    for (int retryCount = 0;
        (job = client.getJob(JenkinsClient.urlEncode(JENKINS_JOB))).isBuilding()
            && retryCount < TEST_RETRY_COUNT;
        retryCount++) {
      Thread.sleep(TEST_RETRY_SLEEP);
    }

    if (job.isBuilding()) {
      throw new Exception("No jobs found in Jenkins Server");
    }

    return job;
  }
  @Test
  public void testCanStopBuild() throws Exception {
    Job job = getJobNotBuilding();
    Build build = buildJob(job.path);
    AbstractNode result =
        client.execute(config.getUrl() + "/job/" + job.path + "/" + build.number + "/stop");
    assertTrue(result instanceof ResetNode);
    for (int retryCount = 0;
        (job = client.getJob(job.path)).isBuilding() && retryCount < TEST_RETRY_COUNT;
        retryCount++) {
      Thread.sleep(TEST_RETRY_SLEEP);
    }

    assertEquals("aborted", job.builds.get(0).result.toLowerCase());
  }
 @Test
 public void testCanTriggerBuildSuccessfully() throws Exception {
   JobName job = getJobNotBuilding();
   buildJob(job.path);
   assertTrue(client.getJob(job.path).isBuilding());
 }
 private Job getJob() throws Exception {
   Job job = client.getJob(JenkinsClient.urlEncode(JENKINS_JOB));
   return job;
 }