01: /*
02: * Copyright 2006-2007 The Scriptella Project Team.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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: * TODO: Add documentation
32: *
33: * @author Fyodor Kupolov
34: * @version 1.0
35: */
36: public class PropertiesTest extends AbstractTestCase {
37: private EtlContext ctx; //execution context
38: private ConnectionParameters params;
39:
40: public void test() throws EtlExecutorException {
41: EtlExecutor se = prepareExecutor(null);
42: se.execute();
43:
44: assertEquals("jdbc:hsqldb:mem:propertiestest", params.getUrl());
45: assertEquals("sa", params.getUser());
46: assertEquals("", params.getPassword());
47:
48: //check substituted properties in a context
49: assertEquals("1", ctx.getParameter("a"));
50: assertEquals("bar", ctx.getParameter("foo"));
51: assertEquals("1", ctx.getParameter("var"));
52: assertEquals("1|1|1|1|1|1", ctx.getParameter("b"));
53: assertEquals("jdbc:hsqldb:mem", ctx.getParameter("url.prefix"));
54: assertEquals("propertiestest", ctx.getParameter("dbname"));
55: assertEquals("org.hsqldb.jdbcDriver", ctx
56: .getParameter("driver"));
57: assertEquals("org.hsqldb.jdbcDriver", ctx
58: .getParameter("driver"));
59: assertEquals("jdbc:hsqldb:mem:propertiestest", ctx
60: .getParameter("url"));
61: assertEquals("sa", ctx.getParameter("user"));
62: assertEquals("", ctx.getParameter("password"));
63: Map<String, String> extra = new HashMap<String, String>();
64: extra.put("var", "2");
65: se = prepareExecutor(extra);
66: se.execute();
67: assertEquals("2", ctx.getParameter("var"));
68: assertEquals("2|2|2|2|2|2", ctx.getParameter("b"));
69: }
70:
71: private EtlExecutor prepareExecutor(Map<String, String> props) {
72: ConfigurationFactory cf = new ConfigurationFactory();
73: cf.setResourceURL(getClass().getResource(
74: getClass().getSimpleName() + ".xml"));
75: cf.setExternalParameters(props);
76: return new EtlExecutor(cf.createConfiguration()) {
77: //overrides prepare method to get ctx and params for connection
78: @Override
79: protected EtlContext prepare(
80: final ProgressIndicator indicator) {
81: ctx = super .prepare(indicator);
82: Map<String, ConnectionManager> connections = SqlTestHelper
83: .getConnections(ctx.getSession());
84: ConnectionManager con = connections.entrySet()
85: .iterator().next().getValue();
86: params = SqlTestHelper.getConnectionParameters(con);
87: return ctx;
88: }
89: };
90:
91: }
92:
93: }
|