@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(items); } catch (Exception e) { throw new RuntimeException(e); } return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(items); } catch ( Exception e) { throw new RuntimeException(e); } return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(items); } catch (Exception e) { throw new RuntimeException(e); } return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(objects); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException("Exception encountered on write", e); } return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(objects); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException("Exception encountered on write", e); } return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(items); } catch (Exception e) { throw new RuntimeException(e); } throw new RuntimeException("Planned"); } });
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(items); } catch (Exception e) { throw new RuntimeException(e); } throw new RuntimeException("Planned"); } });
@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"); } });
@Test(expected = WriterNotOpenException.class) public void testAssertWriterIsInitialized() throws Exception { StaxEventItemWriter<String> writer = new StaxEventItemWriter<>(); writer.write(Collections.singletonList("foo")); }
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(itemsMultiByte); } catch (Exception e) { throw new UnexpectedInputException("Could not write data", e); } // get restart data writer.update(executionContext); return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { // write item writer.write(itemsMultiByte); } catch (Exception e) { throw new UnexpectedInputException("Could not write data", e); } // get restart data writer.update(executionContext); return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { // write item writer.write(items); } catch (Exception e) { throw new UnexpectedInputException("Could not write data", e); } // get restart data writer.update(executionContext); return null; } });
@Override public Void doInTransaction(TransactionStatus status) { try { writer.write(items); } catch (Exception e) { throw new UnexpectedInputException("Could not write data", e); } // get restart data writer.update(executionContext); return null; } });
@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; } });
/** * Item is written to the output file only after flush. */ @Test public void testWriteAndFlush() throws Exception { writer.open(executionContext); writer.write(items); writer.close(); String content = getOutputFileContent(); assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); }
@Test public void testWriteAndForceFlush() throws Exception { writer.setForceSync(true); writer.open(executionContext); writer.write(items); writer.close(); String content = getOutputFileContent(); assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); }
/** * Resource is not deleted when items have been written and shouldDeleteIfEmpty flag is set. */ @Test public void testDeleteIfEmptyRecordsWritten() throws Exception { writer.setShouldDeleteIfEmpty(true); writer.open(executionContext); writer.write(items); writer.close(); String content = getOutputFileContent(); assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); }
/** * Test opening and closing corresponding tags in header- and footer callback. */ @Test public void testOpenAndCloseTagsInCallbacks() throws Exception { initWriterForSimpleCallbackTests(); writer.open(executionContext); writer.write(items); writer.close(); String content = getOutputFileContent(); assertEquals("Wrong content: " + content, "<ns:testroot xmlns:ns=\"http://www.springframework.org/test\"><ns:group><StaxEventItemWriter-testString/></ns:group></ns:testroot>", content); }
/** * Test setting writer name. */ @Test public void testSetName() throws Exception { writer.setName("test"); writer.open(executionContext); writer.write(items); writer.update(executionContext); writer.close(); assertTrue("execution context keys should be prefixed with writer name", executionContext.containsKey("test.position")); }
/** * Resource is not deleted when items have been written and shouldDeleteIfEmpty flag is set. */ @Test public void testDeleteIfEmptyRecordsWrittenRestart() throws Exception { writer.setShouldDeleteIfEmpty(true); writer.open(executionContext); writer.write(items); writer.update(executionContext); writer.close(); writer = createItemWriter(); writer.setShouldDeleteIfEmpty(true); writer.open(executionContext); writer.close(); String content = getOutputFileContent(); assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); }