@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()); }
@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("\")"); }
@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; } }
@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)); }
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()); } }
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; } }
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; }