1 16 package scriptella; 17 18 import scriptella.configuration.ConfigurationFactory; 19 import scriptella.core.ConnectionManager; 20 import scriptella.core.SqlTestHelper; 21 import scriptella.execution.EtlContext; 22 import scriptella.execution.EtlExecutor; 23 import scriptella.execution.EtlExecutorException; 24 import scriptella.interactive.ProgressIndicator; 25 import scriptella.spi.ConnectionParameters; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 31 37 public class PropertiesTest extends AbstractTestCase { 38 private EtlContext ctx; private ConnectionParameters params; 40 41 public void test() throws EtlExecutorException { 42 EtlExecutor se = prepareExecutor(null); 43 se.execute(); 44 45 assertEquals("jdbc:hsqldb:mem:propertiestest", params.getUrl()); 46 assertEquals("sa", params.getUser()); 47 assertEquals("", params.getPassword()); 48 49 assertEquals("1", ctx.getParameter("a")); 51 assertEquals("bar", ctx.getParameter("foo")); 52 assertEquals("1", ctx.getParameter("var")); 53 assertEquals("1|1|1|1|1|1", ctx.getParameter("b")); 54 assertEquals("jdbc:hsqldb:mem", ctx.getParameter("url.prefix")); 55 assertEquals("propertiestest", ctx.getParameter("dbname")); 56 assertEquals("org.hsqldb.jdbcDriver", ctx.getParameter("driver")); 57 assertEquals("org.hsqldb.jdbcDriver", ctx.getParameter("driver")); 58 assertEquals("jdbc:hsqldb:mem:propertiestest", ctx.getParameter("url")); 59 assertEquals("sa", ctx.getParameter("user")); 60 assertEquals("", ctx.getParameter("password")); 61 Map <String ,String > extra = new HashMap <String , String >(); 62 extra.put("var", "2"); 63 se = prepareExecutor(extra); 64 se.execute(); 65 assertEquals("2", ctx.getParameter("var")); 66 assertEquals("2|2|2|2|2|2", ctx.getParameter("b")); 67 } 68 69 private EtlExecutor prepareExecutor(Map <String ,String > props) { 70 ConfigurationFactory cf = new ConfigurationFactory(); 71 cf.setResourceURL(getClass().getResource(getClass().getSimpleName()+".xml")); 72 cf.setExternalProperties(props); 73 return new EtlExecutor(cf.createConfiguration()) { 74 @Override 76 protected EtlContext prepare(final ProgressIndicator indicator) { 77 ctx = super.prepare(indicator); 78 Map <String , ConnectionManager> connections = SqlTestHelper.getConnections(ctx.getSession()); 79 ConnectionManager con = connections.entrySet().iterator().next().getValue(); 80 params = SqlTestHelper.getConnectionParameters(con); 81 return ctx; 82 } 83 }; 84 85 } 86 87 } 88 | Popular Tags |