Source Code Cross Referenced for AbstractParserTest.java in  » Database-DBMS » axion » org » axiondb » parser » 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 DBMS » axion » org.axiondb.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  $Id: AbstractParserTest.java,v 1.9 2005/12/20 18:32:28 ahimanikya Exp $
0003:         *  =======================================================================
0004:         *  Copyright (c) 2002-2003 Axion Development Team.  All rights reserved.
0005:         *
0006:         *  Redistribution and use in source and binary forms, with or without
0007:         *  modification, are permitted provided that the following conditions
0008:         *  are met:
0009:         *
0010:         *  1. Redistributions of source code must retain the above
0011:         *  copyright notice, this list of conditions and the following
0012:         *  disclaimer.
0013:         *
0014:         *  2. Redistributions in binary form must reproduce the above copyright
0015:         *  notice, this list of conditions and the following disclaimer in
0016:         *  the documentation and/or other materials provided with the
0017:         *  distribution.
0018:         *
0019:         *  3. The names "Tigris", "Axion", nor the names of its contributors may
0020:         *  not be used to endorse or promote products derived from this
0021:         *  software without specific prior written permission.
0022:         *
0023:         *  4. Products derived from this software may not be called "Axion", nor
0024:         *  may "Tigris" or "Axion" appear in their names without specific prior
0025:         *  written permission.
0026:         *
0027:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0028:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0029:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
0030:         *  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0031:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0032:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0033:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0034:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0035:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0036:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0037:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0038:         *  =======================================================================
0039:         */
0040:        package org.axiondb.parser;
0041:
0042:        import java.util.Iterator;
0043:        import java.util.List;
0044:
0045:        import junit.framework.TestCase;
0046:
0047:        import org.axiondb.AxionCommand;
0048:        import org.axiondb.AxionException;
0049:        import org.axiondb.BindVariable;
0050:        import org.axiondb.ColumnIdentifier;
0051:        import org.axiondb.Literal;
0052:        import org.axiondb.OrderNode;
0053:        import org.axiondb.Selectable;
0054:        import org.axiondb.TableIdentifier;
0055:        import org.axiondb.constraints.CheckConstraint;
0056:        import org.axiondb.constraints.NotNullConstraint;
0057:        import org.axiondb.constraints.NullConstraint;
0058:        import org.axiondb.constraints.PrimaryKeyConstraint;
0059:        import org.axiondb.constraints.UniqueConstraint;
0060:        import org.axiondb.engine.commands.AddConstraintCommand;
0061:        import org.axiondb.engine.commands.CreateIndexCommand;
0062:        import org.axiondb.engine.commands.CreateTableCommand;
0063:        import org.axiondb.engine.commands.DeleteCommand;
0064:        import org.axiondb.engine.commands.DropConstraintCommand;
0065:        import org.axiondb.engine.commands.DropTableCommand;
0066:        import org.axiondb.engine.commands.InsertCommand;
0067:        import org.axiondb.engine.commands.RemountCommand;
0068:        import org.axiondb.engine.commands.SelectCommand;
0069:        import org.axiondb.engine.commands.ShutdownCommand;
0070:        import org.axiondb.engine.commands.UpdateCommand;
0071:        import org.axiondb.functions.FunctionIdentifier;
0072:        import org.axiondb.types.BooleanType;
0073:        import org.axiondb.types.CharacterType;
0074:
0075:        /**
0076:         * @version $Revision: 1.9 $ $Date: 2005/12/20 18:32:28 $
0077:         * @author  Rodney Waldhoff
0078:         * @author  Chuck Burdick
0079:         * @author  Dave Pekarek Krohn
0080:         */
0081:        public abstract class AbstractParserTest extends TestCase {
0082:
0083:            //------------------------------------------------------------ Conventional
0084:
0085:            public AbstractParserTest(String testName) {
0086:                super (testName);
0087:            }
0088:
0089:            //---------------------------------------------------------------- Abstract
0090:
0091:            public abstract Parser getParser();
0092:
0093:            //--------------------------------------------------------------- Lifecycle
0094:
0095:            //------------------------------------------------------------------- Tests
0096:
0097:            public void testBadSQL() throws Exception {
0098:                Parser parser = getParser();
0099:                try {
0100:                    parser.parse("xyzzy");
0101:                    fail("Expected AxionException");
0102:                } catch (AxionException e) {
0103:                    // expected
0104:                }
0105:            }
0106:
0107:            public void testVarious() throws Exception {
0108:                Parser parser = getParser();
0109:                assertNotNull(parser
0110:                        .parse("select * from foobar where foo or bar"));
0111:                assertNotNull(parser
0112:                        .parse("select * from foobar where foo or true"));
0113:                assertNotNull(parser
0114:                        .parse("select * from foobar where true or foo"));
0115:                assertNotNull(parser.parse("select 1 + foo from foobar"));
0116:                assertNotNull(parser.parse("select foo + 1 from foobar"));
0117:                assertNotNull(parser
0118:                        .parse("select * from foobar where foo + 1 > 5"));
0119:            }
0120:
0121:            // create unique index BAR on FOO ( NUM )
0122:            public void test_create_unique_index_bar_on_foo_num()
0123:                    throws Exception {
0124:                Parser parser = getParser();
0125:                AxionCommand cmd = parser
0126:                        .parse("create unique index BAR on FOO ( NUM )");
0127:                assertNotNull("Command should not be null", cmd);
0128:                assertTrue("Command should be a CreateIndexCommand",
0129:                        cmd instanceof  CreateIndexCommand);
0130:                CreateIndexCommand create = (CreateIndexCommand) cmd;
0131:                assertTrue("Should be unique", create.isUnique());
0132:                assertTrue("Type should be null", null == create.getType());
0133:                assertEquals("Name of index should be BAR", "BAR", create
0134:                        .getObjectName());
0135:                assertEquals("Name of table should be FOO", "FOO", create
0136:                        .getTable().getTableName());
0137:                assertEquals("Should have one column", 1, create
0138:                        .getColumnCount());
0139:                assertEquals("Name of column should be NUM", "NUM", create
0140:                        .getColumn(0).getName());
0141:            }
0142:
0143:            // create index BAR on FOO ( NUM )
0144:            public void test_create_index_bar_on_foo_num() throws Exception {
0145:                Parser parser = getParser();
0146:                AxionCommand cmd = parser
0147:                        .parse("create index BAR on FOO ( NUM )");
0148:                assertNotNull("Command should not be null", cmd);
0149:                assertTrue("Command should be a CreateIndexCommand",
0150:                        cmd instanceof  CreateIndexCommand);
0151:                CreateIndexCommand create = (CreateIndexCommand) cmd;
0152:                assertTrue("Should not be unique", !create.isUnique());
0153:                assertTrue("Type should be null", null == create.getType());
0154:                assertEquals("Name of index should be BAR", "BAR", create
0155:                        .getObjectName());
0156:                assertEquals("Name of table should be FOO", "FOO", create
0157:                        .getTable().getTableName());
0158:                assertEquals("Should have one column", 1, create
0159:                        .getColumnCount());
0160:                assertEquals("Name of column should be NUM", "NUM", create
0161:                        .getColumn(0).getName());
0162:            }
0163:
0164:            // create index BAR on FOO ( NUM, DESCR )
0165:            public void test_create_index_bar_on_foo_num_descr()
0166:                    throws Exception {
0167:                Parser parser = getParser();
0168:                AxionCommand cmd = parser
0169:                        .parse("create index BAR on FOO ( NUM, DESCR )");
0170:                assertNotNull("Command should not be null", cmd);
0171:                assertTrue("Command should be a CreateIndexCommand",
0172:                        cmd instanceof  CreateIndexCommand);
0173:                CreateIndexCommand create = (CreateIndexCommand) cmd;
0174:                assertTrue("Should not be unique", !create.isUnique());
0175:                assertTrue("Type should be null", null == create.getType());
0176:                assertEquals("Name of index should be BAR", "BAR", create
0177:                        .getObjectName());
0178:                assertEquals("Name of table should be FOO", "FOO", create
0179:                        .getTable().getTableName());
0180:                assertEquals("Should have two columns", 2, create
0181:                        .getColumnCount());
0182:                assertEquals("Name of column should be NUM", "NUM", create
0183:                        .getColumn(0).getName());
0184:                assertEquals("Name of column should be DESCR", "DESCR", create
0185:                        .getColumn(1).getName());
0186:            }
0187:
0188:            // create TRANSIENT index BAR on FOO ( NUM )
0189:            public void test_create_transient_index_bar_on_foo_num()
0190:                    throws Exception {
0191:                Parser parser = getParser();
0192:                AxionCommand cmd = parser
0193:                        .parse("create TRANSIENT index BAR on FOO ( NUM )");
0194:                assertNotNull("Command should not be null", cmd);
0195:                assertTrue("Command should be a CreateIndexCommand",
0196:                        cmd instanceof  CreateIndexCommand);
0197:                CreateIndexCommand create = (CreateIndexCommand) cmd;
0198:                assertTrue("Should not be unique", !create.isUnique());
0199:                assertEquals("Type should be TRANSIENT", "TRANSIENT", create
0200:                        .getType());
0201:                assertEquals("Name of index should be BAR", "BAR", create
0202:                        .getObjectName());
0203:                assertEquals("Name of table should be FOO", "FOO", create
0204:                        .getTable().getTableName());
0205:                assertEquals("Should have one column", 1, create
0206:                        .getColumnCount());
0207:                assertEquals("Name of column should be NUM", "NUM", create
0208:                        .getColumn(0).getName());
0209:            }
0210:
0211:            // create unique TRANSIENT index BAR on FOO ( NUM )
0212:            public void test_create_unique_transient_index_bar_on_foo_num()
0213:                    throws Exception {
0214:                Parser parser = getParser();
0215:                AxionCommand cmd = parser
0216:                        .parse("create unique TRANSIENT index BAR on FOO ( NUM )");
0217:                assertNotNull("Command should not be null", cmd);
0218:                assertTrue("Command should be a CreateIndexCommand",
0219:                        cmd instanceof  CreateIndexCommand);
0220:                CreateIndexCommand create = (CreateIndexCommand) cmd;
0221:                assertTrue("Should be unique", create.isUnique());
0222:                assertEquals("Type should be TRANSIENT", "TRANSIENT", create
0223:                        .getType());
0224:                assertEquals("Name of index should be BAR", "BAR", create
0225:                        .getObjectName());
0226:                assertEquals("Name of table should be FOO", "FOO", create
0227:                        .getTable().getTableName());
0228:                assertEquals("Should have one column", 1, create
0229:                        .getColumnCount());
0230:                assertEquals("Name of column should be NUM", "NUM", create
0231:                        .getColumn(0).getName());
0232:            }
0233:
0234:            // create table FOO ( NUM integer, DESCR string )
0235:            public void testCreateTable() throws Exception {
0236:                Parser parser = getParser();
0237:
0238:                AxionCommand cmd = parser
0239:                        .parse("create table FOO ( NUM integer, DESCR varchar(10) )");
0240:                assertNotNull("Command should not be null", cmd);
0241:                assertTrue("Command should be a CreateTableCommand",
0242:                        cmd instanceof  CreateTableCommand);
0243:                CreateTableCommand create = (CreateTableCommand) cmd;
0244:                assertNull(create.getType());
0245:                assertTrue(!create.isIfNotExists());
0246:            }
0247:
0248:            // create table if not exists FOO ( NUM integer, DESCR string )
0249:            public void testCreateTableIfNotExists() throws Exception {
0250:                Parser parser = getParser();
0251:
0252:                AxionCommand cmd = parser
0253:                        .parse("create table if not exists FOO ( NUM integer, DESCR varchar(10) )");
0254:                assertNotNull("Command should not be null", cmd);
0255:                assertTrue("Command should be a CreateTableCommand",
0256:                        cmd instanceof  CreateTableCommand);
0257:                CreateTableCommand create = (CreateTableCommand) cmd;
0258:                assertTrue(create.isIfNotExists());
0259:            }
0260:
0261:            // create table FOO ( NUM integer, blah VARCHAR (30) )
0262:            public void testCreateTableWithVarChar() throws Exception {
0263:                Parser parser = getParser();
0264:
0265:                AxionCommand cmd = parser
0266:                        .parse("create table FOO ( NUM integer, blah VARCHAR(30) )");
0267:                assertNotNull("Command should not be null", cmd);
0268:                assertTrue("Command should be a CreateTableCommand",
0269:                        cmd instanceof  CreateTableCommand);
0270:                CreateTableCommand create = (CreateTableCommand) cmd;
0271:                assertNull(create.getType());
0272:            }
0273:
0274:            // create table FOO ( NUM integer, blah VARCHAR (30), foo INTEGER )
0275:            public void testCreateTableWithVarCharAndInteger() throws Exception {
0276:                Parser parser = getParser();
0277:
0278:                AxionCommand cmd = parser
0279:                        .parse("create table FOO ( NUM integer, blah VARCHAR(30), foo INTEGER )");
0280:                assertNotNull("Command should not be null", cmd);
0281:                assertTrue("Command should be a CreateTableCommand",
0282:                        cmd instanceof  CreateTableCommand);
0283:                CreateTableCommand create = (CreateTableCommand) cmd;
0284:                assertNull(create.getType());
0285:            }
0286:
0287:            // create table FOO ( NUM integer, DESCR string );
0288:            public void testCreateTableWithSemicolon() throws Exception {
0289:                Parser parser = getParser();
0290:                AxionCommand cmd = parser
0291:                        .parse("create table FOO ( NUM integer, DESCR varchar(10) );");
0292:                assertNotNull("Command should not be null", cmd);
0293:                assertTrue("Command should be a CreateTableCommand",
0294:                        cmd instanceof  CreateTableCommand);
0295:                CreateTableCommand create = (CreateTableCommand) cmd;
0296:                assertNull(create.getType());
0297:            }
0298:
0299:            // create MYTYPE table FOO ( NUM integer, DESCR string )
0300:            public void testTypedCreateTable() throws Exception {
0301:                Parser parser = getParser();
0302:
0303:                AxionCommand cmd = parser
0304:                        .parse("create MYTPE table FOO ( NUM integer, DESCR varchar(10) )");
0305:                assertNotNull("Command should not be null", cmd);
0306:                assertTrue("Command should be a CreateTableCommand",
0307:                        cmd instanceof  CreateTableCommand);
0308:                CreateTableCommand create = (CreateTableCommand) cmd;
0309:                assertEquals("MYTPE", create.getType());
0310:            }
0311:
0312:            // create table FOO ( NUM integer, NUM2 integer, DESCR string, PRIMARY KEY(NUM, NUM2) )
0313:            public void testCreateTableWithPrimaryKey() throws Exception {
0314:                Parser parser = getParser();
0315:
0316:                AxionCommand cmd = parser
0317:                        .parse("create table FOO ( NUM integer, NUM2 integer, DESCR varchar(10), PRIMARY KEY(NUM, NUM2) )");
0318:                assertNotNull("Command should not be null", cmd);
0319:                assertTrue("Command should be a CreateTableCommand",
0320:                        cmd instanceof  CreateTableCommand);
0321:                CreateTableCommand create = (CreateTableCommand) cmd;
0322:
0323:                List columns = create.getColumnNames();
0324:                assertEquals("NUM", columns.get(0));
0325:                assertEquals("NUM2", columns.get(1));
0326:                assertEquals("DESCR", columns.get(2));
0327:
0328:                assertEquals("Should have one child command", 1, create
0329:                        .getChildCommandCount());
0330:                assertTrue(
0331:                        "Child command should be an AddConstraintCommand",
0332:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0333:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0334:                        .getChildCommand(0));
0335:                assertTrue("Constraint should be a PrimaryKeyConstraint", ccmd
0336:                        .getConstraint() instanceof  PrimaryKeyConstraint);
0337:                PrimaryKeyConstraint pk = (PrimaryKeyConstraint) (ccmd
0338:                        .getConstraint());
0339:                assertEquals("Number of primary key columns", 2, pk
0340:                        .getSelectableCount());
0341:                assertEquals("PK column name", "NUM", pk.getSelectable(0)
0342:                        .getLabel());
0343:                assertEquals("PK column name", "NUM2", pk.getSelectable(1)
0344:                        .getLabel());
0345:                assertNotNull("Constraint name should not be null", pk
0346:                        .getName());
0347:            }
0348:
0349:            // create table FOO ( NUM integer, NUM2 integer, DESCR string, constraint PRIMARY KEY(NUM, NUM2) )
0350:            public void testCreateTableWithConstraintPrimaryKey()
0351:                    throws Exception {
0352:                Parser parser = getParser();
0353:
0354:                AxionCommand cmd = parser
0355:                        .parse("create table FOO ( NUM integer, NUM2 integer, DESCR varchar(10), constraint PRIMARY KEY(NUM, NUM2) )");
0356:                assertNotNull("Command should not be null", cmd);
0357:                assertTrue("Command should be a CreateTableCommand",
0358:                        cmd instanceof  CreateTableCommand);
0359:                CreateTableCommand create = (CreateTableCommand) cmd;
0360:
0361:                List columns = create.getColumnNames();
0362:                assertEquals("NUM", columns.get(0));
0363:                assertEquals("NUM2", columns.get(1));
0364:                assertEquals("DESCR", columns.get(2));
0365:
0366:                assertEquals("Should have one child command", 1, create
0367:                        .getChildCommandCount());
0368:                assertTrue(
0369:                        "Child command should be an AddConstraintCommand",
0370:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0371:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0372:                        .getChildCommand(0));
0373:                assertTrue("Constraint should be a PrimaryKeyConstraint", ccmd
0374:                        .getConstraint() instanceof  PrimaryKeyConstraint);
0375:                PrimaryKeyConstraint pk = (PrimaryKeyConstraint) (ccmd
0376:                        .getConstraint());
0377:                assertEquals("Number of primary key columns", 2, pk
0378:                        .getSelectableCount());
0379:                assertEquals("PK column name", "NUM", pk.getSelectable(0)
0380:                        .getLabel());
0381:                assertEquals("PK column name", "NUM2", pk.getSelectable(1)
0382:                        .getLabel());
0383:                assertNotNull("Constraint name should not be null", pk
0384:                        .getName());
0385:            }
0386:
0387:            // create table FOO ( NUM integer, NUM2 integer, DESCR string, constraint FOO_PK primary key(NUM, NUM2) )
0388:            public void testCreateTableWithNamedPrimaryKey() throws Exception {
0389:                Parser parser = getParser();
0390:
0391:                AxionCommand cmd = parser
0392:                        .parse("create table FOO ( NUM integer, NUM2 integer, DESCR varchar(10), constraint FOO_PK primary key (NUM, NUM2) )");
0393:                assertNotNull("Command should not be null", cmd);
0394:                assertTrue("Command should be a CreateTableCommand",
0395:                        cmd instanceof  CreateTableCommand);
0396:                CreateTableCommand create = (CreateTableCommand) cmd;
0397:
0398:                List columns = create.getColumnNames();
0399:                assertEquals("NUM", columns.get(0));
0400:                assertEquals("NUM2", columns.get(1));
0401:                assertEquals("DESCR", columns.get(2));
0402:
0403:                assertEquals("Should have one child command", 1, create
0404:                        .getChildCommandCount());
0405:                assertTrue(
0406:                        "Child command should be an AddConstraintCommand",
0407:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0408:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0409:                        .getChildCommand(0));
0410:                assertTrue("Constraint should be a PrimaryKeyConstraint", ccmd
0411:                        .getConstraint() instanceof  PrimaryKeyConstraint);
0412:                PrimaryKeyConstraint pk = (PrimaryKeyConstraint) (ccmd
0413:                        .getConstraint());
0414:                assertEquals("Number of primary key columns", 2, pk
0415:                        .getSelectableCount());
0416:                assertEquals("PK column name", "NUM", pk.getSelectable(0)
0417:                        .getLabel());
0418:                assertEquals("PK column name", "NUM2", pk.getSelectable(1)
0419:                        .getLabel());
0420:                assertNotNull("Constraint name should not be null", pk
0421:                        .getName());
0422:                assertEquals("Constraint name should be FOO_PK", "FOO_PK", pk
0423:                        .getName());
0424:            }
0425:
0426:            // create table FOO ( NUM integer, NUM2 integer, DESCR string, UNIQUE (NUM, NUM2) )
0427:            public void testCreateTableWithUniqueTableConstraint()
0428:                    throws Exception {
0429:                Parser parser = getParser();
0430:
0431:                AxionCommand cmd = parser
0432:                        .parse("create table FOO ( NUM integer, NUM2 integer, DESCR varchar(10), UNIQUE (NUM, NUM2) )");
0433:                assertNotNull("Command should not be null", cmd);
0434:                assertTrue("Command should be a CreateTableCommand",
0435:                        cmd instanceof  CreateTableCommand);
0436:                CreateTableCommand create = (CreateTableCommand) cmd;
0437:
0438:                List columns = create.getColumnNames();
0439:                assertEquals("NUM", columns.get(0));
0440:                assertEquals("NUM2", columns.get(1));
0441:                assertEquals("DESCR", columns.get(2));
0442:
0443:                assertEquals("Should have one child command", 1, create
0444:                        .getChildCommandCount());
0445:                assertTrue(
0446:                        "Child command should be an AddConstraintCommand",
0447:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0448:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0449:                        .getChildCommand(0));
0450:                assertTrue("Constraint should be a UniqueConstraint", ccmd
0451:                        .getConstraint() instanceof  UniqueConstraint);
0452:                UniqueConstraint constraint = (UniqueConstraint) (ccmd
0453:                        .getConstraint());
0454:                assertEquals("Number of unique columns", 2, constraint
0455:                        .getSelectableCount());
0456:                assertEquals("column name", "NUM", constraint.getSelectable(0)
0457:                        .getLabel());
0458:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
0459:                        .getLabel());
0460:                assertNotNull("Constraint name should not be null", constraint
0461:                        .getName());
0462:            }
0463:
0464:            // create table FOO ( NUM integer, NUM2 integer, DESCR string, UNIQUE (NUM, NUM2) DEFERRABLE INITIALLY DEFERRED)
0465:            public void testCreateTableWithDeferredUniqueTableConstraint()
0466:                    throws Exception {
0467:                Parser parser = getParser();
0468:
0469:                AxionCommand cmd = parser
0470:                        .parse("create table FOO ( NUM integer, NUM2 integer, DESCR varchar(10), UNIQUE (NUM, NUM2) DEFERRABLE INITIALLY DEFERRED)");
0471:                assertNotNull("Command should not be null", cmd);
0472:                assertTrue("Command should be a CreateTableCommand",
0473:                        cmd instanceof  CreateTableCommand);
0474:                CreateTableCommand create = (CreateTableCommand) cmd;
0475:
0476:                List columns = create.getColumnNames();
0477:                assertEquals("NUM", columns.get(0));
0478:                assertEquals("NUM2", columns.get(1));
0479:                assertEquals("DESCR", columns.get(2));
0480:
0481:                assertEquals("Should have one child command", 1, create
0482:                        .getChildCommandCount());
0483:                assertTrue(
0484:                        "Child command should be an AddConstraintCommand",
0485:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0486:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0487:                        .getChildCommand(0));
0488:                assertTrue("Constraint should be a UniqueConstraint", ccmd
0489:                        .getConstraint() instanceof  UniqueConstraint);
0490:                UniqueConstraint constraint = (UniqueConstraint) (ccmd
0491:                        .getConstraint());
0492:                assertEquals("Number of unique columns", 2, constraint
0493:                        .getSelectableCount());
0494:                assertEquals("column name", "NUM", constraint.getSelectable(0)
0495:                        .getLabel());
0496:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
0497:                        .getLabel());
0498:                assertNotNull("Constraint name should not be null", constraint
0499:                        .getName());
0500:                assertTrue("Constraint should be deferrable", constraint
0501:                        .isDeferrable());
0502:                assertTrue("Constraint should be deferred", constraint
0503:                        .isDeferred());
0504:            }
0505:
0506:            // create table FOO ( NUM integer, NUM2 integer, DESCR string, UNIQUE (NUM, DESCR), PRIMARY KEY (NUM, NUM2) )
0507:            public void testCreateTableWithUniqueAndPrimaryKeyTableConstraints()
0508:                    throws Exception {
0509:                Parser parser = getParser();
0510:
0511:                AxionCommand cmd = parser
0512:                        .parse("create table FOO ( NUM integer, NUM2 integer, DESCR varchar(10), UNIQUE (NUM, DESCR), PRIMARY KEY (NUM, NUM2) )");
0513:                assertNotNull("Command should not be null", cmd);
0514:                assertTrue("Command should be a CreateTableCommand",
0515:                        cmd instanceof  CreateTableCommand);
0516:                CreateTableCommand create = (CreateTableCommand) cmd;
0517:
0518:                List columns = create.getColumnNames();
0519:                assertEquals("NUM", columns.get(0));
0520:                assertEquals("NUM2", columns.get(1));
0521:                assertEquals("DESCR", columns.get(2));
0522:
0523:                assertEquals("Should have one child commands", 2, create
0524:                        .getChildCommandCount());
0525:                {
0526:                    assertTrue(
0527:                            "Child command should be an AddConstraintCommand",
0528:                            create.getChildCommand(0) instanceof  AddConstraintCommand);
0529:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0530:                            .getChildCommand(0));
0531:                    assertTrue("Constraint should be a UniqueConstraint", ccmd
0532:                            .getConstraint() instanceof  UniqueConstraint);
0533:                    UniqueConstraint constraint = (UniqueConstraint) (ccmd
0534:                            .getConstraint());
0535:                    assertEquals("Number of unique columns", 2, constraint
0536:                            .getSelectableCount());
0537:                    assertEquals("column name", "NUM", constraint
0538:                            .getSelectable(0).getLabel());
0539:                    assertEquals("column name", "DESCR", constraint
0540:                            .getSelectable(1).getLabel());
0541:                    assertNotNull("Constraint name should not be null",
0542:                            constraint.getName());
0543:                }
0544:                {
0545:                    assertTrue(
0546:                            "Child command should be an AddConstraintCommand",
0547:                            create.getChildCommand(1) instanceof  AddConstraintCommand);
0548:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0549:                            .getChildCommand(1));
0550:                    assertTrue(
0551:                            "Constraint should be a PrimaryKeyConstraint",
0552:                            ccmd.getConstraint() instanceof  PrimaryKeyConstraint);
0553:                    PrimaryKeyConstraint constraint = (PrimaryKeyConstraint) (ccmd
0554:                            .getConstraint());
0555:                    assertEquals("Number of unique columns", 2, constraint
0556:                            .getSelectableCount());
0557:                    assertEquals("column name", "NUM", constraint
0558:                            .getSelectable(0).getLabel());
0559:                    assertEquals("column name", "NUM2", constraint
0560:                            .getSelectable(1).getLabel());
0561:                    assertNotNull("Constraint name should not be null",
0562:                            constraint.getName());
0563:                }
0564:            }
0565:
0566:            // create table FOO ( NUM integer NOT NULL, NUM2 integer NULL, DESCR string )
0567:            public void testCreateTableWithNotNullAndNullConstraints()
0568:                    throws Exception {
0569:                Parser parser = getParser();
0570:
0571:                AxionCommand cmd = parser
0572:                        .parse("create table FOO ( NUM integer NOT NULL, NUM2 integer NULL, DESCR varchar(10) )");
0573:                assertNotNull("Command should not be null", cmd);
0574:                assertTrue("Command should be a CreateTableCommand",
0575:                        cmd instanceof  CreateTableCommand);
0576:                CreateTableCommand create = (CreateTableCommand) cmd;
0577:
0578:                List columns = create.getColumnNames();
0579:                assertEquals("NUM", columns.get(0));
0580:                assertEquals("NUM2", columns.get(1));
0581:                assertEquals("DESCR", columns.get(2));
0582:
0583:                assertEquals("Should have two child commands", 2, create
0584:                        .getChildCommandCount());
0585:                {
0586:                    assertTrue(
0587:                            "Child command should be an AddConstraintCommand",
0588:                            create.getChildCommand(0) instanceof  AddConstraintCommand);
0589:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0590:                            .getChildCommand(0));
0591:                    assertTrue("Constraint should be a NotNullConstraint", ccmd
0592:                            .getConstraint() instanceof  NotNullConstraint);
0593:                    NotNullConstraint constraint = (NotNullConstraint) (ccmd
0594:                            .getConstraint());
0595:                    assertNotNull(constraint.getSelectable(0));
0596:                    assertEquals("nn column name", "NUM", constraint
0597:                            .getSelectable(0).getLabel());
0598:                    assertNotNull("Constraint name should not be null",
0599:                            constraint.getName());
0600:                }
0601:                {
0602:                    assertTrue(
0603:                            "Child command should be an AddConstraintCommand",
0604:                            create.getChildCommand(1) instanceof  AddConstraintCommand);
0605:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0606:                            .getChildCommand(1));
0607:                    assertTrue("Constraint should be a NullConstraint", ccmd
0608:                            .getConstraint() instanceof  NullConstraint);
0609:                    NullConstraint constraint = (NullConstraint) (ccmd
0610:                            .getConstraint());
0611:                    assertNotNull(constraint.getSelectable(0));
0612:                    assertEquals("nn column name", "NUM2", constraint
0613:                            .getSelectable(0).getLabel());
0614:                    assertNotNull("Constraint name should not be null",
0615:                            constraint.getName());
0616:                }
0617:            }
0618:
0619:            // create table FOO ( NUM integer, NUM2 integer UNIQUE, DESCR string )
0620:            public void testCreateTableWithUniqueConstraint() throws Exception {
0621:                Parser parser = getParser();
0622:
0623:                AxionCommand cmd = parser
0624:                        .parse("create table FOO ( NUM integer, NUM2 integer UNIQUE, DESCR varchar(10) )");
0625:                assertNotNull("Command should not be null", cmd);
0626:                assertTrue("Command should be a CreateTableCommand",
0627:                        cmd instanceof  CreateTableCommand);
0628:                CreateTableCommand create = (CreateTableCommand) cmd;
0629:
0630:                List columns = create.getColumnNames();
0631:                assertEquals("NUM", columns.get(0));
0632:                assertEquals("NUM2", columns.get(1));
0633:                assertEquals("DESCR", columns.get(2));
0634:
0635:                assertEquals("Should have one child command", 1, create
0636:                        .getChildCommandCount());
0637:                assertTrue(
0638:                        "Child command should be an AddConstraintCommand",
0639:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0640:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0641:                        .getChildCommand(0));
0642:                assertTrue("Constraint should be a UniqueConstraint", ccmd
0643:                        .getConstraint() instanceof  UniqueConstraint);
0644:                UniqueConstraint constraint = (UniqueConstraint) (ccmd
0645:                        .getConstraint());
0646:                assertEquals("Number of unique columns", 1, constraint
0647:                        .getSelectableCount());
0648:                assertEquals("Unique column name", "NUM2", constraint
0649:                        .getSelectable(0).getLabel());
0650:                assertNotNull("Constraint name should not be null", constraint
0651:                        .getName());
0652:            }
0653:
0654:            // create table FOO ( NUM integer, NUM2 integer constraint FOO_UNIQUE unique, DESCR string )
0655:            public void testCreateTableWithNamedUniqueConstraint()
0656:                    throws Exception {
0657:                Parser parser = getParser();
0658:
0659:                AxionCommand cmd = parser
0660:                        .parse("create table FOO ( NUM integer, NUM2 integer constraint FOO_UNIQUE unique, DESCR varchar(10) )");
0661:                assertNotNull("Command should not be null", cmd);
0662:                assertTrue("Command should be a CreateTableCommand",
0663:                        cmd instanceof  CreateTableCommand);
0664:                CreateTableCommand create = (CreateTableCommand) cmd;
0665:
0666:                List columns = create.getColumnNames();
0667:                assertEquals("NUM", columns.get(0));
0668:                assertEquals("NUM2", columns.get(1));
0669:                assertEquals("DESCR", columns.get(2));
0670:
0671:                assertEquals("Should have one child command", 1, create
0672:                        .getChildCommandCount());
0673:                assertTrue(
0674:                        "Child command should be an AddConstraintCommand",
0675:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0676:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0677:                        .getChildCommand(0));
0678:                assertTrue("Constraint should be a UniqueConstraint", ccmd
0679:                        .getConstraint() instanceof  UniqueConstraint);
0680:                UniqueConstraint constraint = (UniqueConstraint) (ccmd
0681:                        .getConstraint());
0682:                assertEquals("Number of unique columns", 1, constraint
0683:                        .getSelectableCount());
0684:                assertEquals("Unique column name", "NUM2", constraint
0685:                        .getSelectable(0).getLabel());
0686:                assertEquals("Constraint name", "FOO_UNIQUE", constraint
0687:                        .getName());
0688:            }
0689:
0690:            // create table FOO ( NUM integer, NUM2 integer CHECK ( NUM2 > NUM), DESCR string )
0691:            public void testCreateTableWithCheckConstraint() throws Exception {
0692:                Parser parser = getParser();
0693:
0694:                AxionCommand cmd = parser
0695:                        .parse("create table FOO ( NUM integer, NUM2 integer CHECK ( NUM2 > NUM), DESCR varchar(10) )");
0696:                assertNotNull("Command should not be null", cmd);
0697:                assertTrue("Command should be a CreateTableCommand",
0698:                        cmd instanceof  CreateTableCommand);
0699:                CreateTableCommand create = (CreateTableCommand) cmd;
0700:
0701:                List columns = create.getColumnNames();
0702:                assertEquals("NUM", columns.get(0));
0703:                assertEquals("NUM2", columns.get(1));
0704:                assertEquals("DESCR", columns.get(2));
0705:
0706:                assertEquals("Should have one child command", 1, create
0707:                        .getChildCommandCount());
0708:                assertTrue(
0709:                        "Child command should be an AddConstraintCommand",
0710:                        create.getChildCommand(0) instanceof  AddConstraintCommand);
0711:                AddConstraintCommand ccmd = (AddConstraintCommand) (create
0712:                        .getChildCommand(0));
0713:                assertTrue("Constraint should be a UniqueConstraint", ccmd
0714:                        .getConstraint() instanceof  CheckConstraint);
0715:                CheckConstraint constraint = (CheckConstraint) (ccmd
0716:                        .getConstraint());
0717:                assertNotNull(constraint.getCondition());
0718:
0719:                assertTrue(constraint.getCondition() instanceof  FunctionIdentifier);
0720:                assertEquals(">", constraint.getCondition().getName());
0721:            }
0722:
0723:            // create table FOO ( NUM integer NOT NULL, NUM2 integer UNIQUE NOT NULL, DESCR string NOT NULL, PRIMARY KEY(NUM, NUM2) )
0724:            public void testCreateTableWithMultipleConstraints()
0725:                    throws Exception {
0726:                Parser parser = getParser();
0727:
0728:                AxionCommand cmd = parser
0729:                        .parse("create table FOO ( NUM integer NOT NULL, NUM2 integer UNIQUE NOT NULL, DESCR varchar(10) NOT NULL, PRIMARY KEY(NUM, NUM2) )");
0730:                assertNotNull("Command should not be null", cmd);
0731:                assertTrue("Command should be a CreateTableCommand",
0732:                        cmd instanceof  CreateTableCommand);
0733:                CreateTableCommand create = (CreateTableCommand) cmd;
0734:
0735:                List columns = create.getColumnNames();
0736:                assertEquals("NUM", columns.get(0));
0737:                assertEquals("NUM2", columns.get(1));
0738:                assertEquals("DESCR", columns.get(2));
0739:
0740:                //assertEquals("Should have five child commands",5,create.getChildCommandCount());
0741:                {
0742:                    assertTrue(
0743:                            "Child command should be an AddConstraintCommand",
0744:                            create.getChildCommand(0) instanceof  AddConstraintCommand);
0745:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0746:                            .getChildCommand(0));
0747:                    assertTrue("Constraint should be a NotNullConstraint", ccmd
0748:                            .getConstraint() instanceof  NotNullConstraint);
0749:                    NotNullConstraint constraint = (NotNullConstraint) (ccmd
0750:                            .getConstraint());
0751:                    assertNotNull(constraint.getSelectable(0));
0752:                    assertEquals("nn column name", "NUM", constraint
0753:                            .getSelectable(0).getLabel());
0754:                    assertNotNull("Constraint name should not be null",
0755:                            constraint.getName());
0756:                }
0757:                {
0758:                    assertTrue(
0759:                            "Child command should be an AddConstraintCommand",
0760:                            create.getChildCommand(1) instanceof  AddConstraintCommand);
0761:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0762:                            .getChildCommand(1));
0763:                    assertTrue("Constraint should be a UniqueConstraint", ccmd
0764:                            .getConstraint() instanceof  UniqueConstraint);
0765:                    UniqueConstraint constraint = (UniqueConstraint) (ccmd
0766:                            .getConstraint());
0767:                    assertNotNull(constraint.getSelectable(0));
0768:                    assertEquals("nn column name", "NUM2", constraint
0769:                            .getSelectable(0).getLabel());
0770:                    assertNotNull("Constraint name should not be null",
0771:                            constraint.getName());
0772:                }
0773:                {
0774:                    assertTrue(
0775:                            "Child command should be an AddConstraintCommand",
0776:                            create.getChildCommand(2) instanceof  AddConstraintCommand);
0777:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0778:                            .getChildCommand(2));
0779:                    assertTrue("Constraint should be a NotNullConstraint", ccmd
0780:                            .getConstraint() instanceof  NotNullConstraint);
0781:                    NotNullConstraint constraint = (NotNullConstraint) (ccmd
0782:                            .getConstraint());
0783:                    assertNotNull(constraint.getSelectable(0));
0784:                    assertEquals("nn column name", "NUM2", constraint
0785:                            .getSelectable(0).getLabel());
0786:                    assertNotNull("Constraint name should not be null",
0787:                            constraint.getName());
0788:                }
0789:                {
0790:                    assertTrue(
0791:                            "Child command should be an AddConstraintCommand",
0792:                            create.getChildCommand(3) instanceof  AddConstraintCommand);
0793:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0794:                            .getChildCommand(3));
0795:                    assertTrue("Constraint should be a NotNullConstraint", ccmd
0796:                            .getConstraint() instanceof  NotNullConstraint);
0797:                    NotNullConstraint constraint = (NotNullConstraint) (ccmd
0798:                            .getConstraint());
0799:                    assertNotNull(constraint.getSelectable(0));
0800:                    assertEquals("nn column name", "DESCR", constraint
0801:                            .getSelectable(0).getLabel());
0802:                    assertNotNull("Constraint name should not be null",
0803:                            constraint.getName());
0804:                }
0805:                {
0806:                    assertTrue(
0807:                            "Child command should be an AddConstraintCommand",
0808:                            create.getChildCommand(4) instanceof  AddConstraintCommand);
0809:                    AddConstraintCommand ccmd = (AddConstraintCommand) (create
0810:                            .getChildCommand(4));
0811:                    assertTrue(
0812:                            "Constraint should be a PrimaryKeyConstraint",
0813:                            ccmd.getConstraint() instanceof  PrimaryKeyConstraint);
0814:                    PrimaryKeyConstraint pk = (PrimaryKeyConstraint) (ccmd
0815:                            .getConstraint());
0816:                    assertEquals("Number of primary key columns", 2, pk
0817:                            .getSelectableCount());
0818:                    assertEquals("PK column name", "NUM", pk.getSelectable(0)
0819:                            .getLabel());
0820:                    assertEquals("PK column name", "NUM2", pk.getSelectable(1)
0821:                            .getLabel());
0822:                    assertNotNull("Constraint name should not be null", pk
0823:                            .getName());
0824:                }
0825:            }
0826:
0827:            // alter table FOO add constraint primary key (NUM, NUM2)
0828:            public void testAlterTableAddConstraintPrimaryKey()
0829:                    throws Exception {
0830:                Parser parser = getParser();
0831:
0832:                AxionCommand cmd = parser
0833:                        .parse("alter table FOO add constraint primary key (NUM, NUM2)");
0834:                assertNotNull("Command should not be null", cmd);
0835:                assertTrue("Command should be an AddConstraintCommand",
0836:                        cmd instanceof  AddConstraintCommand);
0837:                AddConstraintCommand add = (AddConstraintCommand) cmd;
0838:                assertEquals("FOO", add.getTableName());
0839:                assertTrue("Constraint should be a PrimaryKeyConstraint", add
0840:                        .getConstraint() instanceof  PrimaryKeyConstraint);
0841:                PrimaryKeyConstraint pk = (PrimaryKeyConstraint) (add
0842:                        .getConstraint());
0843:                assertEquals("Number of primary key columns", 2, pk
0844:                        .getSelectableCount());
0845:                assertEquals("PK column name", "NUM", pk.getSelectable(0)
0846:                        .getLabel());
0847:                assertEquals("PK column name", "NUM2", pk.getSelectable(1)
0848:                        .getLabel());
0849:                assertNotNull("Constraint name should not be null", pk
0850:                        .getName());
0851:            }
0852:
0853:            // alter table FOO add constraint BAR primary key (NUM, NUM2)
0854:            public void testAlterTableAddConstraintNamePrimaryKey()
0855:                    throws Exception {
0856:                Parser parser = getParser();
0857:
0858:                AxionCommand cmd = parser
0859:                        .parse("alter table FOO add constraint BAR primary key(NUM, NUM2)");
0860:                assertNotNull("Command should not be null", cmd);
0861:                assertTrue("Command should be an AddConstraintCommand",
0862:                        cmd instanceof  AddConstraintCommand);
0863:                AddConstraintCommand add = (AddConstraintCommand) cmd;
0864:                assertEquals("FOO", add.getTableName());
0865:                assertTrue("Constraint should be a PrimaryKeyConstraint", add
0866:                        .getConstraint() instanceof  PrimaryKeyConstraint);
0867:                PrimaryKeyConstraint pk = (PrimaryKeyConstraint) (add
0868:                        .getConstraint());
0869:                assertEquals("Number of primary key columns", 2, pk
0870:                        .getSelectableCount());
0871:                assertEquals("PK column name", "NUM", pk.getSelectable(0)
0872:                        .getLabel());
0873:                assertEquals("PK column name", "NUM2", pk.getSelectable(1)
0874:                        .getLabel());
0875:                assertNotNull("Constraint name should not be null", pk
0876:                        .getName());
0877:                assertEquals("Constraint name should be BAR", "BAR", pk
0878:                        .getName());
0879:            }
0880:
0881:            // alter table FOO add constraint unique (NUM, NUM2)
0882:            public void testAlterTableAddConstraintUnique() throws Exception {
0883:                Parser parser = getParser();
0884:
0885:                AxionCommand cmd = parser
0886:                        .parse("alter table FOO add constraint unique (NUM, NUM2)");
0887:                assertNotNull("Command should not be null", cmd);
0888:                assertTrue("Command should be an AddConstraintCommand",
0889:                        cmd instanceof  AddConstraintCommand);
0890:                AddConstraintCommand add = (AddConstraintCommand) cmd;
0891:                assertEquals("FOO", add.getTableName());
0892:                assertTrue("Constraint should be a UniqueConstraint", add
0893:                        .getConstraint() instanceof  UniqueConstraint);
0894:                UniqueConstraint constraint = (UniqueConstraint) (add
0895:                        .getConstraint());
0896:                assertEquals("Number of columns", 2, constraint
0897:                        .getSelectableCount());
0898:                assertEquals("column name", "NUM", constraint.getSelectable(0)
0899:                        .getLabel());
0900:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
0901:                        .getLabel());
0902:                assertNotNull("Constraint name should not be null", constraint
0903:                        .getName());
0904:            }
0905:
0906:            // alter table FOO add constraint BAR unique (NUM, NUM2)
0907:            public void testAlterTableAddConstraintNameUnique()
0908:                    throws Exception {
0909:                Parser parser = getParser();
0910:
0911:                AxionCommand cmd = parser
0912:                        .parse("alter table FOO add constraint BAR unique (NUM, NUM2)");
0913:                assertNotNull("Command should not be null", cmd);
0914:                assertTrue("Command should be an AddConstraintCommand",
0915:                        cmd instanceof  AddConstraintCommand);
0916:                AddConstraintCommand add = (AddConstraintCommand) cmd;
0917:                assertEquals("FOO", add.getTableName());
0918:                assertTrue("Constraint should be a UniqueConstraint", add
0919:                        .getConstraint() instanceof  UniqueConstraint);
0920:                UniqueConstraint constraint = (UniqueConstraint) (add
0921:                        .getConstraint());
0922:                assertEquals("Number of columns", 2, constraint
0923:                        .getSelectableCount());
0924:                assertEquals("column name", "NUM", constraint.getSelectable(0)
0925:                        .getLabel());
0926:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
0927:                        .getLabel());
0928:                assertNotNull("Constraint name should not be null", constraint
0929:                        .getName());
0930:                assertEquals("Constraint name should be BAR", "BAR", constraint
0931:                        .getName());
0932:                assertTrue("Constraint should not be deferrable", !constraint
0933:                        .isDeferrable());
0934:                assertTrue("Constraint should not be deferred", !constraint
0935:                        .isDeferred());
0936:            }
0937:
0938:            // alter table FOO add constraint unique (NUM, NUM2) deferrable
0939:            public void testAlterTableAddConstraintUniqueDeferrable()
0940:                    throws Exception {
0941:                Parser parser = getParser();
0942:
0943:                AxionCommand cmd = parser
0944:                        .parse("alter table FOO add constraint unique (NUM, NUM2) deferrable");
0945:                assertNotNull("Command should not be null", cmd);
0946:                assertTrue("Command should be an AddConstraintCommand",
0947:                        cmd instanceof  AddConstraintCommand);
0948:                AddConstraintCommand add = (AddConstraintCommand) cmd;
0949:                assertEquals("FOO", add.getTableName());
0950:                assertTrue("Constraint should be a UniqueConstraint", add
0951:                        .getConstraint() instanceof  UniqueConstraint);
0952:                UniqueConstraint constraint = (UniqueConstraint) (add
0953:                        .getConstraint());
0954:                assertEquals("Number of columns", 2, constraint
0955:                        .getSelectableCount());
0956:                assertEquals("column name", "NUM", constraint.getSelectable(0)
0957:                        .getLabel());
0958:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
0959:                        .getLabel());
0960:                assertNotNull("Constraint name should not be null", constraint
0961:                        .getName());
0962:                assertTrue("Constraint should be deferrable", constraint
0963:                        .isDeferrable());
0964:                assertTrue("Constraint should not be deferred", !constraint
0965:                        .isDeferred());
0966:            }
0967:
0968:            // alter table FOO add constraint unique (NUM, NUM2) deferrable initially deferred
0969:            public void testAlterTableAddConstraintUniqueDeferrableInitiallyDeferred()
0970:                    throws Exception {
0971:                Parser parser = getParser();
0972:
0973:                AxionCommand cmd = parser
0974:                        .parse("alter table FOO add constraint unique (NUM, NUM2) deferrable initially deferred");
0975:                assertNotNull("Command should not be null", cmd);
0976:                assertTrue("Command should be an AddConstraintCommand",
0977:                        cmd instanceof  AddConstraintCommand);
0978:                AddConstraintCommand add = (AddConstraintCommand) cmd;
0979:                assertEquals("FOO", add.getTableName());
0980:                assertTrue("Constraint should be a UniqueConstraint", add
0981:                        .getConstraint() instanceof  UniqueConstraint);
0982:                UniqueConstraint constraint = (UniqueConstraint) (add
0983:                        .getConstraint());
0984:                assertEquals("Number of columns", 2, constraint
0985:                        .getSelectableCount());
0986:                assertEquals("column name", "NUM", constraint.getSelectable(0)
0987:                        .getLabel());
0988:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
0989:                        .getLabel());
0990:                assertNotNull("Constraint name should not be null", constraint
0991:                        .getName());
0992:                assertTrue("Constraint should be deferrable", constraint
0993:                        .isDeferrable());
0994:                assertTrue("Constraint should be deferred", constraint
0995:                        .isDeferred());
0996:            }
0997:
0998:            // alter table FOO add constraint unique (NUM, NUM2) deferrable initially immediate
0999:            public void testAlterTableAddConstraintUniqueDeferrableInitiallyImmediate()
1000:                    throws Exception {
1001:                Parser parser = getParser();
1002:
1003:                AxionCommand cmd = parser
1004:                        .parse("alter table FOO add constraint unique (NUM, NUM2) deferrable initially immediate");
1005:                assertNotNull("Command should not be null", cmd);
1006:                assertTrue("Command should be an AddConstraintCommand",
1007:                        cmd instanceof  AddConstraintCommand);
1008:                AddConstraintCommand add = (AddConstraintCommand) cmd;
1009:                assertEquals("FOO", add.getTableName());
1010:                assertTrue("Constraint should be a UniqueConstraint", add
1011:                        .getConstraint() instanceof  UniqueConstraint);
1012:                UniqueConstraint constraint = (UniqueConstraint) (add
1013:                        .getConstraint());
1014:                assertEquals("Number of columns", 2, constraint
1015:                        .getSelectableCount());
1016:                assertEquals("column name", "NUM", constraint.getSelectable(0)
1017:                        .getLabel());
1018:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
1019:                        .getLabel());
1020:                assertNotNull("Constraint name should not be null", constraint
1021:                        .getName());
1022:                assertTrue("Constraint should be deferrable", constraint
1023:                        .isDeferrable());
1024:                assertTrue("Constraint should not be deferred", !constraint
1025:                        .isDeferred());
1026:            }
1027:
1028:            // alter table FOO add constraint unique (NUM, NUM2) not deferrable
1029:            public void testAlterTableAddConstraintUniqueNotDeferrableInitiallyImmediate()
1030:                    throws Exception {
1031:                Parser parser = getParser();
1032:
1033:                AxionCommand cmd = parser
1034:                        .parse("alter table FOO add constraint unique (NUM, NUM2) not deferrable");
1035:                assertNotNull("Command should not be null", cmd);
1036:                assertTrue("Command should be an AddConstraintCommand",
1037:                        cmd instanceof  AddConstraintCommand);
1038:                AddConstraintCommand add = (AddConstraintCommand) cmd;
1039:                assertEquals("FOO", add.getTableName());
1040:                assertTrue("Constraint should be a UniqueConstraint", add
1041:                        .getConstraint() instanceof  UniqueConstraint);
1042:                UniqueConstraint constraint = (UniqueConstraint) (add
1043:                        .getConstraint());
1044:                assertEquals("Number of columns", 2, constraint
1045:                        .getSelectableCount());
1046:                assertEquals("column name", "NUM", constraint.getSelectable(0)
1047:                        .getLabel());
1048:                assertEquals("column name", "NUM2", constraint.getSelectable(1)
1049:                        .getLabel());
1050:                assertNotNull("Constraint name should not be null", constraint
1051:                        .getName());
1052:                assertTrue("Constraint should not be deferrable", !constraint
1053:                        .isDeferrable());
1054:                assertTrue("Constraint should not be deferred", !constraint
1055:                        .isDeferred());
1056:            }
1057:
1058:            // alter table FOO add constraint not null (NUM)
1059:            public void testAlterTableAddConstraintNotNull() throws Exception {
1060:                Parser parser = getParser();
1061:
1062:                AxionCommand cmd = parser
1063:                        .parse("alter table FOO add constraint not null (NUM)");
1064:                assertNotNull("Command should not be null", cmd);
1065:                assertTrue("Command should be an AddConstraintCommand",
1066:                        cmd instanceof  AddConstraintCommand);
1067:                AddConstraintCommand add = (AddConstraintCommand) cmd;
1068:                assertEquals("FOO", add.getTableName());
1069:                assertTrue("Constraint should be a NotNullConstraint", add
1070:                        .getConstraint() instanceof  NotNullConstraint);
1071:                NotNullConstraint constraint = (NotNullConstraint) (add
1072:                        .getConstraint());
1073:                assertEquals("column name", "NUM", constraint.getSelectable(0)
1074:                        .getLabel());
1075:                assertNotNull("Constraint name should not be null", constraint
1076:                        .getName());
1077:            }
1078:
1079:            // alter table FOO add constraint BAR not null (NUM)
1080:            public void testAlterTableAddConstraintNameNotNull()
1081:                    throws Exception {
1082:                Parser parser = getParser();
1083:
1084:                AxionCommand cmd = parser
1085:                        .parse("alter table FOO add constraint BAR not null (NUM)");
1086:                assertNotNull("Command should not be null", cmd);
1087:                assertTrue("Command should be an AddConstraintCommand",
1088:                        cmd instanceof  AddConstraintCommand);
1089:                AddConstraintCommand add = (AddConstraintCommand) cmd;
1090:                assertEquals("FOO", add.getTableName());
1091:                assertTrue("Constraint should be a NotNullConstraint", add
1092:                        .getConstraint() instanceof  NotNullConstraint);
1093:                NotNullConstraint constraint = (NotNullConstraint) (add
1094:                        .getConstraint());
1095:                assertEquals("column name", "NUM", constraint.getSelectable(0)
1096:                        .getLabel());
1097:                assertNotNull("Constraint name should not be null", constraint
1098:                        .getName());
1099:                assertEquals("Constraint name should be BAR", "BAR", constraint
1100:                        .getName());
1101:            }
1102:
1103:            // alter table FOO drop constraint BAR
1104:            public void testAlterTableDropConstraint() throws Exception {
1105:                Parser parser = getParser();
1106:
1107:                AxionCommand cmd = parser
1108:                        .parse("alter table FOO drop constraint BAR");
1109:                assertNotNull("Command should not be null", cmd);
1110:                assertTrue("Command should be an DropConstraintCommand",
1111:                        cmd instanceof  DropConstraintCommand);
1112:                DropConstraintCommand add = (DropConstraintCommand) cmd;
1113:                assertEquals("FOO", add.getTableName());
1114:                assertEquals("BAR", add.getConstraintName());
1115:            }
1116:
1117:            // drop table FOO
1118:            public void testDropTable() throws Exception {
1119:                Parser parser = getParser();
1120:                AxionCommand cmd = parser.parse("drop table FOO");
1121:                assertNotNull("Command should not be null", cmd);
1122:                assertTrue("Command should be a DropTableCommand",
1123:                        cmd instanceof  DropTableCommand);
1124:            }
1125:
1126:            // delete from FOO
1127:            public void test_delete_from_foo() throws Exception {
1128:                Parser parser = getParser();
1129:                AxionCommand cmd = parser.parse("delete from FOO");
1130:                assertNotNull("Command should not be null", cmd);
1131:                assertTrue("Command should be a DeleteCommand",
1132:                        cmd instanceof  DeleteCommand);
1133:                DeleteCommand delete = (DeleteCommand) cmd;
1134:                assertEquals("Table name should be FOO", "FOO", delete
1135:                        .getTable().getTableName());
1136:                assertTrue("Where clause should be null.", null == delete
1137:                        .getWhere());
1138:            }
1139:
1140:            // delete from FOO where NUM = 7 and BAR > 9
1141:            public void test_delete_from_foo_with_where() throws Exception {
1142:                Parser parser = getParser();
1143:                AxionCommand cmd = parser
1144:                        .parse("delete from FOO where NUM = 7 and BAR > 9");
1145:                assertNotNull("Command should not be null", cmd);
1146:                assertTrue("Command should be a DeleteCommand",
1147:                        cmd instanceof  DeleteCommand);
1148:                DeleteCommand delete = (DeleteCommand) cmd;
1149:                assertEquals("Table name should be FOO", "FOO", delete
1150:                        .getTable().getTableName());
1151:                assertNotNull("Where clause should not be null.", delete
1152:                        .getWhere());
1153:            }
1154:
1155:            // delete FOO
1156:            public void test_delete_foo() throws Exception {
1157:                Parser parser = getParser();
1158:                AxionCommand cmd = parser.parse("delete FOO");
1159:                assertNotNull("Command should not be null", cmd);
1160:                assertTrue("Command should be a DeleteCommand",
1161:                        cmd instanceof  DeleteCommand);
1162:                DeleteCommand delete = (DeleteCommand) cmd;
1163:                assertEquals("Table name should be FOO", "FOO", delete
1164:                        .getTable().getTableName());
1165:                assertTrue("Where clause should be null.", null == delete
1166:                        .getWhere());
1167:            }
1168:
1169:            // delete FOO where NUM = 7 and BAR > 9
1170:            public void test_delete_foo_with_where() throws Exception {
1171:                Parser parser = getParser();
1172:                AxionCommand cmd = parser
1173:                        .parse("delete FOO where NUM = 7 and BAR > 9");
1174:                assertNotNull("Command should not be null", cmd);
1175:                assertTrue("Command should be a DeleteCommand",
1176:                        cmd instanceof  DeleteCommand);
1177:                DeleteCommand delete = (DeleteCommand) cmd;
1178:                assertEquals("Table name should be FOO", "FOO", delete
1179:                        .getTable().getTableName());
1180:                assertNotNull("Where clause should not be null.", delete
1181:                        .getWhere());
1182:            }
1183:
1184:            // delete FOO where NUM = 7 and BAR > 9;
1185:            public void test_delete_foo_with_where_semicolon() throws Exception {
1186:                Parser parser = getParser();
1187:                AxionCommand cmd = parser
1188:                        .parse("delete FOO where NUM = 7 and BAR > 9;");
1189:                assertNotNull("Command should not be null", cmd);
1190:                assertTrue("Command should be a DeleteCommand",
1191:                        cmd instanceof  DeleteCommand);
1192:                DeleteCommand delete = (DeleteCommand) cmd;
1193:                assertEquals("Table name should be FOO", "FOO", delete
1194:                        .getTable().getTableName());
1195:                assertNotNull("Where clause should not be null.", delete
1196:                        .getWhere());
1197:            }
1198:
1199:            // select VAL from FOO
1200:            public void test_select_val_from_foo() throws Exception {
1201:                Parser parser = getParser();
1202:
1203:                AxionCommand cmd = parser.parse("select VAL from FOO");
1204:                assertNotNull("Command should not be null", cmd);
1205:                assertTrue("Command should be a SelectCommand",
1206:                        cmd instanceof  SelectCommand);
1207:
1208:                SelectCommand select = (SelectCommand) cmd;
1209:                assertEquals(
1210:                        "SelectCommand should have exactly one column in the SELECT part",
1211:                        1, select.getQueryContext().getSelectCount());
1212:                assertTrue("Selected column should be named VAL", "VAL"
1213:                        .equalsIgnoreCase(((ColumnIdentifier) (select
1214:                                .getQueryContext().getSelect(0))).getName()));
1215:
1216:                assertEquals(
1217:                        "SelectCommand should have exactly one table in the FROM part",
1218:                        1, select.getQueryContext().getFromCount());
1219:                assertTrue("Selected table should be named FOO", "FOO"
1220:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
1221:                                .getTableName()));
1222:            }
1223:
1224:            // select VAL from FOO where FALSE
1225:            public void test_select_val_from_foo_where_true() throws Exception {
1226:                Parser parser = getParser();
1227:
1228:                AxionCommand cmd = parser
1229:                        .parse("select VAL from FOO where FALSE");
1230:                assertTrue("Command should be a SelectCommand",
1231:                        cmd instanceof  SelectCommand);
1232:
1233:                SelectCommand select = (SelectCommand) cmd;
1234:
1235:                assertNotNull("SelectCommand should have WHERE part", select
1236:                        .getQueryContext().getWhere());
1237:                assertTrue(select.getQueryContext().getWhere() instanceof  Literal);
1238:                Literal literal = (Literal) (select.getQueryContext()
1239:                        .getWhere());
1240:                assertTrue(literal.evaluate(null) instanceof  Boolean);
1241:                assertTrue(!((Boolean) literal.evaluate(null)).booleanValue());
1242:
1243:            }
1244:
1245:            // select 'Literal' from FOO
1246:            public void test_select_string_literal_from_foo() throws Exception {
1247:                Parser parser = getParser();
1248:
1249:                AxionCommand cmd = parser.parse("select 'Literal' from FOO");
1250:                assertNotNull("Command should not be null", cmd);
1251:                assertTrue("Command should be a SelectCommand",
1252:                        cmd instanceof  SelectCommand);
1253:
1254:                SelectCommand select = (SelectCommand) cmd;
1255:                assertEquals(
1256:                        "SelectCommand should have exactly one selectable in the SELECT part",
1257:                        1, select.getQueryContext().getSelectCount());
1258:                assertTrue("Selected column should be a literal", select
1259:                        .getQueryContext().getSelect(0) instanceof  Literal);
1260:                Literal literal = (Literal) (select.getQueryContext()
1261:                        .getSelect(0));
1262:                assertEquals("Literal should have the value \"Literal\".",
1263:                        "Literal", literal.evaluate(null));
1264:            }
1265:
1266:            // select 'Literal'
1267:            public void test_select_string_literal_without_from()
1268:                    throws Exception {
1269:                Parser parser = getParser();
1270:
1271:                AxionCommand cmd = parser.parse("select 'Literal'");
1272:                assertNotNull("Command should not be null", cmd);
1273:                assertTrue("Command should be a SelectCommand",
1274:                        cmd instanceof  SelectCommand);
1275:
1276:                SelectCommand select = (SelectCommand) cmd;
1277:                assertEquals(
1278:                        "SelectCommand should have exactly one selectable in the SELECT part",
1279:                        1, select.getQueryContext().getSelectCount());
1280:                assertTrue("Selected column should be a literal", select
1281:                        .getQueryContext().getSelect(0) instanceof  Literal);
1282:                Literal literal = (Literal) (select.getQueryContext()
1283:                        .getSelect(0));
1284:                assertEquals("Literal should have the value \"Literal\".",
1285:                        "Literal", literal.evaluate(null));
1286:            }
1287:
1288:            // select max(VAL) from FOO
1289:            public void test_select_max_of_val_from_foo() throws Exception {
1290:                Parser parser = getParser();
1291:
1292:                AxionCommand cmd = parser.parse("select max(VAL) from FOO");
1293:                assertNotNull("Command should not be null", cmd);
1294:                assertTrue("Command should be a SelectCommand",
1295:                        cmd instanceof  SelectCommand);
1296:                SelectCommand select = (SelectCommand) cmd;
1297:                assertEquals(
1298:                        "SelectCommand should have exactly one Selectable in the SELECT part",
1299:                        1, select.getQueryContext().getSelectCount());
1300:                Selectable selected = select.getQueryContext().getSelect(0);
1301:                assertTrue("Selectable should be a FunctionIdentifier",
1302:                        selected instanceof  FunctionIdentifier);
1303:                FunctionIdentifier funid = (FunctionIdentifier) (selected);
1304:                assertEquals("Function's name should be \"max\"", "MAX", funid
1305:                        .getName());
1306:                assertEquals("Function should have one argument.", 1, funid
1307:                        .getArgumentCount());
1308:                assertTrue(
1309:                        "Function's one argument should be a ColumnIdentifier.",
1310:                        funid.getArgument(0) instanceof  ColumnIdentifier);
1311:                assertTrue("Argument's column should be named VAL", "VAL"
1312:                        .equalsIgnoreCase(((ColumnIdentifier) (funid
1313:                                .getArgument(0))).getName()));
1314:            }
1315:
1316:            // select count(*) from FOO
1317:            public void test_select_countstar_from_foo() throws Exception {
1318:                Parser parser = getParser();
1319:
1320:                AxionCommand cmd = parser.parse("select count(*) from FOO");
1321:                assertNotNull("Command should not be null", cmd);
1322:                assertTrue("Command should be a SelectCommand",
1323:                        cmd instanceof  SelectCommand);
1324:                SelectCommand select = (SelectCommand) cmd;
1325:                assertEquals(
1326:                        "SelectCommand should have exactly one Selectable in the SELECT part",
1327:                        1, select.getQueryContext().getSelectCount());
1328:                Selectable selected = select.getQueryContext().getSelect(0);
1329:                assertTrue("Selectable should be a FunctionIdentifier",
1330:                        selected instanceof  FunctionIdentifier);
1331:                FunctionIdentifier funid = (FunctionIdentifier) (selected);
1332:                assertEquals("Function's name should be \"count\"", "COUNT",
1333:                        funid.getName());
1334:                assertEquals("Function should have one argument.", 1, funid
1335:                        .getArgumentCount());
1336:                assertTrue(
1337:                        "Function's one argument should be a ColumnIdentifier.",
1338:                        funid.getArgument(0) instanceof  ColumnIdentifier);
1339:                assertTrue("Argument's column should be named *", "*"
1340:                        .equalsIgnoreCase(((ColumnIdentifier) (funid
1341:                                .getArgument(0))).getName()));
1342:            }
1343:
1344:            // select xyzzy() from FOO
1345:            public void test_select_xyzzy_from_foo() throws Exception {
1346:                Parser parser = getParser();
1347:
1348:                AxionCommand cmd = parser.parse("select xyzzy() from FOO");
1349:                assertNotNull("Command should not be null", cmd);
1350:                assertTrue("Command should be a SelectCommand",
1351:                        cmd instanceof  SelectCommand);
1352:                SelectCommand select = (SelectCommand) cmd;
1353:                assertEquals(
1354:                        "SelectCommand should have exactly one Selectable in the SELECT part",
1355:                        1, select.getQueryContext().getSelectCount());
1356:                Selectable selected = select.getQueryContext().getSelect(0);
1357:                assertTrue("Selectable should be a FunctionIdentifier",
1358:                        selected instanceof  FunctionIdentifier);
1359:                FunctionIdentifier funid = (FunctionIdentifier) (selected);
1360:                assertEquals("Function's name should be \"xyzzy\"", "XYZZY",
1361:                        funid.getName());
1362:                assertEquals("Function should have no arguments.", 0, funid
1363:                        .getArgumentCount());
1364:            }
1365:
1366:            // select VAL, VALTWO, VALTHREE from FOO
1367:            public void test_select_val_valtwo_valthree_from_foo()
1368:                    throws Exception {
1369:                Parser parser = getParser();
1370:
1371:                AxionCommand cmd = parser
1372:                        .parse("select VAL, VALTWO, VALTHREE from FOO");
1373:                assertNotNull("Command should not be null", cmd);
1374:                assertTrue("Command should be a SelectCommand",
1375:                        cmd instanceof  SelectCommand);
1376:
1377:                SelectCommand select = (SelectCommand) cmd;
1378:                assertEquals(
1379:                        "SelectCommand should have exactly three columns in the SELECT part",
1380:                        3, select.getQueryContext().getSelectCount());
1381:                assertTrue("First column should be named VAL", "VAL"
1382:                        .equalsIgnoreCase(((ColumnIdentifier) (select
1383:                                .getQueryContext().getSelect(0))).getName()));
1384:                assertTrue("First column should be named VALTWO", "VALTWO"
1385:                        .equalsIgnoreCase(((ColumnIdentifier) select
1386:                                .getQueryContext().getSelect(1)).getName()));
1387:                assertTrue("First column should be named VALTHREE", "VALTHREE"
1388:                        .equalsIgnoreCase(((ColumnIdentifier) select
1389:                                .getQueryContext().getSelect(2)).getName()));
1390:
1391:                assertEquals(
1392:                        "SelectCommand should have exactly one table in the FROM part",
1393:                        1, select.getQueryContext().getFromCount());
1394:                assertTrue("Selected table should be named FOO", "FOO"
1395:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
1396:                                .getTableName()));
1397:            }
1398:
1399:            // select VAL, VALTWO from FOO, BAR
1400:            public void test_select_val_valtwo_from_foo_bar() throws Exception {
1401:                Parser parser = getParser();
1402:
1403:                AxionCommand cmd = parser
1404:                        .parse("select VAL, VALTWO from FOO, BAR");
1405:                assertNotNull("Command should not be null", cmd);
1406:                assertTrue("Command should be a SelectCommand",
1407:                        cmd instanceof  SelectCommand);
1408:
1409:                SelectCommand select = (SelectCommand) cmd;
1410:                assertEquals(
1411:                        "SelectCommand should have exactly two columns in the SELECT part",
1412:                        2, select.getQueryContext().getSelectCount());
1413:                assertTrue("First column should be named VAL", "VAL"
1414:                        .equalsIgnoreCase(((ColumnIdentifier) (select
1415:                                .getQueryContext().getSelect(0))).getName()));
1416:                assertTrue("First column should be named VALTWO", "VALTWO"
1417:                        .equalsIgnoreCase(((ColumnIdentifier) select
1418:                                .getQueryContext().getSelect(1)).getName()));
1419:
1420:                assertEquals(
1421:                        "SelectCommand should have exactly two tables in the FROM part",
1422:                        2, select.getQueryContext().getFromCount());
1423:                assertTrue("First selected table should be named FOO", "FOO"
1424:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
1425:                                .getTableName()));
1426:                assertTrue("Second selected table should be named BAR", "BAR"
1427:                        .equalsIgnoreCase(select.getQueryContext().getFrom(1)
1428:                                .getTableName()));
1429:            }
1430:
1431:            // select VAL, VALTWO from FOO, BAR limit 10
1432:            public void test_select_val_from_foo_limit() throws Exception {
1433:                Parser parser = getParser();
1434:                AxionCommand cmd = parser
1435:                        .parse("select VAL, VALTWO from FOO, BAR limit 10");
1436:                assertNotNull("Command should not be null", cmd);
1437:                assertTrue("Command should be a SelectCommand",
1438:                        cmd instanceof  SelectCommand);
1439:                SelectCommand select = (SelectCommand) cmd;
1440:                assertNotNull("Should have a limit", select.getQueryContext()
1441:                        .getLimit());
1442:                assertEquals("Limit should be 10", 10, ((Number) (select
1443:                        .getQueryContext().getLimit().evaluate(null)))
1444:                        .intValue());
1445:            }
1446:
1447:            // select VAL, VALTWO from FOO, BAR where FOO.ID = BAR.ID limit 10
1448:            public void test_select_with_literal_limit() throws Exception {
1449:                Parser parser = getParser();
1450:                AxionCommand cmd = parser
1451:                        .parse("select VAL, VALTWO from FOO, BAR where FOO.ID = BAR.ID limit 10");
1452:                assertNotNull("Command should not be null", cmd);
1453:                assertTrue("Command should be a SelectCommand",
1454:                        cmd instanceof  SelectCommand);
1455:                SelectCommand select = (SelectCommand) cmd;
1456:                assertNotNull("Should have a limit", select.getQueryContext()
1457:                        .getLimit());
1458:                assertEquals("Limit should be 10", 10, ((Number) (select
1459:                        .getQueryContext().getLimit().evaluate(null)))
1460:                        .intValue());
1461:            }
1462:
1463:            // select VAL, VALTWO from FOO, BAR where FOO.ID = BAR.ID limit ?
1464:            public void test_select_with_bindvar_limit() throws Exception {
1465:                Parser parser = getParser();
1466:                AxionCommand cmd = parser
1467:                        .parse("select VAL, VALTWO from FOO, BAR where FOO.ID = BAR.ID limit ?");
1468:                assertNotNull("Command should not be null", cmd);
1469:                assertTrue("Command should be a SelectCommand",
1470:                        cmd instanceof  SelectCommand);
1471:                SelectCommand select = (SelectCommand) cmd;
1472:                assertNotNull("Should have a limit", select.getQueryContext()
1473:                        .getLimit());
1474:                assertTrue("Limit should be a bind variable", select
1475:                        .getQueryContext().getLimit() instanceof  BindVariable);
1476:            }
1477:
1478:            // select VAL from FOO where VALTWO = 3
1479:            public void test_select_val_from_foo_where_valtwo_eq_3()
1480:                    throws Exception {
1481:                Parser parser = getParser();
1482:
1483:                AxionCommand cmd = parser
1484:                        .parse("select VAL from FOO where VALTWO = 3");
1485:                assertNotNull("Command should not be null", cmd);
1486:                assertTrue("Command should be a SelectCommand",
1487:                        cmd instanceof  SelectCommand);
1488:
1489:                SelectCommand select = (SelectCommand) cmd;
1490:                assertEquals(
1491:                        "SelectCommand should have exactly one column in the SELECT part",
1492:                        1, select.getQueryContext().getSelectCount());
1493:                assertTrue("Selected column should be named VAL", "VAL"
1494:                        .equalsIgnoreCase(((ColumnIdentifier) (select
1495:                                .getQueryContext().getSelect(0))).getName()));
1496:
1497:                assertEquals(
1498:                        "SelectCommand should have exactly one table in the FROM part",
1499:                        1, select.getQueryContext().getFromCount());
1500:                assertTrue("Selected table should be named FOO", "FOO"
1501:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
1502:                                .getTableName()));
1503:
1504:                assertNotNull("SelectCommand should have WHERE part", select
1505:                        .getQueryContext().getWhere());
1506:            }
1507:
1508:            // where VALTWO = 3
1509:            public void testSelectWhereValEqNumericLiteral() throws Exception {
1510:                Parser parser = getParser();
1511:
1512:                AxionCommand cmd = parser
1513:                        .parse("select VAL from FOO where VALTWO = 3");
1514:                assertNotNull("Command should not be null", cmd);
1515:                assertTrue("Command should be a SelectCommand",
1516:                        cmd instanceof  SelectCommand);
1517:                SelectCommand select = (SelectCommand) cmd;
1518:
1519:                assertNotNull("SelectCommand should have WHERE part", select
1520:                        .getQueryContext().getWhere());
1521:                /*
1522:                assertTrue("WHERE should be a LeafWhereNode", select.getQueryContext().getWhere() instanceof LeafWhereNode);
1523:                LeafWhereNode leaf = (LeafWhereNode)(select.getQueryContext().getWhere());
1524:                assertNotNull("Left side should not be null", leaf.getLeft());
1525:                assertTrue("Left side should be a ColumnIdentifier", leaf.getLeft() instanceof ColumnIdentifier);
1526:                assertEquals("Column name should be VALTWO", "VALTWO", ((ColumnIdentifier)(leaf.getLeft())).getName());
1527:                assertEquals(ComparisonOperator.EQUAL, leaf.getOperator());
1528:                assertNotNull("Right side should not be null", leaf.getOperator());
1529:                assertTrue("Right side should be a Literal", leaf.getRight() instanceof Literal);
1530:                assertEquals("Right value should be 3", new Long(3), ((Literal)(leaf.getRight())).evaluate(null));
1531:                 */
1532:            }
1533:
1534:            // where VALTWO > 3
1535:            public void testSelectWhereValGtNumericLiteral() throws Exception {
1536:                Parser parser = getParser();
1537:                AxionCommand cmd = parser
1538:                        .parse("select VAL from FOO where VALTWO > 3");
1539:                SelectCommand select = (SelectCommand) cmd;
1540:                assertEquals(">", select.getQueryContext().getWhere().getName());
1541:            }
1542:
1543:            // where VALTWO >= 3
1544:            public void testSelectWhereValGtEqNumericLiteral() throws Exception {
1545:                Parser parser = getParser();
1546:                AxionCommand cmd = parser
1547:                        .parse("select VAL from FOO where VALTWO >= 3");
1548:                SelectCommand select = (SelectCommand) cmd;
1549:                assertEquals(">=", select.getQueryContext().getWhere()
1550:                        .getName());
1551:            }
1552:
1553:            // where VALTWO < 3
1554:            public void testSelectWhereValLtNumericLiteral() throws Exception {
1555:                Parser parser = getParser();
1556:                AxionCommand cmd = parser
1557:                        .parse("select VAL from FOO where VALTWO < 3");
1558:                SelectCommand select = (SelectCommand) cmd;
1559:                assertEquals("<", select.getQueryContext().getWhere().getName());
1560:            }
1561:
1562:            // where VALTWO <= 3
1563:            public void testSelectWhereValLtEqNumericLiteral() throws Exception {
1564:                Parser parser = getParser();
1565:                AxionCommand cmd = parser
1566:                        .parse("select VAL from FOO where VALTWO <= 3");
1567:                SelectCommand select = (SelectCommand) cmd;
1568:                assertEquals("<=", select.getQueryContext().getWhere()
1569:                        .getName());
1570:            }
1571:
1572:            // where VALTWO != 3
1573:            public void testSelectWhereValBangEqNumericLiteral()
1574:                    throws Exception {
1575:                Parser parser = getParser();
1576:                AxionCommand cmd = parser
1577:                        .parse("select VAL from FOO where VALTWO != 3");
1578:                SelectCommand select = (SelectCommand) cmd;
1579:                assertEquals("!=", select.getQueryContext().getWhere()
1580:                        .getName());
1581:            }
1582:
1583:            // where NOT VALTWO = 3
1584:            public void testSelectWhereNotValEqNumericLiteral()
1585:                    throws Exception {
1586:                Parser parser = getParser();
1587:                AxionCommand cmd = parser
1588:                        .parse("select VAL from FOO where NOT VALTWO = 3");
1589:                SelectCommand select = (SelectCommand) cmd;
1590:                FunctionIdentifier not = (FunctionIdentifier) (select
1591:                        .getQueryContext().getWhere());
1592:                assertEquals("NOT", not.getName());
1593:                assertEquals(1, not.getArgumentCount());
1594:                assertEquals("=", not.getArgument(0).getName());
1595:            }
1596:
1597:            // where NOT (VALTWO = 3)
1598:            public void testSelectWhereNotParenValEqNumericLiteralParen()
1599:                    throws Exception {
1600:                Parser parser = getParser();
1601:                AxionCommand cmd = parser
1602:                        .parse("select VAL from FOO where NOT (VALTWO = 3)");
1603:                SelectCommand select = (SelectCommand) cmd;
1604:                FunctionIdentifier not = (FunctionIdentifier) (select
1605:                        .getQueryContext().getWhere());
1606:                assertEquals("NOT", not.getName());
1607:                assertEquals(1, not.getArgumentCount());
1608:                assertEquals("=", not.getArgument(0).getName());
1609:            }
1610:
1611:            // where (NOT (VALTWO = 3))
1612:            public void testSelectWhereParenNotParenValEqNumericLiteralParenParen()
1613:                    throws Exception {
1614:                Parser parser = getParser();
1615:                AxionCommand cmd = parser
1616:                        .parse("select VAL from FOO where (NOT (VALTWO = 3))");
1617:                SelectCommand select = (SelectCommand) cmd;
1618:                FunctionIdentifier not = (FunctionIdentifier) (select
1619:                        .getQueryContext().getWhere());
1620:                assertEquals("NOT", not.getName());
1621:                assertEquals(1, not.getArgumentCount());
1622:                assertEquals("=", not.getArgument(0).getName());
1623:            }
1624:
1625:            // where VALTWO <> 3
1626:            public void testSelectWhereValLtGtNumericLiteral() throws Exception {
1627:                Parser parser = getParser();
1628:                AxionCommand cmd = parser
1629:                        .parse("select VAL from FOO where VALTWO <> 3");
1630:                SelectCommand select = (SelectCommand) cmd;
1631:                assertEquals("!=", select.getQueryContext().getWhere()
1632:                        .getName());
1633:            }
1634:
1635:            // where VALTWO between 3 and 5
1636:            public void testSelectWhereValBetweenNumericLiteral()
1637:                    throws Exception {
1638:                Parser parser = getParser();
1639:                AxionCommand cmd = parser
1640:                        .parse("select VAL from FOO where VALTWO between 3 and 5");
1641:                SelectCommand select = (SelectCommand) cmd;
1642:                assertNotNull(select.getQueryContext().getWhere());
1643:            }
1644:
1645:            // where VALTWO between 3 and vALTHREE
1646:            public void testSelectWhereValBetweenNumericLiteralAndColumn()
1647:                    throws Exception {
1648:                Parser parser = getParser();
1649:                AxionCommand cmd = parser
1650:                        .parse("select VAL from FOO where VALTWO between 3 and vALTHREE");
1651:                SelectCommand select = (SelectCommand) cmd;
1652:                assertNotNull(select.getQueryContext().getWhere());
1653:            }
1654:
1655:            // where VALTWO = 'Literal'
1656:            public void testSelectWhereValEqStringLiteral() throws Exception {
1657:                Parser parser = getParser();
1658:
1659:                AxionCommand cmd = parser
1660:                        .parse("select VAL from FOO where VALTWO = 'Literal'");
1661:                assertNotNull("Command should not be null", cmd);
1662:                assertTrue("Command should be a SelectCommand",
1663:                        cmd instanceof  SelectCommand);
1664:                SelectCommand select = (SelectCommand) cmd;
1665:
1666:                assertNotNull("SelectCommand should have WHERE part", select
1667:                        .getQueryContext().getWhere());
1668:                /*
1669:                assertTrue("WHERE should be a LeafWhereNode", select.getQueryContext().getWhere() instanceof LeafWhereNode);
1670:                LeafWhereNode leaf = (LeafWhereNode)(select.getQueryContext().getWhere());
1671:                assertNotNull("Left side should not be null", leaf.getLeft());
1672:                assertTrue("Left side should be a ColumnIdentifier", leaf.getLeft() instanceof ColumnIdentifier);
1673:                assertEquals("Column name should be VALTWO", "VALTWO", ((ColumnIdentifier)(leaf.getLeft())).getName());
1674:                assertEquals(ComparisonOperator.EQUAL, leaf.getOperator());
1675:                assertNotNull("Right side should not be null", leaf.getOperator());
1676:                assertTrue("Right side should be a Literal", leaf.getRight() instanceof Literal);
1677:                assertEquals("Right value should be \"Literal\"", "Literal", ((Literal) (leaf.getRight())).evaluate(null));
1678:                 */
1679:            }
1680:
1681:            // where VALTWO = 'Liter''l'
1682:            public void testSelectWhereValEqStringLiteral2() throws Exception {
1683:                Parser parser = getParser();
1684:
1685:                AxionCommand cmd = parser
1686:                        .parse("select VAL from FOO where VALTWO = 'Liter''l'");
1687:                assertNotNull("Command should not be null", cmd);
1688:                assertTrue("Command should be a SelectCommand",
1689:                        cmd instanceof  SelectCommand);
1690:                SelectCommand select = (SelectCommand) cmd;
1691:
1692:                assertNotNull("SelectCommand should have WHERE part", select
1693:                        .getQueryContext().getWhere());
1694:                /*
1695:                assertTrue("WHERE should be a LeafWhereNode", select.getQueryContext().getWhere() instanceof LeafWhereNode);
1696:                LeafWhereNode leaf = (LeafWhereNode)(select.getQueryContext().getWhere());
1697:                assertNotNull("Left side should not be null", leaf.getLeft());
1698:                assertTrue("Left side should be a ColumnIdentifier", leaf.getLeft() instanceof ColumnIdentifier);
1699:                assertEquals("Column name should be VALTWO", "VALTWO", ((ColumnIdentifier)(leaf.getLeft())).getName());
1700:                assertEquals(ComparisonOperator.EQUAL, leaf.getOperator());
1701:                assertNotNull("Right side should not be null", leaf.getOperator());
1702:                assertTrue("Right side should be a Literal", leaf.getRight() instanceof Literal);
1703:                assertEquals("Right value should be \"Liter'l\"", "Liter'l", ((Literal)(leaf.getRight())).evaluate(null));
1704:                 */
1705:            }
1706:
1707:            // select VAL from FOO where VALTWO = 3 and A = B;
1708:            public void test_select_val_from_foo_where_valtwo_eq_3_and_a_eq_b_semicolon()
1709:                    throws Exception {
1710:                Parser parser = getParser();
1711:                AxionCommand cmd = parser
1712:                        .parse("select VAL from FOO where VALTWO = 3 and A = B;");
1713:                assertNotNull("Command should not be null", cmd);
1714:                assertTrue("Command should be a SelectCommand",
1715:                        cmd instanceof  SelectCommand);
1716:                SelectCommand select = (SelectCommand) cmd;
1717:                assertEquals(
1718:                        "SelectCommand should have exactly one column in the SELECT part",
1719:                        1, select.getQueryContext().getSelectCount());
1720:                assertTrue("Selected column should be named VAL", "VAL"
1721:                        .equalsIgnoreCase(((ColumnIdentifier) (select
1722:                                .getQueryContext().getSelect(0))).getName()));
1723:                assertEquals(
1724:                        "SelectCommand should have exactly one table in the FROM part",
1725:                        1, select.getQueryContext().getFromCount());
1726:                assertTrue("Selected table should be named FOO", "FOO"
1727:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
1728:                                .getTableName()));
1729:                assertNotNull("SelectCommand should have WHERE part", select
1730:                        .getQueryContext().getWhere());
1731:            }
1732:
1733:            // select VAL from FOO where VALTWO = 3 and A = B
1734:            public void test_select_val_from_foo_where_valtwo_eq_3_and_a_eq_b()
1735:                    throws Exception {
1736:                Parser parser = getParser();
1737:
1738:                AxionCommand cmd = parser
1739:                        .parse("select VAL from FOO where VALTWO = 3 and A = B");
1740:                assertNotNull("Command should not be null", cmd);
1741:                assertTrue("Command should be a SelectCommand",
1742:                        cmd instanceof  SelectCommand);
1743:
1744:                SelectCommand select = (SelectCommand) cmd;
1745:                assertEquals(
1746:                        "SelectCommand should have exactly one column in the SELECT part",
1747:                        1, select.getQueryContext().getSelectCount());
1748:                assertTrue("Selected column should be named VAL", "VAL"
1749:                        .equalsIgnoreCase(((ColumnIdentifier) (select
1750:                                .getQueryContext().getSelect(0))).getName()));
1751:
1752:                assertEquals(
1753:                        "SelectCommand should have exactly one table in the FROM part",
1754:                        1, select.getQueryContext().getFromCount());
1755:                assertTrue("Selected table should be named FOO", "FOO"
1756:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
1757:                                .getTableName()));
1758:
1759:                assertNotNull("SelectCommand should have WHERE part", select
1760:                        .getQueryContext().getWhere());
1761:            }
1762:
1763:            //  where (VALTWO = 3 and A = B)
1764:            public void test_select_val_from_foo_where_paren_valtwo_eq_3_and_a_eq_b_paren()
1765:                    throws Exception {
1766:                Parser parser = getParser();
1767:                AxionCommand cmd = parser
1768:                        .parse("select VAL from FOO where (VALTWO = 3 and A = B)");
1769:                assertNotNull("Command should not be null", cmd);
1770:                assertTrue("Command should be a SelectCommand",
1771:                        cmd instanceof  SelectCommand);
1772:                SelectCommand select = (SelectCommand) cmd;
1773:                assertNotNull("SelectCommand should have WHERE part", select
1774:                        .getQueryContext().getWhere());
1775:                assertTrue(
1776:                        "Root WHERE node should be AND",
1777:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1778:                assertEquals("Root WHERE node should be AND", "AND",
1779:                        ((FunctionIdentifier) (select.getQueryContext()
1780:                                .getWhere())).getName());
1781:            }
1782:
1783:            //  where VALTWO = 3 and (A = B)
1784:            public void test_select_val_from_foo_where_valtwo_eq_3_and_paren_a_eq_b_paren()
1785:                    throws Exception {
1786:                Parser parser = getParser();
1787:                AxionCommand cmd = parser
1788:                        .parse("select VAL from FOO where VALTWO = 3 and (A = B)");
1789:                assertNotNull("Command should not be null", cmd);
1790:                assertTrue("Command should be a SelectCommand",
1791:                        cmd instanceof  SelectCommand);
1792:                SelectCommand select = (SelectCommand) cmd;
1793:                assertNotNull("SelectCommand should have WHERE part", select
1794:                        .getQueryContext().getWhere());
1795:                assertTrue(
1796:                        "Root WHERE node should be AND",
1797:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1798:                assertEquals("Root WHERE node should be AND", "AND",
1799:                        ((FunctionIdentifier) (select.getQueryContext()
1800:                                .getWhere())).getName());
1801:            }
1802:
1803:            //  where A = 1 and B = 2 or C = 3
1804:            public void test_where_A_and_B_or_C() throws Exception {
1805:                Parser parser = getParser();
1806:                AxionCommand cmd = parser
1807:                        .parse("select VAL from FOO where A = 1 and B = 2 or C = 3");
1808:                assertNotNull("Command should not be null", cmd);
1809:                assertTrue("Command should be a SelectCommand",
1810:                        cmd instanceof  SelectCommand);
1811:                SelectCommand select = (SelectCommand) cmd;
1812:                assertNotNull("SelectCommand should have WHERE part", select
1813:                        .getQueryContext().getWhere());
1814:                assertTrue(
1815:                        "Root WHERE node should be OR",
1816:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1817:                assertEquals("Root WHERE node should be OR", "OR",
1818:                        ((FunctionIdentifier) (select.getQueryContext()
1819:                                .getWhere())).getName());
1820:            }
1821:
1822:            //  where A = 1 and B = 2 or (C = 3)
1823:            public void test_where_A_and_B_or_paren_C_paren() throws Exception {
1824:                Parser parser = getParser();
1825:                AxionCommand cmd = parser
1826:                        .parse("select VAL from FOO where A = 1 and B = 2 or ( C = 3 )");
1827:                assertNotNull("Command should not be null", cmd);
1828:                assertTrue("Command should be a SelectCommand",
1829:                        cmd instanceof  SelectCommand);
1830:                SelectCommand select = (SelectCommand) cmd;
1831:                assertNotNull("SelectCommand should have WHERE part", select
1832:                        .getQueryContext().getWhere());
1833:                assertTrue(
1834:                        "Root WHERE node should be OR",
1835:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1836:                assertEquals("Root WHERE node should be OR", "OR",
1837:                        ((FunctionIdentifier) (select.getQueryContext()
1838:                                .getWhere())).getName());
1839:            }
1840:
1841:            //  where A = 1 and (B = 2 or C = 3)
1842:            public void test_where_A_and_paren_B_or_C_paren() throws Exception {
1843:                Parser parser = getParser();
1844:                AxionCommand cmd = parser
1845:                        .parse("select VAL from FOO where A = 1 and ( B = 2 or C = 3 )");
1846:                assertNotNull("Command should not be null", cmd);
1847:                assertTrue("Command should be a SelectCommand",
1848:                        cmd instanceof  SelectCommand);
1849:                SelectCommand select = (SelectCommand) cmd;
1850:                assertNotNull("SelectCommand should have WHERE part", select
1851:                        .getQueryContext().getWhere());
1852:                assertTrue(
1853:                        "Root WHERE node should be AND",
1854:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1855:                assertEquals("Root WHERE node should be AND", "AND",
1856:                        ((FunctionIdentifier) (select.getQueryContext()
1857:                                .getWhere())).getName());
1858:            }
1859:
1860:            //  where (A = 1 and B = 2 or C = 3)
1861:            public void test_where_paren_A_and_B_or_C_paren() throws Exception {
1862:                Parser parser = getParser();
1863:                AxionCommand cmd = parser
1864:                        .parse("select VAL from FOO where ( A = 1 and B = 2 or C = 3 )");
1865:                assertNotNull("Command should not be null", cmd);
1866:                assertTrue("Command should be a SelectCommand",
1867:                        cmd instanceof  SelectCommand);
1868:                SelectCommand select = (SelectCommand) cmd;
1869:                assertNotNull("SelectCommand should have WHERE part", select
1870:                        .getQueryContext().getWhere());
1871:                assertTrue(
1872:                        "Root WHERE node should be OR",
1873:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1874:                assertEquals("Root WHERE node should be OR", "OR",
1875:                        ((FunctionIdentifier) (select.getQueryContext()
1876:                                .getWhere())).getName());
1877:            }
1878:
1879:            //  where (A = 1 and B = 2 or (C = 3))
1880:            public void test_where_paren_A_and_B_or_paren_C_paren_paren()
1881:                    throws Exception {
1882:                Parser parser = getParser();
1883:                AxionCommand cmd = parser
1884:                        .parse("select VAL from FOO where ( A = 1 and B = 2 or ( C = 3 ) )");
1885:                assertNotNull("Command should not be null", cmd);
1886:                assertTrue("Command should be a SelectCommand",
1887:                        cmd instanceof  SelectCommand);
1888:                SelectCommand select = (SelectCommand) cmd;
1889:                assertNotNull("SelectCommand should have WHERE part", select
1890:                        .getQueryContext().getWhere());
1891:                assertTrue(
1892:                        "Root WHERE node should be OR",
1893:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1894:                assertEquals("Root WHERE node should be OR", "OR",
1895:                        ((FunctionIdentifier) (select.getQueryContext()
1896:                                .getWhere())).getName());
1897:            }
1898:
1899:            //  where (A = 1 and (B = 2 or C = 3))
1900:            public void test_where_paren_A_and_paren_B_or_C_paren_paren()
1901:                    throws Exception {
1902:                Parser parser = getParser();
1903:                AxionCommand cmd = parser
1904:                        .parse("select VAL from FOO where ( A = 1 and ( B = 2 or C = 3 ) )");
1905:                assertNotNull("Command should not be null", cmd);
1906:                assertTrue("Command should be a SelectCommand",
1907:                        cmd instanceof  SelectCommand);
1908:                SelectCommand select = (SelectCommand) cmd;
1909:                assertNotNull("SelectCommand should have WHERE part", select
1910:                        .getQueryContext().getWhere());
1911:                assertTrue(
1912:                        "Root WHERE node should be AND",
1913:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1914:                assertEquals("Root WHERE node should be AND", "AND",
1915:                        ((FunctionIdentifier) (select.getQueryContext()
1916:                                .getWhere())).getName());
1917:            }
1918:
1919:            //  where ((A = 1 and B = 2) or C = 3)
1920:            public void test_where_paren_paren_A_and_B_paren_or_C_paren()
1921:                    throws Exception {
1922:                Parser parser = getParser();
1923:                AxionCommand cmd = parser
1924:                        .parse("select VAL from FOO where ( ( A = 1 and B = 2 ) or C = 3 )");
1925:                assertNotNull("Command should not be null", cmd);
1926:                assertTrue("Command should be a SelectCommand",
1927:                        cmd instanceof  SelectCommand);
1928:                SelectCommand select = (SelectCommand) cmd;
1929:                assertNotNull("SelectCommand should have WHERE part", select
1930:                        .getQueryContext().getWhere());
1931:                assertTrue(
1932:                        "Root WHERE node should be OR",
1933:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1934:                assertEquals("Root WHERE node should be OR", "OR",
1935:                        ((FunctionIdentifier) (select.getQueryContext()
1936:                                .getWhere())).getName());
1937:            }
1938:
1939:            //  where ((A = 1) and B = 2 or C = 3)
1940:            public void test_where_paren_paren_A_paren_and_B_or_C_paren()
1941:                    throws Exception {
1942:                Parser parser = getParser();
1943:                AxionCommand cmd = parser
1944:                        .parse("select VAL from FOO where ( ( A = 1 ) and B = 2 or C = 3 )");
1945:                assertNotNull("Command should not be null", cmd);
1946:                assertTrue("Command should be a SelectCommand",
1947:                        cmd instanceof  SelectCommand);
1948:                SelectCommand select = (SelectCommand) cmd;
1949:                assertNotNull("SelectCommand should have WHERE part", select
1950:                        .getQueryContext().getWhere());
1951:                assertTrue(
1952:                        "Root WHERE node should be OR",
1953:                        select.getQueryContext().getWhere() instanceof  FunctionIdentifier);
1954:                assertEquals("Root WHERE node should be OR", "OR",
1955:                        ((FunctionIdentifier) (select.getQueryContext()
1956:                                .getWhere())).getName());
1957:            }
1958:
1959:            // insert into FOO ( VAL ) values ( 1 )
1960:            public void test_insert_into_foo_val_values_1() throws Exception {
1961:                Parser parser = getParser();
1962:
1963:                AxionCommand cmd = parser
1964:                        .parse("insert into FOO ( VAL ) values ( 1 )");
1965:                assertNotNull("Command should not be null", cmd);
1966:                assertTrue("Command should be an Insert",
1967:                        cmd instanceof  InsertCommand);
1968:
1969:                InsertCommand insert = (InsertCommand) cmd;
1970:
1971:                Iterator colIter = insert.getColumnIterator();
1972:                assertNotNull(colIter);
1973:                assertTrue(colIter.hasNext());
1974:                ColumnIdentifier colid = (ColumnIdentifier) (colIter.next());
1975:                assertTrue("VAL".equalsIgnoreCase(colid.getName()));
1976:                assertTrue(!colIter.hasNext());
1977:
1978:                Iterator valIter = insert.getValueIterator();
1979:                assertNotNull(valIter);
1980:                assertTrue(valIter.hasNext());
1981:                Literal value = (Literal) valIter.next();
1982:                assertEquals(1, ((Number) (value.evaluate(null))).intValue());
1983:                assertTrue(!valIter.hasNext());
1984:
1985:                assertNotNull("Insert should have a table", insert.getTable());
1986:                assertTrue("Table should be named FOO", "FOO"
1987:                        .equalsIgnoreCase(insert.getTable().getTableName()));
1988:            }
1989:
1990:            // insert into FOO ( VAL ) values ( [LOTS_OF_DIGITS] )
1991:            public void test_insert_into_foo_val_values_manydigits()
1992:                    throws Exception {
1993:                Parser parser = getParser();
1994:
1995:                long time = System.currentTimeMillis();
1996:                AxionCommand cmd = parser
1997:                        .parse("insert into FOO ( VAL ) values ( " + time
1998:                                + " )");
1999:                assertNotNull("Command should not be null", cmd);
2000:                assertTrue("Command should be an Insert",
2001:                        cmd instanceof  InsertCommand);
2002:
2003:                InsertCommand insert = (InsertCommand) cmd;
2004:
2005:                Iterator valIter = insert.getValueIterator();
2006:                assertNotNull(valIter);
2007:                assertTrue(valIter.hasNext());
2008:                Literal value = (Literal) valIter.next();
2009:                assertEquals(time, ((Number) (value.evaluate(null)))
2010:                        .longValue());
2011:                assertTrue(!valIter.hasNext());
2012:            }
2013:
2014:            // insert into FOO ( VAL, VALTWO ) values ( 1, 2 )
2015:            public void test_insert_into_foo_val_valtwo_values_1_2()
2016:                    throws Exception {
2017:                Parser parser = getParser();
2018:
2019:                AxionCommand cmd = parser
2020:                        .parse("insert into FOO ( VAL, VALTWO ) values ( 1, 2 )");
2021:                assertNotNull("Command should not be null", cmd);
2022:                assertTrue("Command should be an Insert",
2023:                        cmd instanceof  InsertCommand);
2024:
2025:                InsertCommand insert = (InsertCommand) cmd;
2026:
2027:                Iterator colIter = insert.getColumnIterator();
2028:                assertNotNull(colIter);
2029:                assertTrue(colIter.hasNext());
2030:                ColumnIdentifier colid = (ColumnIdentifier) (colIter.next());
2031:                assertTrue("VAL".equalsIgnoreCase(colid.getName()));
2032:                colid = (ColumnIdentifier) (colIter.next());
2033:                assertTrue("VALTWO".equalsIgnoreCase(colid.getName()));
2034:                assertTrue(!colIter.hasNext());
2035:
2036:                Iterator valIter = insert.getValueIterator();
2037:                assertNotNull(valIter);
2038:                assertTrue(valIter.hasNext());
2039:                Literal value = (Literal) valIter.next();
2040:                assertEquals(1, ((Number) (value.evaluate(null))).intValue());
2041:                value = (Literal) valIter.next();
2042:                assertEquals(2, ((Number) (value.evaluate(null))).intValue());
2043:                assertTrue(!valIter.hasNext());
2044:
2045:                assertNotNull("Insert should have a table", insert.getTable());
2046:                assertTrue("Table should be named FOO", "FOO"
2047:                        .equalsIgnoreCase(insert.getTable().getTableName()));
2048:            }
2049:
2050:            // insert into FOO columns (val, valtwo) values (1, 'a')
2051:            public void test_insert_into_foo_val_valtwo_values_1_a()
2052:                    throws Exception {
2053:                Parser parser = getParser();
2054:
2055:                AxionCommand cmd = parser
2056:                        .parse("insert into FOO columns(VAL,TYPE) values(1,'a')");
2057:                assertNotNull("Command should not be null", cmd);
2058:                assertTrue("Command should be an Insert",
2059:                        cmd instanceof  InsertCommand);
2060:
2061:                InsertCommand insert = (InsertCommand) cmd;
2062:
2063:                Iterator colIter = insert.getColumnIterator();
2064:                assertNotNull(colIter);
2065:                assertTrue(colIter.hasNext());
2066:                ColumnIdentifier colid = (ColumnIdentifier) (colIter.next());
2067:                assertTrue("VAL".equalsIgnoreCase(colid.getName()));
2068:                colid = (ColumnIdentifier) (colIter.next());
2069:                assertTrue("TYPE".equalsIgnoreCase(colid.getName()));
2070:                assertTrue(!colIter.hasNext());
2071:
2072:                Iterator valIter = insert.getValueIterator();
2073:                assertNotNull(valIter);
2074:                assertTrue(valIter.hasNext());
2075:                Literal value = (Literal) valIter.next();
2076:                assertEquals(1, ((Number) (value.evaluate(null))).intValue());
2077:                value = (Literal) valIter.next();
2078:                assertEquals("a", value.evaluate(null));
2079:                assertTrue(!valIter.hasNext());
2080:
2081:                assertNotNull("Insert should have a table", insert.getTable());
2082:                assertTrue("Table should be named FOO", "FOO"
2083:                        .equalsIgnoreCase(insert.getTable().getTableName()));
2084:            }
2085:
2086:            // insert into FOO columns (val, valtwo) values (1, '\u0145')
2087:            public void testInsertUnicode() throws Exception {
2088:                /*
2089:                 * Insert an L stroke character and read it back
2090:                 */
2091:                Parser parser = getParser();
2092:
2093:                AxionCommand cmd = parser
2094:                        .parse("insert into FOO columns(VAL,TYPE) values(1,'\u0145')");
2095:                assertNotNull("Command should not be null", cmd);
2096:                assertTrue("Command should be an Insert",
2097:                        cmd instanceof  InsertCommand);
2098:
2099:                InsertCommand insert = (InsertCommand) cmd;
2100:
2101:                Iterator colIter = insert.getColumnIterator();
2102:                assertNotNull(colIter);
2103:                assertTrue(colIter.hasNext());
2104:                ColumnIdentifier colid = (ColumnIdentifier) (colIter.next());
2105:                assertTrue("VAL".equalsIgnoreCase(colid.getName()));
2106:                colid = (ColumnIdentifier) (colIter.next());
2107:                assertTrue("TYPE".equalsIgnoreCase(colid.getName()));
2108:                assertTrue(!colIter.hasNext());
2109:
2110:                Iterator valIter = insert.getValueIterator();
2111:                assertNotNull(valIter);
2112:                assertTrue(valIter.hasNext());
2113:                Literal value = (Literal) valIter.next();
2114:                assertEquals(1, ((Number) (value.evaluate(null))).intValue());
2115:                value = (Literal) valIter.next();
2116:                assertEquals("\u0145", value.evaluate(null));
2117:                assertTrue(!valIter.hasNext());
2118:
2119:                assertNotNull("Insert should have a table", insert.getTable());
2120:                assertTrue("Table should be named FOO", "FOO"
2121:                        .equalsIgnoreCase(insert.getTable().getTableName()));
2122:            }
2123:
2124:            // select VAL from FOO order by VAL
2125:            public void test_select_val_from_foo_order_by_val()
2126:                    throws Exception {
2127:                Parser parser = getParser();
2128:
2129:                AxionCommand cmd = parser
2130:                        .parse("select VAL from FOO order by VAL");
2131:                assertNotNull("Command should not be null", cmd);
2132:                SelectCommand select = (SelectCommand) cmd;
2133:
2134:                assertEquals("Should have 1 orderby node", 1, select
2135:                        .getQueryContext().getOrderByCount());
2136:                OrderNode order = select.getQueryContext().getOrderBy(0);
2137:                assertEquals("Should indicate VAL column", "VAL", order
2138:                        .getSelectable().getName());
2139:                assertTrue("Should not be descending", !order.isDescending());
2140:            }
2141:
2142:            // select VAL from FOO order by VAL desc
2143:            public void test_select_val_from_foo_order_by_val_desc()
2144:                    throws Exception {
2145:                Parser parser = getParser();
2146:
2147:                AxionCommand cmd = parser
2148:                        .parse("select VAL from FOO order by VAL desc");
2149:                assertNotNull("Command should not be null", cmd);
2150:                SelectCommand select = (SelectCommand) cmd;
2151:
2152:                assertEquals("Should have 1 orderby node", 1, select
2153:                        .getQueryContext().getOrderByCount());
2154:                OrderNode order = select.getQueryContext().getOrderBy(0);
2155:                assertEquals("Should indicate VAL column", "VAL", order
2156:                        .getSelectable().getName());
2157:                assertTrue("Should be descending", order.isDescending());
2158:            }
2159:
2160:            // select VAL from FOO order by VAL asc
2161:            public void test_select_val_from_foo_order_by_val_asc()
2162:                    throws Exception {
2163:                Parser parser = getParser();
2164:
2165:                AxionCommand cmd = parser
2166:                        .parse("select VAL from FOO order by VAL asc");
2167:                assertNotNull("Command should not be null", cmd);
2168:                SelectCommand select = (SelectCommand) cmd;
2169:
2170:                assertEquals("Should have 1 orderby node", 1, select
2171:                        .getQueryContext().getOrderByCount());
2172:                OrderNode order = select.getQueryContext().getOrderBy(0);
2173:                assertEquals("Should indicate VAL column", "VAL", order
2174:                        .getSelectable().getName());
2175:                assertTrue("Should not be descending", !order.isDescending());
2176:            }
2177:
2178:            // select VAL from FOO order by UPPER(VAL) asc
2179:            public void test_select_val_from_foo_order_by_upper_val_asc()
2180:                    throws Exception {
2181:                Parser parser = getParser();
2182:
2183:                AxionCommand cmd = parser
2184:                        .parse("select VAL from FOO order by UPPER(VAL) asc");
2185:                assertNotNull("Command should not be null", cmd);
2186:                SelectCommand select = (SelectCommand) cmd;
2187:
2188:                assertEquals("Should have 1 orderby node", 1, select
2189:                        .getQueryContext().getOrderByCount());
2190:                OrderNode order = select.getQueryContext().getOrderBy(0);
2191:                assertTrue(order.getSelectable() instanceof  FunctionIdentifier);
2192:                assertTrue("Should not be descending", !order.isDescending());
2193:            }
2194:
2195:            // select VAL from FOO order by UPPER(VAL)
2196:            public void test_select_val_from_foo_order_by_upper_val()
2197:                    throws Exception {
2198:                Parser parser = getParser();
2199:
2200:                AxionCommand cmd = parser
2201:                        .parse("select VAL from FOO order by UPPER(VAL)");
2202:                assertNotNull("Command should not be null", cmd);
2203:                SelectCommand select = (SelectCommand) cmd;
2204:
2205:                assertEquals("Should have 1 orderby node", 1, select
2206:                        .getQueryContext().getOrderByCount());
2207:                OrderNode order = select.getQueryContext().getOrderBy(0);
2208:                assertTrue(order.getSelectable() instanceof  FunctionIdentifier);
2209:                assertTrue("Should not be descending", !order.isDescending());
2210:            }
2211:
2212:            // select VAL from FOO order by UPPER(TRIM(VAL)) asc
2213:            public void test_select_val_from_foo_order_by_upper_trim_val_asc()
2214:                    throws Exception {
2215:                Parser parser = getParser();
2216:
2217:                AxionCommand cmd = parser
2218:                        .parse("select VAL from FOO order by UPPER(TRIM(VAL)) asc");
2219:                assertNotNull("Command should not be null", cmd);
2220:                SelectCommand select = (SelectCommand) cmd;
2221:
2222:                assertEquals("Should have 1 orderby node", 1, select
2223:                        .getQueryContext().getOrderByCount());
2224:                OrderNode order = select.getQueryContext().getOrderBy(0);
2225:                assertTrue(order.getSelectable() instanceof  FunctionIdentifier);
2226:                assertTrue("Should not be descending", !order.isDescending());
2227:            }
2228:
2229:            public void test_update_foo_set_bar_eq_3() throws Exception {
2230:                Parser parser = getParser();
2231:
2232:                AxionCommand cmd = parser.parse("update FOO set BAR = 3");
2233:                assertNotNull("Command should not be null", cmd);
2234:                assertTrue("Command should be an UpdateCommand",
2235:                        cmd instanceof  UpdateCommand);
2236:                UpdateCommand update = (UpdateCommand) cmd;
2237:                assertNotNull("Should have a table", update.getTable());
2238:                assertEquals("Table name should be FOO", "FOO", update
2239:                        .getTable().getTableName());
2240:                assertNotNull("Should have a table", update.getTable());
2241:                assertEquals("Should have one column", 1, update
2242:                        .getColumnCount());
2243:                assertEquals(
2244:                        "First column should be named BAR",
2245:                        "BAR",
2246:                        ((ColumnIdentifier) (update.getColumnIterator().next()))
2247:                                .getName());
2248:                assertEquals("Should have one value", 1, update.getValueCount());
2249:                assertTrue("First value should be a literal", (update
2250:                        .getValueIterator().next()) instanceof  Literal);
2251:                assertEquals(3, ((Number) (((Literal) (update
2252:                        .getValueIterator().next())).evaluate(null)))
2253:                        .intValue());
2254:                assertTrue("Should not have a where clause", null == update
2255:                        .getWhere());
2256:            }
2257:
2258:            // update FOO set BAR = 3 where BARTWO > 7
2259:            public void test_update_foo_set_bar_eq_3_where_bar_gt_7()
2260:                    throws Exception {
2261:                Parser parser = getParser();
2262:
2263:                AxionCommand cmd = parser
2264:                        .parse("update FOO set BAR = 3 where BARTWO > 7");
2265:                assertNotNull("Command should not be null", cmd);
2266:                assertTrue("Command should be an UpdateCommand",
2267:                        cmd instanceof  UpdateCommand);
2268:                UpdateCommand update = (UpdateCommand) cmd;
2269:                assertNotNull("Should have a table", update.getTable());
2270:                assertEquals("Table name should be FOO", "FOO", update
2271:                        .getTable().getTableName());
2272:                assertNotNull("Should have a table", update.getTable());
2273:                assertEquals("Should have one column", 1, update
2274:                        .getColumnCount());
2275:                assertEquals(
2276:                        "First column should be named BAR",
2277:                        "BAR",
2278:                        ((ColumnIdentifier) (update.getColumnIterator().next()))
2279:                                .getName());
2280:                assertEquals("Should have one value", 1, update.getValueCount());
2281:                assertTrue("First value should be a literal", (update
2282:                        .getValueIterator().next()) instanceof  Literal);
2283:                assertEquals(3, ((Number) (((Literal) (update
2284:                        .getValueIterator().next())).evaluate(null)))
2285:                        .intValue());
2286:
2287:                assertNotNull("Should have WHERE part", update.getWhere());
2288:                /*
2289:                assertTrue("WHERE should be a LeafWhereNode", update.getWhere() instanceof LeafWhereNode);
2290:                LeafWhereNode leaf = (LeafWhereNode)(update.getWhere());
2291:                assertNotNull("Left side should not be null", leaf.getLeft());
2292:                assertTrue("Left side should be a ColumnIdentifier", leaf.getLeft() instanceof ColumnIdentifier);
2293:                assertEquals("Column name should be BARTWO", "BARTWO", ((ColumnIdentifier)(leaf.getLeft())).getName());
2294:                assertEquals(ComparisonOperator.GREATER_THAN, leaf.getOperator());
2295:                assertNotNull("Right side should not be null", leaf.getOperator());
2296:                assertTrue("Right side should be a Literal", leaf.getRight() instanceof Literal);
2297:                assertEquals("Right value should be 7", new Long(7), ((Literal)(leaf.getRight())).evaluate(null));
2298:                 */
2299:            }
2300:
2301:            // update FOO set BAR = 3, BARSTR = 'Literal' where BARTWO > 7
2302:            public void test_update_foo_set_bar_eq_3_barstr_eq_literalstr_where_bar_gt_7()
2303:                    throws Exception {
2304:                Parser parser = getParser();
2305:
2306:                AxionCommand cmd = parser
2307:                        .parse("update FOO set BAR = 3, BARSTR = 'Literal' where BARTWO > 7");
2308:                assertNotNull("Command should not be null", cmd);
2309:                assertTrue("Command should be an UpdateCommand",
2310:                        cmd instanceof  UpdateCommand);
2311:                UpdateCommand update = (UpdateCommand) cmd;
2312:                assertNotNull("Should have a table", update.getTable());
2313:                assertEquals("Table name should be FOO", "FOO", update
2314:                        .getTable().getTableName());
2315:                assertNotNull("Should have a table", update.getTable());
2316:                assertEquals("Should have two columns", 2, update
2317:                        .getColumnCount());
2318:                {
2319:                    Iterator iter = update.getColumnIterator();
2320:                    assertEquals("First column should be named BAR", "BAR",
2321:                            ((ColumnIdentifier) (iter.next())).getName());
2322:                    assertEquals("First column should be named BARSTR",
2323:                            "BARSTR", ((ColumnIdentifier) (iter.next()))
2324:                                    .getName());
2325:                }
2326:                assertEquals("Should have two values", 2, update
2327:                        .getValueCount());
2328:                {
2329:                    Iterator iter = update.getValueIterator();
2330:                    assertEquals(3, ((Number) (((Literal) (iter.next()))
2331:                            .evaluate(null))).intValue());
2332:                    assertEquals("Second value should be 'Literal'", "Literal",
2333:                            ((Literal) (iter.next())).evaluate(null));
2334:                }
2335:                assertNotNull("Should have WHERE part", update.getWhere());
2336:                /*
2337:                assertTrue("WHERE should be a LeafWhereNode", update.getWhere() instanceof LeafWhereNode);
2338:                LeafWhereNode leaf = (LeafWhereNode)(update.getWhere());
2339:                assertNotNull("Left side should not be null", leaf.getLeft());
2340:                assertTrue("Left side should be a ColumnIdentifier", leaf.getLeft() instanceof ColumnIdentifier);
2341:                assertEquals("Column name should be BARTWO", "BARTWO", ((ColumnIdentifier)(leaf.getLeft())).getName());
2342:                assertEquals(ComparisonOperator.GREATER_THAN, leaf.getOperator());
2343:                assertNotNull("Right side should not be null", leaf.getOperator());
2344:                assertTrue("Right side should be a Literal", leaf.getRight() instanceof Literal);
2345:                assertEquals("Right value should be 7", new Long(7), ((Literal)(leaf.getRight())).evaluate(null));
2346:                 */
2347:            }
2348:
2349:            // these tests moved here from TestAxionSqlParser,
2350:            // but are as generic as anything else
2351:
2352:            public void testCreateTableOneColumn() throws Exception {
2353:                AxionCommand command = getParser().parse(
2354:                        "create table myTable (myCol varchar)");
2355:                assertNotNull("Command should not be null", command);
2356:            }
2357:
2358:            public void testCreateTableMultipleColumns() throws Exception {
2359:                AxionCommand command = getParser().parse(
2360:                        "create table myTable (myCol varchar, myCol2 integer)");
2361:                assertNotNull("Command should not be null", command);
2362:            }
2363:
2364:            public void testInsert() throws Exception {
2365:                AxionCommand command = getParser()
2366:                        .parse(
2367:                                "insert into myTable ( a, b, c) values ( 'aa', 'bb', 'cc' )");
2368:                assertNotNull("Command should not be null", command);
2369:            }
2370:
2371:            public void testSelectColumnFromOneTable() throws Exception {
2372:                AxionCommand command = getParser().parse(
2373:                        "select fins from tunafish");
2374:
2375:                assertNotNull("Command should not be null", command);
2376:                assertTrue("Command should not be of type SelectCommand",
2377:                        (command instanceof  SelectCommand));
2378:
2379:                SelectCommand select = (SelectCommand) command;
2380:                assertEquals("There should be one ColumnIdentifier", 1, select
2381:                        .getQueryContext().getSelectCount());
2382:                assertTrue("Should have column \"fins\"",
2383:                        ((ColumnIdentifier) (select.getQueryContext()
2384:                                .getSelect(0))).getName().equalsIgnoreCase(
2385:                                "fins"));
2386:            }
2387:
2388:            public void testSelectColumnsFromOneTable() throws Exception {
2389:                AxionCommand command = getParser().parse(
2390:                        "select fins, fishy from tunafish");
2391:
2392:                assertNotNull("Command should not be null", command);
2393:                assertTrue("Command should not be of type SelectCommand",
2394:                        (command instanceof  SelectCommand));
2395:
2396:                SelectCommand select = (SelectCommand) command;
2397:                assertEquals("There should be two ColumnIdentifiers", 2, select
2398:                        .getQueryContext().getSelectCount());
2399:
2400:                boolean hasFins = false;
2401:                boolean hasFishy = false;
2402:
2403:                for (int i = 0; i < select.getQueryContext().getSelectCount(); i++) {
2404:                    hasFins |= ((ColumnIdentifier) (select.getQueryContext()
2405:                            .getSelect(i))).getName().equalsIgnoreCase("fins");
2406:                    hasFishy |= ((ColumnIdentifier) (select.getQueryContext()
2407:                            .getSelect(i))).getName().equalsIgnoreCase("fishy");
2408:                }
2409:
2410:                assertTrue("Should have column \"fins\"", hasFins);
2411:                assertTrue("Should have column \"fishy\"", hasFishy);
2412:            }
2413:
2414:            public void testSelectAllFromOneTable() throws Exception {
2415:                AxionCommand command = getParser().parse(
2416:                        "select * from tunafish");
2417:                assertNotNull("Command should not be null", command);
2418:                assertTrue("Command should not be of type SelectCommand",
2419:                        (command instanceof  SelectCommand));
2420:                SelectCommand select = (SelectCommand) command;
2421:                assertEquals("There should be one ColumnIdentifier", 1, select
2422:                        .getQueryContext().getSelectCount());
2423:                assertTrue("Should have column \"*\"",
2424:                        ((ColumnIdentifier) (select.getQueryContext()
2425:                                .getSelect(0))).getName().equals("*"));
2426:            }
2427:
2428:            public void test_shutdown() throws Exception {
2429:                AxionCommand command = getParser().parse("shutdown");
2430:                assertNotNull("Command should not be null", command);
2431:                assertTrue("Command should be of type ShutdownCommand",
2432:                        (command instanceof  ShutdownCommand));
2433:            }
2434:
2435:            public void test_remount() throws Exception {
2436:                AxionCommand command = getParser().parse(
2437:                        "remount 'D:\\\\f''oo//bar'");
2438:                assertNotNull("Command should not be null", command);
2439:                assertTrue("Command should be of type RemountCommand",
2440:                        (command instanceof  RemountCommand));
2441:                RemountCommand remount = (RemountCommand) (command);
2442:                assertEquals("D:\\\\f'oo//bar", remount.getDirectory());
2443:                assertNull(remount.getTable());
2444:                assertTrue(!remount.getDataFilesOnly());
2445:            }
2446:
2447:            public void test_remount_with_bindvar() throws Exception {
2448:                AxionCommand command = getParser().parse("remount ?");
2449:                assertNotNull("Command should not be null", command);
2450:                assertTrue("Command should be of type RemountCommand",
2451:                        (command instanceof  RemountCommand));
2452:                RemountCommand remount = (RemountCommand) (command);
2453:                assertTrue(remount.getDirectory() instanceof  BindVariable);
2454:            }
2455:
2456:            public void test_remount_table() throws Exception {
2457:                AxionCommand command = getParser().parse(
2458:                        "remount BAR '/dbs/foo/bar'");
2459:                assertNotNull("Command should not be null", command);
2460:                assertTrue("Command should be of type RemountCommand",
2461:                        (command instanceof  RemountCommand));
2462:                RemountCommand remount = (RemountCommand) (command);
2463:                assertEquals("/dbs/foo/bar", remount.getDirectory());
2464:                assertNotNull(remount.getTable());
2465:                assertEquals(new TableIdentifier("BAR"), remount.getTable());
2466:                assertTrue(!remount.getDataFilesOnly());
2467:            }
2468:
2469:            public void test_remount_table_data() throws Exception {
2470:                AxionCommand command = getParser().parse(
2471:                        "remount BAR data '/dbs/foo/bar'");
2472:                assertNotNull("Command should not be null", command);
2473:                assertTrue("Command should be of type RemountCommand",
2474:                        (command instanceof  RemountCommand));
2475:                RemountCommand remount = (RemountCommand) (command);
2476:                assertEquals("/dbs/foo/bar", remount.getDirectory());
2477:                assertNotNull(remount.getTable());
2478:                assertEquals(new TableIdentifier("BAR"), remount.getTable());
2479:                assertTrue(remount.getDataFilesOnly());
2480:            }
2481:
2482:            public void test_bad_remount() throws Exception {
2483:                try {
2484:                    getParser().parse("remount");
2485:                    fail("Expected exception to be thrown.");
2486:                } catch (Exception e) {
2487:                    // expected
2488:                }
2489:            }
2490:
2491:            public void testWithComment() throws Exception {
2492:                Parser parser = getParser();
2493:                AxionCommand cmd = parser
2494:                        .parse("select VAL /* this is a comment */ from /* this is a comment */ FOO where /* this is a comment */ VALTWO = 3");
2495:                assertNotNull("Command should not be null", cmd);
2496:                assertTrue("Command should be a SelectCommand",
2497:                        cmd instanceof  SelectCommand);
2498:                SelectCommand select = (SelectCommand) cmd;
2499:                assertEquals(
2500:                        "SelectCommand should have exactly one column in the SELECT part",
2501:                        1, select.getQueryContext().getSelectCount());
2502:                assertTrue("Selected column should be named VAL", "VAL"
2503:                        .equalsIgnoreCase(((ColumnIdentifier) (select
2504:                                .getQueryContext().getSelect(0))).getName()));
2505:                assertEquals(
2506:                        "SelectCommand should have exactly one table in the FROM part",
2507:                        1, select.getQueryContext().getFromCount());
2508:                assertTrue("Selected table should be named FOO", "FOO"
2509:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
2510:                                .getTableName()));
2511:                assertNotNull("SelectCommand should have WHERE part", select
2512:                        .getQueryContext().getWhere());
2513:            }
2514:
2515:            public void testAxionSpecificKeywordsAreSafe() throws Exception {
2516:                Parser parser = getParser();
2517:                AxionCommand cmd = parser
2518:                        .parse("create table ARRAY ( CHECKPOINT integer, REMOUNT integer, SHUTDOWN integer, \"DATA\" integer, TYPE integer, \"INTEGER\" integer )");
2519:                assertNotNull(cmd);
2520:            }
2521:
2522:            public void testBooleanLiterals() throws Exception {
2523:                Parser parser = getParser();
2524:                AxionCommand cmd = parser
2525:                        .parse("insert into FOO values ( TRUE, FALSE, true, false, 'true', 'false' )");
2526:                assertNotNull("Command should not be null", cmd);
2527:                assertTrue("Command should be an Insert",
2528:                        cmd instanceof  InsertCommand);
2529:
2530:                InsertCommand insert = (InsertCommand) cmd;
2531:
2532:                Iterator valIter = insert.getValueIterator();
2533:                assertNotNull(valIter);
2534:
2535:                {
2536:                    assertTrue(valIter.hasNext());
2537:                    Literal value = (Literal) valIter.next();
2538:                    assertEquals(Boolean.TRUE, value.evaluate(null));
2539:                    assertTrue(value.getDataType() instanceof  BooleanType);
2540:                }
2541:                {
2542:                    assertTrue(valIter.hasNext());
2543:                    Literal value = (Literal) valIter.next();
2544:                    assertEquals(Boolean.FALSE, value.evaluate(null));
2545:                    assertTrue(value.getDataType() instanceof  BooleanType);
2546:                }
2547:                {
2548:                    assertTrue(valIter.hasNext());
2549:                    Literal value = (Literal) valIter.next();
2550:                    assertEquals(Boolean.TRUE, value.evaluate(null));
2551:                    assertTrue(value.getDataType() instanceof  BooleanType);
2552:                }
2553:                {
2554:                    assertTrue(valIter.hasNext());
2555:                    Literal value = (Literal) valIter.next();
2556:                    assertEquals(Boolean.FALSE, value.evaluate(null));
2557:                    assertTrue(value.getDataType() instanceof  BooleanType);
2558:                }
2559:                {
2560:                    assertTrue(valIter.hasNext());
2561:                    Literal value = (Literal) valIter.next();
2562:                    assertEquals("true", value.evaluate(null));
2563:                    assertTrue(value.getDataType() instanceof  CharacterType);
2564:                }
2565:                {
2566:                    assertTrue(valIter.hasNext());
2567:                    Literal value = (Literal) valIter.next();
2568:                    assertEquals("false", value.evaluate(null));
2569:                    assertTrue(value.getDataType() instanceof  CharacterType);
2570:                }
2571:
2572:                assertTrue(!valIter.hasNext());
2573:
2574:            }
2575:
2576:            public void testWhereIn() throws Exception {
2577:                Parser parser = getParser();
2578:                AxionCommand cmd = parser
2579:                        .parse("select VAL from FOO where VALTWO in (1,2, 3)");
2580:                assertNotNull("Command should not be null", cmd);
2581:                assertTrue("Command should be a SelectCommand",
2582:                        cmd instanceof  SelectCommand);
2583:                SelectCommand select = (SelectCommand) cmd;
2584:                assertEquals(
2585:                        "SelectCommand should have exactly one column in the SELECT part",
2586:                        1, select.getQueryContext().getSelectCount());
2587:                assertTrue("Selected column should be named VAL", "VAL"
2588:                        .equalsIgnoreCase(((ColumnIdentifier) (select
2589:                                .getQueryContext().getSelect(0))).getName()));
2590:                assertEquals(
2591:                        "SelectCommand should have exactly one table in the FROM part",
2592:                        1, select.getQueryContext().getFromCount());
2593:                assertTrue("Selected table should be named FOO", "FOO"
2594:                        .equalsIgnoreCase(select.getQueryContext().getFrom(0)
2595:                                .getTableName()));
2596:                assertNotNull("SelectCommand should have WHERE part", select
2597:                        .getQueryContext().getWhere());
2598:                //        assertTrue("Where clause should be IN type", select.getQueryContext().getWhere() instanceof InWhereNode);
2599:            }
2600:
2601:            //    public void testRejectionOfNegativePrecision() throws Exception {
2602:            //        Parser parser = getParser();
2603:            //        try {
2604:            //            // ISO/IEC 9075-2:2003, Section 6.1, BNF definition of precision
2605:            //            parser.parse("create table foo (mybadnum numeric(-1))");
2606:            //            fail("Expected parser to reject negative precision value.");
2607:            //        } catch (AxionException ignore) {
2608:            //            // Expected this exception - move on.
2609:            //        }        
2610:            //    }
2611:            //    
2612:            //    public void testRejectionOfZeroPrecisionNoScaleSupplied() throws Exception {
2613:            //        Parser parser = getParser();
2614:            //        try {
2615:            //            // ISO/IEC 9075-2:2003, Section 6.1, Syntax Rule 4
2616:            //            parser.parse("create table foo (mybadnum numeric(0))");
2617:            //            fail("Expected parser to reject precision value of zero (no scale supplied).");
2618:            //        } catch (AxionException ignore) {
2619:            //            // Expected this exception - move on.
2620:            //        }
2621:            //    }
2622:            //    
2623:            //    public void testRejectionOfZeroPrecisionWithScaleSupplied() throws Exception {
2624:            //        Parser parser = getParser();        
2625:            //        try {
2626:            //            // ISO/IEC 9075-2:2003, Section 6.1, Syntax Rule 4
2627:            //            parser.parse("create table foo (mybadnum numeric(0, 4))");
2628:            //            fail("Expected parser to reject precision value of zero (with scale supplied).");
2629:            //        } catch (AxionException ignore) {
2630:            //            // Expected this exception - move on.
2631:            //        }        
2632:            //    }
2633:            //    
2634:            //    public void testRejectionOfNegativeScale() throws Exception {
2635:            //        Parser parser = getParser();
2636:            //        try {
2637:            //            // ISO/IEC 9075-2:2003, Section 6.1, BNF definition of scale
2638:            //            parser.parse("create table foo (mybadnum numeric(10, -1))");
2639:            //            fail("Expected parser to reject negative scale value.");
2640:            //        } catch (AxionException ignore) {
2641:            //            // Expected this exception - move on.
2642:            //        }        
2643:            //    }
2644:            //    
2645:            //    public void testRejectionOfScaleLargerThanPrecision() throws Exception {
2646:            //        Parser parser = getParser();
2647:            //        try {
2648:            //            // ISO/IEC 9075-2:2003, Section 6.1, Syntax Rule 19
2649:            //            parser.parse("create table foo (mybadnum numeric(3,10))");
2650:            //            fail("Expected parser to reject scale value that is larger than precision value.");
2651:            //        } catch (AxionException ignore) {
2652:            //            // Expected this exception - move on.
2653:            //        }
2654:            //    }
2655:            //    
2656:            //    public void testRejectionOfZeroCharLength() throws Exception {
2657:            //        Parser parser = getParser();
2658:            //        try {
2659:            //            // ISO/IEC 9075-2:2003, Section 6.1, Syntax Rule 4
2660:            //            parser.parse("create table foo (mybadchar char(0))");
2661:            //            fail("Expected parser to reject zero length value for char datatype.");
2662:            //        } catch (AxionException ignore) {
2663:            //            // Expected this exception - move on.
2664:            //        }
2665:            //    }
2666:            //    
2667:            //    public void testRejectionOfZeroVarcharLength() throws Exception {
2668:            //        Parser parser = getParser();        
2669:            //        try {
2670:            //            // ISO/IEC 9075-2:2003, Section 6.1, Syntax Rule 4
2671:            //            parser.parse("create table foo (mybadvarchar varchar(0))");
2672:            //            fail("Expected parser to reject zero length value for varchar datatype.");
2673:            //        } catch (AxionException ignore) {
2674:            //            // Expected this exception - move on.
2675:            //        }
2676:            //    }
2677:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.