SlideShare a Scribd company logo
1 of 14
DBSetup
By Franck Benault
Created 03/07/2014
Last updated 13/08/2015
DBSetup plan
DBSetup : introduction
● I have used DBUnit for several years in Java EE project
including access to Dabase (often with Hibernate)
● I have a lot of Junit tests with DBUnit
● DBUnit has helpt me a lot... but I am not satisfy by the
result
● The test are heavy, slow, difficult to maintain
● The solution is new library DBSetup
Issues with DBUnit
● DBUnit is not independant, this is a Junit extension
● DBUnit is using XML files (verbious, far from Java code)
● DBUnit is larger than DbSetup
– DBSetup : data injection in database only
– DBUnit : it is possible to check the content of the
database (not useful)
Presentation of DBSetup
● Goal : setup your database to execute unit tests
– Like DbUnit but simplier
● Web site :
● http://dbsetup.ninja-squad.com/
● Last version 1.6.0 (06/2015)
Advantages of DBSetup
● No XML
– Data are defined in Java
● Easy to factory the data set
● No dependencies
– DbUnit has 3 dependencies
● Fast
● OpenSource
Example1 : clean insert in a table
Operation DELETE_ALL = deleteAllFrom("USERS");
Operation INSERT_USERS_DATA =insertInto("USERS")
.columns("ID", "LOGIN", "PASSWORD")
.values(1L, "root", "pwd")
.values(2L, "guest", "pwd").build();
Operation operation = Operations.sequenceOf(
DBSetupCommonOperations.DELETE_ALL,
DBSetupCommonOperations.INSERT_USERS_DATA);
DbSetup dbSetup = new DbSetup(new DataSourceDestination(getDataSource()),
operation);
dbSetup.launch();
Example 2a: auto increment for the
keys
Operation DELETE_ALL = deleteAllFrom("USERS");
Operation INSERT_USERS_DATA = insertInto("USERS")
.withGeneratedValue("ID",
ValueGenerators.sequence().startingAt(100L).incrementingBy(10))
.columns("LOGIN", "PASSWORD")
.values("root", "pwd")
.values("guest", "pwd").build();
Operation operation = Operations.sequenceOf(
DBSetupCommonOperations.DELETE_ALL,
DBSetupCommonOperations.INSERT_USERS_DATA);
DbSetup dbSetup = new DbSetup(new DataSourceDestination(getDataSource()), operation);
dbSetup.launch();
Example 2b: repeating values
Operation DELETE_ALL = deleteAllFrom("USERS");
Operation INSERT_USERS_DATA_REPEATING = insertInto("USERS")
.withGeneratedValue("ID", ValueGenerators.sequence().startingAt(1L))
.withGeneratedValue("LOGIN",
ValueGenerators.stringSequence("user-").startingAt(1L))
.withGeneratedValue("PASSWORD",
ValueGenerators.stringSequence("pwd-").startingAt(1L))
.columns("DESCRIPTION").repeatingValues("fake description")
.times(10).build();
Operation operation = Operations.sequenceOf(
DBSetupCommonOperations.DELETE_ALL,
DBSetupCommonOperations.INSERT_USERS_DATA_REPEATING);
../..
Example 3: date
● I want in my dataset a date = yesterday or tomorrow or
one year ago...
● Very difficult with DBUnit
● Very easy DbSetup because the dataset is defined in the
java code
Operation INSERT_USERS_DATA = insertInto("USERS")
.columns("ID","LOGIN", "PASSWORD", "DEACTIVATION_DATE")
.values(1L,"root", "pwd", DateUtil.getTomorrow())
.values(2L,"guest", "pwd", DateUtil.getTomorrow())
.values(3L,"guest", "pwd", DateUtil.getYesterday()).build();
Example 4: setup tracker
● My data set may be modified by the tests
@Before
public void setUp() {
.../...
DbSetup dbSetup = new DbSetup(new DataSourceDestination(dbManager.getDataSource()), operation);
dbSetupTracker.launchIfNecessary(dbSetup);
}
@Test
public void testFindAllUsers() {
dbSetupTracker.skipNextLaunch();
// a test which does not modify the data set
}
Example5 : cyclic dependencies
● How to update a (bad designed) data model when two tables a
linked with foreign
● With DBUnit no solution / DbSetup add sql request...
Operation insertVendorsAndProducts = sequenceOf(
insertInto("VENDOR")
.columns("ID", "VCODE", "NAME")
.values(1L, "AMA", "AMAZON")
.build(),
insertInto("PRODUCT")
.columns("ID", "NAME", "VENDOR_ID")
.values(1L, "Kindle", 1L).build(),
sql("update VENDOR set FEATURED_PRODUCT_ID = 1 where ID = 1"));
Example 6 : DBUnit compare
tables
● DBSetup is limited to fill database
● With DBUnit it is possible to compare the content of the database
with an excepted result defined in XML
// Fetch database data after executing your code
IDatabaseConnection dc = new DatabaseConnection(dbManager.getConnection());
IDataSet databaseDataSet = dc.createDataSet();
ITable actualTable = databaseDataSet.getTable("USERS");
// Load expected data from an XML dataset
InputStream is = UserQueriesTestWithDbUnit.class.getResourceAsStream("/usersWithoutGuest.xml");
IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
ITable expectedTable = expectedDataSet.getTable("USERS");
// Assert actual database table match expected table
new DbUnitAssert().assertEquals(expectedTable, actualTable);
Conclusion
● DBSetup as fast or a little faster as DBUnit
● Ready to use DBSetup ?
● Questions
– How to migrate from DBUnit to DBSetup
● Tools XML -> Java
– Futur of DBSetup ?

