org.dbunit.dataset.ITable Java Examples

The following examples show how to use org.dbunit.dataset.ITable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OldSchoolDbUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenProductIgnoredAndDelete_thenItemIsRemoved() throws Exception {
    try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader()
        .getResourceAsStream("dbunit/items_exp_delete_no_produced.xml")) {
        // given
        ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");

        // when
        connection.createStatement().executeUpdate("delete from ITEMS where id = 2");

        // then
        IDataSet databaseDataSet = tester.getConnection().createDataSet();
        ITable actualTable = databaseDataSet.getTable("ITEMS");
        actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[] { "produced" });
        assertEquals(expectedTable, actualTable);
    }
}
 
Example #2
Source File: OldSchoolDbUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenUpdate_thenItemHasNewName() throws Exception {
    try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader()
        .getResourceAsStream("dbunit/items_exp_rename.xml")) {
        // given
        ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");

        // when
        connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");

        // then
        IDataSet databaseDataSet = tester.getConnection().createDataSet();
        ITable actualTable = databaseDataSet.getTable("ITEMS");
        assertEquals(expectedTable, actualTable);
    }
}
 
Example #3
Source File: KylinTestBase.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected void execAndCompColumnCount(String input, int expectedColumnCount) throws Exception {
    logger.info("---------- test column count: " + input);
    Set<String> sqlSet = ImmutableSet.of(input);

    for (String sql : sqlSet) {
        // execute Kylin
        logger.info("Query Result from Kylin - " + sql);
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, sql, sql, false);

        try {
            // compare the result
            Assert.assertEquals(expectedColumnCount, kylinTable.getTableMetaData().getColumns().length);
        } catch (Throwable t) {
            logger.info("execAndCompColumnCount failed on: " + sql);
            throw t;
        }
    }
}
 
Example #4
Source File: KylinTestBase.java    From Kylin with Apache License 2.0 6 votes vote down vote up
protected void verifyResultRowCount(String queryFolder) throws Exception {
    printInfo("---------- verify result count in folder: " + queryFolder);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        String sql = getTextFromFile(sqlFile);

        File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected");
        int expectRowCount = Integer.parseInt(Files.readFirstLine(expectResultFile, Charset.defaultCharset()));

        // execute Kylin
        printInfo("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);

        // compare the result
        Assert.assertEquals(expectRowCount, kylinTable.getRowCount());
        // Assertion.assertEquals(expectRowCount, kylinTable.getRowCount());
    }
}
 
Example #5
Source File: KylinTestBase.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected void verifyResultContent(String queryFolder) throws Exception {
    logger.info("---------- verify result content in folder: " + queryFolder);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        String sql = getTextFromFile(sqlFile);

        File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected.xml");
        IDataSet expect = new FlatXmlDataSetBuilder().build(expectResultFile);
        // Get expected table named "expect". FIXME Only support default table name
        ITable expectTable = expect.getTable("expect");

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);

        // compare the result
        assertTableEquals(expectTable, kylinTable);
    }
}
 
Example #6
Source File: DataSourceDBUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenInsertUnexpectedData_thenFail() throws Exception {
    try (InputStream is = getClass().getClassLoader()
        .getResourceAsStream("dbunit/expected-multiple-failures.xml")) {

        // given
        IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
        ITable expectedTable = expectedDataSet.getTable("ITEMS");
        Connection conn = getDataSource().getConnection();
        DiffCollectingFailureHandler collectingHandler = new DiffCollectingFailureHandler();

        // when
        conn.createStatement().executeUpdate("INSERT INTO ITEMS (title, price) VALUES ('Battery', '1000000')");
        ITable actualData = getConnection().createDataSet().getTable("ITEMS");

        // then
        Assertion.assertEquals(expectedTable, actualData, collectingHandler);
        if (!collectingHandler.getDiffList().isEmpty()) {
            String message = (String) collectingHandler.getDiffList().stream()
                .map(d -> formatDifference((Difference) d)).collect(joining("\n"));
            logger.error(() -> message);
        }
    }
}
 
Example #7
Source File: KylinTestBase.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected static void printResult(ITable resultTable) throws DataSetException {
    StringBuilder sb = new StringBuilder();

    int columnCount = resultTable.getTableMetaData().getColumns().length;
    String[] columns = new String[columnCount];

    for (int i = 0; i < columnCount; i++) {
        sb.append(resultTable.getTableMetaData().getColumns()[i].getColumnName());
        sb.append("-");
        sb.append(resultTable.getTableMetaData().getColumns()[i].getDataType());
        sb.append("\t");
        columns[i] = resultTable.getTableMetaData().getColumns()[i].getColumnName();
    }
    sb.append("\n");

    for (int i = 0; i < resultTable.getRowCount(); i++) {
        for (int j = 0; j < columns.length; j++) {
            sb.append(resultTable.getValue(i, columns[j]));
            sb.append("\t");
        }
        sb.append("\n");
    }
    System.out.println(sb.toString());
}
 
