KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > SQLParametersTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.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 JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Set JavaDoc;
28
29
30 /**
31  * TODO: Add documentation
32  *
33  * @author Fyodor Kupolov
34  * @version 1.0
35  */

36 public class SQLParametersTest extends DBTestCase {
37     /**
38      * Tests substitution of global and local properties.
39      * See <a HREF="../../resources/SQLParametersTest.xml">SQLParametersTest.xml</a> for details.
40      */

41     public void testSubstitution() throws EtlExecutorException {
42         final Connection JavaDoc 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 JavaDoc id = (Integer JavaDoc) rowEvaluator.getParameter("id");
51                         final String JavaDoc text = (String JavaDoc) 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 JavaDoc c = getConnection("sqlparamstst2");
67         EtlExecutor e = newEtlExecutor("SQLParametersTest2.xml");
68         e.execute();
69
70         QueryHelper q = new QueryHelper("select * from test");
71         final Set JavaDoc expectedIds = new HashSet JavaDoc(Arrays.asList(
72                 new Integer JavaDoc[]{1, 2, 3, 10, 20, 30}));
73         q.execute(c,
74                 new QueryCallback() {
75                     public void processRow(final ParametersCallback rowEvaluator) {
76                         final Integer JavaDoc id = (Integer JavaDoc) rowEvaluator.getParameter("id");
77                         assertTrue("id must be one of " + expectedIds,
78                                 expectedIds.contains(id));
79                     }
80                 });
81     }
82 }
83
Popular Tags