KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > optim > TestPushNotInExpressionRule


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2002 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.optim;
24
25 import junit.framework.Test;
26 import junit.framework.TestSuite;
27 import junit.textui.TestRunner;
28 import org.objectweb.jorm.type.api.PTypeSpace;
29 import org.objectweb.medor.api.MedorException;
30 import org.objectweb.medor.filter.TestExpressionHelper;
31 import org.objectweb.medor.expression.lib.And;
32 import org.objectweb.medor.filter.lib.BasicFieldOperand;
33 import org.objectweb.medor.expression.lib.DivideBy;
34 import org.objectweb.medor.filter.lib.ExpressionPrinter;
35 import org.objectweb.medor.expression.lib.Greater;
36 import org.objectweb.medor.expression.lib.Not;
37 import org.objectweb.medor.expression.lib.Or;
38 import org.objectweb.medor.expression.lib.UMinus;
39 import org.objectweb.medor.expression.lib.BasicOperand;
40 import org.objectweb.medor.expression.api.Expression;
41 import org.objectweb.medor.lib.BasicField;
42 import org.objectweb.medor.lib.Log;
43 import org.objectweb.medor.lib.TestMedorHelper;
44 import org.objectweb.medor.optim.lib.PushNotInExpressionRule;
45 import org.objectweb.util.monolog.api.BasicLevel;
46
47 /*
48  * @author S.Chassande-Barrioz
49  */

50
51 public class TestPushNotInExpressionRule extends TestMedorHelper {
52
53     /**
54      * main method to launch the tests manually
55      */

56     public static void main(String JavaDoc[] args) {
57         TestRunner.run(suite());
58     }
59
60     /**
61      * This method creates a TestSuite object with the current tests
62      */

63     public static Test suite() {
64         return new TestSuite(TestPushNotInExpressionRule.class);
65     }
66
67     public TestPushNotInExpressionRule() {
68         super("TestPushNotInExpressionRule", Log.MEDOR_PREFIX + ".optim.pushnotinexpression");
69     }
70
71     public TestPushNotInExpressionRule(String JavaDoc testName) {
72         super(testName, Log.MEDOR_PREFIX + ".optim.groupsamedb");
73     }
74
75
76     protected void setUp() {
77     }
78
79     protected void tearDown() {
80     }
81
82     public void testPushNotInExpression() {
83         Expression e1, e2, e3;
84         e1 = new BasicOperand(true);
85         e2 = new BasicFieldOperand(new BasicField("b", PTypeSpace.BOOLEAN));
86         e1 = new Or(e1, e2);
87         e1 = new Not(e1);
88         e2 = new BasicFieldOperand(new BasicField("a", PTypeSpace.LONG));
89         e2 = new UMinus(e2);
90         e3 = new BasicOperand((long) 3);
91         e2 = new DivideBy(e2, e3);
92         e3 = new BasicOperand((long) 12);
93         e2 = new Greater(e2, e3);
94         e1 = new And(e2, e1);
95
96         PushNotInExpressionRule pnier = new PushNotInExpressionRule();
97         PushNotInExpressionRule.ModifiedExpression me = null;
98         logger.log(BasicLevel.DEBUG, "Before: exp=" + ExpressionPrinter.e2str(e1));
99         try {
100             me = pnier.pushNotInExpression(e1, false);
101         }
102         catch (MedorException e) {
103             e.printStackTrace();
104             fail("Impossible to pushNotInExpression" + e.getMessage());
105         }
106         logger.log(BasicLevel.DEBUG, "After: exp=" + ExpressionPrinter.e2str(me.e));
107         assertTrue("The expression has not been modified", me.isModified);
108
109         e2 = new BasicFieldOperand(new BasicField("a", PTypeSpace.LONG));
110         e2 = new UMinus(e2);
111         e3 = new BasicOperand((long) 3);
112         e2 = new DivideBy(e2, e3);
113         e3 = new BasicOperand((long) 12);
114         e1 = new Greater(e2, e3);
115
116         e2 = new BasicOperand(true);
117         e3 = new BasicFieldOperand(new BasicField("b", PTypeSpace.BOOLEAN));
118         e2 = new And(new Not(e2), new Not(e3));
119         e1 = new And(e1, e2);
120
121         try {
122             TestExpressionHelper.equals("", me.e, e1, logger);
123         }
124         catch (MedorException e) {
125             fail(e.getMessage());
126         }
127     }
128 }
129
Popular Tags