Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
symmetric/src/test/java/org/jumpmind/symmetric/db/SqlScriptUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.jumpmind.symmetric.db; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.datasource.SingleConnectionDataSource; | ||
|
||
public class SqlScriptUnitTest { | ||
|
||
@Test | ||
public void testSimpleSqlScript() throws Exception { | ||
SingleConnectionDataSource ds = getDataSource(); | ||
SqlScript script = new SqlScript(getClass().getResource("sqlscript-simple.sql"), ds); | ||
script.execute(); | ||
JdbcTemplate template = new JdbcTemplate(ds); | ||
Assert.assertEquals(2, template.queryForInt("select count(*) from test")); | ||
Assert.assertEquals(3, template.queryForObject("select test from test where test_id=2", String.class).split("\r\n|\r|\n").length); | ||
ds.destroy(); | ||
} | ||
|
||
private SingleConnectionDataSource getDataSource() throws Exception { | ||
Connection c = DriverManager.getConnection("jdbc:h2:mem:sqlscript"); | ||
return new SingleConnectionDataSource(c, true); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
symmetric/src/test/resources/org/jumpmind/symmetric/db/sqlscript-simple.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
create table TEST (TEST_ID INTEGER PRIMARY KEY, TEST VARCHAR(100)); | ||
|
||
insert into TEST values(1, 'one'); | ||
insert into TEST values(2, 'line1 | ||
line2 | ||
line3'); |