Example #8
Source File: DataSourceDBUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenInsert_thenTableHasNewClient() throws Exception {
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("dbunit/expected-user.xml")) {
        // given
        IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
        ITable expectedTable = expectedDataSet.getTable("CLIENTS");
        Connection conn = getDataSource().getConnection();

        // when
        conn.createStatement()
            .executeUpdate("INSERT INTO CLIENTS (first_name, last_name) VALUES ('John', 'Jansen')");
        ITable actualData = getConnection()
            .createQueryTable("result_name", "SELECT * FROM CLIENTS WHERE last_name='Jansen'");

        // then
        assertEqualsIgnoreCols(expectedTable, actualData, new String[] { "id" });
    }
}
 
Example #9
Source File: DataSourceDBUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenDelete_thenItemIsDeleted() throws Exception {
    try (InputStream is = DataSourceDBUnitTest.class.getClassLoader()
        .getResourceAsStream("dbunit/items_exp_delete.xml")) {
        // given
        ITable expectedTable = (new FlatXmlDataSetBuilder().build(is)).getTable("ITEMS");

        // when
        connection.createStatement().executeUpdate("delete from ITEMS where id = 2");

        // then
        IDataSet databaseDataSet = getConnection().createDataSet();
        ITable actualTable = databaseDataSet.getTable("ITEMS");
        Assertion.assertEquals(expectedTable, actualTable);
    }
}
 
Example #10
Source File: ITKylinQueryTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersionQuery() throws Exception {
    String expectVersion = KylinVersion.getCurrentVersion().toString();
    logger.info("---------- verify expect version: " + expectVersion);

    String queryName = "QueryKylinVersion";
    String sql = "SELECT VERSION() AS version";

    // execute Kylin
    logger.info("Query Result from Kylin - " + queryName);
    IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
    ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);
    String queriedVersion = String.valueOf(kylinTable.getValue(0, "version"));

    // compare the result
    Assert.assertEquals(expectVersion, queriedVersion);
}
 
Example #11
Source File: OldSchoolDbUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenUpdateWithNoProduced_thenItemHasNewName() throws Exception {
    try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader()
        .getResourceAsStream("dbunit/items_exp_rename_no_produced.xml")) {
        // given
        ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");
        expectedTable = DefaultColumnFilter.excludedColumnsTable(expectedTable, new String[] { "produced" });

        // when
        connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");

        // then
        IDataSet databaseDataSet = tester.getConnection().createDataSet();
        ITable actualTable = databaseDataSet.getTable("ITEMS");
        actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[] { "produced" });
        assertEquals(expectedTable, actualTable);
    }
}
 
Example #12
Source File: KylinTestBase.java    From Kylin with Apache License 2.0 6 votes vote down vote up
protected static void printResult(ITable resultTable) throws DataSetException {
    StringBuilder sb = new StringBuilder();

    int columnCount = resultTable.getTableMetaData().getColumns().length;
    String[] columns = new String[columnCount];

    for (int i = 0; i < columnCount; i++) {
        sb.append(resultTable.getTableMetaData().getColumns()[i].getColumnName());
        sb.append("-");
        sb.append(resultTable.getTableMetaData().getColumns()[i].getDataType());
        sb.append("\t");
        columns[i] = resultTable.getTableMetaData().getColumns()[i].getColumnName();
    }
    sb.append("\n");

    for (int i = 0; i < resultTable.getRowCount(); i++) {
        for (int j = 0; j < columns.length; j++) {
            sb.append(resultTable.getValue(i, columns[j]));
            sb.append("\t");
        }
        sb.append("\n");
    }
    System.out.println(sb.toString());
}
 
Example #13
Source File: HackedDbUnitAssert.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void compareDataContains(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler) throws DataSetException {
    logger.debug("compareData(expectedTable={}, actualTable={}, " + "comparisonCols={}, failureHandler={}) - start", new Object[] { expectedTable, actualTable, comparisonCols, failureHandler });

    if (expectedTable == null) {
        throw new NullPointerException("The parameter 'expectedTable' must not be null");
    }
    if (actualTable == null) {
        throw new NullPointerException("The parameter 'actualTable' must not be null");
    }
    if (comparisonCols == null) {
        throw new NullPointerException("The parameter 'comparisonCols' must not be null");
    }
    if (failureHandler == null) {
        throw new NullPointerException("The parameter 'failureHandler' must not be null");
    }

    for (int index = 0; index < actualTable.getRowCount(); index++) {
        if (!findRowInExpectedTable(expectedTable, actualTable, comparisonCols, failureHandler, index)) {
            throw new IllegalStateException();
        }
    }

}
 
