Esempio n. 1
0
  @Test
  public void testGetCommandStatus_ReturnsResponseContainingStatusSpecifiedJob() {
    // Setup
    Integer jobId = 1;
    CommandJob job = createCommandJob(jobId, createImportCommand(), new Date(1l));
    CommandJobService mockCommandJobService = createMock(CommandJobService.class);
    expect(mockCommandJobService.getCommand(jobId)).andReturn(job).atLeastOnce();

    WebShellResource sut = new WebShellResource();
    sut.setCommandJobService(mockCommandJobService);

    replay(mockCommandJobService);

    // Exercise
    Response response = sut.getCommandStatus(jobId);

    // Verify mocks
    verify(mockCommandJobService);

    // Verify that the HTTP response code was OK (200) and that the body contains
    // the status of the specified task.
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    assertThat(response.getEntity()).isNotNull();
    assertThat(response.getEntity()).isEqualTo(job.getStatus().toString());
  }
Esempio n. 2
0
  private void assertDtoListMatchesJobList(
      List<CommandStateDto> dtoList, List<CommandJob> jobList) {
    assertThat(jobList.size()).isEqualTo(dtoList.size());

    for (int i = 0; i < dtoList.size(); i++) {
      CommandStateDto dto = dtoList.get(i);
      CommandJob job = jobList.get(i);

      assertThat(job.getCommand().getName()).isEqualTo(dto.getCommand());
      assertThat(job.getOwner()).isEqualTo(dto.getOwner());
      assertThat(job.getStatus().toString()).isEqualTo(dto.getStatus());
    }
  }
Esempio n. 3
0
  private boolean containsDtoForJob(Response response, CommandJob job) {
    Object entity = response.getEntity();

    if (entity != null) {
      if (entity instanceof CommandStateDto) {
        CommandStateDto dto = (CommandStateDto) entity;
        return dto.getId() == job.getId()
            && dto.getCommand().equals(job.getCommand().getName())
            && dto.getCommandArgs().equals(job.getCommand().toString())
            && dto.getOwner().equals(job.getOwner())
            && dto.getStatus().equals(job.getStatus().toString());
      } else {
        return false;
      }
    } else {
      return false;
    }
  }