KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > query > jorm > TestNavigatorNodeFactory


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 package org.objectweb.medor.query.jorm;
24
25 import org.objectweb.jorm.metainfo.api.GenClassRef;
26 import org.objectweb.medor.api.Field;
27 import org.objectweb.medor.api.MedorException;
28 import org.objectweb.medor.expression.lib.Equal;
29 import org.objectweb.medor.expression.lib.Or;
30 import org.objectweb.medor.expression.lib.BasicVariableOperand;
31 import org.objectweb.medor.filter.lib.BasicFieldOperand;
32 import org.objectweb.medor.filter.jorm.lib.NavigatorOperator;
33 import org.objectweb.medor.jorm.TestJormHelper;
34 import org.objectweb.medor.optim.api.QueryRewriter;
35 import org.objectweb.medor.optim.jorm.JormFlatten2Rdb;
36 import org.objectweb.medor.optim.lib.BasicQueryRewriter;
37 import org.objectweb.medor.optim.lib.FlattenQueryTreeRule;
38 import org.objectweb.medor.query.TestQueryTreeHelper;
39 import org.objectweb.medor.query.api.PropagatedField;
40 import org.objectweb.medor.query.api.QueryNode;
41 import org.objectweb.medor.query.api.QueryTree;
42 import org.objectweb.medor.query.api.QueryTreeField;
43 import org.objectweb.medor.query.jorm.api.JormExtent;
44 import org.objectweb.medor.query.jorm.lib.ClassExtent;
45 import org.objectweb.medor.query.jorm.lib.GenClassExtent;
46 import org.objectweb.medor.query.jorm.lib.JormQueryTreeHelper;
47 import org.objectweb.medor.query.jorm.lib.NavigatorNodeFactory;
48 import org.objectweb.medor.query.jorm.lib.PNameField;
49 import org.objectweb.medor.query.lib.JoinProject;
50 import org.objectweb.medor.query.lib.MemberOfHelper;
51 import org.objectweb.medor.query.lib.QueryTreePrinter;
52 import org.objectweb.util.monolog.api.BasicLevel;
53
54 import java.util.ArrayList JavaDoc;
55 import java.util.Iterator JavaDoc;
56
57 /**
58  * @author S.Chassande-Barrioz
59  */

