/**
   * Starts a servers, verifies that jobs are created correctly and an be retrieved from the job
   * services
   */
  @Test(dependsOnMethods = "testServerLifecycle", enabled = true)
  public void testJobs() {
    final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
    serversToDeleteAfterTheTests.add(nameOfServer);

    Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();

    String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName();

    Server createdServer =
        client
            .getServerServices()
            .addServer(
                nameOfServer,
                "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
                ram,
                Iterables.getLast(availableIps).getIp());

    assert serverLatestJobCompleted.apply(createdServer);

    // restart the server
    client.getServerServices().power(nameOfServer, PowerCommand.RESTART);

    Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);

    Job latestJob = Iterables.getLast(jobs);
    Long latestJobId = latestJob.getId();

    Job latestJobFetched =
        Iterables.getOnlyElement(client.getJobServices().getJobsById(latestJobId));

    assert latestJob.equals(latestJobFetched)
        : "Job and its representation found by ID don't match";

    long[] idsOfAllJobs = new long[jobs.size()];
    int i = 0;
    for (Job job : jobs) {
      idsOfAllJobs[i++] = job.getId();
    }

    Set<Job> jobsFetched = client.getJobServices().getJobsById(idsOfAllJobs);
    assert jobsFetched.size() == jobs.size()
        : format(
            "Number of jobs fetched by ids doesn't match the number of jobs "
                + "requested. Requested/expected: %d. Found: %d.",
            jobs.size(), jobsFetched.size());

    // delete the server
    client.getServerServices().deleteByName(nameOfServer);
  }
  @Test
  public void testPredicate() {
    final String serverName = "SERVER_NAME";
    Server server = createMock(Server.class);
    expect(server.getName()).andStubReturn(serverName);

    Job job = createMock(Job.class);
    expect(job.getCurrentState()).andReturn(JobState.SUCCEEDED);

    GridJobApi client = createMock(GridJobApi.class);
    expect(client.getJobList(latestJobForObjectByName(serverName)))
        .andReturn(ImmutableSet.<Job>of(job));

    replay(job);
    replay(client);
    replay(server);

    ServerLatestJobCompleted predicate = new ServerLatestJobCompleted(client);
    assertTrue(predicate.apply(server), "The result of the predicate should've been 'true'");
  }