Package org.springframework.batch.item.file.transform

Examples of org.springframework.batch.item.file.transform.DelimitedLineTokenizer


  public void testLeads() throws Exception {

    FlatFileItemReader<FieldSet> reader = new FlatFileItemReader<FieldSet>();
    reader.setResource(new ClassPathResource("/data/test.txt"));
    DefaultLineMapper<FieldSet> lineMapper = new DefaultLineMapper<FieldSet>();
    lineMapper.setLineTokenizer(new DelimitedLineTokenizer());
    lineMapper.setFieldSetMapper(new PassThroughFieldSetMapper());
    reader.setLinesToSkip(1);
    final List<String> headers = new ArrayList<String>();
    reader.setSkippedLinesCallback(new LineCallbackHandler() {
      public void handleLine(String line) {
View Full Code Here


    tested.mapLine("foo", 1);
  }
 
  @Test(expected=IllegalArgumentException.class)
  public void testMandatoryMapper() throws Exception {
    tested.setLineTokenizer(new DelimitedLineTokenizer());
    tested.afterPropertiesSet();
    tested.mapLine("foo", 1);
  }
View Full Code Here

  private PatternMatchingCompositeLineMapper<Name> mapper = new PatternMatchingCompositeLineMapper<Name>();

  @Test(expected = IllegalArgumentException.class)
  public void testNoMappers() throws Exception {
    mapper.setTokenizers(Collections.singletonMap("", (LineTokenizer) new DelimitedLineTokenizer()));
    Map<String, FieldSetMapper<Name>> fieldSetMappers = Collections.emptyMap();
    mapper.setFieldSetMappers(fieldSetMappers);
    mapper.afterPropertiesSet();
  }
View Full Code Here

    protected TradeItemReader(Resource resource) throws Exception {
      super();
      setResource(resource);
      DefaultLineMapper<Trade> mapper = new DefaultLineMapper<Trade>();
      mapper.setLineTokenizer(new DelimitedLineTokenizer());
      mapper.setFieldSetMapper(new TradeMapper());
      setLineMapper(mapper);
      afterPropertiesSet();
    }
View Full Code Here

  @Test(expected = NotWritablePropertyException.class)
  public void testFuzzyMatchingWithKeyCandidateCollision() throws BindException {
    BeanWrapperFieldSetMapper<GreenBean> mapper = new BeanWrapperFieldSetMapper<GreenBean>();
    mapper.setStrict(true);
    mapper.setTargetType(GreenBean.class);
    DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
    String[] names = { "brown", "green", "great", "groin", "braun" };
    lineTokenizer.setNames(names);
    GreenBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("brown,green,great,groin,braun"));
    Assert.assertEquals("green", bean.getGreen());
  }
View Full Code Here

  public void testFuzzyMatchingWithLowerLimit() throws BindException {
    BeanWrapperFieldSetMapper<GreenBean> mapper = new BeanWrapperFieldSetMapper<GreenBean>();
    mapper.setDistanceLimit(0);
    mapper.setStrict(false);
    mapper.setTargetType(GreenBean.class);
    DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
    String[] names = { "brown", "green", "great", "groin", "braun" };
    lineTokenizer.setNames(names);
    GreenBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("brown,green,great,groin,braun"));
    Assert.assertEquals("green", bean.getGreen());
  }
View Full Code Here

  @Test
  public void testFuzzyMatchingWithPropertyCollision() throws BindException {
    BeanWrapperFieldSetMapper<BlueBean> mapper = new BeanWrapperFieldSetMapper<BlueBean>();
    mapper.setStrict(true);
    mapper.setTargetType(BlueBean.class);
    DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
    String[] names = { "blue" };
    lineTokenizer.setNames(names);
    BlueBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("blue"));
    // An exact match always wins...
    Assert.assertEquals("blue", bean.getBlue());
    Assert.assertEquals(null, bean.getBleu());
  }
View Full Code Here

  public void testConcurrentUsage() throws Exception {
    final BeanWrapperFieldSetMapper<GreenBean> mapper = new BeanWrapperFieldSetMapper<GreenBean>();
    mapper.setStrict(true);
    mapper.setTargetType(GreenBean.class);
    // mapper.setDistanceLimit(0);
    final DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
    String[] names = { "blue", "green" };
    lineTokenizer.setNames(names);

    ExecutorService executorService = Executors.newFixedThreadPool(5);
    Collection<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
    for (int i = 0; i < 10; i++) {
      Future<Boolean> result = executorService.submit(new Callable<Boolean>() {
                @Override
        public Boolean call() throws Exception {
          for (int i = 0; i < 10; i++) {
            GreenBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("blue,green"));
            Assert.assertEquals("green", bean.getGreen());
          }
          return true;
        }
      });
View Full Code Here

TOP

Related Classes of org.springframework.batch.item.file.transform.DelimitedLineTokenizer

Copyright © 2018 www.massapicom. 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.