SlideShare une entreprise Scribd logo
1  sur  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 ?

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

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
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...SUHANI PANDEY
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...SUHANI PANDEY
 
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.soniya singh
 
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 Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
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
 

Dernier (20)

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
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Rani Bagh Escort Service Delhi N.C.R.
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
 
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 Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
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...
 

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 ?