Java 类org.springframework.batch.core.JobParameters 实例源码

项目:composed-task-runner    文件:ComposedTaskRunnerConfigurationWithPropertiesTests.java   
@Test
@DirtiesContext
public void testComposedConfiguration() throws Exception {
    JobExecution jobExecution = this.jobRepository.createJobExecution(
            "ComposedTest", new JobParameters());
    job.execute(jobExecution);

    Map<String, String> props = new HashMap<>(1);
    props.put("format", "yyyy");
    assertEquals(1010, composedTaskProperties.getMaxWaitTime());
    assertEquals(1100, composedTaskProperties.getIntervalTimeBetweenChecks());
    assertEquals("http://bar", composedTaskProperties.getDataflowServerUri().toASCIIString());

    List<String> args = new ArrayList<>(1);
    args.add("--baz=boo");
    Assert.isNull(job.getJobParametersIncrementer(), "JobParametersIncrementer must be null.");
    verify(this.taskOperations).launch("AAA", props, args);
}
项目:eMonocot    文件:PalmwebIntegrationTest.java   
@Test
public void testCreateGenericArchive() throws NoSuchJobException,
JobExecutionAlreadyRunningException, JobRestartException,
JobInstanceAlreadyCompleteException, JobParametersInvalidException, IOException {
    Map<String, JobParameter> parameters =
            new HashMap<String, JobParameter>();

    JobParameters jobParameters = new JobParameters(parameters);

    Job palmwebArchive = jobLocator.getJob("PalmWeb");
    assertNotNull("Palmweb must not be null",  palmwebArchive);
    JobExecution jobExecution = jobLauncher.run(palmwebArchive, jobParameters);
    assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED");
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        logger.info(stepExecution.getStepName() + " "
                + stepExecution.getReadCount() + " "
                + stepExecution.getFilterCount() + " "
                + stepExecution.getWriteCount() + " " + stepExecution.getCommitCount());
    }
}
项目:composed-task-runner    文件:ComposedTaskRunnerConfigurationNoPropertiesTests.java   
@Test
@DirtiesContext
public void testComposedConfiguration() throws Exception {
    JobExecution jobExecution = this.jobRepository.createJobExecution(
            "ComposedTest", new JobParameters());
    job.execute(jobExecution);

    Assert.isNull(job.getJobParametersIncrementer(), "JobParametersIncrementer must be null.");
    verify(this.taskOperations).launch("AAA", new HashMap<String, String>(0), new ArrayList<String>(0));
}
项目:nixmash-blog    文件:DemoJobRunner.java   
@Scheduled(fixedDelayString = "${demo.job.fixed.delay.seconds:60}000")
public void runDemoJob() {

    SimpleDateFormat format = new SimpleDateFormat("M-dd-yy hh:mm:ss");
    String startDateTime = format.format(new Date());

    JobParameters jobParameters =
            new JobParametersBuilder()
                    .addLong("iterations", iterations)
                    .addString("username", username)
                    .addLong("time", System.currentTimeMillis()).toJobParameters();

    try {
        logger.info("");
        logger.info("STARTING BATCH JOB AT " + startDateTime);
        JobExecution execution = jobLauncher.run(demoJob, jobParameters);
        logger.info("JOB STATUS : " + execution.getStatus());
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("JOB FAILED!!!");
    }

}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JobLauncherCommandLineRunner.java   
private void executeRegisteredJobs(JobParameters jobParameters)
        throws JobExecutionException {
    if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) {
        String[] jobsToRun = this.jobNames.split(",");
        for (String jobName : jobsToRun) {
            try {
                Job job = this.jobRegistry.getJob(jobName);
                if (this.jobs.contains(job)) {
                    continue;
                }
                execute(job, jobParameters);
            }
            catch (NoSuchJobException ex) {
                logger.debug("No job found in registry for job name: " + jobName);
                continue;
            }
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:BatchAutoConfigurationTests.java   
@Test
public void testUsingJpa() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    // The order is very important here: DataSource -> Hibernate -> Batch
    this.context.register(TestConfiguration.class,
            EmbeddedDataSourceConfiguration.class,
            HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    PlatformTransactionManager transactionManager = this.context
            .getBean(PlatformTransactionManager.class);
    // It's a lazy proxy, but it does render its target if you ask for toString():
    assertThat(transactionManager.toString().contains("JpaTransactionManager"))
            .isTrue();
    assertThat(this.context.getBean(EntityManagerFactory.class)).isNotNull();
    // Ensure the JobRepository can be used (no problem with isolation level)
    assertThat(this.context.getBean(JobRepository.class).getLastJobExecution("job",
            new JobParameters())).isNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:BatchAutoConfigurationTests.java   
@Test
public void testRenamePrefix() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.name:batchtest",
            "spring.batch.schema:classpath:batch/custom-schema-hsql.sql",
            "spring.batch.tablePrefix:PREFIX_");
    this.context.register(TestConfiguration.class,
            EmbeddedDataSourceConfiguration.class,
            HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(JobLauncher.class)).isNotNull();
    assertThat(new JdbcTemplate(this.context.getBean(DataSource.class))
            .queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
    JobExplorer jobExplorer = this.context.getBean(JobExplorer.class);
    assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty();
    JobRepository jobRepository = this.context.getBean(JobRepository.class);
    assertThat(jobRepository.getLastJobExecution("test", new JobParameters()))
            .isNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JobLauncherCommandLineRunnerTests.java   
@Test
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
    this.job = this.jobs.get("job").preventRestart()
            .start(this.steps.get("step").tasklet(new Tasklet() {
                @Override
                public RepeatStatus execute(StepContribution contribution,
                        ChunkContext chunkContext) throws Exception {
                    throw new RuntimeException("Planned");
                }
            }).build()).incrementer(new RunIdIncrementer()).build();
    this.runner.execute(this.job, new JobParameters());
    this.runner.execute(this.job, new JobParameters());
    // A failed job that is not restartable does not re-use the job params of
    // the last execution, but creates a new job instance when running it again.
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JobLauncherCommandLineRunnerTests.java   
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
    this.job = this.jobs.get("job")
            .start(this.steps.get("step").tasklet(new Tasklet() {
                @Override
                public RepeatStatus execute(StepContribution contribution,
                        ChunkContext chunkContext) throws Exception {
                    throw new RuntimeException("Planned");
                }
            }).build()).incrementer(new RunIdIncrementer()).build();
    JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
            .addLong("foo", 2L, false).toJobParameters();
    this.runner.execute(this.job, jobParameters);
    this.runner.execute(this.job, jobParameters);
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
项目:spring-boot-concourse    文件:JobLauncherCommandLineRunner.java   
private void executeRegisteredJobs(JobParameters jobParameters)
        throws JobExecutionException {
    if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) {
        String[] jobsToRun = this.jobNames.split(",");
        for (String jobName : jobsToRun) {
            try {
                Job job = this.jobRegistry.getJob(jobName);
                if (this.jobs.contains(job)) {
                    continue;
                }
                execute(job, jobParameters);
            }
            catch (NoSuchJobException ex) {
                logger.debug("No job found in registry for job name: " + jobName);
                continue;
            }
        }
    }
}
项目:spring-boot-concourse    文件:BatchAutoConfigurationTests.java   
@Test
public void testUsingJpa() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    // The order is very important here: DataSource -> Hibernate -> Batch
    this.context.register(TestConfiguration.class,
            EmbeddedDataSourceConfiguration.class,
            HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    PlatformTransactionManager transactionManager = this.context
            .getBean(PlatformTransactionManager.class);
    // It's a lazy proxy, but it does render its target if you ask for toString():
    assertThat(transactionManager.toString().contains("JpaTransactionManager"))
            .isTrue();
    assertThat(this.context.getBean(EntityManagerFactory.class)).isNotNull();
    // Ensure the JobRepository can be used (no problem with isolation level)
    assertThat(this.context.getBean(JobRepository.class).getLastJobExecution("job",
            new JobParameters())).isNull();
}
项目:spring-boot-concourse    文件:BatchAutoConfigurationTests.java   
@Test
public void testRenamePrefix() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.name:batchtest",
            "spring.batch.schema:classpath:batch/custom-schema-hsql.sql",
            "spring.batch.tablePrefix:PREFIX_");
    this.context.register(TestConfiguration.class,
            EmbeddedDataSourceConfiguration.class,
            HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(JobLauncher.class)).isNotNull();
    assertThat(new JdbcTemplate(this.context.getBean(DataSource.class))
            .queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
    JobExplorer jobExplorer = this.context.getBean(JobExplorer.class);
    assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty();
    JobRepository jobRepository = this.context.getBean(JobRepository.class);
    assertThat(jobRepository.getLastJobExecution("test", new JobParameters()))
            .isNull();
}
项目:spring-boot-concourse    文件:JobLauncherCommandLineRunnerTests.java   
@Test
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
    this.job = this.jobs.get("job").preventRestart()
            .start(this.steps.get("step").tasklet(new Tasklet() {
                @Override
                public RepeatStatus execute(StepContribution contribution,
                        ChunkContext chunkContext) throws Exception {
                    throw new RuntimeException("Planned");
                }
            }).build()).incrementer(new RunIdIncrementer()).build();
    this.runner.execute(this.job, new JobParameters());
    this.runner.execute(this.job, new JobParameters());
    // A failed job that is not restartable does not re-use the job params of
    // the last execution, but creates a new job instance when running it again.
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
项目:spring-boot-concourse    文件:JobLauncherCommandLineRunnerTests.java   
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
    this.job = this.jobs.get("job")
            .start(this.steps.get("step").tasklet(new Tasklet() {
                @Override
                public RepeatStatus execute(StepContribution contribution,
                        ChunkContext chunkContext) throws Exception {
                    throw new RuntimeException("Planned");
                }
            }).build()).incrementer(new RunIdIncrementer()).build();
    JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
            .addLong("foo", 2L, false).toJobParameters();
    this.runner.execute(this.job, jobParameters);
    this.runner.execute(this.job, jobParameters);
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("multiResourceItemReaderJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("customReaderWriterProcesorJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("taskletJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("customListeners");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("flatFileItemWriterJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("parallelStepsJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("chunkJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("secuentialControlFlow");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("xmlReadersWritersJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Spring-Batch-en-Castellano    文件:Main.java   
public static void main(String[] args) {

        String[] springConfig = { "spring/batch/jobs/job-config.xml" };

        @SuppressWarnings("resource")
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

        JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("taskletJob");

        try {
            JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println("Exit Status : " + execution.getStatus());
            System.out.println("Exit Status : " + execution.getAllFailureExceptions());

        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("Done");

    }
项目:Camel    文件:SpringBatchProducer.java   
@Override
public void process(Exchange exchange) throws Exception {

    JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders());
    String messageJobName = jobParameters.getString(SpringBatchConstants.JOB_NAME);

    Job job2run = this.job;

    if (messageJobName != null) {
        job2run = CamelContextHelper.mandatoryLookup(getEndpoint().getCamelContext(), messageJobName, Job.class);
    }

    if (job2run == null) {
        exchange.setException(new CamelExchangeException("jobName was not specified in the endpoint construction "
                + " and header " + SpringBatchConstants.JOB_NAME + " could not be found", exchange));
        return;
    }

    JobExecution jobExecution = jobLauncher.run(job2run, jobParameters);
    exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
    exchange.getOut().setBody(jobExecution);
}
项目:Camel    文件:SpringBatchProducer.java   
/**
 * Helper method converting the Camel message headers into the Spring Batch parameters map. Date, Long and Double
 * header values are converted to the appropriate types. All the other header values are converted to string
 * representation.
 *
 * @param headers Camel message header to be converted
 * @return Camel message headers converted into the Spring Batch parameters map
 */
protected JobParameters prepareJobParameters(Map<String, Object> headers) {
    JobParametersBuilder parametersBuilder = new JobParametersBuilder();
    for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
        String headerKey = headerEntry.getKey();
        Object headerValue = headerEntry.getValue();
        if (headerValue instanceof Date) {
            parametersBuilder.addDate(headerKey, (Date) headerValue);
        } else if (headerValue instanceof Long) {
            parametersBuilder.addLong(headerKey, (Long) headerValue);
        } else if (headerValue instanceof Double) {
            parametersBuilder.addDouble(headerKey, (Double) headerValue);
        } else if (headerValue != null) {
            parametersBuilder.addString(headerKey, headerValue.toString());
        } else {
            // if the value is null we just put String with null value here to avoid the NPE
            parametersBuilder.addString(headerKey, null);
        }
    }
    JobParameters jobParameters = parametersBuilder.toJobParameters();
    log.debug("Prepared parameters for Spring Batch job: {}", jobParameters);
    return jobParameters;
}
项目:spring-cloud-dataflow    文件:JobCommandTests.java   
private static void createSampleJob(String jobName, int jobExecutionCount) {
    JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
    jobInstances.add(instance);
    TaskExecution taskExecution = dao.createTaskExecution(jobName, new Date(), new ArrayList<String>(), null);
    Map<String, JobParameter> jobParameterMap = new HashMap<>();
    jobParameterMap.put("foo", new JobParameter("FOO", true));
    jobParameterMap.put("bar", new JobParameter("BAR", false));
    JobParameters jobParameters = new JobParameters(jobParameterMap);
    JobExecution jobExecution = null;
    for (int i = 0; i < jobExecutionCount; i++) {
        jobExecution = jobRepository.createJobExecution(instance, jobParameters, null);
        taskBatchDao.saveRelationship(taskExecution, jobExecution);
        StepExecution stepExecution = new StepExecution("foobar", jobExecution);
        jobRepository.add(stepExecution);
    }
}
项目:spring-cloud-dataflow    文件:DataflowTemplateTests.java   
private void assertCorrectMixins(RestTemplate restTemplate) {
    boolean containsMappingJackson2HttpMessageConverter = false;

    for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) {
        if (converter instanceof MappingJackson2HttpMessageConverter) {
            containsMappingJackson2HttpMessageConverter = true;

            final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
            final ObjectMapper objectMapper = jacksonConverter.getObjectMapper();

            assertNotNull(objectMapper.findMixInClassFor(JobExecution.class));
            assertNotNull(objectMapper.findMixInClassFor(JobParameters.class));
            assertNotNull(objectMapper.findMixInClassFor(JobParameter.class));
            assertNotNull(objectMapper.findMixInClassFor(JobInstance.class));
            assertNotNull(objectMapper.findMixInClassFor(ExitStatus.class));
            assertNotNull(objectMapper.findMixInClassFor(StepExecution.class));
            assertNotNull(objectMapper.findMixInClassFor(ExecutionContext.class));
            assertNotNull(objectMapper.findMixInClassFor(StepExecutionHistory.class));
        }
    }

    if (!containsMappingJackson2HttpMessageConverter) {
        fail("Expected that the restTemplate's list of Message Converters contained a "
                + "MappingJackson2HttpMessageConverter");
    }
}
项目:contestparser    文件:JobLauncherCommandLineRunner.java   
private void executeRegisteredJobs(JobParameters jobParameters)
        throws JobExecutionException {
    if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) {
        String[] jobsToRun = this.jobNames.split(",");
        for (String jobName : jobsToRun) {
            try {
                Job job = this.jobRegistry.getJob(jobName);
                if (this.jobs.contains(job)) {
                    continue;
                }
                execute(job, jobParameters);
            }
            catch (NoSuchJobException nsje) {
                logger.debug("No job found in registry for job name: " + jobName);
                continue;
            }
        }
    }
}
项目:contestparser    文件:BatchAutoConfigurationTests.java   
@Test
public void testUsingJpa() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    // The order is very important here: DataSource -> Hibernate -> Batch
    this.context.register(TestConfiguration.class,
            EmbeddedDataSourceConfiguration.class,
            HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    PlatformTransactionManager transactionManager = this.context
            .getBean(PlatformTransactionManager.class);
    // It's a lazy proxy, but it does render its target if you ask for toString():
    assertTrue(transactionManager.toString().contains("JpaTransactionManager"));
    assertNotNull(this.context.getBean(EntityManagerFactory.class));
    // Ensure the JobRepository can be used (no problem with isolation level)
    assertNull(this.context.getBean(JobRepository.class).getLastJobExecution("job",
            new JobParameters()));
}
项目:contestparser    文件:JobLauncherCommandLineRunnerTests.java   
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
    this.job = this.jobs.get("job")
            .start(this.steps.get("step").tasklet(new Tasklet() {
                @Override
                public RepeatStatus execute(StepContribution contribution,
                        ChunkContext chunkContext) throws Exception {
                    throw new RuntimeException("Planned");
                }
            }).build()).incrementer(new RunIdIncrementer()).build();
    JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
            .addLong("foo", 2L, false).toJobParameters();
    this.runner.execute(this.job, jobParameters);
    this.runner.execute(this.job, jobParameters);
    assertEquals(1, this.jobExplorer.getJobInstances("job", 0, 100).size());
}
项目:powop    文件:FlatFileCreatorIntegrationTest.java   
@Test
public void testWriteChecklistPdf() throws Exception {
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("query", new JobParameter(""));
    parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae"));
    parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon))));
    parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".pdf"));
    parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString()));
    parameters.put("download.fieldsTerminatedBy", new JobParameter("\t"));
    parameters.put("download.fieldsEnclosedBy", new JobParameter("\""));
    parameters.put("download.sort", new JobParameter("searchable.label_sort_asc"));
    parameters.put("download.format", new JobParameter("hierarchicalChecklist"));
    parameters.put("download.template.filepath", new JobParameter("org/emonocot/job/download/reports/name_report1.jrxml"));

    JobParameters jobParameters = new JobParameters(parameters);
    Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation");
    assertNotNull("flatFileCreator Job must exist", archiveCreatorJob);
    JobExecution jobExecution = jobLauncher.run(archiveCreatorJob,
            jobParameters);

    assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