More Related Content

What's hot

Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 
New Authorization library for Joomla 4 (proposal)
New Authorization library for Joomla 4 (proposal)New Authorization library for Joomla 4 (proposal)
New Authorization library for Joomla 4 (proposal)Klas Berlič Fras
 
Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8Théodore Biadala
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLAntony T Curtis
 
Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Serhii Kartashov
 
Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?Marcin Gajda
 
Struts database access
Struts database accessStruts database access
Struts database accessAbass Ndiaye
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersJim Mlodgenski
 
Drupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in DrupalDrupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in DrupalBryan Braun
 
Core Data Performance Guide Line
Core Data Performance Guide LineCore Data Performance Guide Line
Core Data Performance Guide LineGagan Vishal Mishra
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
Utopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K usersUtopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K usersJaime Buelta
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component PresentationJohn Coonen
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Antony T Curtis
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLJohn David Duncan
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBAntony T Curtis
 
Db examples
Db examplesDb examples
Db examplesABDUmomo
 

What's hot (20)

Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
New Authorization library for Joomla 4 (proposal)
New Authorization library for Joomla 4 (proposal)New Authorization library for Joomla 4 (proposal)
New Authorization library for Joomla 4 (proposal)
 
My sql tutorial-oscon-2012
My sql tutorial-oscon-2012My sql tutorial-oscon-2012
My sql tutorial-oscon-2012
 
Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
 
Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.
 
Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?Czym jest webpack i dlaczego chcesz go używać?
Czym jest webpack i dlaczego chcesz go używać?
 
Struts database access
Struts database accessStruts database access
Struts database access
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL Triggers
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Drupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in DrupalDrupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in Drupal
 
Core Data Performance Guide Line
Core Data Performance Guide LineCore Data Performance Guide Line
Core Data Performance Guide Line
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
Utopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K usersUtopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K users
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
 
Unit testing
Unit testingUnit testing
Unit testing
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
 
Db examples
Db examplesDb examples
Db examples
 

Similar to DbSetup

Java Unit Testing with Unitils
Java Unit Testing with UnitilsJava Unit Testing with Unitils
Java Unit Testing with UnitilsMikalai Alimenkou
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentationsourabh aggarwal
 
How To Build A Personal Portal On Google App Engine With Django
How To Build A Personal Portal On Google App Engine With DjangoHow To Build A Personal Portal On Google App Engine With Django
How To Build A Personal Portal On Google App Engine With DjangoJimmy Lu
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring DataCorneil du Plessis
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-featuresNavneet Upneja
 
Connect2016 AD1387 Integrate with XPages and Java
Connect2016 AD1387 Integrate with XPages and JavaConnect2016 AD1387 Integrate with XPages and Java
Connect2016 AD1387 Integrate with XPages and JavaJulian Robichaux
 
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...panagenda
 
Ride the database in JUnit tests with Database Rider
Ride the database in JUnit tests with Database RiderRide the database in JUnit tests with Database Rider
Ride the database in JUnit tests with Database RiderMikalai Alimenkou
 
4 Essential Checklist to Manage Drupal Projects
4 Essential Checklist to Manage Drupal Projects4 Essential Checklist to Manage Drupal Projects
4 Essential Checklist to Manage Drupal ProjectsSnake Hill Web Agency
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIstyomo4ka
 
SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBUniFabric
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?Dmitri Shiryaev
 
