Permalink
Browse files

[ARQ-887] Allow to use to more than one SQL script file.

  • Loading branch information...
bartoszmajsak committed Apr 22, 2012
1 parent 296f66a commit e0f272a0936bff4437ccacf6ca90ad4e6733debc
@@ -38,9 +38,9 @@
private String defaultSqlScriptLocation = "scripts/";
- private String scriptsToExecuteBeforeTest;
+ private String[] scriptsToExecuteBeforeTest;
- private String scriptsToExecuteAfterTest;
+ private String[] scriptsToExecuteAfterTest;
private TransactionMode defaultTransactionMode = TransactionMode.COMMIT;
@@ -93,7 +93,7 @@ public boolean isDefaultDataSourceDefined()
return isDefined(defaultDataSource);
}
- public String getScriptsToExecuteBeforeTest()
+ public String[] getScriptsToExecuteBeforeTest()
{
return scriptsToExecuteBeforeTest;
}
@@ -102,12 +102,12 @@ public String getScriptsToExecuteBeforeTest()
* @param scriptsToExecuteBeforeTest Ad-hoc scripts or file location to be used before every test.
* Might be handy for turning off integrity checks.
*/
- public void setScriptsToExecuteBeforeTest(String scriptsToExecuteBeforeTest)
+ public void setScriptsToExecuteBeforeTest(String[] scriptsToExecuteBeforeTest)
{
this.scriptsToExecuteBeforeTest = scriptsToExecuteBeforeTest;
}
- public String getScriptsToExecuteAfterTest()
+ public String[] getScriptsToExecuteAfterTest()
{
return scriptsToExecuteAfterTest;
}
@@ -116,7 +116,7 @@ public String getScriptsToExecuteAfterTest()
* @param scriptsToExecuteAfterTest Ad-hoc scripts or file location to be used after every test.
* Could be used to revert operations applied by {@link #scriptsToExecuteBeforeTest}
*/
- public void setScriptsToExecuteAfterTest(String scriptsToExecuteAfterTest)
+ public void setScriptsToExecuteAfterTest(String[] scriptsToExecuteAfterTest)
{
this.scriptsToExecuteAfterTest = scriptsToExecuteAfterTest;
}
@@ -76,8 +76,8 @@ public void process(Archive<?> applicationArchive, TestClass testClass)
addResources(applicationArchive, toJavaArchive(allDataResources));
}
- addSqlScriptAsResource(applicationArchive, configurationInstance.get().getScriptsToExecuteAfterTest());
- addSqlScriptAsResource(applicationArchive, configurationInstance.get().getScriptsToExecuteBeforeTest());
+ addSqlScriptsAsResource(applicationArchive, configurationInstance.get().getScriptsToExecuteAfterTest());
+ addSqlScriptsAsResource(applicationArchive, configurationInstance.get().getScriptsToExecuteBeforeTest());
}
// Private helper methods
@@ -148,11 +148,19 @@ private JavaArchive createArchiveWithResources(String ... resourcePaths)
return dataSetsArchive;
}
- private void addSqlScriptAsResource(Archive<?> applicationArchive, String script)
+ private void addSqlScriptsAsResource(Archive<?> applicationArchive, String[] scripts)
{
- if (ScriptHelper.isSqlScriptFile(script))
+ if (scripts == null)
{
- addResources(applicationArchive, createArchiveWithResources(script));
+ return;
+ }
+
+ for (String script : scripts)
+ {
+ if (ScriptHelper.isSqlScriptFile(script))
+ {
+ addResources(applicationArchive, createArchiveWithResources(script));
+ }
}
}
@@ -18,6 +18,7 @@
package org.jboss.arquillian.persistence.core.lifecycle;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.jboss.arquillian.core.api.Event;
@@ -67,30 +68,37 @@ public void executeAfterTest(@Observes(precedence = 10) AfterPersistenceTest aft
private void executeScriptsBeforeTest(BeforePersistenceTest beforePersistenceTest)
{
final PersistenceConfiguration persistenceConfiguration = configuration.get();
- String scriptsToExecuteBeforeTest = persistenceConfiguration.getScriptsToExecuteBeforeTest();
+ String[] scriptsToExecuteBeforeTest = persistenceConfiguration.getScriptsToExecuteBeforeTest();
final List<SqlScriptResourceDescriptor> scripts = processScripts(scriptsToExecuteBeforeTest);
applyScriptsBeforeTestEvent.fire(new ApplyScriptsBeforeTest(beforePersistenceTest, scripts));
}
private void executeScriptsAfterTest(AfterPersistenceTest afterPersistenceTest)
{
final PersistenceConfiguration persistenceConfiguration = configuration.get();
- String scriptsToExecuteAfterTest = persistenceConfiguration.getScriptsToExecuteAfterTest();
+ String[] scriptsToExecuteAfterTest = persistenceConfiguration.getScriptsToExecuteAfterTest();
final List<SqlScriptResourceDescriptor> scripts = processScripts(scriptsToExecuteAfterTest);
applyScriptsAfterTestEvent.fire(new ApplyScriptsAfterTest(afterPersistenceTest, scripts));
-
}
- private List<SqlScriptResourceDescriptor> processScripts(String script)
+ private List<SqlScriptResourceDescriptor> processScripts(String[] scripts)
{
- final List<SqlScriptResourceDescriptor> processedScripts = new ArrayList<SqlScriptResourceDescriptor>();
- if (ScriptHelper.isSqlScriptFile(script))
+ if (scripts == null)
{
- processedScripts.add(new FileSqlScriptResourceDescriptor(script));
+ return Collections.emptyList();
}
- else if (!Strings.isEmpty(script))
+
+ final List<SqlScriptResourceDescriptor> processedScripts = new ArrayList<SqlScriptResourceDescriptor>();
+ for (String script : scripts)
{
- processedScripts.add(new InlineSqlScriptResourceDescriptor(script));
+ if (ScriptHelper.isSqlScriptFile(script))
+ {
+ processedScripts.add(new FileSqlScriptResourceDescriptor(script));
+ }
+ else if (!Strings.isEmpty(script))
+ {
+ processedScripts.add(new InlineSqlScriptResourceDescriptor(script));
+ }
}
return processedScripts;
}
@@ -55,7 +55,7 @@ public void should_extract_scripts_to_execute_before_test_from_external_configur
Configuration.importTo(configuration).loadFromPropertyFile("properties/custom.arquillian.persistence.properties");
// then
- assertThat(configuration.getScriptsToExecuteBeforeTest()).isEqualTo(expectedInitStatement);
+ assertThat(configuration.getScriptsToExecuteBeforeTest()).containsOnly(expectedInitStatement);
}
@Test
@@ -55,7 +55,7 @@ public void should_extract_init_statement_from_external_configuration_file() thr
Configuration.importTo(configuration).loadFrom(descriptor);
// then
- assertThat(configuration.getScriptsToExecuteBeforeTest()).isEqualTo(expectedInitStatement);
+ assertThat(configuration.getScriptsToExecuteBeforeTest()).containsOnly(expectedInitStatement);
}
@Test
@@ -21,7 +21,7 @@
<extension qualifier="persistence">
<property name="defaultDataSource">java:app/datasources/mssql_ds</property>
<property name="userTransactionJndi">java:jboss/UserTransaction</property>
- <property name="scriptsToExecuteBeforeTest">scripts/mssql-identity-insert-on.sql</property>
+ <property name="scriptsToExecuteBeforeTest">scripts/mssql-identity-insert-off.sql, scripts/mssql-identity-insert-on.sql</property>
<property name="scriptsToExecuteAfterTest">scripts/mssql-identity-insert-off.sql</property>
<property name="alwaysExcludeFromDataSetsComparision">id</property>
</extension>

0 comments on commit e0f272a

Please sign in to comment.