KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > jdbc > SqlTokenizerITest


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.jdbc;
17
18 import scriptella.DBTestCase;
19 import scriptella.execution.EtlExecutorException;
20 import scriptella.spi.ParametersCallback;
21 import scriptella.spi.QueryCallback;
22
23 import java.sql.Connection JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Set JavaDoc;
27
28 /**
29  * Integration test for {@link SqlReaderTokenizer}.
30  *
31  * @author Fyodor Kupolov
32  * @version 1.0
33  */

34 public class SqlTokenizerITest extends DBTestCase {
35     public void test() throws EtlExecutorException {
36         Connection JavaDoc con = getConnection("toktest");
37         newEtlExecutor().execute();
38         //now check the data
39
final Set JavaDoc<String JavaDoc> expectedOrcl = new HashSet JavaDoc<String JavaDoc>(Arrays.asList(new String JavaDoc[] {"222", "333", "444"}));
40         new QueryHelper("select * from TestOrcl").execute(con, new QueryCallback() {
41             private int row=1;
42             public void processRow(final ParametersCallback parameters) {
43                 assertEquals(row, parameters.getParameter("1"));
44                 Object JavaDoc p = parameters.getParameter("2");
45                 assertTrue("Unexpected value "+p, expectedOrcl.remove(p));
46                 row++;
47             }
48         });
49         assertTrue("The following values were not inserted: "+expectedOrcl, expectedOrcl.isEmpty());
50         //now test sybase like script, i.e. go separated
51
final Set JavaDoc<String JavaDoc> expectedSyb = new HashSet JavaDoc<String JavaDoc>(Arrays.asList(new String JavaDoc[] {"quoted go is ignored\n" +
52                 " go\n" +
53                 " ", "333", "444"}));
54         new QueryHelper("select * from TestSyb").execute(con, new QueryCallback() {
55             private int row=1;
56             public void processRow(final ParametersCallback parameters) {
57                 assertEquals(row, parameters.getParameter("1"));
58                 Object JavaDoc p = parameters.getParameter("2");
59                 assertTrue("Unexpected value "+p, expectedSyb.remove(p));
60                 row++;
61             }
62         });
63         assertTrue("The following values were not inserted: "+expectedSyb, expectedSyb.isEmpty());
64
65     }
66 }
67
Popular Tags