001: package test;
002:
003: import org.makumba.providers.QueryAnalysis;
004: import org.makumba.providers.QueryProvider;
005:
006: import junit.framework.Test;
007: import junit.framework.TestCase;
008: import junit.framework.TestResult;
009: import junit.framework.TestSuite;
010:
011: public class oqlanalyzer extends TestCase {
012:
013: public static void main(String[] args) {
014: junit.textui.TestRunner.run(suite());
015: }
016:
017: public static Test suite() {
018: return new TestSuite(oqlanalyzer.class);
019: }
020:
021: public void run(TestResult r) {
022: try {
023: super .run(r);
024:
025: } catch (Throwable t) {
026: t.printStackTrace();
027: }
028: }
029:
030: private QueryProvider qP = QueryProvider.makeQueryAnalzyer("oql");
031:
032: public void testDateParameterType() {
033: String q1 = "SELECT p as id FROM test.Person p WHERE $1<p.TS_create";
034: QueryAnalysis oA = qP.getQueryAnalysis(q1);
035:
036: assertEquals("id", oA.getProjectionType().getFieldDefinition(0)
037: .getName());
038: assertEquals("ptr", oA.getProjectionType()
039: .getFieldDefinition(0).getType());
040: // assertEquals("id", oA.getProjectionType().getFieldDefinition(0).getDescription());
041:
042: assertEquals("dateCreate", oA.getParameterTypes()
043: .getFieldDefinition(0).getType());
044: // assertEquals("param", oA.getProjectionType().getFieldDefinition(1).getDescription());
045: }
046:
047: public void testAnalysisComplexSet() {
048:
049: String q1 = "SELECT p AS pointer, i.surname as surname, a.description as addressdescription FROM test.Person p, p.indiv i, p.address a";
050: QueryAnalysis oA = qP.getQueryAnalysis(q1);
051:
052: assertEquals("pointer", oA.getProjectionType()
053: .getFieldDefinition(0).getName());
054: assertEquals("ptr", oA.getProjectionType()
055: .getFieldDefinition(0).getType());
056: // assertEquals("id", oA.getProjectionType().getFieldDefinition(0).getDescription());
057:
058: assertEquals("surname", oA.getProjectionType()
059: .getFieldDefinition(1).getName());
060: assertEquals("char", oA.getProjectionType().getFieldDefinition(
061: 1).getType());
062: // assertEquals("surname", oA.getProjectionType().getFieldDefinition(1).getDescription());
063:
064: assertEquals("addressdescription", oA.getProjectionType()
065: .getFieldDefinition(2).getName());
066: assertEquals("char", oA.getProjectionType().getFieldDefinition(
067: 2).getType());
068: // assertEquals("description", oA.getProjectionType().getFieldDefinition(2).getDescription());
069:
070: }
071:
072: public void testAnalysisSimpleFields() {
073:
074: String q2 = "SELECT p AS pointer, p AS key, p.birthdate AS birthdate, p.uniqInt, p.hobbies AS text FROM test.Person p";
075: QueryAnalysis oA = qP.getQueryAnalysis(q2);
076:
077: assertEquals("pointer", oA.getProjectionType()
078: .getFieldDefinition(0).getName());
079: assertEquals("ptr", oA.getProjectionType()
080: .getFieldDefinition(0).getType());
081: // assertEquals("id", oA.getProjectionType().getFieldDefinition(0).getDescription());
082:
083: assertEquals("key", oA.getProjectionType()
084: .getFieldDefinition(1).getName());
085: assertEquals("ptr", oA.getProjectionType()
086: .getFieldDefinition(1).getType());
087: // assertEquals("id", oA.getProjectionType().getFieldDefinition(1).getDescription());
088:
089: assertEquals("birthdate", oA.getProjectionType()
090: .getFieldDefinition(2).getName());
091: assertEquals("date", oA.getProjectionType().getFieldDefinition(
092: 2).getType());
093: // assertEquals("birthdate", oA.getProjectionType().getFieldDefinition(2).getDescription());
094:
095: assertEquals("col4", oA.getProjectionType().getFieldDefinition(
096: 3).getName());
097: assertEquals("int", oA.getProjectionType()
098: .getFieldDefinition(3).getType());
099: // assertEquals("uniqInt", oA.getProjectionType().getFieldDefinition(3).getDescription());
100:
101: assertEquals("text", oA.getProjectionType().getFieldDefinition(
102: 4).getName());
103: assertEquals("text", oA.getProjectionType().getFieldDefinition(
104: 4).getType());
105: // assertEquals("hobbies", oA.getProjectionType().getFieldDefinition(4).getDescription());
106: }
107:
108: public void testAnalysisExtenalSetSimple() {
109:
110: String q3 = "SELECT l.name as n FROM test.Person p, p.speaks as l";
111: QueryAnalysis oA = qP.getQueryAnalysis(q3);
112:
113: assertEquals("n", oA.getProjectionType().getFieldDefinition(0)
114: .getName());
115: assertEquals("char", oA.getProjectionType().getFieldDefinition(
116: 0).getType());
117: // assertEquals("name", oA.getProjectionType().getFieldDefinition(0).getDescription());
118:
119: }
120:
121: public void testAnalysisExtenalSetSelectSetPointer() {
122:
123: String q3 = "SELECT l FROM test.Person p, p.speaks l";
124: QueryAnalysis oA = qP.getQueryAnalysis(q3);
125:
126: assertEquals("col1", oA.getProjectionType().getFieldDefinition(
127: 0).getName());
128: assertEquals("ptr", oA.getProjectionType()
129: .getFieldDefinition(0).getType());
130: // assertEquals("id", oA.getProjectionType().getFieldDefinition(0).getDescription());
131:
132: }
133:
134: public void testAnalysisSelectPointer() {
135:
136: String q3 = "SELECT p FROM test.Person p";
137: QueryAnalysis oA = qP.getQueryAnalysis(q3);
138:
139: assertEquals("col1", oA.getProjectionType().getFieldDefinition(
140: 0).getName());
141: assertEquals("ptr", oA.getProjectionType()
142: .getFieldDefinition(0).getType());
143: // assertEquals("id", oA.getProjectionType().getFieldDefinition(0).getDescription());
144:
145: }
146:
147: public void testAnalysisSetIntEnum() {
148:
149: String q = "SELECT q.enum as intset FROM test.Person p, p.intSet q";
150: QueryAnalysis oA = qP.getQueryAnalysis(q);
151:
152: assertEquals("intset", oA.getProjectionType()
153: .getFieldDefinition(0).getName());
154: assertEquals("intEnum", oA.getProjectionType()
155: .getFieldDefinition(0).getType());
156: // assertEquals("enum", oA.getProjectionType().getFieldDefinition(0).getDescription());
157:
158: }
159:
160: public void testAnalysisInSet() {
161:
162: String q = "SELECT p as id, p.age as age FROM test.Person p WHERE p.age IN SET($1)";
163: QueryAnalysis oA = qP.getQueryAnalysis(q);
164:
165: assertEquals("id", oA.getProjectionType().getFieldDefinition(0)
166: .getName());
167: assertEquals("ptr", oA.getProjectionType()
168: .getFieldDefinition(0).getType());
169: // assertEquals("id", oA.getProjectionType().getFieldDefinition(0).getDescription());
170:
171: assertEquals("age", oA.getProjectionType()
172: .getFieldDefinition(1).getName());
173: assertEquals("int", oA.getProjectionType()
174: .getFieldDefinition(1).getType());
175: // assertEquals("age", oA.getProjectionType().getFieldDefinition(1).getDescription());
176:
177: }
178:
179: public void testAnalysisArithmeticOperationOk() {
180:
181: String q1 = "SELECT p as id, p.age+17 as agePlus17 FROM test.Person p";
182: QueryAnalysis oA1 = qP.getQueryAnalysis(q1);
183:
184: assertEquals("id", oA1.getProjectionType()
185: .getFieldDefinition(0).getName());
186: assertEquals("ptr", oA1.getProjectionType().getFieldDefinition(
187: 0).getType());
188: // assertEquals("id", oA1.getProjectionType().getFieldDefinition(0).getDescription());
189:
190: assertEquals("agePlus17", oA1.getProjectionType()
191: .getFieldDefinition(1).getName());
192: assertEquals("int", oA1.getProjectionType().getFieldDefinition(
193: 1).getType());
194: // assertEquals("agePlus17", oA1.getProjectionType().getFieldDefinition(1).getDescription());
195:
196: String q2 = "SELECT p as id, p.age+1.2 as agePlus1dot2 FROM test.Person p";
197: QueryAnalysis oA2 = qP.getQueryAnalysis(q2);
198:
199: assertEquals("id", oA2.getProjectionType()
200: .getFieldDefinition(0).getName());
201: assertEquals("ptr", oA2.getProjectionType().getFieldDefinition(
202: 0).getType());
203: // assertEquals("id", oA2.getProjectionType().getFieldDefinition(0).getDescription());
204:
205: assertEquals("agePlus1dot2", oA2.getProjectionType()
206: .getFieldDefinition(1).getName());
207: assertEquals("int", oA2.getProjectionType().getFieldDefinition(
208: 1).getType());
209: // assertEquals("agePlus1dot2", oA2.getProjectionType().getFieldDefinition(1).getDescription());
210:
211: String q4 = "SELECT p as id, p.hobbies+p.comment as text FROM test.Person p";
212: QueryAnalysis oA4 = qP.getQueryAnalysis(q4);
213:
214: assertEquals("id", oA4.getProjectionType()
215: .getFieldDefinition(0).getName());
216: assertEquals("ptr", oA4.getProjectionType().getFieldDefinition(
217: 0).getType());
218: // assertEquals("id", oA4.getProjectionType().getFieldDefinition(0).getDescription());
219:
220: assertEquals("text", oA4.getProjectionType()
221: .getFieldDefinition(1).getName());
222: assertEquals("text", oA4.getProjectionType()
223: .getFieldDefinition(1).getType());
224: // assertEquals("text", oA4.getProjectionType().getFieldDefinition(1).getDescription());
225: }
226:
227: public void testAnalysisArithmeticOperationParameter() {
228:
229: String q1 = "SELECT p as id, p.age+$1 as param FROM test.Person p";
230: QueryAnalysis oA = qP.getQueryAnalysis(q1);
231:
232: assertEquals("id", oA.getProjectionType().getFieldDefinition(0)
233: .getName());
234: assertEquals("ptr", oA.getProjectionType()
235: .getFieldDefinition(0).getType());
236: // assertEquals("id", oA.getProjectionType().getFieldDefinition(0).getDescription());
237:
238: assertEquals("param", oA.getProjectionType()
239: .getFieldDefinition(1).getName());
240: assertEquals("int", oA.getProjectionType()
241: .getFieldDefinition(1).getType());
242: // assertEquals("param", oA.getProjectionType().getFieldDefinition(1).getDescription());
243:
244: }
245:
246: }
|