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

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


  public void testNumberFormatWithDefaultAndCustomEditor() throws Exception {

    BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
    mapper.setTargetType(TestObject.class);

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "9.876,1", "7,890.1" }, new String[] { "varDouble",
        "varFloat" });

    Map<Class<?>, PropertyEditor> editors = new HashMap<Class<?>, PropertyEditor>();
    editors.put(Double.TYPE, new CustomNumberEditor(Double.class, NumberFormat.getInstance(Locale.GERMAN), true));
    editors.put(Float.TYPE, new CustomNumberEditor(Float.class, NumberFormat.getInstance(Locale.UK), true));
View Full Code Here


  public void testBinderWithErrors() throws Exception {

    BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
    mapper.setTargetType(TestObject.class);

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "foo", "7890.1" }, new String[] { "varDouble",
        "varFloat" });
    try {
      mapper.mapFieldSet(fieldSet);
      fail("Expected BindException");
    }
View Full Code Here

            .getNumberInstance(Locale.GERMAN), true));
      }
    };
    mapper.setTargetType(TestTwoDoubles.class);

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "9.876,1", "7890.1" }, new String[] { "value", "other" });
    TestTwoDoubles bean = mapper.mapFieldSet(fieldSet);

    assertEquals(9876.1, bean.getValue(), 0.01);
    assertEquals(7890.1, bean.getOther(), 0.01);
  }
View Full Code Here

            .getNumberInstance(Locale.GERMAN), true));
      }
    };
    mapper.setTargetType(TestTwoDoubles.class);

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "9.876,1", "7890.1" }, new String[] { "value", "other" });
    TestTwoDoubles bean = mapper.mapFieldSet(fieldSet);

    assertEquals(9876.1, bean.getValue(), 0.01);
    assertEquals(7890.1, bean.getOther(), 0.01);
  }
View Full Code Here

    BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
    mapper.setStrict(true);
    mapper.setTargetType(TestObject.class);
    mapper.afterPropertiesSet();

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "This won't be mapped",
        "true", "C" }, new String[] { "varString", "illegalPropertyName", "varBoolean", "varChar" });
    try {
      mapper.mapFieldSet(fieldSet);
      fail("expected error");
    }
View Full Code Here

    BeanWrapperFieldSetMapper<TestObject> mapper = new BeanWrapperFieldSetMapper<TestObject>();
    mapper.setStrict(false);
    mapper.setTargetType(TestObject.class);
    mapper.afterPropertiesSet();

    FieldSet fieldSet = new DefaultFieldSet(new String[] { "This is some dummy string", "This won't be mapped",
        "true", "C" }, new String[] { "varString", "illegalPropertyName", "varBoolean", "varChar" });
    TestObject result = mapper.mapFieldSet(fieldSet);
    assertEquals("This is some dummy string", result.getVarString());
    assertEquals(true, result.isVarBoolean());
    assertEquals('C', result.getVarChar());
View Full Code Here

  }
 
  @Test
  public void testMapping() throws Exception {
    final String line = "TEST";
    final FieldSet fs = new DefaultFieldSet(new String[]{"token1", "token2"});
    final String item = "ITEM";
   
    LineTokenizer tokenizer = mock(LineTokenizer.class);
    when(tokenizer.tokenize(line)).thenReturn(fs);
   
View Full Code Here

  /**
   * Test method for
   * {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#mapFieldSet(org.springframework.batch.item.file.transform.FieldSet)}.
   */
  public void testMapLine() {
    FieldSet fieldSet = new DefaultFieldSet(new String[] { "foo", "bar" });
    assertEquals(fieldSet, mapper.mapFieldSet(fieldSet));
  }
View Full Code Here

   * need create mock objects for input source, mapper and validator.
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testNext() throws Exception {
    FieldSet headerFS = new DefaultFieldSet(new String[] { Order.LINE_ID_HEADER });
    FieldSet customerFS = new DefaultFieldSet(new String[] { Customer.LINE_ID_NON_BUSINESS_CUST });
    FieldSet billingFS = new DefaultFieldSet(new String[] { Address.LINE_ID_BILLING_ADDR });
    FieldSet shippingFS = new DefaultFieldSet(new String[] { Address.LINE_ID_SHIPPING_ADDR });
    FieldSet billingInfoFS = new DefaultFieldSet(new String[] { BillingInfo.LINE_ID_BILLING_INFO });
    FieldSet shippingInfoFS = new DefaultFieldSet(new String[] { ShippingInfo.LINE_ID_SHIPPING_INFO });
    FieldSet itemFS = new DefaultFieldSet(new String[] { LineItem.LINE_ID_ITEM });
    FieldSet footerFS = new DefaultFieldSet(new String[] { Order.LINE_ID_FOOTER, "100", "3", "3" }, new String[] {
        "ID", "TOTAL_PRICE", "TOTAL_LINE_ITEMS", "TOTAL_ITEMS" });

    when(input.read()).thenReturn(headerFS, customerFS, billingFS, shippingFS, billingInfoFS,
        shippingInfoFS, itemFS, itemFS, itemFS, footerFS, null);

View Full Code Here

  @Override
  public FieldSet tokenize(String line) {
   
    if(line.charAt(0) == 'F'){
      //line starts with F, so the footer tokenizer should tokenize it.
      FieldSet fs = footerTokenizer.tokenize(line);
      long customerUpdateTotal = stepExecution.getReadCount();
      long fileUpdateTotal = fs.readLong(1);
      if(customerUpdateTotal != fileUpdateTotal){
        throw new IllegalStateException("The total number of customer updates in the file footer does not match the " +
            "number entered  File footer total: [" + fileUpdateTotal + "] Total encountered during processing: [" +
            customerUpdateTotal + "]");
      }
View Full Code Here

TOP

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

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.