willis7 / dbunit-gradle-plugin

Execute DbUnit tasks form Gradle projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DbUnit Gradle Plugin

The DbUnit Gradle Plugin allows you to easily launch DbUnit tasks from your gradle project. It is based on the DbUnit Maven Plugin to provide the same (and more) functionality but simplifying the configuration process.

Build

Tasks

There are three tasks included in the plugin:

  • Operation: Allows to specify a list of sources to operate against the database. Each source contains the file path with the data and the database operation. Available operations are INSERT, CLEAN, CLEAN_INSERT, DELETE, ...
  • Compare: Compares a file against the current database content.
  • Export: Exports the current database content to file.

Getting started

  1. Install the dbunit-gradle-plugin (in your local Maven repository, for example): gradle publishToMavenLocal

  2. Inside the build.gradle file of your current project include the plugin and the library with the database driver:

buildscript {
   repositories {
      mavenLocal()
      mavenCentral()
   }
   dependencies {
      classpath "com.ferigma:dbunit-gradle-plugin:0.1.0"
      classpath "com.h2database:h2:1.4.179"
   }
}
  1. Apply the plugin wherever you want using the DSL gradle syntax. Example:
  • Create a new task that populates your DB, executing the operation CLEAN_INSERT and using the file $rootFir/db/sample-data.xml:
dbunit {
   username = "sa"
   password = "sa"
   url = "jdbc:h2:/tmp/h2_test"
   driver = "org.h2.Driver"
   dataTypeFactoryName = "org.dbunit.ext.h2.H2DataTypeFactory"
}

task populateTestDb(type: com.ferigma.gradle.dbunit.tasks.OperationTask) {
   sources = [
      new com.ferigma.gradle.dbunit.tasks.vo.OperationSource(
      transaction: true, type: "CLEAN_INSERT", format: "xml",
      file: "$rootDir/db/sample-data.xml")
   ]
}

Tip: You can execute this task just before another. A typical use case is to populate the database with sample data for tests:

test.dependsOn populateTestDb

References

About

Execute DbUnit tasks form Gradle projects

License:MIT License


Languages

Language:Groovy 100.0%