Example #14
Source File: HackedDbUnitAssert.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void compareDataContains(ITable expectedTable, ITable actualTable, ComparisonColumn[] comparisonCols, FailureHandler failureHandler) throws DataSetException {
    logger.debug("compareData(expectedTable={}, actualTable={}, " + "comparisonCols={}, failureHandler={}) - start", new Object[] { expectedTable, actualTable, comparisonCols, failureHandler });

    if (expectedTable == null) {
        throw new NullPointerException("The parameter 'expectedTable' must not be null");
    }
    if (actualTable == null) {
        throw new NullPointerException("The parameter 'actualTable' must not be null");
    }
    if (comparisonCols == null) {
        throw new NullPointerException("The parameter 'comparisonCols' must not be null");
    }
    if (failureHandler == null) {
        throw new NullPointerException("The parameter 'failureHandler' must not be null");
    }

    for (int index = 0; index < actualTable.getRowCount(); index++) {
        if (!findRowInExpectedTable(expectedTable, actualTable, comparisonCols, failureHandler, index)) {
            throw new IllegalStateException();
        }
    }

}
 
Example #15
Source File: OldSchoolDbUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenDelete_thenItemIsRemoved() throws Exception {
    try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader()
        .getResourceAsStream("dbunit/items_exp_delete.xml")) {
        // given
        ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");

        // when
        connection.createStatement().executeUpdate("delete from ITEMS where id = 2");

        // then
        IDataSet databaseDataSet = tester.getConnection().createDataSet();
        ITable actualTable = databaseDataSet.getTable("ITEMS");
        assertEquals(expectedTable, actualTable);
    }
}
 
Example #16
Source File: KylinTestBase.java    From kylin with Apache License 2.0 6 votes vote down vote up
protected void execAndCompColumnCount(String input, int expectedColumnCount) throws Exception {
    logger.info("---------- test column count: " + input);
    Set<String> sqlSet = ImmutableSet.of(input);

    for (String sql : sqlSet) {
        // execute Kylin
        logger.info("Query Result from Kylin - " + sql);
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, sql, sql, false);

        try {
            // compare the result
            Assert.assertEquals(expectedColumnCount, kylinTable.getTableMetaData().getColumns().length);
        } catch (Throwable t) {
            logger.info("execAndCompColumnCount failed on: " + sql);
            throw t;
        }
    }
}
 
Example #17
Source File: DataSetComparator.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
private List<String> extractColumnsToBeIgnored(final ITable expectedTableState, final ITable currentTableState)
        throws DataSetException {
    final List<String> columnsToIgnore = extractNotExpectedColumnNames(expectedTableState, currentTableState);
    final String tableName = expectedTableState.getTableMetaData().getTableName();

    columnsToIgnore.addAll(toExclude.getColumns(tableName));

    final List<String> nonExistingColumns = new ArrayList<>(columnsToIgnore);
    nonExistingColumns.removeAll(extractColumnNames(currentTableState.getTableMetaData().getColumns()));

    if (!nonExistingColumns.isEmpty()) {
        LOG.debug("Columns which are specified to be filtered out {} are not existing in the table {}",
                Arrays.toString(nonExistingColumns.toArray()), tableName);
    }
    return columnsToIgnore;
}
 
Example #18
Source File: KylinTestBase.java    From kylin with Apache License 2.0 6 votes vote down vote up
protected static void printResult(ITable resultTable) throws DataSetException {
    StringBuilder sb = new StringBuilder();

    int columnCount = resultTable.getTableMetaData().getColumns().length;
    String[] columns = new String[columnCount];

    for (int i = 0; i < columnCount; i++) {
        sb.append(resultTable.getTableMetaData().getColumns()[i].getColumnName());
        sb.append("-");
        sb.append(resultTable.getTableMetaData().getColumns()[i].getDataType());
        sb.append("\t");
        columns[i] = resultTable.getTableMetaData().getColumns()[i].getColumnName();
    }
    sb.append("\n");

    for (int i = 0; i < resultTable.getRowCount(); i++) {
        for (int j = 0; j < columns.length; j++) {
            sb.append(resultTable.getValue(i, columns[j]));
            sb.append("\t");
        }
        sb.append("\n");
    }
    System.out.println(sb.toString());
}
 
Example #19
Source File: ITMassInQueryTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
protected void run(String queryFolder, String[] exclusiveQuerys, boolean needSort) throws Exception {
    logger.info("---------- test folder: " + queryFolder);
    Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        if (exclusiveSet.contains(queryName)) {
            continue;
        }
        String sql = getTextFromFile(sqlFile);

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, needSort);
        printResult(kylinTable);

    }
}
 