60 public abstract class TestNavigatorNodeFactory extends TestJormPDHelper {
61
62     public TestNavigatorNodeFactory(String JavaDoc testName, String JavaDoc loggerName) {
63         super(testName, loggerName);
64     }
65
66     public NavigatorOperator getNavigatorOperator(Field f, String JavaDoc[] path)
67             throws MedorException {
68         if (path.length == 0)
69             return null;
70         NavigatorOperator nav = new NavigatorOperator(new BasicFieldOperand(f),
71                 path[0]);
72         for (int i = 1; i < path.length; i++) {
73             nav = new NavigatorOperator(nav, path[i]);
74         }
75         return nav;
76     }
77
78     /**
79      * Test the NavigatorNodeFactory.navigate method. - start with a pname of
80      * the class - d.f1 where f1 is a primitive field. ==> The result is the
81      * same QueryTree
82      */

83     public void test1a() {
84         TestJormHelper.Example e = getExtentOfD();
85         QueryTree result = null;
86         try {
87             Field f = e.extent.getField(getFieldName(e.extent.getName(),
88                     e.pnameFieldName));
89             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".f1" };
90             NavigatorOperator nav = getNavigatorOperator(f, path);
91             result = NavigatorNodeFactory.navigate(nav, null,
92                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
93             logger
94                     .log(BasicLevel.DEBUG,
95                             "test1a (d.f1): Constructed QueryTree");
96             QueryTreePrinter.printQueryTree(result, logger);
97             TestQueryTreeHelper.equals("", e.extent, result, logger);
98         } catch (MedorException me) {
99             me.printStackTrace();
100             fail(me.getMessage());
101         }
102     }
103
104     /**
105      * Test the NavigatorNodeFactory.navigate method. - start with a pname of
106      * the class - d.e where e is a reference field. ==> The result is the same
107      * QueryTree.
108      */

109     public void test1b() {
110         TestJormHelper.Example e = getExtentOfD();
111         QueryTree result = null;
112         try {
113             Field f = e.extent.getField(getFieldName(e.extent.getName(),
114                     e.pnameFieldName));
115             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".e" };
116             NavigatorOperator nav = getNavigatorOperator(f, path);
117             result = NavigatorNodeFactory.navigate(nav, null,
118                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
119             logger.log(BasicLevel.DEBUG, "test1b (d.e): Constructed QueryTree");
120             QueryTreePrinter.printQueryTree(result, logger);
121             TestQueryTreeHelper.equals("", e.extent, result, logger);
122         } catch (MedorException me) {
123             me.printStackTrace();
124             fail(me.getMessage());
125         }
126     }
127
128     /**
129      * Test the NavigatorNodeFactory.navigate method. - start with a pname of
130      * the class - d.es where es is a GenClass of E. The result is a join with
131      * the GC node.
132      */

133     public void test1c() {
134         TestJormHelper.Example e = getExtentOfD();
135         QueryTree result = null;
136         try {
137             NavigatorNodeFactory.resetNameIndexes();
138             Field f = e.extent.getField(getFieldName(e.extent.getName(),
139                     e.pnameFieldName));
140             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".setOfE" };
141             NavigatorOperator nav = getNavigatorOperator(f, path);
142             result = NavigatorNodeFactory.navigate(nav, null,
143                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
144             logger
145                     .log(BasicLevel.DEBUG,
146                             "test1c (d.es): Constructed QueryTree");
147             QueryTreePrinter.printQueryTree(result, logger);
148
149             NavigatorNodeFactory.resetNameIndexes();
150             PNameField pnf = (PNameField) e.extent.getTupleStructure()
151                     .getField(e.clazz.getFQName() + ".setOfE");
152             GenClassRef gcr = (GenClassRef) pnf.getReference();
153             GenClassExtent extent = new GenClassExtent(gcr, e.clazz.getFQName()
154                     + ".setOfE", "object1", "element");
155
156             JoinProject join = new JoinProject("");
157
158             //'pnf' references the PNameField of the GenClass
159
pnf = (PNameField) extent.getField(extent.getPNameFieldName());
160             f = e.extent.getField(e.clazz.getFQName() + ".setOfE");
161             //add the join condition: pnf should be equal to the
162
//PName of the extent
163
join.setQueryFilter(new Equal(new BasicFieldOperand(f),
164                     new BasicFieldOperand(pnf)));
165
166             //project in 'join' all fields of the inherited node
167
Field[] fToAdd = e.extent.getFields();
168             for (int i = 0; i < fToAdd.length; i++) {
169                 join.addPropagatedField(fToAdd[i].getName(), fToAdd[i]
170                         .getType(),
171                         new QueryTreeField[] { (QueryTreeField) fToAdd[i] });
172             }
173
174             //project in 'join' the element field of the GenClassExtent
175
Field elemToAdd = extent.getField(extent.getElementFieldName());
176             join.addPropagatedField(elemToAdd.getName(), elemToAdd.getType(),
177                     new QueryTreeField[] { (QueryTreeField) elemToAdd });
178
179             join.setQueryFilter(new Equal(new BasicFieldOperand(f),
180                     new BasicFieldOperand(pnf)));
181             logger.log(BasicLevel.DEBUG, "test1c (d.es): Expected QueryTree");
182             QueryTreePrinter.printQueryTree(join, logger);
183
184             TestQueryTreeHelper.equals("", join, result, logger);
185         } catch (MedorException me) {
186             me.printStackTrace();
187             fail(me.getMessage());
188         }
189     }
190
191     /**
192      * Test the NavigatorNodeFactory.navigate/IS_EMPTY method. - start with a
193      * pname of the class - d.es where es is a GenClass of E. - add isEmpty to
194      * the path traversal The result is a join with the GC node.
195      */

196     public void test1cEmpty() {
197         TestJormHelper.Example e = getExtentOfD();
198         QueryTree result1, result = null;
199         try {
200             Field f = e.extent.getField(getFieldName(e.extent.getName(),
201                     e.pnameFieldName));
202             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".setOfE" };
203             NavigatorOperator nav = getNavigatorOperator(f, path);
204             result1 = NavigatorNodeFactory.navigate(nav, null,
205                     NavigatorNodeFactory.IS_EMPTY).getQueryTree();
206             logger.log(BasicLevel.DEBUG,
207                     "test1cEmpty (d.es): Constructed QueryTree");
208             QueryTreePrinter.printQueryTree(result1, logger);
209
210             ArrayList JavaDoc rules = new ArrayList JavaDoc(2);
211             rules.add(new FlattenQueryTreeRule());
212             rules.add(new JormFlatten2Rdb());
213             QueryRewriter jqr = new BasicQueryRewriter(rules);
214
215             //assign mapper to all extents
216
Iterator JavaDoc extents = JormQueryTreeHelper.getJormExtents(result1)
217                     .iterator();
218             while (extents.hasNext()) {
219                 JormExtent ext = (JormExtent) extents.next();
220                 logger.log(BasicLevel.DEBUG, "Setting mapper for extent "
221                         + ext.getName());
222                 ext.setPMapper(mapper, PROJECT_NAME);
223                 ext.setProjectName("test");
224             }
225             result = jqr.transform(result1);
226             logger.log(BasicLevel.DEBUG,
227                     "test1cEmpty (d.es): Rewritten QueryTree");
228             QueryTreePrinter.printQueryTree(result, logger);
229             //TODO add expected query result
230

231             /*
232              * PNameField pnf = (PNameField)
233              * e.extent.getTupleStructure().getField(e.clazz.getFQName() +
234              * ".setOfE"); GenClassRef gcr = (GenClassRef) pnf.getReference();
235              * GenClassExtent extent = new GenClassExtent(gcr,
236              * e.clazz.getFQName() + ".setOfE", "object",
237              * NavigatorNodeFactory.GENCLASS_ELEMENT_NAME);
238              *
239              * JoinProject join = new JoinProject("", null);
240              *
241              * //'pnf' references the PNameField of the GenClass pnf =
242              * (PNameField) extent.getField(extent.getPNameFieldName()); f =
243              * e.extent.getField(e.clazz.getFQName() + ".setOfE"); //add the
244              * join condition: pnf should be equal to the //PName of the extent
245              * join.setQueryFilter( new Equal( new BasicFieldOperand(f), new
246              * BasicFieldOperand(pnf) ) );
247              *
248              * //project in 'join' all fields of the inherited node Field[]
249              * fToAdd = e.extent.getFields(); for (int i = 0; i < fToAdd.length;
250              * i++) { join.addPropagatedField( fToAdd[i].getName(),
251              * fToAdd[i].getType(), new QueryTreeField[]{(QueryTreeField)
252              * fToAdd[i]}); }
253              *
254              * //project in 'join' the element field of the GenClassExtent Field
255              * elemToAdd = extent.getField(extent.getElementFieldName());
256              * join.addPropagatedField(elemToAdd.getName(), elemToAdd.getType(),
257              * new QueryTreeField[]{(QueryTreeField) elemToAdd});
258              *
259              * join.setQueryFilter( new Equal( new BasicFieldOperand(f), new
260              * BasicFieldOperand(pnf) ) ); logger.log(BasicLevel.DEBUG,
261              * "Expected QueryTree"); QueryTreePrinter.printQueryTree(join,
262              * logger);
263              *
264              * TestQueryTreeHelper.equals("", join, result, logger);
265              */

266         } catch (MedorException me) {
267             me.printStackTrace();
268             fail(me.getMessage());
269         }
270     }
271
272     /**
273      * d.setOfE
274      */

