本文整理汇总了Java中org.dbunit.dataset.ITableMetaData类的典型用法代码示例。如果您正苦于以下问题:Java ITableMetaData类的具体用法?Java ITableMetaData怎么用?Java ITableMetaData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITableMetaData类属于org.dbunit.dataset包,在下文中一共展示了ITableMetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTableMetaData
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
private ITableMetaData createTableMetaData() throws DataSetException {
if (beans.isEmpty()) {
return new DefaultTableMetaData(tableName, new Column[0]);
} else {
try {
List<Column> columns = new ArrayList<Column>();
BeanInfo info = Introspector.getBeanInfo(beans.get(0).getClass());
PropertyDescriptor[] descs = info.getPropertyDescriptors();
for (PropertyDescriptor desc : descs) {
if (!isIgnoreProperty(desc)) {
System.out.println(desc.getName());
columns.add(new Column(desc.getName(), DataType.UNKNOWN));
}
}
Column[] c = (Column[]) columns.toArray(new Column[columns.size()]);
return new DefaultTableMetaData(tableName, c);
} catch (IntrospectionException e) {
throw new DataSetException(e);
}
}
}
示例2: testProduceDataSetFromEmptyFile
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@Test
public void testProduceDataSetFromEmptyFile() throws DataSetException {
// GIVEN
final IDataSetConsumer consumer = mock(IDataSetConsumer.class);
final IDataSetProducer producer = new YamlDataSetProducer(emptyStream);
producer.setConsumer(consumer);
// WHEN
producer.produce();
// THEN
verify(consumer).startDataSet();
verify(consumer, times(0)).startTable(any(ITableMetaData.class));
verify(consumer, times(0)).row(any(Object[].class));
verify(consumer, times(0)).endTable();
verify(consumer).endDataSet();
}
示例3: getValue
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@Override
public Object getValue(int row, String column) throws DataSetException {
if (row < table.getRowCount()) {
return table.getValue(row, column);
} else {
if (columnToBeReplaced.equalsIgnoreCase(column)) {
Column c = null;
ITableMetaData metaData = table.getTableMetaData();
for (Column cl : metaData.getColumns()) {
if (cl.getColumnName().equalsIgnoreCase(column)) {
c = cl;
}
}
return c.getDataType().typeCast(valueToBeReplaced);
}
return table.getValue(row - table.getRowCount(), column);
}
}
示例4: getTables
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public List<ITable> getTables(InputStream jsonStream) {
List<ITable> rtables = new ArrayList<ITable>();
Map<String, Object> dataset = mapper.fromJson(new InputStreamReader(jsonStream), Map.class);
for (Map.Entry<String, Object> entry : dataset.entrySet()) {
List<Map<String, Object>> rows = (List<Map<String, Object>>) entry.getValue();
ITableMetaData meta = getMetaData(entry.getKey(), rows);
DefaultTable table = new DefaultTable(meta);
int rowIndex = 0;
for (Map<String, Object> row : rows) {
fillRow(table, row, rowIndex++);
}
rtables.add(table);
}
return rtables;
}
示例5: startTable
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@Override
public void startTable(ITableMetaData metaData) throws DataSetException {
// Формируем целевой файл
currentFile = new File(targetDirectory, String.format("%s.%s", metaData.getTableName(), extension));
try {
// Формируем сервис записи файла
currentWriter = createWriter();
// Формируем название колонок
Column[] columns = metaData.getColumns();
currentHeaders = new String[columns.length];
for (int i = 0; i < currentHeaders.length; i++) {
currentHeaders[i] = columns[i].getColumnName();
}
// Записываем название колонок
writeHeader();
} catch (IOException ex) {
throw new DataSetException(ex);
}
}
示例6: testConvert
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
public void testConvert() throws Exception {
ITableMetaData tableMetaData = new DefaultTableMetaData(
"testDictionary",
new Column[]{new Column("column1", DataType.UNKNOWN), new Column("column2", DataType.UNKNOWN)}
);
Dictionary dictionary = converter.convert(tableMetaData);
assertNotNull(dictionary);
assertEquals(dictionary.getName(), "testDictionary");
// check META-fields
List<MetaField> metaFields = ModelUtils.sortMetaFieldsByOrdinal(dictionary.getDescendants());
assertEquals(metaFields.size(), 2);
for (int i = 0; i < metaFields.size(); i++) {
assertMetaField(metaFields.get(i), tableMetaData.getColumns(), i, i == 0);
}
// check serialize
assertObjectSerialization(dictionary);
}
示例7: startTable
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@Override
public void startTable(ITableMetaData metaData) throws DataSetException {
this.metaData = metaData;
rowCount = 0;
try {
out.write(DOUBLE_SPACES+"\""+metaData.getTableName() + "\": [" + NEW_LINE);
} catch (IOException e) {
logger.warn("Could not start table.", e);
}
}
示例8: startTable
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@Override
public void startTable(ITableMetaData metaData) throws DataSetException {
this.metaData = metaData;
try {
out.write(metaData.getTableName()+":"+NEW_LINE);
} catch (IOException e) {
logger.warn("Could not start table.", e);
}
}
示例9: createMeta
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
ITableMetaData createMeta(String name, List<String> columnNames) {
Column[] columns = null;
if (columnNames != null) {
columns = new Column[columnNames.size()];
for (int i = 0; i < columnNames.size(); i++)
columns[i] = new Column(columnNames.get(i), DataType.UNKNOWN);
} else {
columns = new Column[0];
}
return new DefaultTableMetaData(name, columns);
}
示例10: getTableMetaData
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@Override
public ITableMetaData getTableMetaData(final String tableName) throws DataSetException {
MyTable myTable = tables.get(tableName.toUpperCase());
if (myTable != null) {
return myTable.getTableMetaData();
}
return null;
}
示例11: BeanDataSet
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
public BeanDataSet(String tableName, List<?> beans, ITableMetaData metaData)
throws DataSetException {
tables = createTableNameMap();
ITable table = new BeanTable(tableName, beans, metaData);
tables.add(tableName, table);
}
示例12: assertDataSetEquals
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
public void assertDataSetEquals(IDataSet expected, List<?>...actuals) throws DatabaseUnitException {
BeanDataSet actualDataSet = new BeanDataSet();
for (List<?> actual : actuals) {
String tableName = null;
if (actual.size() > 0 ) {
tableName = actual.get(0).getClass().getSimpleName();
}
ITableMetaData metaData = expected.getTableMetaData(tableName);
BeanTable table = new BeanTable(tableName, actual, metaData);
actualDataSet.addTable(table);
}
Assertion.assertEquals(expected, actualDataSet);
}
示例13: produce
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
@Override
public void produce() throws DataSetException {
consumer.startDataSet();
final Map<String, List<Map<String, String>>> dataset = loadDataSet();
for (final Map.Entry<String, List<Map<String, String>>> entry : dataset.entrySet()) {
// an entry represents a table
final List<Map<String, String>> rows = entry.getValue();
// each row represents a record in a table
final Collection<String> columnNames = extractColumnNames(rows);
final ITableMetaData tableMetaData = new DefaultTableMetaData(entry.getKey(), createColumns(columnNames));
consumer.startTable(tableMetaData);
for (final Map<String, String> row : rows) {
final List<String> values = new ArrayList<>();
for (final Column column : tableMetaData.getColumns()) {
final Object rawValue = row.get(column.getColumnName());
final String value = rawValue == null ? null : String.valueOf(rawValue);
values.add(value);
}
consumer.row(values.toArray());
}
consumer.endTable();
}
consumer.endDataSet();
}
示例14: getColumnsToIgnore
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
protected String[] getColumnsToIgnore(ITableMetaData expectedMetaData, ITableMetaData actualMetaData)
throws DataSetException {
Column[] notSpecifiedInExpected = Columns.getColumnDiff(expectedMetaData, actualMetaData).getActual();
List<String> result = new LinkedList<String>();
for (Column column : notSpecifiedInExpected) {
result.add(column.getColumnName());
}
return result.toArray(new String[result.size()]);
}
示例15: getTableMetaData
import org.dbunit.dataset.ITableMetaData; //导入依赖的package包/类
public ITableMetaData getTableMetaData() {
ITableMetaData meta = delegate.getTableMetaData();
try {
return new DefaultTableMetaData(tableName, meta.getColumns(), meta.getPrimaryKeys());
} catch (DataSetException e) {
throw new QtafException("Don't get the meta info from " + meta, e);
}
}