Example #20
Source File: ITKylinQueryTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersionQuery() throws Exception {
    String expectVersion = KylinVersion.getCurrentVersion().toString();
    logger.info("---------- verify expect version: " + expectVersion);

    String queryName = "QueryKylinVersion";
    String sql = "SELECT VERSION() AS version";

    // execute Kylin
    logger.info("Query Result from Kylin - " + queryName);
    IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
    ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);
    String queriedVersion = String.valueOf(kylinTable.getValue(0, "version"));

    // compare the result
    Assert.assertEquals(expectVersion, queriedVersion);
}
 
Example #21
Source File: DataSetLoaderProviderTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.jsonLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.json"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("JSON_TABLE_1", "JSON_TABLE_2"));

    final ITable table1 = dataSet.getTable("JSON_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("JSON_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
Example #22
Source File: DataSetLoaderProviderTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
public void testYamlLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.yamlLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.yaml"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("YAML_TABLE_1", "YAML_TABLE_2"));

    final ITable table1 = dataSet.getTable("YAML_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("YAML_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
Example #23
Source File: DataSetLoaderProviderTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
public void testXmlLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xmlLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.xml"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("XML_TABLE_1", "XML_TABLE_2"));

    final ITable table1 = dataSet.getTable("XML_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("XML_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
Example #24
Source File: DataSetLoaderProviderTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore("Somehow the given zip file (xlsx) is invalid, even Excel opens it without issues")
public void testXlsxLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.xlsx"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("XLS_TABLE_1", "XLS_TABLE_2"));

    final ITable table1 = dataSet.getTable("XLS_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("XLS_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
Example #25
Source File: DataSetLoaderProviderTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore("Somehow the given zip file (xlsx) is invalid, even Excel opens it without issues")
public void testXlsLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.xls"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("XLS_TABLE_1", "XLS_TABLE_2"));

    final ITable table1 = dataSet.getTable("XLS_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("XLS_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
Example #26
Source File: DataSetLoaderProviderTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
public void testCsvLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.csvLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("CSV_TABLE_1", "CSV_TABLE_2"));

    final ITable table1 = dataSet.getTable("CSV_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("CSV_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
Example #27
Source File: OldSchoolDbUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenDataSet_whenInsert_thenGetResultsAreStillEqualIfIgnoringColumnsWithDifferentProduced()
    throws Exception {
    String[] excludedColumns = { "id", "produced" };
    try (InputStream is = getClass().getClassLoader()
        .getResourceAsStream("dbunit/expected-ignoring-registered_at.xml")) {
        // given
        IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
        ITable expectedTable = DefaultColumnFilter
            .excludedColumnsTable(expectedDataSet.getTable("ITEMS"), excludedColumns);

        // when
        connection.createStatement()
            .executeUpdate("INSERT INTO ITEMS (title, price, produced)  VALUES('Necklace', 199.99, now())");

        // then
        IDataSet databaseDataSet = tester.getConnection().createDataSet();
        ITable actualTable = DefaultColumnFilter
            .excludedColumnsTable(databaseDataSet.getTable("ITEMS"), excludedColumns);
        Assertion.assertEquals(expectedTable, actualTable);
    }
}
 
Example #28
Source File: CaptureTest.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Capture events test 1.
 */
public void testCommissionCases() throws Exception {
    String epcToCheck = "urn:epc:id:sgtin:0614141.107340.1";
    ITable table = FosstrakDatabaseHelper.getObjectEventByEpc(getConnection(), epcToCheck);
    assertEquals(0, table.getRowCount());

    runCaptureTest(COMMISSION_CASES_XML);

    table = FosstrakDatabaseHelper.getObjectEventByEpc(getConnection(), epcToCheck);
    assertEquals(1, table.getRowCount());
}
 
Example #29
Source File: CaptureTest.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Capture events test 3.
 */
public void testPackCases() throws Exception {
    String epcToCheck = "urn:epc:id:sgtin:0614141.107340.1";
    ITable table = FosstrakDatabaseHelper.getAggregationEventByChildEpc(getConnection(), epcToCheck);
    assertEquals(0, table.getRowCount());

    runCaptureTest(PACK_CASES_XML);

    table = FosstrakDatabaseHelper.getAggregationEventByChildEpc(getConnection(), epcToCheck);
    assertEquals(1, table.getRowCount());
}
 
Example #30
Source File: CaptureTest.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Capture events test 5.
 */
public void testPickOrder() throws Exception {
    String epcToCheck = "urn:epc:id:sgtin:0614141.107341.1";
    ITable table = FosstrakDatabaseHelper.getObjectEventByEpc(getConnection(), epcToCheck);
    assertEquals(0, table.getRowCount());

    runCaptureTest(PICK_ORDER_XML);

    table = FosstrakDatabaseHelper.getObjectEventByEpc(getConnection(), epcToCheck);
    assertEquals(1, table.getRowCount());
}