Git Product home page Git Product logo

dbunit-friend's Introduction

๐Ÿงธ dbunit-friend

Convert user-friendly inline CSV into table data using DBUnit.

Dependencies

<dependency>
    <groupId>com.yo1000</groupId>
    <artifactId>dbunit-friend</artifactId>
    <version>1.0.0</version>
</dependency>

Examples

Details refer to src/test/kotlin/com/yo1000/dbunit/friend/NamedCsvStringDataSetTest.kt

for Kotlin

dataSource.connection.use { conn ->
    val dbConn = DatabaseConnection(conn).also { dbConn ->
        dbConn.config.setProperty(DatabaseConfig.FEATURE_ALLOW_EMPTY_FIELDS, true)
    }

    val dataSet = NamedCsvStringDataSet.builder()
        .table("owners")
        .csv(
            """
            id | name  | Age | BLooD   | BIRTH_DATE
            10 | Alice | 20  | A       | 2000-03-05
            20 | Bob   | 18  |         | 2002-01-02
            """
        )
        .table("PETS")
        .csv(
            """
            ID   | NAME   | PRICE     | CATEGORY | OWNERS_ID
            1000 | Max    | 500000    | dogs     | 10
            1001 | Bella  | 500000    | dogs     | 10
            1002 |        |           | dogs     | 10
            1003 |        |           | dogs     | 10
            1004 |        |           | dogs     | 10
            1005 | ''     | 123456.70 | dogs     | 10
            1006 | null   | 123456.70 | dogs     | 10
            2000 | Tama   | 200000    | cats     | 20
            2001 | '  '   | 200000.1  | cats     | 20
            9000 |        |           | dogs     | 
            """
        )
        .build()

    DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet)

    Assertion.assertEquals(dataSet, dbConn.createDataSet())
}

for Java13+

try (Connection conn = dataSource.getConnection()) {
    DatabaseConnection dbConn = new DatabaseConnection(conn);
    dbConn.getConfig().setProperty(DatabaseConfig.FEATURE_ALLOW_EMPTY_FIELDS, true);

    IDataSet dataSet = NamedCsvStringDataSet.builder()
        .table("owners")
        .csv(
            """
            id | name  | Age | BLooD   | BIRTH_DATE
            10 | Alice | 20  | A       | 2000-03-05
            20 | Bob   | 18  |         | 2002-01-02
            """
        )
        .table("PETS")
        .csv(
            """
            ID   | NAME   | PRICE     | CATEGORY | OWNERS_ID
            1000 | Max    | 500000    | dogs     | 10
            1001 | Bella  | 500000    | dogs     | 10
            1002 |        |           | dogs     | 10
            1003 |        |           | dogs     | 10
            1004 |        |           | dogs     | 10
            1005 | ''     | 123456.70 | dogs     | 10
            1006 | null   | 123456.70 | dogs     | 10
            2000 | Tama   | 200000    | cats     | 20
            2001 | '  '   | 200000.1  | cats     | 20
            9000 |        |           | dogs     | 
            """
        )
        .build();

    DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet);

    Assertion.assertEquals(dataSet, dbConn.createDataSet());
}

dbunit-friend's People

Contributors

yo1000 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.