List of usage examples for org.springframework.batch.test MetaDataInstanceFactory createStepExecution
public static StepExecution createStepExecution()
From source file:uk.ac.ebi.eva.pipeline.io.readers.NonAnnotatedVariantsMongoReaderTest.java
@Test public void shouldReadVariantsWithoutAnnotationField() throws Exception { ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext(); insertDocuments();//from w w w . j a v a 2 s.co m NonAnnotatedVariantsMongoReader mongoItemReader = new NonAnnotatedVariantsMongoReader( jobOptions.getPipelineOptions()); mongoItemReader.open(executionContext); int itemCount = 0; DBObject doc; while ((doc = mongoItemReader.read()) != null) { itemCount++; assertTrue(doc.containsField(DOC_CHR)); assertTrue(doc.containsField(DOC_START)); assertFalse(doc.containsField(DOC_ANNOT)); } assertEquals(itemCount, 1); mongoItemReader.close(); }
From source file:de.langmi.spring.batch.examples.readers.file.csv.CsvFlatFileItemReaderTest.java
/** * Test should read succesfully./*from w w w .ja v a 2 s. c o m*/ * * @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(); } }
From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReaderTest.java
/** * Test with one ZIP file containing two text files with 20 lines each. * One file is a .csv, the other a .txt, only the .csv should be used. * * @throws Exception /*from w w w . j ava 2s. c om*/ */ @Test public void testOneZipFileWithFilter() throws Exception { LOG.debug("testOneZipFileWithFilter"); ArchiveMultiResourceItemReader<String> mReader = new ArchiveMultiResourceItemReader<String>(); // setup multResourceReader // zip file contains 2 files, one with suffix .csv, which contains 20 lines mReader.setArchives(new Resource[] { new FileSystemResource("src/test/resources/input/file/archive/input-mixed-files.zip") }); // setup filter DefaultArchiveFileNameFilter fileNameFilter = new DefaultArchiveFileNameFilter(); fileNameFilter.setSuffixes(new String[] { ".csv" }); mReader.setFilenameFilter(fileNameFilter); // call general setup last, includes call to afterPropertiesSet generalMultiResourceReaderWithFilterSetup(mReader, fileNameFilter); // open with mock context mReader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { String item = null; int count = 0; do { item = mReader.read(); if (item != null) { assertEquals(String.valueOf(count), item); count++; } } while (item != null); assertEquals(20, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }
From source file:uk.ac.ebi.eva.pipeline.io.readers.AnnotationFlatFileReaderTest.java
@Test(expected = FlatFileParseException.class) public void malformedCoordinatesAnnotationLinesShouldBeSkipped() throws Exception { ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext(); File file = JobTestUtils.makeGzipFile(VepOutputContent.vepOutputContentMalformedCoordinates); AnnotationFlatFileReader annotationFlatFileReader = new AnnotationFlatFileReader(file); annotationFlatFileReader.open(executionContext); annotationFlatFileReader.read();//from ww w . j a va2s . c o m }
From source file:de.langmi.spring.batch.examples.readers.jdbc.JdbcPagingItemReaderTests.java
@Test public void testWithoutFactory() throws Exception { // setup queryProvider HsqlPagingQueryProvider queryProvider = new HsqlPagingQueryProvider(); queryProvider.setSelectClause("select ID, NAME"); queryProvider.setFromClause("from TEST"); queryProvider.setWhereClause("where NAME <> 'foo'"); queryProvider.setSortKey("ID"); // call init to imitate spring context startup behaviour queryProvider.init(dataSource);/*w w w .ja v a 2s.c om*/ // setup reader JdbcPagingItemReader<String> reader = new JdbcPagingItemReader<String>(); reader.setDataSource(dataSource); reader.setQueryProvider(queryProvider); reader.setRowMapper(new ParameterizedRowMapper<String>() { @Override public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString("NAME"); } }); reader.setPageSize(2); // needed call, normally done at spring application context startup reader.afterPropertiesSet(); reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { int count = 0; String line; while ((line = reader.read()) != null) { assertEquals(String.valueOf(count), line); count++; } assertEquals(EXPECTED_COUNT, count); } catch (Exception e) { throw e; } finally { reader.close(); } }
From source file:de.langmi.spring.batch.examples.readers.file.peekable.SimplePeekableItemReaderTest.java
/** * Test should read succesfully./*w ww . j a v a 2 s . c o m*/ * * @throws Exception */ @Test public void testSuccessfulReading() throws Exception { // init delegate delegateReader.setLineMapper(new PassThroughLineMapper()); delegateReader.setResource(new FileSystemResource(INPUT_FILE)); // init peekable SingleItemPeekableItemReader<String> peekable = new SingleItemPeekableItemReader<String>(); peekable.setDelegate(delegateReader); // open, provide "mock" ExecutionContext peekable.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { int count = 0; String line; while ((line = peekable.read()) != null) { assertEquals(String.valueOf(count), line); count++; } assertEquals(EXPECTED_COUNT, count); } catch (Exception e) { throw e; } finally { peekable.close(); } }
From source file:uk.ac.ebi.eva.pipeline.io.readers.AnnotationFlatFileReaderTest.java
@Test(expected = FlatFileParseException.class) public void malformedVariantFieldsAnnotationLinesShouldBeSkipped() throws Exception { ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext(); File file = JobTestUtils.makeGzipFile(VepOutputContent.vepOutputContentMalformedVariantFields); AnnotationFlatFileReader annotationFlatFileReader = new AnnotationFlatFileReader(file); annotationFlatFileReader.open(executionContext); annotationFlatFileReader.read();// w ww.j av a 2s .c om }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReaderTest.java
/** * Test with zip file with nested directories, contains 4 text files with * 20 lines each./*from ww w .j av a 2 s. c o m*/ * * @throws Exception */ @Test public void testOneZipFileNestedDirs() throws Exception { LOG.debug("testOneZipFileNestedDirs"); ZipMultiResourceItemReader<String> mReader = new ZipMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource(ZIP_INPUT_NESTED_DIRS) }); // call general setup last generalMultiResourceReaderSetup(mReader); // open with mock context mReader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { String item = null; int count = 0; do { item = mReader.read(); if (item != null) { count++; } } while (item != null); assertEquals(80, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }
From source file:de.langmi.spring.batch.examples.readers.support.CompositeItemStreamReaderTest.java
@Test public void testRead() throws Exception { // setup composite reader reader.setUnifyingMapper(new DefaultUnifyingStringItemsMapper()); reader.setItemReaderStreams(new ArrayList<ItemStreamReader<?>>() { {//ww w .j av a2s.c o m add(createFlatFileItemReader(INPUT_FILE_1)); add(createFlatFileItemReader(INPUT_FILE_2)); } }); // open, provide "mock" ExecutionContext reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { int count = 0; String line; while ((line = reader.read()) != null) { assertEquals(String.valueOf(count) + String.valueOf(count), line); count++; } assertEquals(EXPECTED_COUNT, count); } catch (Exception e) { throw e; } finally { reader.close(); } }
From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReaderTest.java
/** * Test with one ZIP file containing one text file with 20 lines. * * @throws Exception /*from ww w . ja v a2s .c o m*/ */ @Test public void testOneZipFile() throws Exception { LOG.debug("testOneZipFile"); ArchiveMultiResourceItemReader<String> mReader = new ArchiveMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives( new Resource[] { new FileSystemResource("src/test/resources/input/file/archive/input.txt.zip") }); // call general setup last generalMultiResourceReaderSetup(mReader); // open with mock context mReader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { String item = null; int count = 0; do { item = mReader.read(); if (item != null) { assertEquals(String.valueOf(count), item); count++; } } while (item != null); assertEquals(20, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }