/**
   * Test.
   *
   * @throws IOException if an error occurs
   */
  @Test
  public void testParseStdoutForClusterJobInformation() throws IOException {
    final String stdout = IOUtils.toString(getClass().getResourceAsStream("/torque_qstat"));

    Map<String, ClusterJobInformation> jobInformation =
        clusterService.parseStdoutForClusterJobInformation(stdout);

    assertEquals(4, jobInformation.size());

    ClusterJobInformation information = jobInformation.get("506.bssc075dl");
    assertEquals("job", information.getJobName());
    assertEquals(ClusterJobState.Running, information.getJobState());
    assertEquals("qtest", information.getQueue());
    assertEquals("seid_do", information.getUser());

    information = jobInformation.get("507.bssc075dl");
    assertEquals("jib", information.getJobName());
    assertEquals(ClusterJobState.Queued, information.getJobState());
    assertEquals("mem", information.getQueue());
    assertEquals("litz_ma", information.getUser());

    information = jobInformation.get("508.bssc075dl");
    assertEquals("job", information.getJobName());
    assertEquals(ClusterJobState.Completed, information.getJobState());
    assertEquals("qtest", information.getQueue());
    assertEquals("seid_do", information.getUser());

    information = jobInformation.get("509.bssc075dl");
    assertEquals("jab", information.getJobName());
    assertEquals(ClusterJobState.Queued, information.getJobState());
    assertEquals("fast", information.getQueue());
    assertEquals("sipp_ja", information.getUser());
  }
  /** Test. */
  @Test
  public void testEnhanceClusterJobInformation() {
    String jobId0 = RandomStringUtils.random(5);
    String jobId1 = RandomStringUtils.random(5);
    String jobId2 = helperTestClass.localJobId;
    String jobId3 = helperTestClass.remoteJobId;
    String jobId4 = RandomStringUtils.random(5);

    String[] jobIds = new String[] {jobId0, jobId1, jobId2, jobId3};

    Map<String, ClusterJobInformation> jobInformation =
        new HashMap<String, ClusterJobInformation>();
    Map<String, ClusterJobTimesInformation> jobTimesInformation =
        new HashMap<String, ClusterJobTimesInformation>();

    for (String jobId : jobIds) {
      ClusterJobInformationImpl information = new ClusterJobInformationImpl();
      information.setJobId(jobId);
      jobInformation.put(jobId, information);
      if (jobId.equals(jobId1) || jobId.equals(jobId3)) {
        ClusterJobTimesInformation timesInformation = new ClusterJobTimesInformation();
        timesInformation.setJobId(jobId);
        jobTimesInformation.put(jobId, timesInformation);
      }
    }

    String queueTime1 = RandomStringUtils.random(5);
    jobTimesInformation.get(jobId1).setQueueTime(queueTime1);

    String remainingTime3 = RandomStringUtils.random(5);
    String startTime3 = RandomStringUtils.random(5);
    jobTimesInformation.get(jobId3).setRemainingTime(remainingTime3);
    jobTimesInformation.get(jobId3).setStartTime(startTime3);

    Set<ClusterJobInformation> resultJobInformation =
        clusterService.enhanceClusterJobInformation(jobInformation, jobTimesInformation);

    assertEquals(jobInformation.size(), resultJobInformation.size());
    for (ClusterJobInformation information : resultJobInformation) {
      if (information.getJobId().equals(jobId0)) {
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getRemainingTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getStartTime());
      } else if (information.getJobId().equals(jobId1)) {
        assertEquals(queueTime1, information.getQueueTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getRemainingTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getStartTime());
      } else if (information.getJobId().equals(jobId2)) {
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getRemainingTime());
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getStartTime());
      } else if (information.getJobId().equals(jobId3)) {
        assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
        assertEquals(remainingTime3, information.getRemainingTime());
        assertEquals(startTime3, information.getStartTime());
      }
    }
    assertFalse(resultJobInformation.contains(jobId4));
  }
 /** Set up. */
 @Before
 public void setUp() {
   String randomString = RandomStringUtils.random(5);
   SshSessionConfiguration sshConfiguration =
       SshSessionConfigurationFactory.createSshSessionConfigurationWithAuthPhrase(
           helperTestClass.localHost, helperTestClass.port, randomString, randomString);
   clusterService = new TorqueClusterService(sshConfiguration, new HashMap<String, String>());
   clusterService.bindClusterJobSourceService(new ClusterJobSourceServiceImpl());
 }
  /**
   * Test.
   *
   * @throws IOException if an error occurs
   */
  @Test
  public void testParseStdoutForClusterJobTimesInformation() throws IOException {
    final String stdout = IOUtils.toString(getClass().getResourceAsStream("/torque_showq"));

    Map<String, ClusterJobTimesInformation> jobTimesInformation =
        clusterService.parseStdoutForClusterJobTimesInformation(stdout);

    assertEquals(3, jobTimesInformation.size());

    ClusterJobTimesInformation information = jobTimesInformation.get("606");
    assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
    assertEquals("Tue Aug 28 16:54:22", information.getStartTime());
    assertEquals("00:30:02", information.getRemainingTime());

    information = jobTimesInformation.get("569");
    assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getQueueTime());
    assertEquals("Thu Aug 23 14:15:11", information.getStartTime());
    assertEquals("94:20:20:45", information.getRemainingTime());

    information = jobTimesInformation.get("607");
    assertEquals("Tue Aug 28 17:54:24", information.getQueueTime());
    assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getStartTime());
    assertEquals(ClusterJobInformationImpl.NO_VALUE_SET, information.getRemainingTime());
  }