Google BigQuery 101 & What’s New
Google BigQuery 101 & What’s NewGoogle BigQuery 101 & What’s New
Google BigQuery 101 & What’s NewDoiT International
 
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptxJosé Lin
 
13 java beans
13 java beans13 java beans
13 java beanssnopteck
 
Ip project work test your knowledge
Ip project work test your knowledgeIp project work test your knowledge
Ip project work test your knowledgeKïShørê Choudhary
 
In Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitIn Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitMohammad Sabir Khan
 

Similar to DbSetup (20)

Java Unit Testing with Unitils
Java Unit Testing with UnitilsJava Unit Testing with Unitils
Java Unit Testing with Unitils
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
 
How To Build A Personal Portal On Google App Engine With Django
How To Build A Personal Portal On Google App Engine With DjangoHow To Build A Personal Portal On Google App Engine With Django
How To Build A Personal Portal On Google App Engine With Django
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring Data
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-features
 
Connect2016 AD1387 Integrate with XPages and Java
Connect2016 AD1387 Integrate with XPages and JavaConnect2016 AD1387 Integrate with XPages and Java
Connect2016 AD1387 Integrate with XPages and Java
 
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
AD1387: Outside The Box: Integrating with Non-Domino Apps using XPages and Ja...
 
Ride the database in JUnit tests with Database Rider
Ride the database in JUnit tests with Database RiderRide the database in JUnit tests with Database Rider
Ride the database in JUnit tests with Database Rider
 
4 Essential Checklist to Manage Drupal Projects
4 Essential Checklist to Manage Drupal Projects4 Essential Checklist to Manage Drupal Projects
4 Essential Checklist to Manage Drupal Projects
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIs
 
SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DB
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
 
Google BigQuery 101 & What’s New
Google BigQuery 101 & What’s NewGoogle BigQuery 101 & What’s New
Google BigQuery 101 & What’s New
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
 
13 java beans
13 java beans13 java beans
13 java beans
 
Ip project work test your knowledge
Ip project work test your knowledgeIp project work test your knowledge
Ip project work test your knowledge
 
In Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitIn Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnit
 

More from fbenault

Property based-testing
Property based-testingProperty based-testing
Property based-testingfbenault
 
Java concurrency
Java concurrencyJava concurrency
Java concurrencyfbenault
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language Rfbenault
 
Assertj-core
Assertj-coreAssertj-core
Assertj-corefbenault
 
System rules
System rulesSystem rules
System rulesfbenault
 
Db in-memory
Db in-memoryDb in-memory
Db in-memoryfbenault
 

More from fbenault (12)

Bdd java
Bdd javaBdd java
Bdd java
 
Property based-testing
Property based-testingProperty based-testing
Property based-testing
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Test ng
Test ngTest ng
Test ng
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language R
 
Assertj-core
Assertj-coreAssertj-core
Assertj-core
 
Junit
JunitJunit
Junit
 
System rules
System rulesSystem rules
System rules
 
Db in-memory
Db in-memoryDb in-memory
Db in-memory
 
Guava
GuavaGuava
Guava
 
Java8
Java8Java8
Java8
 
Easymock
EasymockEasymock
Easymock
 

Recently uploaded

All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445ruhi
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...SUHANI PANDEY
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋nirzagarg
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubaikojalkojal131
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...SUHANI PANDEY
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...tanu pandey
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceDelhi Call girls
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋nirzagarg
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...nirzagarg
 

Recently uploaded (20)

Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
 

