List of usage examples for org.springframework.batch.test MetaDataInstanceFactory createStepExecution
public static StepExecution createStepExecution()
From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java
@Test public void testRead() throws Exception { // setup composite reader reader.setUnifyingMapper(new DefaultUnifyingStringItemsMapper()); reader.setCursorItemReaders(new ArrayList<AbstractCursorItemReader<?>>() { {/* w w w . ja va 2s.c o m*/ add(createJdbcCursorItemReader(dataSource1, "readerName1")); add(createJdbcCursorItemReader(dataSource2, "readerName2")); } }); // 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.zip.ZipMultiResourceItemReaderTest.java
/** * Test with multiple zip files, together they contain 6 text files with 20 * lines each./*from w w w. j ava2s . c o m*/ * * @throws Exception */ @Test public void testMultipleZipFiles() throws Exception { LOG.debug("testMultipleTarFiles"); ZipMultiResourceItemReader<String> mReader = new ZipMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource(ZIP_INPUT_MULTIPLE_FILES), new FileSystemResource(ZIP_INPUT_SINGLE_FILE), 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(140, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }
From source file:de.langmi.spring.batch.examples.readers.jdbc.JdbcPagingItemReaderTests.java
@Test public void testWithFactory() throws Exception { // setup queryProviderFactory SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean(); factory.setDataSource(dataSource);// w w w . ja v a 2 s .c o m factory.setDatabaseType("HSQL"); factory.setSelectClause("select ID, NAME"); factory.setFromClause("from TEST"); factory.setWhereClause("where NAME <> 'foo'"); factory.setSortKey("ID"); PagingQueryProvider queryProvider = (PagingQueryProvider) factory.getObject(); // call init to imitate spring context startup behaviour queryProvider.init(dataSource); // 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.archive.ArchiveMultiResourceItemReaderTest.java
/** * Test with tar file with nested directories, contains 4 text files with * 20 lines each.//from w w w . j a v a2 s .c o m * * @throws Exception */ @Test public void testOneTarFileNestedDirs() throws Exception { LOG.debug("testOneTarFileNestedDirs"); ArchiveMultiResourceItemReader<String> mReader = new ArchiveMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource("src/test/resources/input/file/archive/input_nested_dir.tar") }); // 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.file.archive.ArchiveMultiResourceItemReaderTest.java
/** * Test with tar file which contains 2 text files, with 20 lines each. * //from www . j a va 2 s .com * @throws Exception */ @Test public void testOneTarFile() throws Exception { LOG.debug("testOneTarFile"); ArchiveMultiResourceItemReader<String> mReader = new ArchiveMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives( new Resource[] { new FileSystemResource("src/test/resources/input/file/archive/input.tar") }); // 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(40, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }
From source file:de.langmi.spring.batch.examples.complex.aggregating.writer.AggregatingSimpleItemsWriterTest.java
/** * Test Initialization, prepares the writer under test. * @throws Exception /*from w w w . j av a 2 s . co m*/ */ @Before public void before() throws Exception { writer = new AggregateSimpleItemsWriter(); // delegate delegate = new TestItemWriter(); writer.setDelegate(delegate); // dummy stepExecutionContext stepExecution = MetaDataInstanceFactory.createStepExecution(); writer.beforeStep(stepExecution); }
From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReaderTest.java
/** * Test with tar file which contains 2 text files, with 20 lines each. * // w w w. j ava2 s . co m * @throws Exception */ @Test public void testOneGzippedTarFile() throws Exception { LOG.debug("testOneGzippedTarFile"); ArchiveMultiResourceItemReader<String> mReader = new ArchiveMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource("src/test/resources/input/file/archive/input_nested_dir.tar.gz") }); // 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.file.archive.ArchiveMultiResourceItemReaderTest.java
/** * Test with multiple tar files, together they contain 6 text files with 20 * lines each./*from w w w . j a va 2 s . co m*/ * * @throws Exception */ @Test public void testMultipleTarFiles() throws Exception { LOG.debug("testMultipleTarFiles"); ArchiveMultiResourceItemReader<String> mReader = new ArchiveMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource("src/test/resources/input/file/archive/input_nested_dir.tar"), new FileSystemResource("src/test/resources/input/file/archive/input.tar") }); // 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(120, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }