Ejemplo n.º 1
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));
  }
Ejemplo n.º 2
0
  @Test
  public void testCreateReport() {
    // Setup
    Integer jobId = 1;
    CommandRegistry mockCommandRegistry = createMockCommandRegistry();
    ReportCommand reportCommand = createReportCommand();
    expect(mockCommandRegistry.<ReportCommandOptions>newCommand(reportCommand.getName()))
        .andReturn(reportCommand)
        .atLeastOnce();

    CommandJobService mockCommandJobService = createMockCommandJobService();
    expect(
            mockCommandJobService.launchCommand(
                eqCommandJob(createCommandJob(jobId, reportCommand, null))))
        .andReturn(jobId)
        .atLeastOnce();

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

    replay(mockCommandRegistry, mockCommandJobService);

    // Exercise
    ReportCommandOptionsDto optionsDto = createReportCommandOptionsDto("test report", "project1");
    Response response = sut.createReport(optionsDto);

    // Verify mocks
    verify(mockCommandRegistry, mockCommandJobService);

    // Verify that the options in the dto were applied to the launched command
    ReportCommandOptions importOptions = reportCommand.getOptions();
    assertThat(optionsDto.getName()).isEqualTo(importOptions.getName());

    // Verify that the HTTP response code was CREATED (201) and that the "Location"
    // header was set to '/shell/command/{jobId}'.
    assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
    assertThat(response.getMetadata().getFirst("Location").toString())
        .isEqualTo("/shell/command/" + jobId);
  }