项目:powop    文件:PalmwebIntegrationTest.java   
@Test
public void testCreateGenericArchive() throws NoSuchJobException,
JobExecutionAlreadyRunningException, JobRestartException,
JobInstanceAlreadyCompleteException, JobParametersInvalidException, IOException {
    Map<String, JobParameter> parameters =
            new HashMap<String, JobParameter>();

    JobParameters jobParameters = new JobParameters(parameters);

    Job palmwebArchive = jobLocator.getJob("PalmWeb");
    assertNotNull("Palmweb must not be null",  palmwebArchive);
    JobExecution jobExecution = jobLauncher.run(palmwebArchive, jobParameters);
    assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED");
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        logger.info(stepExecution.getStepName() + " "
                + stepExecution.getReadCount() + " "
                + stepExecution.getFilterCount() + " "
                + stepExecution.getWriteCount() + " " + stepExecution.getCommitCount());
    }
}
项目:spring-cloud-task    文件:JobExecutionEventTests.java   
@Test
public void testJobParameters() {
    String[] JOB_PARAM_KEYS = {"A", "B", "C", "D"};
    Date testDate = new Date();
    JobParameter[] PARAMETERS = {new JobParameter("FOO", true), new JobParameter(1L, true),
            new JobParameter(1D, true), new JobParameter(testDate, false)};

    Map jobParamMap = new LinkedHashMap<>();
    for (int paramCount = 0; paramCount < JOB_PARAM_KEYS.length; paramCount++) {
        jobParamMap.put(JOB_PARAM_KEYS[paramCount], PARAMETERS[paramCount]);
    }
    jobParameters = new JobParameters(jobParamMap);
    JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters, JOB_CONFIGURATION_NAME);
    JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution);

    assertNotNull("Job Parameter A was expected", jobExecutionEvent.getJobParameters().getString("A"));
    assertNotNull("Job Parameter B was expected", jobExecutionEvent.getJobParameters().getLong("B"));
    assertNotNull("Job Parameter C was expected", jobExecutionEvent.getJobParameters().getDouble("C"));
    assertNotNull("Job Parameter D was expected", jobExecutionEvent.getJobParameters().getDate("D"));

    assertEquals("Job Parameter A value was not correct", "FOO", jobExecutionEvent.getJobParameters().getString("A"));
    assertEquals("Job Parameter B value was not correct", new Long(1), jobExecutionEvent.getJobParameters().getLong("B"));
    assertEquals("Job Parameter C value was not correct", new Double(1), jobExecutionEvent.getJobParameters().getDouble("C"));
    assertEquals("Job Parameter D value was not correct", testDate, jobExecutionEvent.getJobParameters().getDate("D"));
}
项目:eMonocot    文件:JobLauncherImpl.java   
@Override
public void launch(JobLaunchRequest request) {
    Job job;
    try {
        job = jobLocator.getJob(request.getJob());
        Map<String, JobParameter> jobParameterMap = new HashMap<String, JobParameter>();
        for(String parameterName : request.getParameters().keySet()) {
            jobParameterMap.put(parameterName, new JobParameter(request.getParameters().get(parameterName)));
        }
        JobParameters jobParameters = new JobParameters(jobParameterMap);
        try {
            jobLauncher.run(job, jobParameters);
        } catch (JobExecutionAlreadyRunningException jeare) {
            jobStatusNotifier.notify(new JobExecutionException(jeare.getLocalizedMessage()), request.getParameters().get("resource.identifier"));
        } catch (JobRestartException jre) {
            jobStatusNotifier.notify(new JobExecutionException(jre.getLocalizedMessage()), request.getParameters().get("resource.identifier"));
        } catch (JobInstanceAlreadyCompleteException jiace) {
            jobStatusNotifier.notify(new JobExecutionException(jiace.getLocalizedMessage()), request.getParameters().get("resource.identifier"));
        } catch (JobParametersInvalidException jpie) {
            jobStatusNotifier.notify(new JobExecutionException(jpie.getLocalizedMessage()), request.getParameters().get("resource.identifier"));
        }
    } catch (NoSuchJobException nsje) {
        jobStatusNotifier.notify(new JobExecutionException(nsje.getLocalizedMessage()), request.getParameters().get("resource.identifier"));
    }
}
项目:eMonocot    文件:FlatFileCreatorIntegrationTest.java   
/**
 * @throws Exception
 */
