PageRenderTime 34ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/test/org/beanio/spring/BeanIOFlatFileItemReaderTest.java

http://beanio.googlecode.com/
Java | 63 lines | 36 code | 7 blank | 20 comment | 0 complexity | 6c77c014f01bb2227e0f9fc5a2323bf8 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Copyright 2011 Kevin Seim
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.beanio.spring;
  17. import static org.junit.Assert.*;
  18. import org.junit.Test;
  19. import org.springframework.batch.item.*;
  20. import org.springframework.core.io.ClassPathResource;
  21. /**
  22. * JUnit test cases for the {@link BeanIOFlatFileItemReader} class.
  23. * @author Kevin Seim
  24. * @since 1.2
  25. */
  26. public class BeanIOFlatFileItemReaderTest {
  27. @Test
  28. public void testInputFileNotFound() throws Exception {
  29. BeanIOFlatFileItemReader<Object> reader = new BeanIOFlatFileItemReader<Object>();
  30. reader.setStrict(false);
  31. reader.setStreamName("stream1");
  32. reader.setStreamMapping(new ClassPathResource("spring_mapping1.xml", getClass()));
  33. reader.setResource(new ClassPathResource("doesnotexist.txt", getClass()));
  34. reader.afterPropertiesSet();
  35. ExecutionContext ctx = new ExecutionContext();
  36. reader.open(ctx);
  37. assertNull(reader.read());
  38. }
  39. @Test(expected=ItemStreamException.class)
  40. public void testInputFileNotFoundAndStrict() throws Exception {
  41. BeanIOFlatFileItemReader<Object> reader = new BeanIOFlatFileItemReader<Object>();
  42. reader.setStreamName("stream1");
  43. reader.setStreamMapping(new ClassPathResource("spring_mapping1.xml", getClass()));
  44. reader.setResource(new ClassPathResource("doesnotexist.txt", getClass()));
  45. reader.afterPropertiesSet();
  46. reader.open(new ExecutionContext());
  47. }
  48. @Test(expected=IllegalStateException.class)
  49. public void testInvalidStreamName() throws Exception {
  50. BeanIOFlatFileItemReader<Object> reader = new BeanIOFlatFileItemReader<Object>();
  51. reader.setStreamName("xxx");
  52. reader.setStreamMapping(new ClassPathResource("spring_mapping1.xml", getClass()));
  53. reader.setResource(new ClassPathResource("doesnotexist.txt", getClass()));
  54. reader.afterPropertiesSet();
  55. }
  56. }