KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.medor.api.MedorException;
27 import org.objectweb.medor.filter.jorm.lib.SinglePName;
28 import org.objectweb.medor.filter.lib.BasicFieldOperand;
29 import org.objectweb.medor.expression.lib.BasicParameterOperand;
30 import org.objectweb.medor.query.TestQueryTreeHelper;
31 import org.objectweb.medor.query.api.QueryLeaf;
32 import org.objectweb.medor.query.api.QueryTreeField;
33 import org.objectweb.medor.query.lib.QueryTreePrinter;
34 import org.objectweb.medor.query.lib.SelectProject;
35 import org.objectweb.medor.type.lib.PTypeSpaceMedor;
36 import org.objectweb.util.monolog.api.BasicLevel;
37
38 import java.util.Collection JavaDoc;
39
40 /**
41  * @author S.Chassande-Barrioz
42  */

43 public abstract class TestJormLeafRewriter extends TestJormPDHelper {
44
45     public TestJormLeafRewriter(String JavaDoc testName, String JavaDoc loggerName) {
46         super(testName, loggerName);
47     }
48
49     protected abstract QueryLeaf getQueryLeaf_A() throws MedorException;
50
51     protected abstract QueryLeaf getQueryLeaf_One() throws MedorException;
52
53     public Example getExtent(Collection JavaDoc fileNames,
54                              String JavaDoc className,
55                              String JavaDoc pnameFieldName,
56                              String JavaDoc[] fieldNames) {
57         Example e = super.getExtent(fileNames, className, pnameFieldName, fieldNames);
58         e.extent.setPMapper(mapper, PROJECT_NAME);
59         return e;
60     }
61
62     public void testA() {
63         checkRewrittenA(getRewrittenA());
64     }
65
66     public void testOne() {
67         checkRewrittenOne(getRewrittenOne());
68     }
69
70     public void testB() {
71         checkRewrittenB(getRewrittenB());
72     }
73
74     public void testC() {
75         checkRewrittenC(getRewrittenC());
76     }
77
78     public void testD() {
79         checkRewrittenD(getRewrittenD());
80     }
81
82     public void checkRewrittenA(Example e) {
83         try {
84             String JavaDoc prefix = e.clazz.getFQName() + ".";
85             QueryLeaf ql = getQueryLeaf_A();
86             QueryTreeField id = (QueryTreeField)
87                 ql.getTupleStructure().getField(prefix + "id");
88             QueryTreeField f1 = (QueryTreeField)
89                 ql.getTupleStructure().getField(prefix + "field1");
90             QueryTreeField f2 = (QueryTreeField)
91                 ql.getTupleStructure().getField(prefix + "field2");
92
93             SelectProject expected = new SelectProject("");
94             SinglePName spn = new SinglePName(
95                 new BasicFieldOperand(id),
96                 new BasicParameterOperand(
97                     PTypeSpaceMedor.NAMING_CONTEXT, prefix + "object"),
98                 e.extent.getField(prefix + "object").getType());
99             expected.addCalculatedField(prefix + "object", spn.getType(), spn);
100             expected.addPropagatedField(
101                 prefix + "field1", f1.getType(), new QueryTreeField[]{f1});
102             expected.addPropagatedField(
103                 prefix + "field2", f2.getType(), new QueryTreeField[]{f2});
104
105             logger.log(BasicLevel.DEBUG, "Expected QueryTree");
106             QueryTreePrinter.printQueryTree(expected, logger);
107
108             TestQueryTreeHelper.equals("", expected, e.qt, logger);
109         }
110         catch (MedorException me) {
111             me.printStackTrace();
112             fail(me.getMessage());
113         }
114     }
115
116     public void checkRewrittenOne(Example e) {
117         try {
118             QueryLeaf ql = getQueryLeaf_One();
119             String JavaDoc prefix = e.clazz.getFQName() + ".";
120             QueryTreeField id = (QueryTreeField)
121                 ql.getTupleStructure().getField(prefix + "id");
122             QueryTreeField f1 = (QueryTreeField)
123                 ql.getTupleStructure().getField(prefix + "field1");
124             QueryTreeField ida = (QueryTreeField)
125                 ql.getTupleStructure().getField(prefix + "idA");
126
127             SelectProject expected = new SelectProject("");
128             SinglePName spn = new SinglePName(
129                 new BasicFieldOperand(id),
130                 new BasicParameterOperand(
131                     PTypeSpaceMedor.NAMING_CONTEXT, prefix + "." + "object"),
132                 e.extent.getField(prefix + "object").getType());
133             expected.addCalculatedField(prefix + "object", spn.getType(), spn);
134             expected.addPropagatedField(
135                 prefix + "field1", f1.getType(), new QueryTreeField[]{f1});
136             String JavaDoc poName = prefix + "fieldA";
137             spn = new SinglePName(
138                 new BasicFieldOperand(id),
139                 new BasicParameterOperand(
140                     PTypeSpaceMedor.NAMING_CONTEXT, poName),
141                 e.extent.getField(prefix + "fieldA").getType());
142             expected.addCalculatedField(prefix + "fieldA", spn.getType(), spn);
143
144             logger.log(BasicLevel.DEBUG, "Expected QueryTree");
145             QueryTreePrinter.printQueryTree(expected, logger);
146
147             TestQueryTreeHelper.equals("", expected, e.qt, logger);
148         }
149         catch (MedorException me) {
150             me.printStackTrace();
151             fail(me.getMessage());
152         }
153     }
154
155     public void checkRewrittenB(Example e) {
156 //TODO
157
}
158
159     public void checkRewrittenC(Example e) {
160 //TODO
161
}
162
163     public void checkRewrittenD(Example e) {
164 //TODO
165
}
166 }
167
Popular Tags