275     public void test1d() {
276         TestJormHelper.Example e = getExtentOfD();
277         QueryTree result = null;
278         try {
279             NavigatorNodeFactory.resetNameIndexes();
280             Field f = e.extent.getField(getFieldName(e.extent.getName(),
281                     e.pnameFieldName));
282             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".setOfE" };
283             NavigatorOperator nav = getNavigatorOperator(f, path);
284             result = NavigatorNodeFactory.navigate(nav, "test1d",
285                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
286
287             logger.log(BasicLevel.DEBUG,
288                     "test1d (d.setOfE into last): Constructed QueryTree");
289             QueryTreePrinter.printQueryTree(result, logger);
290
291             NavigatorNodeFactory.resetNameIndexes();
292             PNameField pnf = (PNameField) e.extent.getTupleStructure()
293                     .getField(e.clazz.getFQName() + ".setOfE");
294             GenClassRef gcr = (GenClassRef) pnf.getReference();
295             GenClassExtent extent = new GenClassExtent(gcr, e.clazz.getFQName()
296                     + ".setOfE", "object1", "element");
297
298             JoinProject join = new JoinProject("");
299
300             //'pnf' references the PNameField of the GenClass
301
pnf = (PNameField) extent.getField(extent.getPNameFieldName());
302             f = e.extent.getField(e.clazz.getFQName() + ".setOfE");
303             //add the join condition: pnf should be equal to the
304
//PName of the extent
305
join.setQueryFilter(new Equal(new BasicFieldOperand(f),
306                     new BasicFieldOperand(pnf)));
307
308             //project in 'join' all fields of the inherited node
309
Field[] fToAdd = e.extent.getFields();
310             for (int i = 0; i < fToAdd.length; i++) {
311                 join.addPropagatedField(fToAdd[i].getName(), fToAdd[i]
312                         .getType(),
313                         new QueryTreeField[] { (QueryTreeField) fToAdd[i] });
314             }
315
316             //project in 'join' all fields of the GenClassExtent
317
// and find the QueryTreeField which represents the element
318
Field elemToAdd = extent.getField(extent.getElementFieldName());
319             join.addPropagatedField("test1d", elemToAdd.getType(),
320                     new QueryTreeField[] { (QueryTreeField) elemToAdd });
321
322             join.setQueryFilter(new Equal(new BasicFieldOperand(f),
323                     new BasicFieldOperand(pnf)));
324             logger.log(BasicLevel.DEBUG,
325                     "test1d (d.setOfE into last): Expected QueryTree");
326             QueryTreePrinter.printQueryTree(join, logger);
327
328             TestQueryTreeHelper.equals("", join, result, logger);
329         } catch (MedorException me) {
330             me.printStackTrace();
331             fail(me.getMessage());
332         }
333     }
334
335     /**
336      * Test the NavigatorNodeFactory.navigate method. - start with a field of
337      * the class - d.f1 where f1 is a primitive field. ==> The result is a join
338      * with the D node
339      */

