Source Code Cross Referenced for SQLParserTest.java in  » Workflow-Engines » obe-1.0 » org » obe » test » standalone » 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 » Workflow Engines » obe 1.0 » org.obe.test.standalone 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.obe.test.standalone;
002:
003:        import java.io.IOException;
004:        import java.io.StringReader;
005:        import java.io.StringWriter;
006:        import java.math.BigDecimal;
007:        import java.math.BigInteger;
008:        import java.util.Date;
009:        import junit.framework.Test;
010:        import junit.framework.TestCase;
011:        import junit.framework.TestSuite;
012:        import org.apache.commons.logging.Log;
013:        import org.apache.commons.logging.LogFactory;
014:        import org.obe.sql.Node;
015:        import org.obe.sql.ParseException;
016:        import org.obe.sql.SQLParser;
017:
018:        /**
019:         * @author Adrian Price
020:         */
021:        public class SQLParserTest extends TestCase {
022:            private static final Log _logger = LogFactory
023:                    .getLog(SQLParserTest.class);
024:            private static final String[] _tests = { "testStatement",
025:                    "testWhere" };
026:            private static final String STATEMENT_1 = "SELECT a,b,c FROM D WHERE a = 1 AND b <> 2;";
027:            private static final String SQL_OR_EXPR_1 = "i = 456 AND str = 'hello'";
028:            private static final String SQL_OR_EXPR_2 = "str='hello' AND i=456 AND (l = 0 OR l = 789)";
029:            private static final String SQL_OR_EXPR_3 = "processInstanceId = '0' AND ownerId = '0' AND ownerType = 0 AND (type = 0 OR type = 2)";
030:            private static final String SQL_OR_EXPR_4 = "ownerId = '0' AND ownerType = 1 AND (type = 0 OR type = 2)";
031:            //    private static final String SQL_OR_EXPR_4 = "type = 0 OR type = 2";
032:            private static final String SQL_OR_EXPR_5 = "ownerId = '0' AND ownerType = 2 AND (type = 0 OR type = 2)";
033:
034:            public static class TestBean {
035:                private boolean _b;
036:                private byte _z;
037:                private char _c;
038:                private short _s;
039:                private int _i;
040:                private long _l;
041:                private float _f;
042:                private double _d;
043:                private BigDecimal _bd;
044:                private BigInteger _bi;
045:                private String _str;
046:                private Date _date;
047:
048:                public TestBean() {
049:                }
050:
051:                public TestBean(boolean b, byte z, char c, short s, int i,
052:                        long l, float f, double d, BigDecimal bd,
053:                        BigInteger bi, String str, Date date) {
054:
055:                    _b = b;
056:                    _z = z;
057:                    _c = c;
058:                    _s = s;
059:                    _i = i;
060:                    _l = l;
061:                    _f = f;
062:                    _d = d;
063:                    _bd = bd;
064:                    _bi = bi;
065:                    _str = str;
066:                    _date = date;
067:                }
068:
069:                public boolean isB() {
070:                    return _b;
071:                }
072:
073:                public byte getZ() {
074:                    return _z;
075:                }
076:
077:                public char getC() {
078:                    return _c;
079:                }
080:
081:                public short getS() {
082:                    return _s;
083:                }
084:
085:                public int getI() {
086:                    return _i;
087:                }
088:
089:                public long getL() {
090:                    return _l;
091:                }
092:
093:                public float getF() {
094:                    return _f;
095:                }
096:
097:                public double getD() {
098:                    return _d;
099:                }
100:
101:                public BigDecimal getBd() {
102:                    return _bd;
103:                }
104:
105:                public BigInteger getBi() {
106:                    return _bi;
107:                }
108:
109:                public String getStr() {
110:                    return _str;
111:                }
112:
113:                public Date getDate() {
114:                    return _date;
115:                }
116:            }
117:
118:            public static Test suite() {
119:                TestSuite suite = new TestSuite();
120:                for (int i = 0; i < _tests.length; i++)
121:                    suite.addTest(new SQLParserTest(_tests[i]));
122:                return suite;
123:            }
124:
125:            public SQLParserTest(String name) {
126:                super (name);
127:            }
128:
129:            public void testStatement() throws IOException, ParseException {
130:                SQLParser parser = new SQLParser(new StringReader(STATEMENT_1));
131:                Node root = parser.SQLStatement();
132:                _logger.info("STATEMENT_1 parsed to: " + unparse(root));
133:            }
134:
135:            public void testWhere() throws IOException, ParseException {
136:                Date now = new Date();
137:                Object bean = new TestBean(true, (byte) 0x01, 'c', (short) 123,
138:                        456, 789L, (float) 3.14159, 2.7182814, new BigDecimal(
139:                                "123456789012345678911234567892.123456789"),
140:                        new BigInteger("123456789012345678911234567892"),
141:                        "hello", now);
142:
143:                SQLParser parser = new SQLParser(
144:                        new StringReader(SQL_OR_EXPR_1));
145:                Node root = parser.SQLOrExpr();
146:                _logger.info("SQL_OR_EXPR_1 parsed to: " + unparse(root));
147:                Object result = root.execute(bean);
148:                assertEquals("Incorrect result;", Boolean.TRUE, result);
149:
150:                parser = new SQLParser(new StringReader(SQL_OR_EXPR_2));
151:                root = parser.SQLOrExpr();
152:                _logger.info("SQL_OR_EXPR_2 parsed to: " + unparse(root));
153:                result = root.execute(bean);
154:                assertEquals("Incorrect result;", Boolean.TRUE, result);
155:
156:                parser = new SQLParser(new StringReader(SQL_OR_EXPR_3));
157:                root = parser.SQLOrExpr();
158:                _logger.info("SQL_OR_EXPR_3 parsed to: " + unparse(root));
159:
160:                parser = new SQLParser(new StringReader(SQL_OR_EXPR_4));
161:                root = parser.SQLOrExpr();
162:                _logger.info("SQL_OR_EXPR_4 parsed to: " + unparse(root));
163:
164:                parser = new SQLParser(new StringReader(SQL_OR_EXPR_5));
165:                root = parser.SQLOrExpr();
166:                _logger.info("SQL_OR_EXPR_5 parsed to: " + unparse(root));
167:            }
168:
169:            private String unparse(Node node) throws IOException {
170:                StringWriter out = new StringWriter();
171:                node.write(out);
172:                return out.toString();
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.