Source Code Cross Referenced for SQLUtilTest.java in  » Database-Client » sqlshell » nl » improved » sqlclient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » sqlshell » nl.improved.sqlclient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Roy van der Kuil (roy@vanderkuil.nl) and Stefan Rotman (stefan@rotman.net)
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package nl.improved.sqlclient;
018:
019:        import java.util.Arrays;
020:        import java.util.List;
021:        import junit.framework.TestCase;
022:
023:        public class SQLUtilTest extends TestCase {
024:
025:            private static final boolean testFailures = true;
026:
027:            public SQLUtilTest() {
028:            }
029:
030:            public void testGetLastKeyWord() {
031:                String sql = "SELECT *";
032:                assertEquals("SELECT", SQLUtil.getLastKeyWord(sql));
033:                sql = "select *";
034:                assertEquals("select", SQLUtil.getLastKeyWord(sql));
035:                sql = "select * from";
036:                assertEquals("from", SQLUtil.getLastKeyWord(sql));
037:                sql = "SELECT * FROM";
038:                assertEquals("FROM", SQLUtil.getLastKeyWord(sql));
039:                //        sql = "DESC indummy";
040:                //        assertEquals("DESC", SQLUtil.getLastKeyWord(sql));
041:                //        sql = "DESC dummyin ";
042:                //        assertEquals("DESC", SQLUtil.getLastKeyWord(sql));
043:            }
044:
045:            public void testTabCompletionInfoBLANK() {
046:                List<String> sqlCommand = Arrays.asList(new String[] { "" });
047:                Point cursorPos = new Point(0, 0);
048:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
049:                        sqlCommand, cursorPos);
050:                assertNotNull(info);
051:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
052:                        .getMatchType());
053:                List<String> matches = info.getPossibleMatches();
054:                assertTrue(matches.contains("SELECT"));
055:                assertTrue(matches.contains("INSERT INTO"));
056:                assertTrue(matches.contains("DELETE FROM"));
057:                assertTrue(matches.contains("UPDATE"));
058:            }
059:
060:            public void testTabCompletionInfoSELECT() {
061:                List<String> sqlCommand = Arrays
062:                        .asList(new String[] { "SELECT A" });
063:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
064:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
065:                        sqlCommand, cursorPos);
066:                assertNotNull(info);
067:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
068:                        .getMatchType());
069:                List<String> matches = info.getPossibleMatches();
070:                assertEquals(0, matches.size());
071:                assertEquals("A", info.getStart());
072:
073:                sqlCommand = Arrays.asList(new String[] { "SELECT " });
074:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
075:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
076:                assertNotNull(info);
077:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
078:                        .getMatchType());
079:                matches = info.getPossibleMatches();
080:                assertEquals(0, matches.size());
081:
082:                sqlCommand = Arrays.asList(new String[] { "SELECT * " });
083:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
084:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
085:                assertNotNull(info);
086:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
087:                        .getMatchType());
088:                matches = info.getPossibleMatches();
089:                assertEquals(1, matches.size());
090:                assertTrue(matches.contains("FROM"));
091:
092:                sqlCommand = Arrays.asList(new String[] { "SELECT * FR" });
093:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
094:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
095:                assertNotNull(info);
096:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
097:                        .getMatchType());
098:                matches = info.getPossibleMatches();
099:                assertEquals(1, matches.size());
100:                assertTrue(matches.contains("FROM"));
101:                assertEquals("FR", info.getStart());
102:
103:                sqlCommand = Arrays.asList(new String[] { "SELECT a.test FR" });
104:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
105:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
106:                assertNotNull(info);
107:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
108:                        .getMatchType());
109:                matches = info.getPossibleMatches();
110:                assertEquals(1, matches.size());
111:                assertTrue(matches.contains("FROM"));
112:                assertEquals("FR", info.getStart());
113:
114:                sqlCommand = Arrays
115:                        .asList(new String[] { "SELECT a.test, a.tost FR" });
116:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
117:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
118:                assertNotNull(info);
119:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
120:                        .getMatchType());
121:                matches = info.getPossibleMatches();
122:                assertEquals(1, matches.size());
123:                assertTrue(matches.contains("FROM"));
124:                assertEquals("FR", info.getStart());
125:
126:                sqlCommand = Arrays.asList(new String[] { "SELECT A." });
127:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
128:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
129:                assertNotNull(info);
130:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
131:                        .getMatchType());
132:                matches = info.getPossibleMatches();
133:                assertEquals(1, matches.size());
134:                assertEquals("A", matches.get(0));
135:                assertEquals("", info.getStart());
136:            }
137:
138:            public void testTabCompletionInfoFROM() {
139:                List<String> sqlCommand = Arrays
140:                        .asList(new String[] { "SELECT * FROM A" });
141:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
142:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
143:                        sqlCommand, cursorPos);
144:                assertNotNull(info);
145:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
146:                        .getMatchType());
147:                List<String> matches = info.getPossibleMatches();
148:                assertEquals(0, matches.size());
149:                assertEquals("A", info.getStart());
150:
151:                sqlCommand = Arrays.asList(new String[] { "select * from A" });
152:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
153:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
154:                assertNotNull(info);
155:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
156:                        .getMatchType());
157:                matches = info.getPossibleMatches();
158:                assertEquals(0, matches.size());
159:                assertEquals("A", info.getStart());
160:
161:                sqlCommand = Arrays
162:                        .asList(new String[] { "SELECT * FROM A, B" });
163:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
164:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
165:                assertNotNull(info);
166:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
167:                        .getMatchType());
168:                matches = info.getPossibleMatches();
169:                assertEquals(0, matches.size());
170:                assertEquals("B", info.getStart());
171:
172:                sqlCommand = Arrays
173:                        .asList(new String[] { "SELECT * FROM A,B" });
174:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
175:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
176:                assertNotNull(info);
177:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
178:                        .getMatchType());
179:                matches = info.getPossibleMatches();
180:                assertEquals(0, matches.size());
181:                assertEquals("B", info.getStart());
182:
183:                sqlCommand = Arrays
184:                        .asList(new String[] { "SELECT * FROM A,B,C" });
185:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
186:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
187:                assertNotNull(info);
188:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
189:                        .getMatchType());
190:                matches = info.getPossibleMatches();
191:                assertEquals(0, matches.size());
192:                assertEquals("C", info.getStart());
193:
194:                sqlCommand = Arrays
195:                        .asList(new String[] { "select * from testdata, TESTDATA, TESTDATA, t" });
196:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
197:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
198:                assertNotNull(info);
199:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
200:                        .getMatchType());
201:                matches = info.getPossibleMatches();
202:                assertEquals(0, matches.size());
203:                assertEquals("t", info.getStart());
204:
205:                sqlCommand = Arrays
206:                        .asList(new String[] { "SELECT * FROM A WHERE 1=1" });
207:                cursorPos = new Point("SELECT * FROM A".length(), 0);
208:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
209:                assertNotNull(info);
210:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
211:                        .getMatchType());
212:                matches = info.getPossibleMatches();
213:                assertEquals(0, matches.size());
214:                assertEquals("A", info.getStart());
215:
216:                sqlCommand = Arrays
217:                        .asList(new String[] { "SELECT A.b, A.c FROM A" });
218:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
219:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
220:                assertNotNull(info);
221:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
222:                        .getMatchType());
223:                matches = info.getPossibleMatches();
224:                assertEquals(0, matches.size());
225:                assertEquals("A", info.getStart());
226:            }
227:
228:            public void testTabCompletionInfoWHERE() {
229:                List<String> sqlCommand = Arrays
230:                        .asList(new String[] { "SELECT * FROM A,B " });
231:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
232:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
233:                        sqlCommand, cursorPos);
234:                assertNotNull(info);
235:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
236:                        .getMatchType());
237:                List<String> matches = info.getPossibleMatches();
238:                assertEquals(3, matches.size());
239:                assertTrue(matches.contains("WHERE"));
240:                assertTrue(matches.contains("GROUP BY"));
241:                assertTrue(matches.contains("ORDER BY"));
242:
243:                sqlCommand = Arrays
244:                        .asList(new String[] { "SELECT * FROM A,B WH" });
245:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
246:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
247:                assertNotNull(info);
248:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
249:                        .getMatchType());
250:                matches = info.getPossibleMatches();
251:                assertEquals(3, matches.size());
252:                assertTrue(matches.contains("WHERE"));
253:                assertEquals("WH", info.getStart());
254:            }
255:
256:            public void testTabCompletionInfoWHEREConditions() {
257:                List<String> sqlCommand = Arrays
258:                        .asList(new String[] { "SELECT * FROM A,B WHERE " });
259:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
260:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
261:                        sqlCommand, cursorPos);
262:                assertNotNull(info);
263:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
264:                        .getMatchType());
265:                List<String> matches = info.getPossibleMatches();
266:                assertEquals(2, matches.size());
267:                assertTrue(matches.contains("A"));
268:                assertTrue(matches.contains("B"));
269:
270:                sqlCommand = Arrays
271:                        .asList(new String[] { "SELECT * FROM A,B WHERE I" });
272:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
273:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
274:                assertNotNull(info);
275:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
276:                        .getMatchType());
277:                matches = info.getPossibleMatches();
278:                assertEquals(2, matches.size());
279:                assertTrue(matches.contains("A"));
280:                assertTrue(matches.contains("B"));
281:                assertEquals("I", info.getStart());
282:
283:                sqlCommand = Arrays
284:                        .asList(new String[] { "SELECT * FROM A,B WHERE I=bla AND I" });
285:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
286:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
287:                assertNotNull(info);
288:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
289:                        .getMatchType());
290:                matches = info.getPossibleMatches();
291:                assertEquals(2, matches.size());
292:                assertTrue(matches.contains("A"));
293:                assertTrue(matches.contains("B"));
294:                assertEquals("I", info.getStart());
295:
296:                sqlCommand = Arrays
297:                        .asList(new String[] { "SELECT * FROM A,B WHERE A.I" });
298:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
299:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
300:                assertNotNull(info);
301:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
302:                        .getMatchType());
303:                matches = info.getPossibleMatches();
304:                //assertEquals(1, matches.size());
305:                assertTrue(matches.contains("A"));
306:                //System.out.println("I: " + info.getStart());
307:                assertEquals("I", info.getStart());
308:
309:                sqlCommand = Arrays
310:                        .asList(new String[] { "SELECT * FROM A,B WHERE A." });
311:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
312:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
313:                assertNotNull(info);
314:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
315:                        .getMatchType());
316:                matches = info.getPossibleMatches();
317:                //assertEquals(1, matches.size());
318:                assertTrue(matches.contains("A"));
319:                //System.out.println("I:'" + info.getStart() +"'");
320:                assertEquals("", info.getStart());
321:
322:                // with other conditions
323:                sqlCommand = Arrays
324:                        .asList(new String[] { "SELECT * FROM A,B WHERE A.x = 'x' AND " });
325:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
326:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
327:                assertNotNull(info);
328:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
329:                        .getMatchType());
330:                matches = info.getPossibleMatches();
331:                assertEquals(2, matches.size());
332:                assertTrue(matches.contains("A"));
333:                assertTrue(matches.contains("B"));
334:
335:                // same but with different casings
336:                sqlCommand = Arrays
337:                        .asList(new String[] { "select * From A,B whEre A.x = 'x' aNd " });
338:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
339:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
340:                assertNotNull(info);
341:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
342:                        .getMatchType());
343:                matches = info.getPossibleMatches();
344:                assertEquals(2, matches.size());
345:                assertTrue(matches.contains("A"));
346:                assertTrue(matches.contains("B"));
347:
348:                // with other conditions
349:                sqlCommand = Arrays
350:                        .asList(new String[] { "SELECT * FROM A,B WHERE A.x = a" });
351:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
352:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
353:                assertNotNull(info);
354:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
355:                        .getMatchType());
356:                matches = info.getPossibleMatches();
357:                assertTrue(matches.contains("A"));
358:                assertTrue(matches.contains("B"));
359:                assertEquals("a", info.getStart());
360:
361:                sqlCommand = Arrays
362:                        .asList(new String[] { "SELECT * FROM A,B WHERE A.x = " });
363:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
364:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
365:                assertNotNull(info);
366:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
367:                        .getMatchType());
368:                matches = info.getPossibleMatches();
369:                assertTrue(matches.contains("A"));
370:                assertTrue(matches.contains("B"));
371:                assertEquals("", info.getStart());
372:
373:                sqlCommand = Arrays
374:                        .asList(new String[] { "SELECT * FROM A,B WHERE A.x = 'x' " });
375:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
376:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
377:                assertNotNull(info);
378:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
379:                        .getMatchType());
380:                matches = info.getPossibleMatches();
381:                assertTrue(matches.contains("AND"));
382:                assertTrue(matches.contains("OR"));
383:                assertTrue(matches.contains("GROUP BY"));
384:                assertTrue(matches.contains("ORDER BY"));
385:                assertEquals("", info.getStart());
386:
387:                sqlCommand = Arrays
388:                        .asList(new String[] { "select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child = pl" });
389:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
390:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
391:                assertNotNull(info);
392:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
393:                        .getMatchType());
394:                matches = info.getPossibleMatches();
395:                assertEquals("pl", info.getStart());
396:
397:                sqlCommand = Arrays
398:                        .asList(new String[] { "select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child=pl" });
399:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
400:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
401:                assertNotNull(info);
402:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
403:                        .getMatchType());
404:                matches = info.getPossibleMatches();
405:                assertEquals("pl", info.getStart());
406:
407:                sqlCommand = Arrays
408:                        .asList(new String[] { "SELECT * FROM A,B WHERE A.x = 'x' A" });
409:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
410:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
411:                assertNotNull(info);
412:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
413:                        .getMatchType());
414:                matches = info.getPossibleMatches();
415:                assertTrue(matches.contains("AND"));
416:                assertEquals("A", info.getStart());
417:
418:                sqlCommand = Arrays
419:                        .asList(new String[] { "SELECT * FROM A,B WHERE A.x = 'x' a" });
420:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
421:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
422:                assertNotNull(info);
423:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
424:                        .getMatchType());
425:                matches = info.getPossibleMatches();
426:                assertTrue(matches.contains("AND"));
427:                assertEquals("a", info.getStart());
428:
429:                sqlCommand = Arrays
430:                        .asList(new String[] { "SELECT * FROM A,B WHERE c in('c','d','e') and A.x" });
431:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
432:                assertEquals("WHERE", SQLUtil.getLastKeyWord(sqlCommand.get(0)));
433:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
434:                assertNotNull(info);
435:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
436:                        .getMatchType());
437:                matches = info.getPossibleMatches();
438:                assertTrue(matches.contains("A"));
439:                assertEquals("x", info.getStart());
440:            }
441:
442:            public void testGroupBy() {
443:                List<String> sqlCommand = Arrays
444:                        .asList(new String[] { "SELECT c1,c2 FROM A,B WHERE a.b=b.b GROUP BY " });
445:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
446:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
447:                        sqlCommand, cursorPos);
448:                assertNotNull(info);
449:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
450:                        .getMatchType());
451:                List<String> matches = info.getPossibleMatches();
452:                assertEquals(2, matches.size());
453:                assertTrue(matches.contains("c1"));
454:                assertTrue(matches.contains("c2"));
455:
456:                sqlCommand = Arrays
457:                        .asList(new String[] { "SELECT c1 , c2 FROM A,B WHERE a.b=b.b GROUP BY " });
458:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
459:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
460:                assertNotNull(info);
461:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
462:                        .getMatchType());
463:                matches = info.getPossibleMatches();
464:                assertEquals(2, matches.size());
465:                assertTrue(matches.contains("c1"));
466:                assertTrue(matches.contains("c2"));
467:
468:                sqlCommand = Arrays
469:                        .asList(new String[] { "SELECT c1 , c2 FROM A,B WHERE a.b=b.b GROUP BY c" });
470:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
471:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
472:                assertNotNull(info);
473:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
474:                        .getMatchType());
475:                matches = info.getPossibleMatches();
476:                assertEquals(2, matches.size());
477:                assertTrue(matches.contains("c1"));
478:                assertTrue(matches.contains("c2"));
479:
480:                sqlCommand = Arrays
481:                        .asList(new String[] { "SELECT c1 , c2 FROM A,B WHERE a.b=b.b GROUP BY c1, " });
482:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
483:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
484:                assertNotNull(info);
485:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
486:                        .getMatchType());
487:                matches = info.getPossibleMatches();
488:                assertEquals(2, matches.size());
489:                assertTrue(matches.contains("c2"));
490:            }
491:
492:            public void testOrderBy() {
493:                List<String> sqlCommand = Arrays
494:                        .asList(new String[] { "SELECT c1,c2 FROM A,B WHERE a.b=b.b ORDER BY " });
495:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
496:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
497:                        sqlCommand, cursorPos);
498:                assertNotNull(info);
499:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
500:                        .getMatchType());
501:                List<String> matches = info.getPossibleMatches();
502:                assertEquals(2, matches.size());
503:                assertTrue(matches.contains("c1"));
504:                assertTrue(matches.contains("c2"));
505:
506:                sqlCommand = Arrays
507:                        .asList(new String[] { "SELECT c1 , c2 FROM A,B WHERE a.b=b.b ORDER BY " });
508:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
509:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
510:                assertNotNull(info);
511:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
512:                        .getMatchType());
513:                matches = info.getPossibleMatches();
514:                assertEquals(2, matches.size());
515:                assertTrue(matches.contains("c1"));
516:                assertTrue(matches.contains("c2"));
517:            }
518:
519:            public void testParseTableNames() {
520:                List<String> sqlCommand = Arrays
521:                        .asList(new String[] { "SELECT * FROM A WHERE " });
522:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
523:                List<? extends CharSequence> tableNames = SQLUtil
524:                        .parseTableNames(sqlCommand, cursorPos);
525:                assertEquals(1, tableNames.size());
526:                assertTrue(tableNames.contains("A"));
527:
528:                sqlCommand = Arrays
529:                        .asList(new String[] { "SELECT * FROM test1,test2 WHERE " });
530:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
531:                tableNames = SQLUtil.parseTableNames(sqlCommand, cursorPos);
532:                assertEquals(2, tableNames.size());
533:                assertTrue(tableNames.contains("test1"));
534:                assertTrue(tableNames.contains("test2"));
535:
536:                sqlCommand = Arrays
537:                        .asList(new String[] { "SELECT * FROM A,B WHERE " });
538:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
539:                tableNames = SQLUtil.parseTableNames(sqlCommand, cursorPos);
540:                assertEquals(2, tableNames.size());
541:                assertTrue(tableNames.contains("A"));
542:                assertTrue(tableNames.contains("B"));
543:
544:                sqlCommand = Arrays.asList(new String[] { "SELECT * FROM A" });
545:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
546:                tableNames = SQLUtil.parseTableNames(sqlCommand, cursorPos);
547:                assertEquals(1, tableNames.size());
548:                assertTrue(tableNames.contains("A"));
549:            }
550:
551:            public void testUpdateTabCompletion() {
552:                List<String> sqlCommand = Arrays
553:                        .asList(new String[] { "UPDATE A" });
554:                Point cursorPos = new Point(sqlCommand.get(0).length(), 0);
555:                TabCompletionInfo info = SQLUtil.getTabCompletionInfo(
556:                        sqlCommand, cursorPos);
557:                assertNotNull(info);
558:                assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info
559:                        .getMatchType());
560:                List<String> matches = info.getPossibleMatches();
561:                assertEquals(0, matches.size());
562:                assertEquals("A", info.getStart());
563:
564:                sqlCommand = Arrays.asList(new String[] { "UPDATE A " });
565:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
566:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
567:                assertNotNull(info);
568:                assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info
569:                        .getMatchType());
570:                matches = info.getPossibleMatches();
571:                assertEquals(1, matches.size());
572:                assertEquals("SET", matches.get(0));
573:                assertEquals("", info.getStart());
574:
575:                sqlCommand = Arrays.asList(new String[] { "UPDATE A SET " });
576:                cursorPos = new Point(sqlCommand.get(0).length(), 0);
577:                info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
578:                assertNotNull(info);
579:                assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info
580:                        .getMatchType());
581:                matches = info.getPossibleMatches();
582:                assertEquals(1, matches.size());
583:                assertEquals("A", matches.get(0));
584:                assertEquals("", info.getStart());
585:            }
586:
587:            /*    public void testTabCompletionInfoDESC() {
588:             List<String> sqlCommand = Arrays.asList(new String[]{"DESC "});
589:             Point cursorPos = new Point(sqlCommand.get(0).length(),0);
590:             TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
591:             assertNotNull(info);
592:             assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
593:             List<String> matches = info.getPossibleMatches();
594:             assertEquals(0, matches.size());
595:             }
596:             */
597:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.