1 16 package scriptella; 17 18 import scriptella.execution.EtlExecutor; 19 import scriptella.execution.EtlExecutorException; 20 import scriptella.jdbc.QueryHelper; 21 import scriptella.spi.ParametersCallback; 22 import scriptella.spi.QueryCallback; 23 24 import java.sql.Connection ; 25 import java.util.Arrays ; 26 import java.util.HashSet ; 27 import java.util.Set ; 28 29 30 36 public class SQLParametersTest extends DBTestCase { 37 41 public void testSubstitution() throws EtlExecutorException { 42 final Connection c = getConnection("sqlparamstst"); 43 EtlExecutor e = newEtlExecutor(); 44 e.execute(); 45 46 QueryHelper q = new QueryHelper("select * from test"); 47 q.execute(c, 48 new QueryCallback() { 49 public void processRow(final ParametersCallback rowEvaluator) { 50 final Integer id = (Integer ) rowEvaluator.getParameter("id"); 51 final String text = (String ) rowEvaluator.getParameter( 52 "text"); 53 54 if (id.equals(1)) { 55 assertEquals("globalValue", text); 56 } else if (id.equals(2)) { 57 assertEquals("global2ValueThreeglobalValue", text); 58 } else { 59 fail("Unexpected id: " + id); 60 } 61 } 62 }); 63 } 64 65 public void testNumberedParameters() throws EtlExecutorException { 66 final Connection c = getConnection("sqlparamstst2"); 67 EtlExecutor e = newEtlExecutor("SQLParametersTest2.xml"); 68 e.execute(); 69 70 QueryHelper q = new QueryHelper("select * from test"); 71 final Set expectedIds = new HashSet (Arrays.asList( 72 new Integer []{1, 2, 3, 10, 20, 30})); 73 q.execute(c, 74 new QueryCallback() { 75 public void processRow(final ParametersCallback rowEvaluator) { 76 final Integer id = (Integer ) rowEvaluator.getParameter("id"); 77 assertTrue("id must be one of " + expectedIds, 78 expectedIds.contains(id)); 79 } 80 }); 81 } 82 } 83 | Popular Tags |