Skip to content

Commit

Permalink
SYMMETRICDS-210 - Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Mar 22, 2010
1 parent 633d9ca commit 28500b4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Expand Up @@ -157,7 +157,9 @@ public Object doInConnection(Connection connection)
line = trimComments(line);
if (line.trim().length() > 0) {
if (checkStatementEnds(line)) {
sql.append(" ");
if (sql.length() > 0) {
sql.append("\n");
}
sql.append(line.substring(0, line
.lastIndexOf(delimiter)).trim());
log.debug("Sql", sql);
Expand Down Expand Up @@ -186,7 +188,7 @@ public Object doInConnection(Connection connection)
}
sql.setLength(0);
} else {
sql.append(" ");
sql.append("\n");
sql.append(line);
}
}
Expand Down
@@ -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);
}
}
@@ -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');

0 comments on commit 28500b4

Please sign in to comment.