Search in sources :

Example 1 with FlatXmlProducer

use of org.dbunit.dataset.xml.FlatXmlProducer in project openmrs-core by openmrs.

the class BaseContextSensitiveTest method executeLargeDataSet.

/**
 * Runs the large flat xml dataset. It does not cache the file as opposed to
 * {@link #executeDataSet(String)}.
 *
 * @param datasetFilename
 * @throws Exception
 * @since 1.10
 */
public void executeLargeDataSet(String datasetFilename) throws Exception {
    InputStream inputStream = null;
    try {
        final File file = new File(datasetFilename);
        if (file.exists()) {
            inputStream = new FileInputStream(datasetFilename);
        } else {
            inputStream = getClass().getClassLoader().getResourceAsStream(datasetFilename);
            if (inputStream == null)
                throw new FileNotFoundException("Unable to find '" + datasetFilename + "' in the classpath");
        }
        final FlatXmlProducer flatXmlProducer = new FlatXmlProducer(new InputSource(inputStream));
        final StreamingDataSet streamingDataSet = new StreamingDataSet(flatXmlProducer);
        final ReplacementDataSet replacementDataSet = new ReplacementDataSet(streamingDataSet);
        replacementDataSet.addReplacementObject("[NULL]", null);
        executeDataSet(replacementDataSet);
        inputStream.close();
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FlatXmlProducer(org.dbunit.dataset.xml.FlatXmlProducer) StreamingDataSet(org.dbunit.dataset.stream.StreamingDataSet) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 ReplacementDataSet (org.dbunit.dataset.ReplacementDataSet)1 StreamingDataSet (org.dbunit.dataset.stream.StreamingDataSet)1 FlatXmlProducer (org.dbunit.dataset.xml.FlatXmlProducer)1 InputSource (org.xml.sax.InputSource)1