DbSetup

  • 1. DBSetup By Franck Benault Created 03/07/2014 Last updated 13/08/2015
  • 3. DBSetup : introduction ● I have used DBUnit for several years in Java EE project including access to Dabase (often with Hibernate) ● I have a lot of Junit tests with DBUnit ● DBUnit has helpt me a lot... but I am not satisfy by the result ● The test are heavy, slow, difficult to maintain ● The solution is new library DBSetup
  • 4. Issues with DBUnit ● DBUnit is not independant, this is a Junit extension ● DBUnit is using XML files (verbious, far from Java code) ● DBUnit is larger than DbSetup – DBSetup : data injection in database only – DBUnit : it is possible to check the content of the database (not useful)
  • 5. Presentation of DBSetup ● Goal : setup your database to execute unit tests – Like DbUnit but simplier ● Web site : ● http://dbsetup.ninja-squad.com/ ● Last version 1.6.0 (06/2015)
  • 6. Advantages of DBSetup ● No XML – Data are defined in Java ● Easy to factory the data set ● No dependencies – DbUnit has 3 dependencies ● Fast ● OpenSource
  • 7. Example1 : clean insert in a table Operation DELETE_ALL = deleteAllFrom("USERS"); Operation INSERT_USERS_DATA =insertInto("USERS") .columns("ID", "LOGIN", "PASSWORD") .values(1L, "root", "pwd") .values(2L, "guest", "pwd").build(); Operation operation = Operations.sequenceOf( DBSetupCommonOperations.DELETE_ALL, DBSetupCommonOperations.INSERT_USERS_DATA); DbSetup dbSetup = new DbSetup(new DataSourceDestination(getDataSource()), operation); dbSetup.launch();
  • 8. Example 2a: auto increment for the keys Operation DELETE_ALL = deleteAllFrom("USERS"); Operation INSERT_USERS_DATA = insertInto("USERS") .withGeneratedValue("ID", ValueGenerators.sequence().startingAt(100L).incrementingBy(10)) .columns("LOGIN", "PASSWORD") .values("root", "pwd") .values("guest", "pwd").build(); Operation operation = Operations.sequenceOf( DBSetupCommonOperations.DELETE_ALL, DBSetupCommonOperations.INSERT_USERS_DATA); DbSetup dbSetup = new DbSetup(new DataSourceDestination(getDataSource()), operation); dbSetup.launch();
  • 9. Example 2b: repeating values Operation DELETE_ALL = deleteAllFrom("USERS"); Operation INSERT_USERS_DATA_REPEATING = insertInto("USERS") .withGeneratedValue("ID", ValueGenerators.sequence().startingAt(1L)) .withGeneratedValue("LOGIN", ValueGenerators.stringSequence("user-").startingAt(1L)) .withGeneratedValue("PASSWORD", ValueGenerators.stringSequence("pwd-").startingAt(1L)) .columns("DESCRIPTION").repeatingValues("fake description") .times(10).build(); Operation operation = Operations.sequenceOf( DBSetupCommonOperations.DELETE_ALL, DBSetupCommonOperations.INSERT_USERS_DATA_REPEATING); ../..
  • 10. Example 3: date ● I want in my dataset a date = yesterday or tomorrow or one year ago... ● Very difficult with DBUnit ● Very easy DbSetup because the dataset is defined in the java code Operation INSERT_USERS_DATA = insertInto("USERS") .columns("ID","LOGIN", "PASSWORD", "DEACTIVATION_DATE") .values(1L,"root", "pwd", DateUtil.getTomorrow()) .values(2L,"guest", "pwd", DateUtil.getTomorrow()) .values(3L,"guest", "pwd", DateUtil.getYesterday()).build();
  • 11. Example 4: setup tracker ● My data set may be modified by the tests @Before public void setUp() { .../... DbSetup dbSetup = new DbSetup(new DataSourceDestination(dbManager.getDataSource()), operation); dbSetupTracker.launchIfNecessary(dbSetup); } @Test public void testFindAllUsers() { dbSetupTracker.skipNextLaunch(); // a test which does not modify the data set }
  • 12. Example5 : cyclic dependencies ● How to update a (bad designed) data model when two tables a linked with foreign ● With DBUnit no solution / DbSetup add sql request... Operation insertVendorsAndProducts = sequenceOf( insertInto("VENDOR") .columns("ID", "VCODE", "NAME") .values(1L, "AMA", "AMAZON") .build(), insertInto("PRODUCT") .columns("ID", "NAME", "VENDOR_ID") .values(1L, "Kindle", 1L).build(), sql("update VENDOR set FEATURED_PRODUCT_ID = 1 where ID = 1"));
  • 13. Example 6 : DBUnit compare tables ● DBSetup is limited to fill database ● With DBUnit it is possible to compare the content of the database with an excepted result defined in XML // Fetch database data after executing your code IDatabaseConnection dc = new DatabaseConnection(dbManager.getConnection()); IDataSet databaseDataSet = dc.createDataSet(); ITable actualTable = databaseDataSet.getTable("USERS"); // Load expected data from an XML dataset InputStream is = UserQueriesTestWithDbUnit.class.getResourceAsStream("/usersWithoutGuest.xml"); IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is); ITable expectedTable = expectedDataSet.getTable("USERS"); // Assert actual database table match expected table new DbUnitAssert().assertEquals(expectedTable, actualTable);
  • 14. Conclusion ● DBSetup as fast or a little faster as DBUnit ● Ready to use DBSetup ? ● Questions – How to migrate from DBUnit to DBSetup ● Tools XML -> Java – Futur of DBSetup ?