
com.crosstreelabs.junited.dbunit.EnhancedXmlDataSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junited.dbunit Show documentation
Show all versions of junited.dbunit Show documentation
Provides DBUnit support for tests.
The newest version!
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.crosstreelabs.junited.dbunit;
import com.crosstreelabs.junited.dbunit.conversion.Converter;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.Map;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.xml.XmlDataSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The EnhancedXmlDataSet offers some additional functionality over the vanilla
* dataset, including the ability to add binary data.
*/
public class EnhancedXmlDataSet extends XmlDataSet {
private static final Logger LOGGER = LoggerFactory.getLogger(EnhancedXmlDataSet.class);
public EnhancedXmlDataSet(final Reader reader) throws DataSetException {
super(reader);
}
public EnhancedXmlDataSet(final InputStream in) throws DataSetException {
super(in);
}
public Map getConverters() {
return Collections.EMPTY_MAP;
}
@Override
public void row(Object[] values) throws DataSetException {
try {
handleSpecialCases(values);
} catch (UnsupportedEncodingException ex) {
throw new DataSetException(ex);
}
super.row(values);
}
private void handleSpecialCases(final Object[] values) throws UnsupportedEncodingException {
if (getConverters() == null || getConverters().isEmpty()) {
LOGGER.warn("No converters present. Unable to handle special values.");
return;
}
for (int i = 0; i < values.length; i++) {
if (values[i] == null || !values[i].toString().contains(":")) {
continue;
}
String str = values[i].toString();
String[] parts = str.split(":", 2);
String function = parts[0];
String remainder = parts[1];
if (getConverters().containsKey(function)) {
values[i] = getConverters().get(function).convert(remainder);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy