org.springframework.batch.item.UnexpectedInputException Java Examples

The following examples show how to use org.springframework.batch.item.UnexpectedInputException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LecturerMappingReaderTest.java    From olat with Apache License 2.0 9 votes vote down vote up
@Test
public void read_twoLecturersList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    List<Lecturer> twoLecturersList = new ArrayList<Lecturer>();
    Lecturer lecturerMock1 = mock(Lecturer.class);
    Lecturer lecturerMock2 = mock(Lecturer.class);
    twoLecturersList.add(lecturerMock1);
    twoLecturersList.add(lecturerMock2);
    when(daoManagerMock.getAllLecturers()).thenReturn(twoLecturersList);
    lecturerMappingReaderTestObject.init();
    // The first read delivers the first lecturer
    assertNotNull(lecturerMappingReaderTestObject.read());
    // The second read delivers the second lecturer
    assertNotNull(lecturerMappingReaderTestObject.read());
    // The third read delivers null
    assertNull(lecturerMappingReaderTestObject.read());
}
 
Example #2
Source File: SeedMultiResourceItemReader.java    From seed with Apache License 2.0 6 votes vote down vote up
/**
 * Reads the next item, jumping to next resource if necessary.
 */
@Override
public T read() throws Exception, UnexpectedInputException, ParseException {

    if (noInput) {
        return null;
    }

    // If there is no resource, then this is the first item, set the current
    // resource to 0 and open the first delegate.
    if (currentResource == -1) {
        currentResource = 0;
        delegate.setResource(resources[currentResource]);
        delegate.open(new ExecutionContext());
    }

    return readNextItem();
}
 
Example #3
Source File: SynchronizationReaderTest.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void read_twoCoursesList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    when(daoManagerMock.chekImportedData()).thenReturn(true);
    List<Long> CreatedSapCourcesIds = new ArrayList<Long>();
    CreatedSapCourcesIds.add(100L);
    CreatedSapCourcesIds.add(200L);
    when(daoManagerMock.getAllCreatedSapCourcesIds()).thenReturn(CreatedSapCourcesIds);

    CampusCourseImportTO courseMock1 = mock(CampusCourseImportTO.class);
    CampusCourseImportTO courseMock2 = mock(CampusCourseImportTO.class);
    when(daoManagerMock.getSapCampusCourse(100L)).thenReturn(courseMock1);
    when(daoManagerMock.getSapCampusCourse(200L)).thenReturn(courseMock2);

    synchronizationReaderTestObject.init();
    // The first read delivers the first course
    assertNotNull(synchronizationReaderTestObject.read());
    // The second read delivers the second course
    assertNotNull(synchronizationReaderTestObject.read());
    // The third read delivers null
    assertNull(synchronizationReaderTestObject.read());
}
 
Example #4
Source File: StudentMappingReaderTest.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void read_twoStudentsList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    List<Student> twoStudentsList = new ArrayList<Student>();
    Student studentMock1 = mock(Student.class);
    Student studentMock2 = mock(Student.class);
    twoStudentsList.add(studentMock1);
    twoStudentsList.add(studentMock2);
    when(daoManagerMock.getAllStudents()).thenReturn(twoStudentsList);
    studentMappingReaderTestObject.init();
    // The first read delivers the first student
    assertNotNull(studentMappingReaderTestObject.read());
    // The second read delivers the second student
    assertNotNull(studentMappingReaderTestObject.read());
    // The third read delivers null
    assertNull(studentMappingReaderTestObject.read());
}
 
Example #5
Source File: MetricsTestItemReader.java    From spring-boot-starter-batch-web with Apache License 2.0 6 votes vote down vote up
@Override
public Item read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
	if (readerTransactional) {
		businessMetrics.increment(MetricNames.READ_COUNT.getName());
		businessMetrics.submit(MetricNames.READ_GAUGE.getName(), 5);
	} else {
		businessMetrics.incrementNonTransactional(MetricNames.READ_COUNT.getName());
		businessMetrics.submitNonTransactional(MetricNames.READ_GAUGE.getName(), 5);
	}
	Item item = delegate.read();
	if (item != null && item.getActions().contains(Action.FAIL_ON_READ)) {
		throw new MetricsTestException(Action.FAIL_ON_READ);
	}
	LOGGER.debug("Read item: {}", item);
	return item;
}
 
Example #6
Source File: SkipItemReader.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public Object read() throws Exception, UnexpectedInputException, ParseException,
		NonTransientResourceException {
	String result = "1";
	if (this.failCount < 2) {
		this.failCount++;
		throw new IllegalStateException("Reader FOOBAR");
	}
	if (this.finished) {
		result = null;
	}
	this.finished = true;
	return result;
}
 
