{"id":844,"date":"2012-01-10T21:12:00","date_gmt":"2012-01-10T21:12:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/db-unit-testing-with-dbunit-json-hsqldb-and-junit-rules.html"},"modified":"2012-10-21T22:48:16","modified_gmt":"2012-10-21T22:48:16","slug":"db-unit-testing-with-dbunit-json-hsqldb","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html","title":{"rendered":"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use <a href=\"http:\/\/www.dbunit.org\/\" target=\"_blank\">dbUnit<\/a>.  My original thought was just to teach dbUnit about JSON, but it turns out that <a href=\"http:\/\/www.insaneprogramming.be\/?p=105\" target=\"_blank\">Lieven Doclo<\/a> has done that already.  So I decided to go a step further and also combine dbUnit with <a href=\"http:\/\/kentbeck.github.com\/junit\/javadoc\/latest\/org\/junit\/rules\/MethodRule.html\" target=\"_blank\">JUnit Rules<\/a>, and provide automatic bootstrapping of an <a href=\"http:\/\/hsqldb.org\/\" target=\"_blank\">HSQLDB<\/a> in-memory object store.<br \/>\n<span><\/span><br \/>\nThe following test shows what I ended up with:<\/p>\n<pre class=\"brush: java;\">package com.danhaywood.tdd.dbunit.test;\r\n\r\nimport static org.hamcrest.Matchers.equalTo;\r\nimport static org.hamcrest.Matchers.is;\r\nimport static org.junit.Assert.assertThat;\r\n\r\nimport java.sql.ResultSet;\r\nimport java.sql.Statement;\r\n\r\nimport org.dbunit.Assertion;\r\nimport org.dbunit.dataset.ITable;\r\nimport org.hsqldb.jdbcDriver;\r\nimport org.junit.Rule;\r\nimport org.junit.Test;\r\n\r\nimport com.danhaywood.tdd.dbunit.DbUnitRule;\r\nimport com.danhaywood.tdd.dbunit.DbUnitRule.Ddl;\r\nimport com.danhaywood.tdd.dbunit.DbUnitRule.JsonData;\r\n\r\npublic class DbUnitRuleExample {\r\n\r\n    @Rule\r\n    public DbUnitRule dbUnit = new DbUnitRule(\r\n            DbUnitRuleExample.class, jdbcDriver.class,\r\n            \"jdbc:hsqldb:file:src\/test\/resources\/testdb\", \"SA\", \"\");\r\n\r\n@Ddl(\"customer.ddl\")\r\n    @JsonData(\"customer.json\")\r\n    @Test\r\n    public void update_lastName() throws Exception {\r\n        \/\/ when\r\n        Statement statement = dbUnit.getConnection().createStatement();\r\n        statement.executeUpdate(\"update customer set last_name='Bloggs' where id=2\");\r\n\r\n        \/\/ then (verify directly)\r\n        ResultSet rs2 = dbUnit.executeQuery(\"select last_name from customer where id = 2\");\r\n        assertThat(rs2.next(), is(true));\r\n        assertThat(rs2.getString(\"last_name\"), equalTo(\"Bloggs\"));\r\n\r\n        \/\/ then (verify using datasets)\r\n        ITable actualTable = dbUnit.createQueryTable(\"customer\", \"select * from customer order by id\");\r\n        ITable expectedTable = dbUnit.jsonDataSet(\"customer-updated.json\").getTable(\"customer\");\r\n\r\n        Assertion.assertEquals(expectedTable, actualTable);\r\n    }\r\n}\r\n<\/pre>\n<p>where <tt>customer.ddl<\/tt> is:<\/p>\n<pre class=\"brush: sql;\">drop table customer if exists;\r\ncreate table customer (\r\n id         int         not null primary key\r\n   ,first_name varchar(30) not null\r\n   ,initial    varchar(1)  null\r\n   ,last_name  varchar(30) not null\r\n)\r\n<\/pre>\n<p>and <tt>customer.json<\/tt> (the initial data set) is:<\/p>\n<pre class=\"brush: java;\">{\r\n  \"customer\":\r\n   [\r\n     {\r\n       \"id\": 1,\r\n       \"first_name\": \"John\",\r\n       \"initial\": \"K\",\r\n       \"last_name\": \"Smith\"\r\n     },\r\n     {\r\n       \"id\": 2,\r\n       \"first_name\": \"Mary\",\r\n       \"last_name\": \"Jones\"\r\n     }\r\n   ]\r\n}\r\n<\/pre>\n<p>and <tt>customer-updated.json<\/tt> (the final data set) is:<\/p>\n<pre class=\"brush: java;\">{\r\n  \"customer\":\r\n   [\r\n     {\r\n       \"id\": 1,\r\n       \"first_name\": \"John\",\r\n       \"initial\": \"K\",\r\n       \"last_name\": \"Smith\"\r\n     },\r\n     {\r\n       \"id\": 2,\r\n       \"first_name\": \"Mary\",\r\n       \"last_name\": \"Bloggs\"\r\n     }\r\n   ]\r\n}\r\n<\/pre>\n<p>As you\u2019ve probably figured out, the <tt>@Ddl<\/tt> annotation optionally specifies DDL script(s) to run against the database, while the <tt>@JsonData<\/tt> defines a JSON-formatted dataset.<\/p>\n<p>The actual implementation of the <tt>DbUnitRule<\/tt> class is:<\/p>\n<pre class=\"brush: java;\">package com.danhaywood.tdd.dbunit;\r\n\r\nimport java.lang.annotation.ElementType;\r\nimport java.lang.annotation.Retention;\r\nimport java.lang.annotation.RetentionPolicy;\r\nimport java.lang.annotation.Target;\r\nimport java.nio.charset.Charset;\r\nimport java.sql.Connection;\r\nimport java.sql.ResultSet;\r\nimport java.sql.SQLException;\r\n\r\nimport org.dbunit.IDatabaseTester;\r\nimport org.dbunit.JdbcDatabaseTester;\r\nimport org.dbunit.database.IDatabaseConnection;\r\nimport org.dbunit.dataset.DataSetException;\r\nimport org.dbunit.dataset.IDataSet;\r\nimport org.dbunit.dataset.ITable;\r\nimport org.junit.rules.MethodRule;\r\nimport org.junit.runners.model.FrameworkMethod;\r\nimport org.junit.runners.model.Statement;\r\n\r\nimport com.google.common.io.Resources;\r\n\r\npublic class DbUnitRule implements MethodRule {\r\n\r\n    @Retention(RetentionPolicy.RUNTIME)\r\n    @Target({ ElementType.METHOD })\r\n    public static @interface Ddl {\r\n        String[] value();\r\n    }\r\n\r\n    @Retention(RetentionPolicy.RUNTIME)\r\n    @Target({ ElementType.METHOD })\r\n    public static @interface JsonData {\r\n        String value();\r\n    }\r\n\r\n    private final Class&lt;?&gt; resourceBase;\r\n\r\n    private IDatabaseTester databaseTester;\r\n    private IDatabaseConnection dbUnitConnection;\r\n\r\n    private Connection connection;\r\n    private java.sql.Statement statement;\r\n\r\n    public DbUnitRule(Class&lt;?&gt; resourceBase, Class&lt;?&gt; driver, String url, String user, String password) {\r\n        this.resourceBase = resourceBase;\r\n        try {\r\n            databaseTester = new JdbcDatabaseTester(driver.getName(), url, user, password);\r\n            dbUnitConnection = databaseTester.getConnection();\r\n            connection = dbUnitConnection.getConnection();\r\n            statement = connection.createStatement();\r\n        } catch (Exception e) {\r\n            throw new RuntimeException(e);\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {\r\n\r\n        return new Statement() {\r\n\r\n            @Override\r\n            public void evaluate() throws Throwable {\r\n\r\n                try {\r\n                    Ddl ddl = method.getAnnotation(Ddl.class);\r\n                    if (ddl != null) {\r\n                        String[] values = ddl.value();\r\n                        for (String value : values) {\r\n                            executeUpdate(Resources.toString(\r\n                                resourceBase.getResource(value), Charset.defaultCharset()));\r\n                        }\r\n                    }\r\n\r\n                    JsonData data = method.getAnnotation(JsonData.class);\r\n                    if (data != null) {\r\n                        IDataSet ds = new JSONDataSet(resourceBase.getResourceAsStream(data.value()));\r\n                        databaseTester.setDataSet(ds);\r\n                    }\r\n\r\n                    databaseTester.onSetup();\r\n                    base.evaluate();\r\n                } finally {\r\n                    databaseTester.onTearDown();\r\n                }\r\n            }\r\n        };\r\n    }\r\n\r\n    public java.sql.Connection getConnection() {\r\n        return connection;\r\n    }\r\n\r\n    public void executeUpdate(String sql) throws SQLException {\r\n        statement.executeUpdate(sql);\r\n    }\r\n\r\n    public ResultSet executeQuery(String sql) throws SQLException {\r\n        return statement.executeQuery(sql);\r\n    }\r\n\r\n    public IDataSet jsonDataSet(String datasetResource) {\r\n        return new JSONDataSet(resourceBase.getResourceAsStream(datasetResource));\r\n    }\r\n\r\n    public ITable createQueryTable(String string, String string2) throws DataSetException, SQLException {\r\n        return dbUnitConnection.createQueryTable(string, string2);\r\n    }\r\n}\r\n<\/pre>\n<p>This uses Lieven Doclo\u2019s JSONDataSet (copied here for your convenience):<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush: java;\">import org.codehaus.jackson.map.ObjectMapper;\r\n\r\nimport org.dbunit.dataset.*;\r\nimport org.dbunit.dataset.datatype.DataType;\r\n\r\nimport java.io.File;\r\nimport java.io.FileInputStream;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.util.*;\r\n\r\n\/**\r\n * DBUnit DataSet format for JSON based datasets. It is similar to the flat XML layout,\r\n * but has some improvements (columns are calculated by parsing the entire dataset, not just\r\n * the first row). It uses Jackson, a fast JSON processor.\r\n * &lt;br\/&gt;&lt;br\/&gt;\r\n * The format looks like this:\r\n * &lt;br\/&gt;\r\n * &lt;pre&gt;\r\n * {\r\n *    \"&amp;lt;table_name&amp;gt;\": [\r\n *        {\r\n *             \"&amp;lt;column&amp;gt;\":&amp;lt;value&amp;gt;,\r\n *             ...\r\n *        },\r\n *        ...\r\n *    ],\r\n *    ...\r\n * }\r\n * &lt;\/pre&gt;\r\n * &lt;br\/&gt;\r\n * I.e.:\r\n * &lt;br\/&gt;\r\n * &lt;pre&gt;\r\n * {\r\n *    \"test_table\": [\r\n *        {\r\n *             \"id\":1,\r\n *             \"code\":\"JSON dataset\",\r\n *        },\r\n *        {\r\n *             \"id\":2,\r\n *             \"code\":\"Another row\",\r\n *        }\r\n *    ],\r\n *    \"another_table\": [\r\n *        {\r\n *             \"id\":1,\r\n *             \"description\":\"Foo\",\r\n *        },\r\n *        {\r\n *             \"id\":2,\r\n *             \"description\":\"Bar\",\r\n *        }\r\n *    ],\r\n *    ...\r\n * }\r\n * &lt;\/pre&gt;\r\n *\r\n * @author Lieven DOCLO\r\n *\/\r\npublic class JSONDataSet extends AbstractDataSet {\r\n    \/\/ The parser for the dataset JSON file\r\n    private JSONITableParser tableParser = new JSONITableParser();\r\n\r\n    \/\/ The tables after parsing\r\n    private List&lt;ITable&gt; tables;\r\n\r\n    \/**\r\n     * Creates a JSON dataset based on a file\r\n     * @param file A JSON dataset file\r\n     *\/\r\n\r\n    public JSONDataSet(File file) {\r\n        tables = tableParser.getTables(file);\r\n    }\r\n\r\n    \/**\r\n     * Creates a JSON dataset based on an inputstream\r\n     * @param is An inputstream pointing to a JSON dataset\r\n     *\/\r\n    public JSONDataSet(InputStream is) {\r\n        tables = tableParser.getTables(is);\r\n    }\r\n\r\n    @Override\r\n    protected ITableIterator createIterator(boolean reverse) throws DataSetException {\r\n        return new DefaultTableIterator(tables.toArray(new ITable[tables.size()]));\r\n    }\r\n\r\n    private class JSONITableParser {\r\n\r\n        private ObjectMapper mapper = new ObjectMapper();\r\n\r\n        \/**\r\n         * Parses a JSON dataset file and returns the list of DBUnit tables contained in\r\n         * that file\r\n         * @param jsonFile A JSON dataset file\r\n         * @return A list of DBUnit tables\r\n         *\/\r\n        public List&lt;ITable&gt; getTables(File jsonFile) {\r\n            try {\r\n                return getTables(new FileInputStream(jsonFile));\r\n            } catch (IOException e) {\r\n                throw new RuntimeException(e.getMessage(), e);\r\n            }\r\n        }\r\n\r\n        \/**\r\n         * Parses a JSON dataset input stream and returns the list of DBUnit tables contained in\r\n         * that input stream\r\n         * @param jsonStream A JSON dataset input stream\r\n         * @return A list of DBUnit tables\r\n         *\/\r\n        @SuppressWarnings(\"unchecked\")\r\n        public List&lt;ITable&gt; getTables(InputStream jsonStream) {\r\n            List&lt;ITable&gt; tables = new ArrayList&lt;ITable&gt;();\r\n            try {\r\n                \/\/ get the base object tree from the JSON stream\r\n                Map&lt;String, Object&gt; dataset = mapper.readValue(jsonStream, Map.class);\r\n                \/\/ iterate over the tables in the object tree\r\n                for (Map.Entry&lt;String, Object&gt; entry : dataset.entrySet()) {\r\n                    \/\/ get the rows for the table\r\n                    List&lt;Map&lt;String, Object&gt;&gt; rows = (List&lt;Map&lt;String, Object&gt;&gt;) entry.getValue();\r\n                    ITableMetaData meta = getMetaData(entry.getKey(), rows);\r\n                    \/\/ create a table based on the metadata\r\n                    DefaultTable table = new DefaultTable(meta);\r\n                    int rowIndex = 0;\r\n                    \/\/ iterate through the rows and fill the table\r\n                    for (Map&lt;String, Object&gt; row : rows) {\r\n                        fillRow(table, row, rowIndex++);\r\n                    }\r\n                    \/\/ add the table to the list of DBUnit tables\r\n                    tables.add(table);\r\n                }\r\n\r\n            } catch (IOException e) {\r\n                throw new RuntimeException(e.getMessage(), e);\r\n            }\r\n            return tables;\r\n        }\r\n\r\n        \/**\r\n         * Gets the table meta data based on the rows for a table\r\n         * @param tableName The name of the table\r\n         * @param rows The rows of the table\r\n         * @return The table metadata for the table\r\n         *\/\r\n        private ITableMetaData getMetaData(String tableName, List&lt;Map&lt;String, Object&gt;&gt; rows) {\r\n            Set&lt;String&gt; columns = new LinkedHashSet&lt;String&gt;();\r\n            \/\/ iterate through the dataset and add the column names to a set\r\n            for (Map&lt;String, Object&gt; row : rows) {\r\n                for (Map.Entry&lt;String, Object&gt; column : row.entrySet()) {\r\n                    columns.add(column.getKey());\r\n                }\r\n            }\r\n            List&lt;Column&gt; list = new ArrayList&lt;Column&gt;(columns.size());\r\n            \/\/ create a list of DBUnit columns based on the column name set\r\n            for (String s : columns) {\r\n                list.add(new Column(s, DataType.UNKNOWN));\r\n            }\r\n            return new DefaultTableMetaData(tableName, list.toArray(new Column[list.size()]));\r\n        }\r\n\r\n        \/**\r\n         * Fill a table row\r\n         * @param table The table to be filled\r\n         * @param row A map containing the column values\r\n         * @param rowIndex The index of the row to te filled\r\n         *\/\r\n        private void fillRow(DefaultTable table, Map&lt;String, Object&gt; row, int rowIndex) {\r\n            try {\r\n                table.addRow();\r\n                \/\/ set the column values for the current row\r\n                for (Map.Entry&lt;String, Object&gt; column : row.entrySet()) {\r\n                    table.setValue(rowIndex, column.getKey(), column.getValue());\r\n\r\n                }\r\n            } catch (Exception e) {\r\n                throw new RuntimeException(e.getMessage(), e);\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>The libraries I used for this (ie are dependencies) are:<\/p>\n<ul>\n<li>hsqldb 2.2.6<\/li>\n<li>dbunit 2.4.8<\/li>\n<li>jackson 1.9.3<\/li>\n<li>slf4j-api-1.6.4, slf4j-nop-1.6.4<\/li>\n<li>google-guava 10.0.1<\/li>\n<li>junit 4.8<\/li>\n<\/ul>\n<p>As ever, comments are welcomed.<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/danhaywood.com\/2011\/12\/20\/db-unit-testing-with-dbunit-json-hsqldb-and-junit-rules\/\">DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a>&nbsp;Dan Haywood at the&nbsp;<a href=\"http:\/\/danhaywood.com\/\">Dan Haywood blog<\/a>.<\/p>\n<p><strong><i>Related Articles :<\/i><\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/09\/rules-in-junit-49-beta-3.html\">Rules in JUnit 4.9 (beta 3)<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/spring-3-testing-with-junit-4.html\">Spring 3 Testing with JUnit 4 &#8211; ContextConfiguration and AbstractTransactionalJUnit4SpringContextTests<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/java-restful-api-integration-testing.html\">Java RESTful API integration testing<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/when-to-replace-unit-tests-with.html\">When to replace Unit Tests with Integration Test<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/my-testing-and-code-analysis-toolbox.html\">My Testing and Code Analysis Toolbox<\/a><\/li>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/my-testing-and-code-analysis-toolbox.html\"><\/a><\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was just to teach dbUnit about JSON, but it turns out that Lieven Doclo has done that already. So I decided to go a step further &hellip;<\/p>\n","protected":false},"author":125,"featured_media":101,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[347,28,69,274],"class_list":["post-844","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-dbunit","tag-hsqldb","tag-json","tag-junit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-01-10T21:12:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T22:48:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/dbunit-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dan Haywood\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dan Haywood\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html\"},\"author\":{\"name\":\"Dan Haywood\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/097f2a343c5a25f5902838872b9a3c46\"},\"headline\":\"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules\",\"datePublished\":\"2012-01-10T21:12:00+00:00\",\"dateModified\":\"2012-10-21T22:48:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html\"},\"wordCount\":239,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/dbunit-logo.jpg\",\"keywords\":[\"dbUnit\",\"HSQLDB\",\"JSON\",\"JUnit\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html\",\"name\":\"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/dbunit-logo.jpg\",\"datePublished\":\"2012-01-10T21:12:00+00:00\",\"dateModified\":\"2012-10-21T22:48:16+00:00\",\"description\":\"In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/dbunit-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/dbunit-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/01\\\/db-unit-testing-with-dbunit-json-hsqldb.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/097f2a343c5a25f5902838872b9a3c46\",\"name\":\"Dan Haywood\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f2802d65ad9600e86cb3c09b9183ffaaa1a819d8b245682055e4728b3b03af9c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f2802d65ad9600e86cb3c09b9183ffaaa1a819d8b245682055e4728b3b03af9c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f2802d65ad9600e86cb3c09b9183ffaaa1a819d8b245682055e4728b3b03af9c?s=96&d=mm&r=g\",\"caption\":\"Dan Haywood\"},\"sameAs\":[\"http:\\\/\\\/danhaywood.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Dan-Haywood\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules - Java Code Geeks","description":"In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html","og_locale":"en_US","og_type":"article","og_title":"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules - Java Code Geeks","og_description":"In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was","og_url":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-01-10T21:12:00+00:00","article_modified_time":"2012-10-21T22:48:16+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/dbunit-logo.jpg","type":"image\/jpeg"}],"author":"Dan Haywood","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Dan Haywood","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html"},"author":{"name":"Dan Haywood","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/097f2a343c5a25f5902838872b9a3c46"},"headline":"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules","datePublished":"2012-01-10T21:12:00+00:00","dateModified":"2012-10-21T22:48:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html"},"wordCount":239,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/dbunit-logo.jpg","keywords":["dbUnit","HSQLDB","JSON","JUnit"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html","url":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html","name":"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/dbunit-logo.jpg","datePublished":"2012-01-10T21:12:00+00:00","dateModified":"2012-10-21T22:48:16+00:00","description":"In this week\u2019s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/dbunit-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/dbunit-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/01\/db-unit-testing-with-dbunit-json-hsqldb.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/097f2a343c5a25f5902838872b9a3c46","name":"Dan Haywood","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f2802d65ad9600e86cb3c09b9183ffaaa1a819d8b245682055e4728b3b03af9c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f2802d65ad9600e86cb3c09b9183ffaaa1a819d8b245682055e4728b3b03af9c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f2802d65ad9600e86cb3c09b9183ffaaa1a819d8b245682055e4728b3b03af9c?s=96&d=mm&r=g","caption":"Dan Haywood"},"sameAs":["http:\/\/danhaywood.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Dan-Haywood"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/125"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=844"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/101"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}