340     public void test2a() {
341         TestJormHelper.Example e = getExtentOfC();
342         QueryTree result = null;
343         NavigatorNodeFactory.resetNameIndexes();
344
345         try {
346             QueryTreeField f = (QueryTreeField) e.extent.getField(e.clazz
347                     .getFQName()
348                     + ".d");
349             String JavaDoc[] path = new String JavaDoc[] { "f1" };
350             NavigatorOperator nav = getNavigatorOperator(f, path);
351             result = NavigatorNodeFactory.navigate(nav, null,
352                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
353             logger.log(BasicLevel.DEBUG,
354                     "test2a (c.d.f1): Constructed QueryTree");
355             QueryTreePrinter.printQueryTree(result, logger);
356             logger.log(BasicLevel.DEBUG, "test2a (c.d.f1): Expected QueryTree");
357             QueryTreePrinter.printQueryTree(get2abExpected(e, "f1"), logger);
358             TestQueryTreeHelper.equals("", get2abExpected(e, "f1"), result,
359                     logger);
360         } catch (MedorException me) {
361             me.printStackTrace();
362             fail(me.getMessage());
363         }
364     }
365
366     /**
367      * Test the NavigatorNodeFactory.navigate method. - start with a field of
368      * the class - d.e where e is a reference field. ==> The result is a join
369      * with the D node
370      */

371     public void test2b() {
372         TestJormHelper.Example e = getExtentOfC();
373         QueryTree result = null;
374         NavigatorNodeFactory.resetNameIndexes();
375
376         try {
377             Field f = e.extent.getField(e.clazz.getFQName() + ".d");
378             String JavaDoc[] path = new String JavaDoc[] { "e" };
379             NavigatorOperator nav = getNavigatorOperator(f, path);
380             result = NavigatorNodeFactory.navigate(nav, null,
381                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
382             logger.log(BasicLevel.DEBUG,
383                     "test2b (c.d.e): Constructed QueryTree");
384             QueryTreePrinter.printQueryTree(result, logger);
385             TestQueryTreeHelper.equals("", get2abExpected(e, "e"), result,
386                     logger);
387         } catch (MedorException me) {
388             me.printStackTrace();
389             fail(me.getMessage());
390         }
391     }
392
393     public QueryTree get2abExpected(Example e, String JavaDoc fn) throws MedorException {
394         Example ed = getExtentOfD(new String JavaDoc[] { fn });
395         ClassExtent extent = ed.extent;
396         JoinProject join = new JoinProject("");
397
398         //project in 'join' all fields of the inherited node
399
Field[] fToAdd = e.extent.getFields();
400         for (int i = 0; i < fToAdd.length; i++) {
401             join.addPropagatedField(fToAdd[i].getName(), fToAdd[i].getType(),
402                     new QueryTreeField[] { (QueryTreeField) fToAdd[i] });
403         }
404
405         fToAdd = extent.getFields();
406         for (int i = 0; i < fToAdd.length; i++) {
407             join.addPropagatedField(fToAdd[i].getName(), fToAdd[i].getType(),
408                     new QueryTreeField[] { (QueryTreeField) fToAdd[i] });
409         }
410
411         join.setQueryFilter(new Equal(new BasicFieldOperand(e.extent
412                 .getField(e.clazz.getFQName() + ".d")), new BasicFieldOperand(
413                 extent.getField(ed.clazz.getFQName() + ".object1"))));
414         return join;
415     }
416
417     /**
418      * Test the NavigatorNodeFactory.navigate method. - start with a field of
419      * the class - d.es where es is a GenClass of E. The result is a
420      * join(join(qt, node(D), node(GC)).
421      */

422     public void test2c() {
423         TestJormHelper.Example e = getExtentOfC();
424         QueryTree result = null;
425         try {
426             Field f = e.extent.getField(e.clazz.getFQName() + ".d");
427             String JavaDoc[] path = new String JavaDoc[] { "setOfE" };
428             NavigatorOperator nav = getNavigatorOperator(f, path);
429             result = NavigatorNodeFactory.navigate(nav, null,
430                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
431             logger.log(BasicLevel.DEBUG,
432                     "test2c (c.d.setOfE into last): Constructed QueryTree");
433             QueryTreePrinter.printQueryTree(result, logger);
434         } catch (MedorException me) {
435             me.printStackTrace();
436             fail(me.getMessage());
437         }
438     }
439
440     //A, b.c.d.f1
441
public void test3a() {
442         TestJormHelper.Example e = getExtentOfA();
443         QueryTree result = null;
444         try {
445             Field f = e.extent.getField(getFieldName(e.extent.getName(),
446                     e.pnameFieldName));
447             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".b", "c",
448                     "d", "f1" };
449             NavigatorOperator nav = getNavigatorOperator(f, path);
450             logger.log(BasicLevel.DEBUG, "Initial field operand is "
451                     + nav.getFieldOperand().getField().getName());
452             logger.log(BasicLevel.DEBUG, "Path is " + nav.getPath());
453             result = NavigatorNodeFactory.navigate(nav, null,
454                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
455             logger.log(BasicLevel.DEBUG,
456                     "test3a (a.b.c.d.f1): Constructed QueryTree");
457             QueryTreePrinter.printQueryTree(result, logger);
458         } catch (MedorException me) {
459             me.printStackTrace();
460             fail(me.getMessage());
461         }
462     }
463
464     //A, b.c.d.e
465
public void test3b() {
466         TestJormHelper.Example e = getExtentOfA();
467         QueryTree result = null;
468         try {
469             Field f = e.extent.getField(getFieldName(e.extent.getName(),
470                     e.pnameFieldName));
471             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".b", "c",
472                     "d", "e" };
473             NavigatorOperator nav = getNavigatorOperator(f, path);
474             result = NavigatorNodeFactory.navigate(nav, null,
475                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
476             logger.log(BasicLevel.DEBUG,
477                     "test3b (a.b.c.d.e): Constructed QueryTree");
478             QueryTreePrinter.printQueryTree(result, logger);
479         } catch (MedorException me) {
480             me.printStackTrace();
481             fail(me.getMessage());
482         }
483     }
484
485     //A, [A.b, c, d, es]
486
public void test3c() {
487         TestJormHelper.Example e = getExtentOfA();
488         QueryTree result = null;
489         try {
490             Field f = e.extent.getField(getFieldName(e.extent.getName(),
491                     e.pnameFieldName));
492             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".b", "c",
493                     "d", "setOfE" };
494             NavigatorOperator nav = getNavigatorOperator(f, path);
495             result = NavigatorNodeFactory.navigate(nav, null,
496                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
497             logger.log(BasicLevel.DEBUG,
498                     "test3c (a.b.c.d.setOfE): Constructed QueryTree");
499             QueryTreePrinter.printQueryTree(result, logger);
500
501         } catch (MedorException me) {
502             me.printStackTrace();
503             fail(me.getMessage());
504         }
505     }
506
507     //A, [A.b, c, d, es] ISEMPTY + OR
508
public void test3cEmpty() {
509         TestJormHelper.Example e = getExtentOfA();
510         QueryTree result, result1 = null;
511         try {
512             Field f = e.extent.getField(getFieldName(e.extent.getName(),
513                     e.pnameFieldName));
514             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".b", "c",
515                     "d", "setOfE" };
516             NavigatorOperator nav = getNavigatorOperator(f, path);
517             result1 = NavigatorNodeFactory.navigate(nav, null,
518                     NavigatorNodeFactory.IS_NOT_EMPTY).getQueryTree();
519
520             //constructing filter with adding "OR f1=12"
521
QueryNode r1 = (QueryNode) result1;
522             Field f1 = r1.getTupleStructure().getField(
523                     getFieldName(e.extent.getName(), "f1"));
524             Field prevF1 = ((PropagatedField) f1).getPreviousFields()[0];
525             r1.setQueryFilter(new Or(r1.getQueryFilter(),
526                     new Equal(new BasicFieldOperand(prevF1),
527                             new BasicVariableOperand(12))));
528
529             logger
530                     .log(BasicLevel.DEBUG,
531                             "test3cEmpty (a.b.c.d.setOfE is not empty): Constructed QueryTree");
532             QueryTreePrinter.printQueryTree(result1, logger);
533
534             ArrayList JavaDoc rules = new ArrayList JavaDoc(2);
535             rules.add(new FlattenQueryTreeRule());
536             rules.add(new JormFlatten2Rdb());
537             QueryRewriter jqr = new BasicQueryRewriter(rules);
538
539             //assign mapper to all extents
540
Iterator JavaDoc extents = JormQueryTreeHelper.getJormExtents(result1)
541                     .iterator();
542             while (extents.hasNext()) {
543                 JormExtent ext = (JormExtent) extents.next();
544                 logger.log(BasicLevel.DEBUG, "Setting mapper for extent "
545                         + ext.getName());
546                 ext.setPMapper(mapper, PROJECT_NAME);
547                 ext.setProjectName("test");
548             }
549             result = jqr.transform(result1);
550             logger.log(BasicLevel.DEBUG, "test3cEmpty: Rewritten QueryTree");
551             QueryTreePrinter.printQueryTree(result, logger);
552             //TODO add expected query result
553

554         } catch (MedorException me) {
555             me.printStackTrace();
556             fail(me.getMessage());
557         }
558     }
559
560     public void test3cMemberOf() {
561         TestJormHelper.Example e = getExtentOfA();
562         QueryTree input = null;
563         try {
564             Field f = e.extent.getField(getFieldName(e.extent.getName(),
565                     e.pnameFieldName));
566             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".b", "c",
567                     "d", "setOfE" };
568             NavigatorOperator nav = getNavigatorOperator(f, path);
569             input = NavigatorNodeFactory.navigate(nav, null,
570                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
571             //TODO add MemberOf
572
logger
573                     .log(BasicLevel.DEBUG,
574                             "test3cMemberOf (a.b.c.d.setOfE into last): Constructed QueryTree");
575             QueryTreePrinter.printQueryTree(input, logger);
576             ArrayList JavaDoc rules = new ArrayList JavaDoc(2);
577             rules.add(new FlattenQueryTreeRule());
578             rules.add(new JormFlatten2Rdb());
579             QueryRewriter jqr = new BasicQueryRewriter(rules);
580
581             //assign mapper to all extents
582
Iterator JavaDoc extents = JormQueryTreeHelper.getJormExtents(input)
583                     .iterator();
584             while (extents.hasNext()) {
585                 JormExtent ext = (JormExtent) extents.next();
586                 logger.log(BasicLevel.DEBUG, "Setting mapper for extent "
587                         + ext.getName());
588                 ext.setPMapper(mapper, PROJECT_NAME);
589                 ext.setProjectName("test");
590             }
591             QueryTree result = jqr.transform(input);
592             logger.log(BasicLevel.DEBUG, "test3cMemberOf: Rewritten QueryTree");
593
594             QueryTreePrinter.printQueryTree(result, logger);
595         } catch (MedorException me) {
596             me.printStackTrace();
597             fail(me.getMessage());
598         }
599     }
600
601     //A, [c.d.es]
602
public void test4a() {
603         TestJormHelper.Example e = getExtentOfA();
604         QueryTree result = null;
605         try {
606             Field f = e.extent.getField(getFieldName(e.extent.getName(), "b"));
607             String JavaDoc[] path = new String JavaDoc[] { "c", "d", "f1" };
608             NavigatorOperator nav = getNavigatorOperator(f, path);
609             result = NavigatorNodeFactory.navigate(nav, null,
610                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
611             logger.log(BasicLevel.DEBUG,
612                     "test4a (a.b.c.d.f1): Constructed QueryTree");
613             QueryTreePrinter.printQueryTree(result, logger);
614         } catch (MedorException me) {
615             me.printStackTrace();
616             fail(me.getMessage());
617         }
618     }
619
620     //A, [c.d.es]
621
public void test4b() {
622         TestJormHelper.Example e = getExtentOfA();
623         QueryTree result = null;
624         try {
625             Field f = e.extent.getField(getFieldName(e.extent.getName(), "b"));
626             String JavaDoc[] path = new String JavaDoc[] { "c", "d", "e" };
627             NavigatorOperator nav = getNavigatorOperator(f, path);
628             result = NavigatorNodeFactory.navigate(nav, null,
629                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
630             logger.log(BasicLevel.DEBUG,
631                     "test4b (a.b.c.d.e): Constructed QueryTree");
632             QueryTreePrinter.printQueryTree(result, logger);
633         } catch (MedorException me) {
634             me.printStackTrace();
635             fail(me.getMessage());
636         }
637     }
638
639     //A, [c.d.es]
640
public void test4c() {
641         TestJormHelper.Example e = getExtentOfA();
642         QueryTree result = null;
643         try {
644             Field f = e.extent.getField(getFieldName(e.extent.getName(), "b"));
645             String JavaDoc[] path = new String JavaDoc[] { "c", "d", "setOfE" };
646             NavigatorOperator nav = getNavigatorOperator(f, path);
647             result = NavigatorNodeFactory.navigate(nav, null,
648                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
649             logger.log(BasicLevel.DEBUG,
650                     "test4b (a.b.c.d.setOfE into last): Constructed QueryTree");
651             QueryTreePrinter.printQueryTree(result, logger);
652         } catch (MedorException me) {
653             me.printStackTrace();
654             fail(me.getMessage());
655         }
656     }
657
658     //c.d.e and c.d.es
659
public void testMemberOf2stepsCDE() throws Exception JavaDoc {
660         NavigatorNodeFactory.resetNameIndexes();
661         TestJormHelper.Example e = getExtentOfC();
662         QueryTree result1, result2 = null;
663         try {
664             Field f = e.extent.getField(getFieldName(e.extent.getName(),
665                     e.pnameFieldName));
666             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".d", "e" };
667             NavigatorOperator nav = getNavigatorOperator(f, path);
668             result1 = NavigatorNodeFactory.navigate(nav, null,
669                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
670             logger.log(BasicLevel.DEBUG,
671                     "testMemberOf2stepsCDE (c.d.e): Constructed QueryTree");
672             QueryTreePrinter.printQueryTree(result1, logger);
673
674             Field fc = result1.getTupleStructure().getField(
675                     "org.objectweb.medor.query.jorm.C.object1");
676             path = new String JavaDoc[] { "d", "setOfE" };
677             NavigatorOperator nav2 = getNavigatorOperator(fc, path);
678             result2 = NavigatorNodeFactory.navigate(nav2, null,
679                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
680             logger.log(BasicLevel.DEBUG,
681                     "testMemberOf2stepsCDE (c.d.es): Constructed QueryTree");
682             QueryTreePrinter.printQueryTree(result2, logger);
683
684             JoinProject jpOnTop = new JoinProject("onTop");
685             ArrayList JavaDoc al1 = new ArrayList JavaDoc(1);
686             al1.add(new BasicFieldOperand(result2.getTupleStructure().getField(
687                     "e")));
688             ArrayList JavaDoc al2 = new ArrayList JavaDoc(1);
689             al2.add(new BasicFieldOperand(result2.getTupleStructure().getField(
690                     "org.objectweb.medor.query.jorm.D.setOfE.element")));
691
692             MemberOfHelper.addMemberOf(jpOnTop, al1, al2);
693             jpOnTop
694                     .addPropagatedField(
695                             "org.objectweb.medor.query.jorm.D.object2",
696                             result2.getTupleStructure().getField(
697                                     "org.objectweb.medor.query.jorm.D.object2")
698                                     .getType(),
699                             new QueryTreeField[] { (QueryTreeField) result2
700                                     .getTupleStructure()
701                                     .getField(
702                                             "org.objectweb.medor.query.jorm.D.object2") });
703             logger.log(BasicLevel.DEBUG,
704                     "testMemberOf2stepsCDE (c.d.es): with MOF on top");
705             QueryTreePrinter.printQueryTree(jpOnTop, logger);
706
707         } catch (MedorException me) {
708             me.printStackTrace();
709             fail(me.getMessage());
710         }
711     }
712
713     //d.e and d.es
714
public void testMemberOf2stepsDE() throws Exception JavaDoc {
715         NavigatorNodeFactory.resetNameIndexes();
716         TestJormHelper.Example e = getExtentOfD();
717         QueryTree result1, result2 = null;
718         try {
719             Field f = e.extent.getField(getFieldName(e.extent.getName(),
720                     e.pnameFieldName));
721             String JavaDoc[] path = new String JavaDoc[] { e.clazz.getFQName() + ".e" };
722             NavigatorOperator nav = getNavigatorOperator(f, path);
723             result1 = NavigatorNodeFactory.navigate(nav, null,
724                     NavigatorNodeFactory.NAVIGATION).getQueryTree();
725             logger.log(BasicLevel.DEBUG,
726                     "testMemberOf2stepsDE (d.e): Constructed QueryTree");
727             QueryTreePrinter.printQueryTree(result1, logger);
728
729             Field fc = result1.getTupleStructure().getField(
730                     "org.objectweb.medor.query.jorm.D.object");
731             path = new String JavaDoc[] { "setOfE" };
732             NavigatorOperator nav2 = getNavigatorOperator(fc, path);
733             result2 = NavigatorNodeFactory.navigate(nav2, null,
734                     NavigatorNodeFactory.NAVIGATION_INTO_LAST).getQueryTree();
735             logger.log(BasicLevel.DEBUG,
736                     "testMemberOf2stepsDE (d.es): Constructed QueryTree");
737             QueryTreePrinter.printQueryTree(result2, logger);
738
739             JoinProject jpOnTop = new JoinProject("onTop");
740             ArrayList JavaDoc al1 = new ArrayList JavaDoc(1);
741             al1.add(new BasicFieldOperand(result2.getTupleStructure().getField(
742                     e.clazz.getFQName() + ".e")));
743             ArrayList JavaDoc al2 = new ArrayList JavaDoc(1);
744             al2.add(new BasicFieldOperand(result2.getTupleStructure().getField(
745                     e.clazz.getFQName() + ".setOfE.element")));
746
747             MemberOfHelper.addMemberOf(jpOnTop, al1, al2);
748             jpOnTop.addPropagatedField(e.clazz.getFQName() + ".object", result2
749                     .getTupleStructure().getField(
750                             e.clazz.getFQName() + ".object").getType(),
751                     new QueryTreeField[] { (QueryTreeField) result2
752                             .getTupleStructure().getField(
753                                     e.clazz.getFQName() + ".object") });
754             logger.log(BasicLevel.DEBUG,
755                     "testMemberOf2stepsDE (d.es): with MOF on top");
756             QueryTreePrinter.printQueryTree(jpOnTop, logger);
757
758         } catch (MedorException me) {
759             me.printStackTrace();
760             fail(me.getMessage());
761         }
762     }
763
764 }
Popular Tags