Example #7
Source File: HelloWorldReader.java    From blog with MIT License 5 votes vote down vote up
public Object read() throws Exception, UnexpectedInputException,
        ParseException {
    Object o = null;
    if (executionTimes > 0) {
        executionTimes--;
        o = new Object();
    }
    return o;
}
 
Example #8
Source File: SpringBatchConfig.java    From tutorials with MIT License 5 votes vote down vote up
public ItemReader<Transaction> itemReader(Resource inputData) throws UnexpectedInputException, ParseException {
    FlatFileItemReader<Transaction> reader = new FlatFileItemReader<>();
    DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
    String[] tokens = {"username", "userid", "transactiondate", "amount"};
    tokenizer.setNames(tokens);
    reader.setResource(inputData);
    DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<>();
    lineMapper.setLineTokenizer(tokenizer);
    lineMapper.setFieldSetMapper(new RecordFieldSetMapper());
    reader.setLinesToSkip(1);
    reader.setLineMapper(lineMapper);
    return reader;
}
 
Example #9
Source File: SpringbatchPartitionConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
@StepScope
public FlatFileItemReader<Transaction> itemReader(@Value("#{stepExecutionContext[fileName]}") String filename) throws UnexpectedInputException, ParseException {
    FlatFileItemReader<Transaction> reader = new FlatFileItemReader<>();
    DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
    String[] tokens = {"username", "userid", "transactiondate", "amount"};
    tokenizer.setNames(tokens);
    reader.setResource(new ClassPathResource("input/partitioner/" + filename));
    DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<>();
    lineMapper.setLineTokenizer(tokenizer);
    lineMapper.setFieldSetMapper(new RecordFieldSetMapper());
    reader.setLinesToSkip(1);
    reader.setLineMapper(lineMapper);
    return reader;
}
 
Example #10
Source File: SpringbatchPartitionConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public Step slaveStep() throws UnexpectedInputException, MalformedURLException, ParseException {
    return steps.get("slaveStep")
      .<Transaction, Transaction>chunk(1)
      .reader(itemReader(null))
      .writer(itemWriter(marshaller(), null))
      .build();
}
 
Example #11
Source File: SpringbatchPartitionConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public Step partitionStep() throws UnexpectedInputException, MalformedURLException, ParseException {
    return steps.get("partitionStep")
      .partitioner("slaveStep", partitioner())
      .step(slaveStep())
      .taskExecutor(taskExecutor())
      .build();
}
 
Example #12
Source File: SynchronizationReader.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a {@link CampusCourseImportTo} via the {@link DaoManager} with the given course id from the list of the sapCoursesIds. <br>
 * It returns null at the end of the list of the sapCoursesIds
 */
public CampusCourseImportTO read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
    if (ListUtil.isNotBlank(sapCoursesIds)) {
        return daoManager.getSapCampusCourse(sapCoursesIds.remove(0));
    }
    return null;
}
 
Example #13
Source File: LecturerMappingReaderTest.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void read_emptyLecturersList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    when(daoManagerMock.getAllLecturers()).thenReturn(Collections.emptyList());
    lecturerMappingReaderTestObject.init();
    assertNull(lecturerMappingReaderTestObject.read());
}
 
Example #14
Source File: AgentCountReader.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public ApplicationAgentsList read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
    return queue.poll();
}
 
Example #15
Source File: LecturerMappingReaderTest.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void read_nullLecturersList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    when(daoManagerMock.getAllLecturers()).thenReturn(null);
    lecturerMappingReaderTestObject.init();
    assertNull(lecturerMappingReaderTestObject.read());
}
 
Example #16
Source File: SpringbatchPartitionConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean(name = "partitionerJob")
public Job partitionerJob() throws UnexpectedInputException, MalformedURLException, ParseException {
    return jobs.get("partitionerJob")
      .start(partitionStep())
      .build();
}
 
Example #17
Source File: StudentMappingReaderTest.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void read_emptyStudentsList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    when(daoManagerMock.getAllStudents()).thenReturn(Collections.emptyList());
    studentMappingReaderTestObject.init();
    assertNull(studentMappingReaderTestObject.read());
}
 
Example #18
Source File: StudentMappingReaderTest.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void read_nullStudentsList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    when(daoManagerMock.getAllStudents()).thenReturn(null);
    studentMappingReaderTestObject.init();
    assertNull(studentMappingReaderTestObject.read());
}
 
Example #19
Source File: SynchronizationReaderTest.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void read_emptyCoursesList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    when(daoManagerMock.getAllCreatedSapCources()).thenReturn(Collections.emptyList());
    synchronizationReaderTestObject.init();
    assertNull(synchronizationReaderTestObject.read());
}
 
Example #20
Source File: SynchronizationReaderTest.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void read_nullCoursesList() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
    when(daoManagerMock.getAllCreatedSapCources()).thenReturn(null);
    synchronizationReaderTestObject.init();
    assertNull(synchronizationReaderTestObject.read());
}