@Test public void testHasNextRecordForEmptyFile() throws Exception { xmlRecordReader.close(); xmlRecordReader = new XmlRecordReader("person", getDataSource("/empty-file.xml")); xmlRecordReader.open(); assertThat(xmlRecordReader.readRecord()).isNull(); }
@Test public void testReadNextNestedRecord() throws Exception { xmlRecordReader.close(); xmlRecordReader = new XmlRecordReader("person", getDataSource("/persons-nested.xml")); xmlRecordReader.open(); XmlRecord xmlRecord = xmlRecordReader.readRecord(); String expectedPayload = getXmlFromFile("/person.xml"); String actualPayload = xmlRecord.getPayload(); XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(expectedPayload, actualPayload); assertThat(xmlRecord.getHeader().getNumber()).isEqualTo(1); assertThat(diff.similar()).isTrue(); }
@Test public void testReadingXmlWithCustomNamespace() throws Exception { xmlRecordReader.close(); xmlRecordReader = new XmlRecordReader("bean", getDataSource("/beans.xml")); xmlRecordReader.open(); XmlRecord record = xmlRecordReader.readRecord(); assertThat(record.getPayload()) .isXmlEqualTo( "<bean id=\"foo\" class=\"java.lang.String\"><description>foo bean</description></bean>"); record = xmlRecordReader.readRecord(); assertThat(record.getPayload()).isXmlEqualTo("<bean id=\"bar\" class=\"java.lang.String\"/>"); record = xmlRecordReader.readRecord(); assertThat(record).isNull(); }
@Test public void testReadingEscapedXml() throws Exception { xmlRecordReader.close(); xmlRecordReader = new XmlRecordReader("website", getDataSource("/websites.xml")); xmlRecordReader.open(); XmlRecord record = xmlRecordReader.readRecord(); assertThat(record.getPayload()) .isXmlEqualTo( "<website name=\"google\" url=\"http://www.google.com?query=test&sort=asc\"/>"); record = xmlRecordReader.readRecord(); assertThat(record.getPayload()) .isXmlEqualTo("<website name=\"l'equipe\" url=\"http://www.lequipe.fr\"/>"); record = xmlRecordReader.readRecord(); assertThat(record.getPayload()) .isXmlEqualTo( "<website name=\"l"internaute.com\" url=\"http://www.linternaute.com\"/>"); record = xmlRecordReader.readRecord(); assertThat(record).isNull(); }
@Before public void setUp() throws Exception { xmlRecordReader = new XmlRecordReader("person", getDataSource("/persons.xml")); xmlRecordReader.open(); }