/** * Test should read succesfully. * * @throws Exception */ @Test public void testSuccessfulReading() throws Exception { // init linetokenizer DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer(); lineTokenizer.setNames(new String[] {"id", "value"}); // init linemapper DefaultLineMapper<FieldSet> lineMapper = new DefaultLineMapper<FieldSet>(); lineMapper.setLineTokenizer(lineTokenizer); lineMapper.setFieldSetMapper(new PassThroughFieldSetMapper()); // init reader reader.setLineMapper(lineMapper); reader.setResource(new FileSystemResource(INPUT_FILE)); // open, provide "mock" ExecutionContext reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { int count = 0; FieldSet line; while ((line = reader.read()) != null) { // really test for the fieldSet names and values assertEquals("id", line.getNames()[0]); assertEquals(String.valueOf(count), line.getValues()[0]); assertEquals("value", line.getNames()[1]); // csv contains entry like '0,foo0' assertEquals("foo" + String.valueOf(count), line.getValues()[1]); count++; } assertEquals(EXPECTED_COUNT, count); } catch (Exception e) { throw e; } finally { reader.close(); } }
@Before public void setUp() { // Job 전체를 생성하지 않고, 특정 Step만을 Dummy로 생성하여 테스트 할 수 있다. stepExecution = MetaDataInstanceFactory.createStepExecution(); jobExecution = MetaDataInstanceFactory.createJobExecution(); decider = new NextDecider(); }
@Override protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) { JobParameters jobParameters = new JobParametersBuilder(super.getUniqueJobParameters()) .addString("input.file.path", "file:build/test-outputs/multiResourceOutput.csv.*") .toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); StepSynchronizationManager.close(); StepSynchronizationManager.register(stepExecution); }
/** * Read compressed test. * * @throws Exception */ @Test public void readCompressed() throws Exception { // setup the reader reader.setBufferedReaderFactory(new GZipBufferedReaderFactory()); reader.setLineMapper(new PassThroughLineMapper()); reader.setResource(new FileSystemResource(PATH_TO_COMPRESSED_TEST_FILE)); // open with dummy execution context reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { int count = 0; String line; while ((line = reader.read()) != null) { assertEquals(String.valueOf(count), line); count++; } assertEquals(count, EXPECTED_COUNT); } finally { reader.close(); } }