Search in sources :

Example 1 with Column

use of io.bootique.jdbc.test.Column in project bootique-jdbc by bootique.

the class CsvDataSetBuilderTest method before.

@Before
public void before() {
    DatabaseChannel mockChannel = mock(DatabaseChannel.class);
    table = Table.builder(mockChannel, "t_t").columns(new Column("c1", Types.VARCHAR), new Column("c2", Types.INTEGER), new Column("c3", Types.VARBINARY)).build();
}
Also used : DatabaseChannel(io.bootique.jdbc.test.DatabaseChannel) Column(io.bootique.jdbc.test.Column) Before(org.junit.Before)

Example 2 with Column

use of io.bootique.jdbc.test.Column in project bootique-jdbc by bootique.

the class CsvReader method loadDataSet.

TableDataSet loadDataSet(Reader dataReader) throws IOException {
    try (CSVParser parser = new CSVParser(dataReader, CSVFormat.DEFAULT, 0, 0)) {
        Iterator<CSVRecord> rows = parser.iterator();
        if (!rows.hasNext()) {
            return new TableDataSet(table, Collections.emptyList(), Collections.emptyList());
        }
        List<Column> header = getHeader(rows.next());
        return readData(header, rows);
    }
}
Also used : Column(io.bootique.jdbc.test.Column) CSVParser(org.apache.commons.csv.CSVParser) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 3 with Column

use of io.bootique.jdbc.test.Column in project bootique-jdbc by bootique.

the class CsvMatcherRunner method matchData.

private void matchData(Map<RowKey, Object[]> mappedData) {
    referenceData.getRecords().forEach(ref -> {
        RowKey rowKey = keyFactory.createKey(ref);
        Object[] row = mappedData.get(rowKey);
        assertNotNull("No DB records for key: " + rowKey, row);
        for (int i = 0; i < row.length; i++) {
            Object refVal = ref[i];
            Object dbVal = row[i];
            Column c = referenceData.getHeader().get(i);
            if (refVal == null) {
                compareNull(c, rowKey, dbVal);
                continue;
            }
            switch(c.getType()) {
                case Types.VARBINARY:
                case Types.BINARY:
                case Types.LONGVARBINARY:
                case Types.BLOB:
                    // TODO: check that data type is actually a byte[]?
                    compareByteArrays(c, rowKey, (byte[]) refVal, (byte[]) dbVal);
                    break;
                default:
                    compareValues(c, rowKey, refVal, dbVal);
                    break;
            }
        }
    });
}
Also used : Column(io.bootique.jdbc.test.Column)

Aggregations

Column (io.bootique.jdbc.test.Column)3 DatabaseChannel (io.bootique.jdbc.test.DatabaseChannel)1 CSVParser (org.apache.commons.csv.CSVParser)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 Before (org.junit.Before)1