List of usage examples for org.springframework.batch.item UnexpectedInputException UnexpectedInputException
public UnexpectedInputException(String message)
From source file:org.springframework.batch.item.xml.StaxEventItemWriterTests.java
@Test public void testTransactionalRestartFailOnFirstWrite() throws Exception { PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); writer.open(executionContext);/*from w w w . j av a 2 s.com*/ try { new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { try { writer.write(items); } catch (Exception e) { throw new IllegalStateException("Could not write data", e); } throw new UnexpectedInputException("Could not write data"); } }); } catch (UnexpectedInputException e) { // expected } writer.close(); String outputFile = getOutputFileContent(); assertEquals("<root></root>", outputFile); // create new writer from saved restart data and continue writing writer = createItemWriter(); new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { writer.open(executionContext); try { writer.write(items); } catch (Exception e) { throw new UnexpectedInputException("Could not write data", e); } // get restart data writer.update(executionContext); return null; } }); writer.close(); // check the output is concatenation of 'before restart' and 'after // restart' writes. outputFile = getOutputFileContent(); assertEquals(1, StringUtils.countOccurrencesOf(outputFile, TEST_STRING)); assertTrue(outputFile.contains("<root>" + TEST_STRING + "</root>")); assertEquals("<root><StaxEventItemWriter-testString/></root>", outputFile); }