Skip to content

Commit

Permalink
refs #41
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Sep 4, 2016
1 parent faa4f47 commit 941d73c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Created by pestano on 03/09/16.
*
* <p/>
* pojo which represents dbunit.yml, used for global which can be overrided via @DataSet annotation
* at class or method level and with @DBUnit at class or method level
*/
Expand All @@ -29,13 +29,6 @@ public static GlobaConfig instance() {
if (instance == null) {
createInstance();
}
if(instance.getDbUnitConfig().getProperties().containsKey("escapePattern")){
if (instance.getDbUnitConfig().getProperties().get("escapePattern").equals("")){
//avoid Caused by: org.dbunit.DatabaseUnitRuntimeException: Empty string is an invalid escape pattern!
// because @DBUnit annotation and dbunit.yml global config have escapePattern defaults to ""
instance.getDbUnitConfig().getProperties().remove("escapePattern");
}
}
return instance;
}

Expand All @@ -45,14 +38,25 @@ public static GlobaConfig newInstance() {
}

private static void createInstance() {
instance = new GlobaConfig();
DBUnitConfig dbUnitConfig;
//try to instance user provided dbunit.yml
InputStream customConfiguration = Thread.currentThread().getContextClassLoader().getResourceAsStream("dbunit.yml");
if(customConfiguration != null){
instance = new Yaml().loadAs(customConfiguration, GlobaConfig.class);
} else{
//default config
instance = new Yaml().loadAs(GlobaConfig.class.getResourceAsStream("/default/dbunit.yml"), GlobaConfig.class);
if (customConfiguration != null) {
dbUnitConfig = new Yaml().loadAs(customConfiguration, DBUnitConfig.class);
} else {
//default config
dbUnitConfig = new Yaml().loadAs(GlobaConfig.class.getResourceAsStream("/default/dbunit.yml"), DBUnitConfig.class);
}

if (dbUnitConfig.getProperties().containsKey("escapePattern")) {
if (dbUnitConfig.getProperties().get("escapePattern").equals("")) {
//avoid Caused by: org.dbunit.DatabaseUnitRuntimeException: Empty string is an invalid escape pattern!
// because @DBUnit annotation and dbunit.yml global config have escapePattern defaults to ""
dbUnitConfig.getProperties().remove("escapePattern");
}
}
instance.setDbUnitConfig(dbUnitConfig);

}

Expand Down
19 changes: 9 additions & 10 deletions core/src/main/resources/default/dbunit.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
dbUnitConfig:
cacheConnection: false
cacheTables: false
properties:
batchedStatements: false
qualifiedTableNames: false
batchSize: 100
fetchSize: 100
allowEmptyFields: false
escapePattern: ""
cacheConnection: false
cacheTables: false
properties:
batchedStatements: false
qualifiedTableNames: false
batchSize: 100
fetchSize: 100
allowEmptyFields: false
escapePattern: ""
19 changes: 9 additions & 10 deletions core/src/test/resources/config/sample-dbunit.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
dbUnitConfig:
cacheConnection: true
cacheTables: true
properties:
batchedStatements: true
qualifiedTableNames: true
batchSize: 200
fetchSize: 200
allowEmptyFields: true
escapePattern: "[?]"
cacheConnection: true
cacheTables: true
properties:
batchedStatements: true
qualifiedTableNames: true
batchSize: 200
fetchSize: 200
allowEmptyFields: true
escapePattern: "[?]"

0 comments on commit 941d73c

Please sign in to comment.