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
 @Override
 public void appendTo(StringBuffer buffer) {
   buffer.append("eqCommandJob(");
   buffer.append(expected.getClass().getName());
   buffer.append(" with command \"");
   buffer.append(expected.getCommand().getName());
   buffer.append(" and toString \"");
   buffer.append(expected.getCommand());
   buffer.append("\")");
 }
Esempio n. 3
0
 @Override
 public boolean matches(Object actual) {
   if (actual instanceof CommandJob) {
     CommandJob actualJob = (CommandJob) actual;
     return actualJob.getCommand().getName().equals(expected.getCommand().getName())
         && actualJob.getCommand().toString().equals(expected.getCommand().toString());
   } else {
     return false;
   }
 }
Esempio n. 4
0
  @Override
  @SuppressWarnings("OverlyStrongTypeCast")
  public void execute(JobExecutionContext context) throws JobExecutionException {
    autowireSelf(context);

    Command<?> command = getCommand(context);
    CommandJob commandJob = new CommandJob(command);
    if (command instanceof ReportCommand) {
      commandJob.setProject(((ReportCommand) command).getOptions().getProject());
    }
    commandJobService.launchCommand(commandJob, getSubject(context));
  }
Esempio n. 5
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. 6
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;
    }
  }
Esempio n. 7
0
  private CommandJob createCommandJob(Integer id, Command<?> command, Date submitTime) {
    CommandJob commandJob = new CommandJob(command);

    commandJob.setId(id);
    commandJob.setOwner("someUser");
    commandJob.setStatus(Status.SUCCEEDED);

    if (submitTime != null) {
      commandJob.setSubmitTime(submitTime);
      commandJob.run();
    }

    return commandJob;
  }