@Test
public void testWriteTaxonFile() throws Exception {
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("query", new JobParameter(""));
    parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae"));
    parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon))));
    parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".txt"));
    parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString()));
    parameters.put("download.fieldsTerminatedBy", new JobParameter("\t"));
    parameters.put("download.fieldsEnclosedBy", new JobParameter("\""));
    parameters.put("download.format", new JobParameter("taxon"));

    JobParameters jobParameters = new JobParameters(parameters);
    Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation");
    assertNotNull("flatFileCreatorJob must exist", archiveCreatorJob);
    JobExecution jobExecution = jobLauncher.run(archiveCreatorJob,
            jobParameters);

    assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
项目:eMonocot    文件:FlatFileCreatorIntegrationTest.java   
@Test
public void testWriteChecklistPdf() throws Exception {
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("query", new JobParameter(""));
    parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae"));
    parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon))));
    parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".pdf"));
    parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString()));
    parameters.put("download.fieldsTerminatedBy", new JobParameter("\t"));
    parameters.put("download.fieldsEnclosedBy", new JobParameter("\""));
    parameters.put("download.sort", new JobParameter("searchable.label_sort_asc"));
    parameters.put("download.format", new JobParameter("hierarchicalChecklist"));
    parameters.put("download.template.filepath", new JobParameter("org/emonocot/job/download/reports/name_report1.jrxml"));

    JobParameters jobParameters = new JobParameters(parameters);
    Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation");
    assertNotNull("flatFileCreator Job must exist", archiveCreatorJob);
    JobExecution jobExecution = jobLauncher.run(archiveCreatorJob,
            jobParameters);

    assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
