Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Apr 29, 2016
1 parent 98e9bf6 commit ee5ee38
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cache:
directories:
- "$HOME/.m2/repository"

script: mvn clean package -Danimal-sniffer.skip=true
script: mvn verify
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jboss.arquillian.persistence.dbunit.cleanup.CleanupStrategyProvider;
import org.jboss.arquillian.persistence.dbunit.configuration.DBUnitConfiguration;
import org.jboss.arquillian.persistence.dbunit.configuration.DBUnitDataSeedStrategyProvider;
import org.jboss.arquillian.persistence.dbunit.data.replacement.DataSetScriptReplacer;
import org.jboss.arquillian.persistence.dbunit.dataset.DataSetRegister;
import org.jboss.arquillian.persistence.dbunit.event.CompareDBUnitData;
import org.jboss.arquillian.persistence.dbunit.event.PrepareDBUnitData;
Expand Down Expand Up @@ -143,6 +144,9 @@ private void seedDatabase() throws Exception {
final ITableFilter databaseSequenceFilter = sequenceFilterProvider.provide(connection, initialDataSet.getTableNames());
initialDataSet = new FilteredDataSet(databaseSequenceFilter, initialDataSet);
}
if(dbunitConfigurationInstance.get().isScriptableDataSets()){
initialDataSet = new DataSetScriptReplacer().replace(initialDataSet);
}
seedingStrategy().execute(connection, initialDataSet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ public class DBUnitConfiguration extends Configuration {
@Property
private IMetadataHandler metadataHandler = new DefaultMetadataHandler();

@Property
private Boolean scriptableDataSets = true;

private boolean useIdentityInsert = false;

private String defaultDataSetLocation = "datasets/";
Expand All @@ -117,6 +114,8 @@ public class DBUnitConfiguration extends Configuration {

private String customTableFilter;

private Boolean scriptableDataSets = true;


public DBUnitConfiguration() {
super("persistence-dbunit", "arquillian.extension.persistence.dbunit.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private Object[] expectedDBUnitProperties() {
JUnitParamsRunner.$(DBUNIT_FEATURES + "datatypeWarning", false),
JUnitParamsRunner.$(DBUNIT_FEATURES + "skipOracleRecycleBinTables", true),
JUnitParamsRunner.$(DBUNIT_FEATURES + "allowEmptyFields", true),
JUnitParamsRunner.$(DBUNIT_PROPERTIES + "scriptableDataSets", true),
JUnitParamsRunner.$(DBUNIT_PROPERTIES + "escapePattern", "?"),
JUnitParamsRunner.$(DBUNIT_PROPERTIES + "batchSize", 200),
JUnitParamsRunner.$(DBUNIT_PROPERTIES + "fetchSize", 300)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
package org.jboss.arquillian.persistence.dbunit.replacer;

import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatDtdDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.dbunit.dataset.xml.XmlDataSet;
import org.jboss.arquillian.persistence.dbunit.data.replacement.DataSetScriptReplacer;
import org.jboss.arquillian.persistence.dbunit.dataset.json.JsonDataSet;
import org.jboss.arquillian.persistence.dbunit.dataset.yaml.YamlDataSet;
import org.jboss.arquillian.persistence.testutils.FileLoader;
import org.jboss.arquillian.persistence.testutils.TableAssert;
Expand All @@ -38,7 +43,7 @@ public void closeStream() {
}

@Test
public void should_load_all_rows_with_content_for_table_from_yaml_file() throws Exception {
public void should_load_all_rows_with_script_content_from_yaml_file() throws Exception {
// given
input = FileLoader.load("scriptable.yml");

Expand All @@ -52,4 +57,34 @@ public void should_load_all_rows_with_content_for_table_from_yaml_file() throws
.hasRow("id: 2", "firstname: Clark", "lastname: Kent", "username: superman", "password: kryptonite", "email: [email protected]", "birthdate: "+new Date());
}

@Test
public void should_load_all_rows_with_script_content_from_json_file() throws Exception {
// given
input = FileLoader.load("scriptable.json");

// when
IDataSet jsonDataSet = new JsonDataSet(input);
jsonDataSet = new DataSetScriptReplacer().replace(jsonDataSet);

// then
TableAssert.assertThat(jsonDataSet.getTable("useraccount"))
.hasRow("id: 1", "firstname: John", "lastname: Smith", "username: doovde", "password: password", "age: 42.0")
.hasRow("id: 2", "firstname: Clark", "lastname: Kent", "username: superman", "password: kryptonite", "email: [email protected]", "birthdate: "+new Date());
}

@Test
public void should_load_all_rows_with_script_content_from_xml_file() throws Exception {
// given
input = FileLoader.load("scriptable.xml");

// when
IDataSet xmlDataSet = new FlatXmlDataSetBuilder().build(input);
xmlDataSet = new DataSetScriptReplacer().replace(xmlDataSet);

// then
TableAssert.assertThat(xmlDataSet.getTable("useraccount"))
.hasRow("id: 1", "firstname: John", "lastname: Smith", "username: doovde", "password: password", "age: 42.0", "email: \"\" ", "birthdate: \"\" ")
.hasRow("id: 2", "firstname: Clark", "lastname: Kent", "username: superman", "password: kryptonite", "age: \"\" ", "email: [email protected]", "birthdate: "+new Date());
}

}
1 change: 0 additions & 1 deletion dbunit/src/test/resources/arquillian-dbunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<property name="defaultDataSetFormat">Format.EXCEL</property>
<property name="defaultDataSetLocation">ds</property>
<property name="schema">ape</property>
<property name="scriptableDataSets">true</property>
</extension>

</arquillian>
21 changes: 21 additions & 0 deletions dbunit/src/test/resources/scriptable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"useraccount": [
{
"id": 1,
"firstname": "John",
"lastname": "Smith",
"username": "doovde",
"password": "password",
"age" : "js:var a=1;var b=1; 40 + a + b"
},
{
"id": 2,
"firstname": "Clark",
"lastname": "Kent",
"username": "superman",
"password": "kryptonite",
"email": "[email protected]",
"birthdate": "groovy: new Date()"
}
]
}
4 changes: 4 additions & 0 deletions dbunit/src/test/resources/scriptable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<dataset>
<useraccount id="1" firstname="John" lastname="Smith" username="doovde" password="password" age="js:var a=1;var b=1; 40 + a + b" email="" birthdate=""/>
<useraccount id="2" firstname="Clark" lastname="Kent" username="superman" password="kryptonite" age="" email="[email protected]" birthdate="groovy: new Date()"/>
</dataset>
1 change: 1 addition & 0 deletions int-tests/src/test/resources-jboss-7.0.2/arquillian.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<extension qualifier="persistence-dbunit">
<property name="datatypeFactory">org.dbunit.ext.h2.H2DataTypeFactory</property>
<property name="scriptableDataSets">true</property>
</extension>

<extension qualifier="transaction">
Expand Down

0 comments on commit ee5ee38

Please sign in to comment.