@Test public void testAfterPropertiesSet() throws Exception { source.afterPropertiesSet(); }
@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { StaxEventItemReader<Foo> reader = (StaxEventItemReader<Foo>) tested; reader.close(); reader.setResource(new ByteArrayResource("<foos />".getBytes())); reader.afterPropertiesSet(); reader.open(new ExecutionContext()); }
@Before public void setUp() throws Exception { reader.setFragmentRootElementName("trade"); reader.setUnmarshaller(getUnmarshaller()); reader.afterPropertiesSet(); }
@Test public void testDirectoryResource() throws Exception { FileSystemResource resource = new FileSystemResource("build/data"); resource.getFile().mkdirs(); assertTrue(resource.getFile().isDirectory()); source.setResource(resource); source.afterPropertiesSet(); source.setStrict(false); source.open(executionContext); assertNull(source.read()); }
@Test public void testAfterPropertesSetException() throws Exception { source = createNewInputSource(); source.setFragmentRootElementName(""); try { source.afterPropertiesSet(); fail(); } catch (IllegalArgumentException e) { // expected } source = createNewInputSource(); source.setUnmarshaller(null); try { source.afterPropertiesSet(); fail(); } catch (IllegalArgumentException e) { // expected } }
@Test(expected = ItemStreamException.class) public void testStrictness() throws Exception { source.setResource(new NonExistentResource()); source.setStrict(true); source.afterPropertiesSet(); source.open(executionContext); }
@Test public void testRuntimeFileCreation() throws Exception { source.setResource(new NonExistentResource()); source.afterPropertiesSet(); source.setResource(new ByteArrayResource(xml.getBytes())); source.open(executionContext); source.read(); }
@Before public void setUp() throws Exception { reader.setResource(resource); reader.setFragmentRootElementName("{urn:org.springframework.batch.io.oxm.domain}trade"); reader.setUnmarshaller(getUnmarshaller()); reader.afterPropertiesSet(); reader.open(new ExecutionContext()); }
@Test public void testNonExistentResource() throws Exception { source.setResource(new NonExistentResource()); source.afterPropertiesSet(); source.setStrict(false); source.open(executionContext); assertNull(source.read()); }
@Test public void testFragmentNamespace() throws Exception { source.setResource(new ByteArrayResource(fooXml.getBytes())); source.afterPropertiesSet(); source.open(executionContext); // see asserts in the mock unmarshaller assertNotNull(source.read()); assertNotNull(source.read()); assertNull(source.read()); // there are only two fragments source.close(); }
@Test public void testFragmentMixedNamespace() throws Exception { source.setResource(new ByteArrayResource(mixedXml.getBytes())); source.setFragmentRootElementName("{urn:org.test.bar}" + FRAGMENT_ROOT_ELEMENT); source.afterPropertiesSet(); source.open(executionContext); // see asserts in the mock unmarshaller assertNotNull(source.read()); assertNotNull(source.read()); assertNull(source.read()); // there are only two fragments source.close(); }
@Test public void testMultiFragmentNameSpace() throws Exception { source.setResource(new ByteArrayResource(xmlMultiFragment.getBytes())); source.setFragmentRootElementNames(new String[] {"{urn:org.test.bar}fragmentA", "fragmentB"}); source.afterPropertiesSet(); source.open(executionContext); // see asserts in the mock unmarshaller assertNotNull(source.read()); assertNotNull(source.read()); assertNull(source.read()); // there are only two fragments (one has wrong namespace) source.close(); }
@Test public void testItemCountAwareFragmentRestart() throws Exception { StaxEventItemReader<ItemCountAwareFragment> source = createNewItemCountAwareInputSource(); source.afterPropertiesSet(); source.open(executionContext); assertEquals(1, source.read().getItemCount()); source.update(executionContext); source.close(); source = createNewItemCountAwareInputSource(); source.afterPropertiesSet(); source.open(executionContext); assertEquals(2, source.read().getItemCount()); assertNull(source.read()); // there are only two fragments source.close(); }
@Test public void testFragmentInvalid() throws Exception { source.setResource(new ByteArrayResource(invalidXml.getBytes())); source.setFragmentRootElementName(FRAGMENT_ROOT_ELEMENT); source.afterPropertiesSet(); source.open(executionContext); // Should fail before it gets to the marshaller try { assertNotNull(source.read()); fail("Expected NonTransientResourceException"); } catch (NonTransientResourceException e) { // expected } assertNull(source.read()); // after an error there is no more output source.close(); }
@Test public void testMultiFragment() throws Exception { source.setResource(new ByteArrayResource(xmlMultiFragment.getBytes())); source.setFragmentRootElementNames(MULTI_FRAGMENT_ROOT_ELEMENTS); source.afterPropertiesSet(); source.open(executionContext); // see asserts in the mock unmarshaller assertNotNull(source.read()); assertNotNull(source.read()); assertNotNull(source.read()); assertNull(source.read()); // there are only three fragments source.close(); }
/** * Regular usage scenario. ItemReader should pass XML fragments to unmarshaller wrapped with StartDocument and * EndDocument events. */ @Test public void testFragmentWrapping() throws Exception { source.afterPropertiesSet(); source.open(executionContext); // see asserts in the mock unmarshaller assertNotNull(source.read()); assertNotNull(source.read()); assertNull(source.read()); // there are only two fragments source.close(); }
@Test public void testMultiFragmentNested() throws Exception { source.setResource(new ByteArrayResource(xmlMultiFragmentNested.getBytes())); source.setFragmentRootElementNames(MULTI_FRAGMENT_ROOT_ELEMENTS); source.afterPropertiesSet(); source.open(executionContext); // see asserts in the mock unmarshaller assertNotNull(source.read()); assertNotNull(source.read()); assertNotNull(source.read()); assertNull(source.read()); // there are only three fragments source.close(); }
@Test public void testMultiFragmentRestart() throws Exception { source.setResource(new ByteArrayResource(xmlMultiFragment.getBytes())); source.setFragmentRootElementNames(MULTI_FRAGMENT_ROOT_ELEMENTS); source.afterPropertiesSet(); source.open(executionContext); // see asserts in the mock unmarshaller assertNotNull(source.read()); assertNotNull(source.read()); source.update(executionContext); assertEquals(2, executionContext.getInt(ClassUtils.getShortName(StaxEventItemReader.class) + ".read.count")); source.close(); source = createNewInputSource(); source.setResource(new ByteArrayResource(xmlMultiFragment.getBytes())); source.setFragmentRootElementNames(MULTI_FRAGMENT_ROOT_ELEMENTS); source.afterPropertiesSet(); source.open(executionContext); assertNotNull(source.read()); assertNull(source.read()); // there are only three fragments source.close(); }
@Test public void testItemCountAwareFragment() throws Exception { StaxEventItemReader<ItemCountAwareFragment> source = createNewItemCountAwareInputSource(); source.afterPropertiesSet(); source.open(executionContext); assertEquals(1, source.read().getItemCount()); assertEquals(2, source.read().getItemCount()); assertNull(source.read()); // there are only two fragments source.close(); }
@Test(expected = ItemStreamException.class) public void testStrict() throws Exception { Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller(); unmarshaller.setClassesToBeBound(Foo.class); StaxEventItemReader<Foo> reader = new StaxEventItemReaderBuilder<Foo>() .name("fooReader") .resource(this.resource) .addFragmentRootElements("foo") .unmarshaller(unmarshaller) .build(); reader.afterPropertiesSet(); ExecutionContext executionContext = new ExecutionContext(); reader.open(executionContext); }