KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > optim > jorm > TestJormGoUpDecodeRule


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2004 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, S. Chassande-Barrioz, A. Lefebvre
22  */

23
24 package org.objectweb.medor.optim.jorm;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28 import junit.textui.TestRunner;
29 import org.objectweb.medor.api.Field;
30 import org.objectweb.medor.api.MedorException;
31 import org.objectweb.medor.expression.api.Expression;
32 import org.objectweb.medor.expression.api.ParameterOperand;
33 import org.objectweb.medor.expression.api.Operand;
34 import org.objectweb.medor.expression.lib.And;
35 import org.objectweb.medor.expression.lib.BasicParameterOperand;
36 import org.objectweb.medor.expression.lib.Equal;
37 import org.objectweb.medor.filter.jorm.lib.EncodePName;
38 import org.objectweb.medor.filter.jorm.lib.SinglePName;
39 import org.objectweb.medor.filter.lib.BasicFieldOperand;
40 import org.objectweb.medor.filter.lib.MemberOf;
41 import org.objectweb.medor.jorm.TestJormHelper;
42 import org.objectweb.medor.optim.lib.DropUselessNodeRule;
43 import org.objectweb.medor.query.TestQueryTreeHelper;
44 import org.objectweb.medor.query.api.CalculatedField;
45 import org.objectweb.medor.query.api.QueryLeaf;
46 import org.objectweb.medor.query.api.QueryNode;
47 import org.objectweb.medor.query.api.QueryTree;
48 import org.objectweb.medor.query.api.QueryTreeField;
49 import org.objectweb.medor.query.lib.JoinProject;
50 import org.objectweb.medor.query.lib.Project;
51 import org.objectweb.medor.query.lib.QueryTreePrinter;
52 import org.objectweb.medor.query.lib.SelectProject;
53 import org.objectweb.util.monolog.api.BasicLevel;
54
55 import java.util.ArrayList JavaDoc;
56 import java.util.Collection JavaDoc;
57
58 public abstract class TestJormGoUpDecodeRule extends TestJormPDHelper {
59
60     /**
61      * main method to launch the tests manually
62      */

63     public static void main(String JavaDoc[] args) {
64         TestRunner.run(suite());
65     }
66
67     /**
68      * This method creates a TestSuite object with the current tests
69      */

70     public static Test suite() {
71         return new TestSuite(TestJormGoUpDecodeRule.class);
72     }
73
74     public TestJormGoUpDecodeRule(String JavaDoc testName, String JavaDoc loggerName) {
75         super(testName, loggerName);
76     }
77
78     public Example getExtent(Collection JavaDoc fileNames,
79                              String JavaDoc className,
80                              String JavaDoc pnameFieldName,
81                              String JavaDoc[] fieldNames) {
82         Example e = super.getExtent(fileNames, className, pnameFieldName, fieldNames);
83         e.extent.setPMapper(mapper, PROJECT_NAME);
84         return e;
85     }
86
87     Example eb;
88     Example ec;
89     Example ed;
90
91     protected void setUp() {
92         logger.log(BasicLevel.DEBUG, "Start of setUp");
93         eb = getRewrittenB();
94         ec = getRewrittenC();
95         ed = getRewrittenD();
96         logger.log(BasicLevel.DEBUG, "End of setUp");
97     }
98
99     protected void tearDown() {
100     }
101
102     public QueryTree getBCQueryTree(TestJormHelper tjh) {
103         try {
104             if (eb == null || ec == null)
105                 fail("All objects are not created by jorm"
106                     + "\n-eb=" + eb
107                     + "\n-ec=" + ec);
108             QueryTreeField f1, f2;
109             // Join B.y = C.x
110
JoinProject j1 = new JoinProject("");
111             Expression e = new Equal(
112                 new BasicFieldOperand(eb.qt.getTupleStructure().getField(eb.clazz.getFQName() + ".y")),
113                 new BasicFieldOperand(ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".x"))
114             );
115             j1.setQueryFilter(e);
116             f1 = (QueryTreeField) eb.qt.getTupleStructure().getField(eb.clazz.getFQName() + ".object");
117             j1.addPropagatedField(f1.getName(), f1.getType(), new QueryTreeField[]{f1});
118             f2 = (QueryTreeField) ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
119             j1.addPropagatedField(f2.getName(), f2.getType(), new QueryTreeField[]{f2});
120             return j1;
121         }
122         catch (MedorException e) {
123             e.printStackTrace();
124             fail(e.getMessage());
125         }
126         return null;
127     }
128
129     public QueryTree getBCDQueryTree(TestJormHelper tjh) {
130         try {
131             if (eb == null || ec == null || ed == null)
132                 fail("All objects are not created by jorm"
133                     + "\n-eb=" + eb
134                     + "\n-ec=" + ec
135                     + "\n-ed=" + ed);
136             QueryTreeField f1, f2;
137
138             // Join B.y = C.x
139
JoinProject j1 = new JoinProject("");
140             Expression e = new Equal(
141                 new BasicFieldOperand(eb.qt.getTupleStructure().getField(eb.clazz.getFQName() + ".y")),
142                 new BasicFieldOperand(ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".x"))
143             );
144             j1.setQueryFilter(e);
145             f1 = (QueryTreeField) eb.qt.getTupleStructure().getField(eb.clazz.getFQName() + ".object");
146             j1.addPropagatedField(f1.getName(), f1.getType(), new QueryTreeField[]{f1});
147             f2 = (QueryTreeField) ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
148             j1.addPropagatedField(f2.getName(), f2.getType(), new QueryTreeField[]{f2});
149
150             // Join B.object = C.object
151
JoinProject j2 = new JoinProject("");
152             f1 = (QueryTreeField) j1.getTupleStructure().getField(eb.clazz.getFQName() + ".object");
153             f2 = (QueryTreeField) ed.qt.getTupleStructure().getField(ed.clazz.getFQName() + ".object");
154             e = new Equal(new BasicFieldOperand(f1), new BasicFieldOperand(f2));
155             j2.setQueryFilter(e);
156             f1 = (QueryTreeField) ed.qt.getTupleStructure().getField(ed.clazz.getFQName() + ".c");
157             f2 = (QueryTreeField) j1.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
158             j2.addPropagatedField(f1.getName(), f1.getType(), new QueryTreeField[]{f1});
159             j2.addPropagatedField(f2.getName(), f2.getType(), new QueryTreeField[]{f2});
160
161                 QueryTreePrinter.printQueryTree(j2, logger);
162             return j2;
163
164         }
165         catch (MedorException e) {
166             e.printStackTrace();
167             fail(e.getMessage());
168         }
169         return null;
170     }
171
172     public void testPnameEqualParam1() {
173         logger.log(BasicLevel.DEBUG, "Start of testPnameEqualParam1");
174         QueryTree j1 = getBCQueryTree(this);
175         SelectProject qt = new SelectProject("");
176
177         try {
178             //filter
179
QueryTreeField f1 = (QueryTreeField)
180                 j1.getTupleStructure().getField(eb.clazz.getFQName() + ".object");
181             ParameterOperand po = new BasicParameterOperand(f1.getType(), "param1");
182             qt.setQueryFilter(new Equal(new BasicFieldOperand(f1), po));
183             //projection
184
f1 = (QueryTreeField)
185                 j1.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
186             qt.addPropagatedField(f1.getName(), f1.getType(), new QueryTreeField[]{f1});
187         }
188         catch (MedorException e) {
189             e.printStackTrace();
190             fail(e.getMessage());
191         }
192
193         logger.log(BasicLevel.DEBUG, "JormLeafRewriter created");
194
195         QueryTree rewritten = null;
196         try {
197             rewritten = new JormGoUpDecodeRule().rewrite(qt);
198             rewritten = new DropUselessNodeRule().rewrite(rewritten);
199         }
200         catch (MedorException e) {
201             e.printStackTrace();
202             fail(e.getMessage());
203         }
204         logger.log(BasicLevel.DEBUG, "BC1 rewritten");
205         logger.log(BasicLevel.DEBUG, "=========================================");
206
207             QueryTreePrinter.printQueryTree(rewritten, logger);
208
209         logger.log(BasicLevel.DEBUG, "Checking of One");
210
211         try {
212             eb = getRewrittenB();
213             ec = getRewrittenC();
214             ed = getRewrittenD();
215             //build the expected tree
216
QueryLeaf qlb = (QueryLeaf) ((QueryNode) eb.qt).getChildren()[0];
217             QueryLeaf qlc = (QueryLeaf) ((QueryNode) ec.qt).getChildren()[0];
218             //Node 1
219
Expression e = new Equal(
220                 new BasicFieldOperand(qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".y")),
221                 new BasicFieldOperand(qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".x")));
222             QueryNode qn1 = new JoinProject(e, "");
223             QueryTreeField qtf = null;
224             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c2");
225             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
226             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c1");
227             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
228             qtf = (QueryTreeField) qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
229             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
230
231             //node 2
232
Field c1 = qn1.getTupleStructure().getField(eb.clazz.getFQName() + ".c1");
233             Field c2 = qn1.getTupleStructure().getField(eb.clazz.getFQName() + ".c2");
234             String JavaDoc paramName = "param1";
235             e = new And(
236                 new Equal(
237                     new BasicFieldOperand(c1),
238                     new EncodePName(
239                         c1.getType(),
240                         paramName,
241                         "f1")),
242                 new Equal(
243                     new BasicFieldOperand(c2),
244                     new EncodePName(
245                         c2.getType(),
246                         paramName,
247                         "f2"))
248             );
249             QueryNode qn2 = new SelectProject(e, "");
250             qtf = (QueryTreeField) qn1.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
251             qn2.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
252
253             //Node 3
254
QueryNode qn3 = new Project("");
255             qtf = (QueryTreeField) qn2.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
256             CalculatedField decodeField = (CalculatedField)
257                 ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
258             SinglePName spn = (SinglePName) decodeField.getExpression();
259             qn3.addCalculatedField(
260                 decodeField.getName(),
261                 decodeField.getType(),
262                 new SinglePName(
263                     new BasicFieldOperand(qtf),
264                     (Operand) spn.getExpression(1),
265                     spn.getType()));
266
267             logger.log(BasicLevel.DEBUG, "BC1 expected");
268             logger.log(BasicLevel.DEBUG, "=========================================");
269
270                 QueryTreePrinter.printQueryTree(qn3, logger);
271             TestQueryTreeHelper.equals("", qn3, rewritten, logger);
272             logger.log(BasicLevel.DEBUG, "End of testPnameEqualParam1");
273         }
274         catch (MedorException me) {
275             me.printStackTrace();
276             fail(me.getMessage());
277         }
278     }
279
280     public void testPnameEqualParam2() {
281         logger.log(BasicLevel.DEBUG, "Start of testPnameEqualParam2");
282         QueryTree j1 = getBCQueryTree(this);
283         SelectProject qt = new SelectProject("");
284
285         try {
286             //filter
287
QueryTreeField f1 = (QueryTreeField)
288                 j1.getTupleStructure().getField(eb.clazz.getFQName() + ".object");
289             ParameterOperand po = new BasicParameterOperand(f1.getType(), "param1");
290             qt.setQueryFilter(new Equal(po, new BasicFieldOperand(f1)));
291             //projection
292
f1 = (QueryTreeField)
293                 j1.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
294             qt.addPropagatedField(f1.getName(), f1.getType(), new QueryTreeField[]{f1});
295         }
296         catch (MedorException e) {
297             e.printStackTrace();
298             fail(e.getMessage());
299         }
300
301         logger.log(BasicLevel.DEBUG, "JormLeafRewriter created");
302
303         QueryTree rewritten = null;
304         try {
305             rewritten = new JormGoUpDecodeRule().rewrite(qt);
306             rewritten = new DropUselessNodeRule().rewrite(rewritten);
307         }
308         catch (MedorException e) {
309             e.printStackTrace();
310             fail(e.getMessage());
311         }
312         logger.log(BasicLevel.DEBUG, "BC2 rewritten");
313         logger.log(BasicLevel.DEBUG, "=========================================");
314
315             QueryTreePrinter.printQueryTree(rewritten, logger);
316
317         logger.log(BasicLevel.DEBUG, "Checking of One");
318
319         try {
320             eb = getRewrittenB();
321             ec = getRewrittenC();
322             ed = getRewrittenD();
323             //build the expected tree
324
QueryLeaf qlb = (QueryLeaf) ((QueryNode) eb.qt).getChildren()[0];
325             QueryLeaf qlc = (QueryLeaf) ((QueryNode) ec.qt).getChildren()[0];
326             //Node 1
327
Expression e = new Equal(
328                 new BasicFieldOperand(qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".y")),
329                 new BasicFieldOperand(qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".x")));
330             QueryNode qn1 = new JoinProject(e, "");
331             QueryTreeField qtf = null;
332             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c2");
333             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
334             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c1");
335             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
336             qtf = (QueryTreeField) qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
337             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
338
339             //node 2
340
Field c1 = qn1.getTupleStructure().getField(eb.clazz.getFQName() + ".c1");
341             Field c2 = qn1.getTupleStructure().getField(eb.clazz.getFQName() + ".c2");
342             String JavaDoc paramName = "param1";
343             e = new And(
344                 new Equal(
345                     new EncodePName(
346                         c1.getType(),
347                         paramName,
348                         "f1"),
349                     new BasicFieldOperand(c1)
350                 ),
351                 new Equal(
352                     new EncodePName(
353                         c2.getType(),
354                         paramName,
355                         "f2"),
356                     new BasicFieldOperand(c2)
357                 )
358             );
359             QueryNode qn2 = new SelectProject(e, "");
360             qtf = (QueryTreeField) qn1.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
361             qn2.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
362
363             //Node 3
364
QueryNode qn3 = new Project("");
365             qtf = (QueryTreeField) qn2.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
366             CalculatedField decodeField = (CalculatedField)
367                 ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
368             SinglePName spn = (SinglePName) decodeField.getExpression();
369             qn3.addCalculatedField(
370                 decodeField.getName(),
371                 decodeField.getType(),
372                 new SinglePName(
373                     new BasicFieldOperand(qtf),
374                     (Operand) spn.getExpression(1),
375                     spn.getType()));
376
377             logger.log(BasicLevel.DEBUG, "BC2 expected");
378             logger.log(BasicLevel.DEBUG, "=========================================");
379
380                 QueryTreePrinter.printQueryTree(qn3, logger);
381             TestQueryTreeHelper.equals("", qn3, rewritten, logger);
382         }
383         catch (MedorException me) {
384             me.printStackTrace();
385             fail(me.getMessage());
386         }
387         logger.log(BasicLevel.DEBUG, "End of testPnameEqualParam2");
388     }
389
390     public void testPnameEqualParam3() {
391         logger.log(BasicLevel.DEBUG, "Start of testPnameEqualParam3");
392         QueryTree j1 = getBCQueryTree(this);
393         SelectProject qt = new SelectProject("");
394
395         try {
396             //filter
397
QueryTreeField f1 = (QueryTreeField)
398                 j1.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
399             ParameterOperand po = new BasicParameterOperand(f1.getType(), "param1");
400             qt.setQueryFilter(new Equal(po, new BasicFieldOperand(f1)));
401             //projection
402
f1 = (QueryTreeField)
403                 j1.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
404             qt.addPropagatedField(f1.getName(), f1.getType(), new QueryTreeField[]{f1});
405         }
406         catch (MedorException e) {
407             e.printStackTrace();
408             fail(e.getMessage());
409         }
410
411         logger.log(BasicLevel.DEBUG, "JormLeafRewriter created");
412
413         QueryTree rewritten = null;
414         try {
415             rewritten = new JormGoUpDecodeRule().rewrite(qt);
416
417             rewritten = new DropUselessNodeRule().rewrite(rewritten);
418         }
419         catch (MedorException e) {
420             e.printStackTrace();
421             fail(e.getMessage());
422         }
423         logger.log(BasicLevel.DEBUG, "BC3 rewritten");
424         logger.log(BasicLevel.DEBUG, "=========================================");
425
426             QueryTreePrinter.printQueryTree(rewritten, logger);
427
428         logger.log(BasicLevel.DEBUG, "Checking of One");
429
430         try {
431             eb = getRewrittenB();
432             ec = getRewrittenC();
433             ed = getRewrittenD();
434             //build the expected tree
435
QueryLeaf qlb = (QueryLeaf) ((QueryNode) eb.qt).getChildren()[0];
436             QueryLeaf qlc = (QueryLeaf) ((QueryNode) ec.qt).getChildren()[0];
437             //Node 1
438
Expression e = new Equal(
439                 new BasicFieldOperand(qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".y")),
440                 new BasicFieldOperand(qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".x")));
441             QueryNode qn1 = new JoinProject(e, "");
442             QueryTreeField qtf = null;
443             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c2");
444             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
445             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c1");
446             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
447             qtf = (QueryTreeField) qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
448             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
449
450             //node 2
451
Field id = qn1.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
452             String JavaDoc paramName = "param1";
453             e = new Equal(
454                 new EncodePName(id.getType(), paramName),
455                 new BasicFieldOperand(id));
456             QueryNode qn2 = new SelectProject(e, "");
457             qtf = (QueryTreeField) qn1.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
458             qn2.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
459
460             //Node 3
461
QueryNode qn3 = new Project("");
462             qtf = (QueryTreeField) qn2.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
463             CalculatedField decodeField = (CalculatedField)
464                 ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
465             SinglePName spn = (SinglePName) decodeField.getExpression();
466             qn3.addCalculatedField(
467                 decodeField.getName(),
468                 decodeField.getType(),
469                 new SinglePName(
470                     new BasicFieldOperand(qtf),
471                     (Operand) spn.getExpression(1),
472                     spn.getType()));
473
474             logger.log(BasicLevel.DEBUG, "BC3 expected");
475             logger.log(BasicLevel.DEBUG, "=========================================");
476
477                 QueryTreePrinter.printQueryTree(qn3, logger);
478             TestQueryTreeHelper.equals("", qn3, rewritten, logger);
479         }
480         catch (MedorException me) {
481             me.printStackTrace();
482             fail(me.getMessage());
483         }
484         logger.log(BasicLevel.DEBUG, "End of testPnameEqualParam3");
485     }
486
487     public void testBCD() {
488         logger.log(BasicLevel.DEBUG, "Start of testBCD");
489         QueryTree qt = getBCDQueryTree(this);
490         logger.log(BasicLevel.DEBUG, "JormLeafRewriter created");
491
492         QueryTree rewritten = null;
493         try {
494             rewritten = new JormGoUpDecodeRule().rewrite(qt);
495             logger.log(BasicLevel.DEBUG, "--------------After GoUpDecode: ");
496             QueryTreePrinter.printQueryTree(rewritten, logger);
497             logger.log(BasicLevel.DEBUG, "--------------Entering DropUselessNode ");
498             
499             rewritten = new DropUselessNodeRule().rewrite(rewritten);
500         }
501         catch (MedorException e) {
502             e.printStackTrace();
503             fail(e.getMessage());
504         }
505         logger.log(BasicLevel.DEBUG, "BCD rewritten");
506         logger.log(BasicLevel.DEBUG, "=========================================");
507
508             QueryTreePrinter.printQueryTree(rewritten, logger);
509
510         logger.log(BasicLevel.DEBUG, "Checking of One");
511
512         try {
513             //build the expected tree
514
Example eb = getRewrittenB();
515             QueryLeaf qlb = (QueryLeaf) ((QueryNode) eb.qt).getChildren()[0];
516
517             Example ec = getRewrittenC();
518             QueryLeaf qlc = (QueryLeaf) ((QueryNode) ec.qt).getChildren()[0];
519
520             Example ed = getRewrittenD();
521             QueryLeaf qld = (QueryLeaf) ((QueryNode) ed.qt).getChildren()[0];
522
523             Expression e = new Equal(
524                 new BasicFieldOperand(qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".y")),
525                 new BasicFieldOperand(qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".x")));
526             QueryNode qn1 = new JoinProject(e, "");
527             QueryTreeField qtf = null;
528             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c2");
529             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
530             qtf = (QueryTreeField) qlb.getTupleStructure().getField(eb.clazz.getFQName() + ".c1");
531             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
532             qtf = (QueryTreeField) qlc.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
533             qn1.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
534
535             e = new And(
536                 new Equal(
537                     new BasicFieldOperand(qn1.getTupleStructure().getField(eb.clazz.getFQName() + ".c1")),
538                     new BasicFieldOperand(qld.getTupleStructure().getField(ed.clazz.getFQName() + ".a"))
539                 ),
540                 new Equal(
541                     new BasicFieldOperand(qn1.getTupleStructure().getField(eb.clazz.getFQName() + ".c2")),
542                     new BasicFieldOperand(qld.getTupleStructure().getField(ed.clazz.getFQName() + ".b"))
543                 )
544             );
545             QueryNode qn2 = new JoinProject(e, "");
546             qtf = (QueryTreeField) qld.getTupleStructure().getField(ed.clazz.getFQName() + ".c");
547             qn2.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
548             qtf = (QueryTreeField) qn1.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
549             qn2.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
550
551             QueryNode qn3 = new Project("");
552             qtf = (QueryTreeField) qn2.getTupleStructure().getField(ec.clazz.getFQName() + ".id");
553             CalculatedField decodeField = (CalculatedField)
554                 ec.qt.getTupleStructure().getField(ec.clazz.getFQName() + ".object");
555             SinglePName spn = (SinglePName) decodeField.getExpression();
556             qn3.addCalculatedField(
557                 decodeField.getName(),
558                 decodeField.getType(),
559                 new SinglePName(
560                     new BasicFieldOperand(qtf),
561                     (Operand) spn.getExpression(1),
562                     spn.getType()));
563             qtf = (QueryTreeField) qn2.getTupleStructure().getField(ed.clazz.getFQName() + ".c");
564             qn3.addPropagatedField(qtf.getName(), qtf.getType(), new QueryTreeField[]{qtf});
565
566             TestQueryTreeHelper.equals("", qn3, rewritten, logger);
567         }
568         catch (MedorException me) {
569             me.printStackTrace();
570             fail(me.getMessage());
571         }
572         logger.log(BasicLevel.DEBUG, "End of testBCD");
573     }
574
575     public void testMemberOf() {
576         logger.log(BasicLevel.DEBUG, "Start of testMemberOf");
577         Example e1 = getRewrittenOne();
578         Example ea = getRewrittenA();
579         try {
580             QueryTreeField qfa = (QueryTreeField)
581                 e1.qt.getTupleStructure().getField(
582                     e1.clazz.getFQName() + ".fieldA");
583             ArrayList JavaDoc al1 = new ArrayList JavaDoc(1);
584             al1.add(new BasicFieldOperand(qfa));
585             ArrayList JavaDoc al2 = new ArrayList JavaDoc(1);
586             al2.add(new BasicFieldOperand(ea.qt.getTupleStructure().getField(
587                 ea.clazz.getFQName() + ".object")));
588             Expression e = new MemberOf(al1, al2);
589             QueryNode qn2 = new JoinProject(e, "");
590             qn2.addPropagatedField("toto", qfa.getType(), new QueryTreeField[]{qfa});
591             logger.log(BasicLevel.DEBUG, "QueryTree before rewriting");
592             QueryTreePrinter.printQueryTree(qn2, logger);
593
594             QueryTree rewritten = new JormGoUpDecodeRule().rewrite(qn2);
595             logger.log(BasicLevel.DEBUG, "QueryTree after rewriting");
596             QueryTreePrinter.printQueryTree(rewritten, logger);
597         }
598         catch (Exception JavaDoc me) {
599             me.printStackTrace();
600             fail(me.getMessage());
601
602         }
603         logger.log(BasicLevel.DEBUG, "End of testMemberOf");
604
605     }
606 }
607
Popular Tags