01: package net.sourceforge.squirrel_sql.plugins.derby.tokenizer;
02:
03: /*
04: * Copyright (C) 2007 Rob Manning
05: * manningr@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21:
22: import static net.sourceforge.squirrel_sql.fw.sql.GenericSQL.*;
23:
24: import java.io.IOException;
25: import java.util.Arrays;
26:
27: import junit.framework.TestCase;
28: import net.sourceforge.squirrel_sql.client.ApplicationManager;
29: import net.sourceforge.squirrel_sql.fw.sql.QueryTokenizer;
30: import net.sourceforge.squirrel_sql.fw.sql.SQLUtil;
31:
32: public class DerbyQueryTokenizerTest extends TestCase {
33:
34: static String nullSQL = null;
35: static String tmpFilename = null;
36: static boolean removeMultilineComment = true;
37: static {
38: ApplicationManager.initApplication();
39: }
40:
41: QueryTokenizer qt = null;
42: static int sqlFileStmtCount = 0;
43:
44: public void setUp() throws Exception {
45: createSQLFile();
46: }
47:
48: public void tearDown() {
49:
50: }
51:
52: public void testHasQuery() {
53: qt = new DerbyQueryTokenizer(";", "--", false);
54: qt.setScriptToTokenize(CREATE_STUDENT);
55: SQLUtil.checkQueryTokenizer(qt, 1);
56:
57: qt = new DerbyQueryTokenizer(";", "--", false);
58: qt.setScriptToTokenize(CREATE_COURSES);
59: SQLUtil.checkQueryTokenizer(qt, 1);
60: }
61:
62: public void testGenericSQL() {
63: String script = SQLUtil.getGenericSQLScript();
64: qt = new DerbyQueryTokenizer(";", "--", false);
65: qt.setScriptToTokenize(script);
66: SQLUtil.checkQueryTokenizer(qt, SQLUtil.getGenericSQLCount());
67: }
68:
69: public void testHasQueryFromFile() {
70: String fileSQL = "run '" + tmpFilename + "'\n";
71: qt = new DerbyQueryTokenizer(";", "--", false);
72: qt.setScriptToTokenize(fileSQL);
73: SQLUtil.checkQueryTokenizer(qt, sqlFileStmtCount);
74: }
75:
76: private static void createSQLFile() throws IOException {
77: if (tmpFilename != null) {
78: return;
79: }
80: String[] sqls = new String[] { CREATE_COURSES,
81: CREATE_PROFESSOR, CREATE_TAKE, CREATE_TEACH,
82: STUDENTS_NOT_TAKING_CS112, };
83:
84: tmpFilename = SQLUtil.createSQLFile(Arrays.asList(sqls), true);
85: sqlFileStmtCount = sqls.length;
86: }
87:
88: }
|