项目:eMonocot    文件:ImageProcessingJobIntegrationTest.java   
/**
 *
 * @throws IOException
 *             if a temporary file cannot be created.
 * @throws NoSuchJobException
 *             if SpeciesPageHarvestingJob cannot be located
 * @throws JobParametersInvalidException
 *             if the job parameters are invalid
 * @throws JobInstanceAlreadyCompleteException
 *             if the job has already completed
 * @throws JobRestartException
 *             if the job cannot be restarted
 * @throws JobExecutionAlreadyRunningException
 *             if the job is already running
 */
@Test
public final void testNotModifiedResponse() throws IOException,
NoSuchJobException, JobExecutionAlreadyRunningException,
JobRestartException, JobInstanceAlreadyCompleteException,
JobParametersInvalidException {
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("query.string", new JobParameter("select i from Image i"));

    JobParameters jobParameters = new JobParameters(parameters);

    Job job = jobLocator.getJob("ImageProcessing");
    assertNotNull("ImageProcessing must not be null", job);
    JobExecution jobExecution = jobLauncher.run(job, jobParameters);
    assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED");

    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        logger.info(stepExecution.getStepName() + " "
                + stepExecution.getReadCount() + " "
                + stepExecution.getFilterCount() + " "
                + stepExecution.getWriteCount());
    }
}
项目:marklogic-spring-batch    文件:JobParametersAdapter.java   
@Override
public JobParameters unmarshal(AdaptedJobParameters params) throws Exception {
    JobParametersBuilder jobParametersBuilder  = new JobParametersBuilder();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
    for (AdaptedJobParameters.AdaptedJobParameter param : params.getParameters()) {
        switch (param.type) {
            case "STRING":
                jobParametersBuilder.addString(param.key, param.value, param.identifier);
                break;
            case "DATE":
                jobParametersBuilder.addDate(param.key, df.parse(param.value), param.identifier);
                break;
            case "DOUBLE":
                jobParametersBuilder.addDouble(param.key, Double.valueOf(param.value), param.identifier);
                break;
            case "LONG":
                jobParametersBuilder.addLong(param.key, Long.valueOf(param.value), param.identifier);
                break;
        }
    }
    return jobParametersBuilder.toJobParameters();
}
项目:marklogic-spring-batch    文件:JobParametersTestUtils.java   
public static JobParameters getJobParameters() {
    JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
    if (jobParameters.isEmpty()) {
        jobParametersBuilder.addLong("id", 1L, true);
        jobParametersBuilder.addString("stringTest", "Joe Cool", true);
        jobParametersBuilder.addDate("start", new Date(), false);
        jobParametersBuilder.addLong("longTest", 1239L, false);
        jobParametersBuilder.addDouble("doubleTest", 1.35D, false);
        jobParameters = jobParametersBuilder.toJobParameters();
    } else {
        JobParametersTestUtils utils = new JobParametersTestUtils();
        jobParameters = utils.getNext(jobParameters);
    }
    return jobParameters;

}