Examples of JobParametersBuilder


Examples of org.springframework.batch.core.JobParametersBuilder

  }

  @Test
  public void testFileSent() throws Exception {

    JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("time.stamp",
        System.currentTimeMillis()).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    // 2 chunks sent to channel (5 items and commit-interval=3)
    assertEquals(2, count);
  }
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

  }

  @Test
  public void testLaunchFailedJob() throws Exception {
    tasklet.setFail(true);
    JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addLong("run.id", 2L).toJobParameters());
    assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
    assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus());
  }
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

    assertEquals(9, stepExecution.getWriteCount());
  }

  @Test
  public void testSkipsInWriter() throws Exception {
    JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("item.three", "fail")
        .addLong("run.id", 1L).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
    assertEquals(9, stepExecution.getReadCount());
    assertEquals(7, stepExecution.getWriteCount());
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

  @SuppressWarnings("unchecked")
  @Test
  @DirtiesContext
  public void testReply() {
    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("dontclash", "12");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(MessageHeaders.REPLY_CHANNEL, "response");
    MessageHeaders headers = new MessageHeaders(map);
    GenericMessage<JobLaunchRequest> trigger = new GenericMessage<JobLaunchRequest>(new JobLaunchRequest(job,
        builder.toJobParameters()), headers);
    requestChannel.send(trigger);
    Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);

    assertNotNull("No response received", executionMessage);
    JobExecution execution = executionMessage.getPayload();
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

  @SuppressWarnings("unchecked")
  @Test
  @DirtiesContext
  public void testReply() {
    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("dontclash", "12");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(MessageHeaders.REPLY_CHANNEL, "response");
    MessageHeaders headers = new MessageHeaders(map);
    GenericMessage<JobLaunchRequest> trigger = new GenericMessage<JobLaunchRequest>(new JobLaunchRequest(job,
        builder.toJobParameters()), headers);
    requestChannel.send(trigger);
    Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);

    assertNotNull("No response received", executionMessage);
    JobExecution execution = executionMessage.getPayload();
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

  @SuppressWarnings("unchecked")
  public void testExceptionRaised() throws InterruptedException {

    this.tasklet.setFail(true);

    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("dontclash", "12");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(MessageHeaders.REPLY_CHANNEL, "response");
    MessageHeaders headers = new MessageHeaders(map);
    GenericMessage<JobLaunchRequest> trigger = new GenericMessage<JobLaunchRequest>(new JobLaunchRequest(testJob,
        builder.toJobParameters()), headers);
    requestChannel.send(trigger);

    Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);

    assertNotNull("No response received", executionMessage);
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

  private StepExecution getStepExecution(Step step) throws JobExecutionAlreadyRunningException, JobRestartException,
  JobInstanceAlreadyCompleteException {
    SimpleJob job = new SimpleJob();
    job.setName("job");
    JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParametersBuilder().addLong(
        "job.counter", jobCounter++).toJobParameters());
    StepExecution stepExecution = jobExecution.createStepExecution(step.getName());
    jobRepository.add(stepExecution);
    return stepExecution;
  }
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

    assertEquals(9, stepExecution.getWriteCount());
  }

  @Test
  public void testSkipsInWriter() throws Exception {
    JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("item.three", "fail")
        .addLong("run.id", 1L).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
    assertEquals(9, stepExecution.getReadCount());
    assertEquals(7, stepExecution.getWriteCount());
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

  }

  @Test
  public void testFileSent() throws Exception {

    JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("time.stamp",
        System.currentTimeMillis()).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    // 2 chunks sent to channel (5 items and commit-interval=3)
    assertEquals(2, count);
  }
View Full Code Here

Examples of org.springframework.batch.core.JobParametersBuilder

    if (props == null || props.isEmpty()) {
      return new JobParameters();
    }

    JobParametersBuilder propertiesBuilder = new JobParametersBuilder();

    for (Iterator<Entry<Object, Object>> it = props.entrySet().iterator(); it.hasNext();) {
      Entry<Object, Object> entry = it.next();
      String key = (String) entry.getKey();
      String value = (String) entry.getValue();

      boolean identifying = isIdentifyingKey(key);
      if(!identifying) {
        key = key.replaceFirst(NON_IDENTIFYING_FLAG, "");
      } else if(identifying && key.startsWith(IDENTIFYING_FLAG)) {
        key = key.replaceFirst("\\" + IDENTIFYING_FLAG, "");
      }

      if (key.endsWith(DATE_TYPE)) {
        Date date;
        synchronized (dateFormat) {
          try {
            date = dateFormat.parse(value);
          }
          catch (ParseException ex) {
            String suffix = (dateFormat instanceof SimpleDateFormat) ? ", use "
                + ((SimpleDateFormat) dateFormat).toPattern() : "";
                throw new IllegalArgumentException("Date format is invalid: [" + value + "]" + suffix);
          }
        }
        propertiesBuilder.addDate(StringUtils.replace(key, DATE_TYPE, ""), date, identifying);
      }
      else if (key.endsWith(LONG_TYPE)) {
        Long result;
        try {
          result = (Long) parseNumber(value);
        }
        catch (ClassCastException ex) {
          throw new IllegalArgumentException("Number format is invalid for long value: [" + value
              + "], use a format with no decimal places");
        }
        propertiesBuilder.addLong(StringUtils.replace(key, LONG_TYPE, ""), result, identifying);
      }
      else if (key.endsWith(DOUBLE_TYPE)) {
        Double result = parseNumber(value).doubleValue();
        propertiesBuilder.addDouble(StringUtils.replace(key, DOUBLE_TYPE, ""), result, identifying);
      }
      else if (StringUtils.endsWithIgnoreCase(key, STRING_TYPE)) {
        propertiesBuilder.addString(StringUtils.replace(key, STRING_TYPE, ""), value, identifying);
      }
      else {
        propertiesBuilder.addString(key, value, identifying);
      }
    }

    return propertiesBuilder.toJobParameters();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.