incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jnee...@apache.org
Subject svn commit: r608716 [5/5] - in /incubator/imperius/trunk/modules/imperius-splcore/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/imperius/ java/org/apache/imperius/spl/ java/org/apache/imperius/spl/tests/
Date Fri, 04 Jan 2008 02:47:50 GMT
Added: incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/StringExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/StringExpressionTest.java?rev=608716&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/StringExpressionTest.java
(added)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/StringExpressionTest.java
Thu Jan  3 18:47:48 2008
@@ -0,0 +1,1113 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Prashant Baliga <prabalig@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.spl.tests;
+
+import java.util.Vector;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expressions.impl.BooleanConstant;
+import org.apache.imperius.spl.parser.expressions.impl.Concatenate;
+import org.apache.imperius.spl.parser.expressions.impl.Contains;
+import org.apache.imperius.spl.parser.expressions.impl.EndsWith;
+import org.apache.imperius.spl.parser.expressions.impl.IntegerConstant;
+import org.apache.imperius.spl.parser.expressions.impl.LeftSubstring;
+import org.apache.imperius.spl.parser.expressions.impl.MiddleSubstring;
+import org.apache.imperius.spl.parser.expressions.impl.ReplaceSubstring;
+import org.apache.imperius.spl.parser.expressions.impl.RightSubstring;
+import org.apache.imperius.spl.parser.expressions.impl.StartsWith;
+import org.apache.imperius.spl.parser.expressions.impl.StringConstant;
+import org.apache.imperius.spl.parser.expressions.impl.StringLength;
+import org.apache.imperius.spl.parser.expressions.impl.ToLower;
+import org.apache.imperius.spl.parser.expressions.impl.ToString;
+import org.apache.imperius.spl.parser.expressions.impl.ToUpper;
+import org.apache.imperius.spl.parser.expressions.impl.Word;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+
+
+
+public class StringExpressionTest extends TestCase {
+
+	static final String CMVC_ID_StringExpressionTest = "$Header: /cvsroot/cimsplpegasus/trunk/modules/imperius-splcore/src/com/ibm/ac/spl/tests/StringExpressionTest.java,v
1.2 2007/12/20 13:07:37 prabalig Exp $";
+	static final String VERSION_StringExpressionTest = "File version $Revision: 1.2 $, last
changed $Date: 2007/12/20 13:07:37 $";
+//	private static Logger logger = SPLLogger.getCIMSPLLogger().getLogger();
+	
+	
+	static Expression propertySensor1 =null;
+	//new ConstantExpression("propertySensor1");
+	static Expression propertySensor2 =null;
+	//new PropertySensor("propertySensor2");
+	static  Expression propertySensor3 =null;
+	//new PropertySensor("propertySensor3");
+	static  Expression propertySensor4 =null;
+	//new PropertySensor("propertySensor4");
+	static  Expression propertySensor5 =null;
+	//new PropertySensor("propertySensor5");
+	static  Expression propertySensor6 =null;
+	//new PropertySensor("propertySensor6");
+	static  Expression propertySensor7 =null;
+	//new PropertySensor("propertySensor7");
+	static  Expression propertySensor8 =null;
+	//new PropertySensor("propertySensor8");
+	static  Expression propertySensor9 =null;
+	//new PropertySensor("propertySensor9");
+	static  Expression propertySensor10 =null;
+	//new PropertySensor("propertySensor10");
+
+	public StringExpressionTest(String arg0) {
+		super(arg0);
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(StringExpressionTest.class);
+		TestSetup wrapper = new TestSetup(suite) {
+
+			protected void setUp() throws Exception {
+				oneTimeSetUp();
+			}
+
+			protected void tearDown() throws Exception {
+				oneTimeTearDown();
+			}
+		};
+		return wrapper;
+	}
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(suite());
+	}
+
+	protected static void oneTimeSetUp() throws Exception {
+	}
+
+	protected static void oneTimeTearDown() throws Exception {
+
+	}
+
+	/*
+	 * This will test MiddleSubstring Expression
+	 */
+	public void testMiddleSubstring() {
+		String string = "\"AutonomicComputing\"";
+		StringConstant lr = new StringConstant("\"LeftToRight\"");
+		StringConstant rl = new StringConstant("\"RightToLeft\"");
+		IntegerConstant ic4 = new IntegerConstant(4);
+		IntegerConstant ic5 = new IntegerConstant(5);
+		//HashMap map = new HashMap();
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			Expression exp;
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(ic5);
+			v.add(lr);
+			Expression esnnl = new MiddleSubstring(v,true);
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(ic5);
+			v.add(rl);
+			Expression esnnr = new MiddleSubstring(v,true);
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(ic5);
+			v.add(lr);
+			Expression essnl = new MiddleSubstring(v,true);
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(ic5);
+			v.add(rl);
+			Expression essnr = new MiddleSubstring(v,true);
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			Expression esnsl = new MiddleSubstring(v,true);
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			Expression esnsr = new MiddleSubstring(v,true);
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"on\""));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			Expression esssl = new MiddleSubstring(v,true);
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"on\""));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			Expression esssr = new MiddleSubstring(v,true);
+
+			assertTrue(((String) esnnl.evaluate()).equals("nomic"));
+			assertTrue(((String) esnnr.evaluate()).equals("ing"));
+			assertTrue(((String) essnl.evaluate()).equals("icCom"));
+			assertTrue(((String) essnr.evaluate()).equals("putin"));
+			assertTrue(((String) esnsl.evaluate()).equals("n"));
+			assertTrue(((String) esnsr.evaluate()).equals("pu"));
+			assertTrue(((String) esssl.evaluate()).equals(""));
+			assertTrue(((String) esssr.evaluate()).equals("Aut"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(4));
+			v.add(new IntegerConstant(5));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("nomic"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(4));
+			v.add(new IntegerConstant(5));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("ing"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(4));
+			v.add(new IntegerConstant(-1));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("o"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(8));
+			v.add(new IntegerConstant(-1));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("o"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new IntegerConstant(5));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("g"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new IntegerConstant(5));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("tonom"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new IntegerConstant(-1));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("n"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new IntegerConstant(-1));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("u"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(19));
+			v.add(new IntegerConstant(5));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(19));
+			v.add(new IntegerConstant(5));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("Auton"));
+			//////////////////////////////////////////////////////
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new IntegerConstant(5));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("icCom"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new IntegerConstant(5));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("putin"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new IntegerConstant(18));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("icComputing"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new IntegerConstant(18));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("puting"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new IntegerConstant(-1));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("n"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new IntegerConstant(-1));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("C"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new IntegerConstant(5));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new IntegerConstant(5));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new IntegerConstant(-1));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new IntegerConstant(-1));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new IntegerConstant(20));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new IntegerConstant(20));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+			///////////////////////////////////////////////
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(4));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("n"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(4));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("pu"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(7));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("icC"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(7));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("g"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new StringConstant("\"bz\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("g"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(-1));
+			v.add(new StringConstant("\"bz\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(4));
+			v.add(new StringConstant("\"bz\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(
+					((String) exp.evaluate()).equals("nomicComputing"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(4));
+			v.add(new StringConstant("\"bz\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(20));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(20));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(20));
+			v.add(new StringConstant("\"bz\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new IntegerConstant(20));
+			v.add(new StringConstant("\"bz\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+			/////////////////////////////////////
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("icC"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("icC"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new StringConstant("\"bz\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("icComputing"));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new StringConstant("\"bz\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals("AutonomicC"));
+
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new StringConstant("\"bz\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"bz\""));
+			v.add(new StringConstant("\"bz\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new StringConstant("\"icC\""));
+			v.add(lr);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(new StringConstant("\"icC\""));
+			v.add(rl);
+			exp = new MiddleSubstring(v,true);
+			assertTrue(((String) exp.evaluate()).equals(""));
+
+
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test RightSubstring Expression
+	 */
+	public void testRightSubstring() {
+		String string = "\"AutonomicComputing\"";
+		StringConstant lr = new StringConstant("\"LeftToRight\"");
+		StringConstant rl = new StringConstant("\"RightToLeft\"");
+		IntegerConstant icmin1 = new IntegerConstant(-1);
+
+		IntegerConstant ic4 = new IntegerConstant(4);
+//		IntegerConstant ic5 = new IntegerConstant(5);
+		//HashMap map = new HashMap();
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(lr);
+			Expression esnl = new RightSubstring(v,true);
+			// Examples: RightSubstring("AutonomicComputing", 4, LeftToRight) = "ting".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(icmin1);
+			v.add(lr);
+			Expression esnlmin1 = new RightSubstring(v,true);
+			// Examples: RightSubstring("AutonomicComputing", -1, LeftToRight) = "AutonomicComputing".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(rl);
+			Expression esnr = new RightSubstring(v,true);
+			// RightSubstring("AutonomicComputing", 4, RightToLeft) = "nomicComputing".<p>
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(icmin1);
+			v.add(rl);
+			Expression esnrmin1 = new RightSubstring(v,true);
+			// Examples: RightSubstring("AutonomicComputing", -1, RightToLeft) = "".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			Expression essl = new RightSubstring(v,true);
+			// Examples: RightSubstring("AutonomicComputing", "om", LeftToRight)="icComputing" 
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"jj\""));
+			v.add(lr);
+			Expression esslne = new RightSubstring(v,true);
+			// Examples: RightSubstring("AutonomicComputing", "jj", LeftToRight)="" 
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			Expression essr = new RightSubstring(v,true);
+			// RightSubstring("AutonomicComputing", "om", RightToLeft)="puting".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"jj\""));
+			v.add(rl);
+			Expression essrne = new RightSubstring(v,true);
+			// RightSubstring("AutonomicComputing", "jj", RightToLeft)="".
+
+			assertTrue(((String) esnl.evaluate()).equals("ting"));
+			assertTrue(
+					((String) esnlmin1.evaluate()).equals(
+					"AutonomicComputing"));
+			assertTrue(
+					((String) esnr.evaluate()).equals("nomicComputing"));
+			assertTrue(((String) esnrmin1.evaluate()).equals(""));
+			assertTrue(((String) essl.evaluate()).equals("icComputing"));
+			assertTrue(((String) esslne.evaluate()).equals(""));
+			assertTrue(((String) essr.evaluate()).equals("puting"));
+			assertTrue(((String) essrne.evaluate()).equals(""));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test LeftSubstring Expression
+	 */
+	public void testLeftSubstring() {
+		String string = "\"AutonomicComputing\"";
+		StringConstant lr = new StringConstant("\"LeftToRight\"");
+		StringConstant rl = new StringConstant("\"RightToLeft\"");
+		IntegerConstant ic4 = new IntegerConstant(4);
+//		IntegerConstant ic5 = new IntegerConstant(5);
+		//HashMap map = new HashMap();
+		//SensorLookup lookup = new SensorLookupImpl(map);
+		IntegerConstant icmin1 = new IntegerConstant(-1);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(lr);
+			Expression esnl = new LeftSubstring(v,true);
+			// Examples: LeftSubstring("AutonomicComputing", 4, LeftToRight) = "Auto".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(icmin1);
+			v.add(lr);
+			Expression esnlmin1 = new LeftSubstring(v,true);
+			// Examples: LeftSubstring("AutonomicComputing", -1, LeftToRight) = "AutonomicComputing".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(ic4);
+			v.add(rl);
+			Expression esnr = new LeftSubstring(v,true);
+			// LeftSubstring("AutonomicComputing", 4, RightToLeft) = "AutonomicCompu".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(icmin1);
+			v.add(rl);
+			Expression esnrmin1 = new LeftSubstring(v,true);
+			// Examples: LeftSubstring("AutonomicComputing", -1, RightToLeft) = "".
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(lr);
+			Expression essl = new LeftSubstring(v,true);
+			// Examples: LeftSubstring("AutonomicComputing", "om", LeftToRight)="Auton" 
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"\""));
+			v.add(lr);
+			Expression esslempty = new LeftSubstring(v,true);
+			// Examples: LeftSubstring("AutonomicComputing", "", LeftToRight)="" 
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"om\""));
+			v.add(rl);
+			Expression essr = new LeftSubstring(v,true);
+			// LeftSubstring("AutonomicComputing", "om", RightToLeft)="AutonomicC"
+
+			v.clear();
+			v.add(new StringConstant(string));
+			v.add(new StringConstant("\"\""));
+			v.add(lr);
+			Expression essrempty = new LeftSubstring(v,true);
+			// Examples: LeftSubstring("AutonomicComputing", "", RightToLeft)="" 
+
+			assertTrue(((String) esnl.evaluate()).equals("Auto"));
+			assertTrue(
+					((String) esnlmin1.evaluate()).equals(
+					"AutonomicComputing"));
+			assertTrue(
+					((String) esnr.evaluate()).equals("AutonomicCompu"));
+			assertTrue(((String) esnrmin1.evaluate()).equals(""));
+			assertTrue(((String) essl.evaluate()).equals("Auton"));
+			assertTrue(((String) esslempty.evaluate()).equals(""));
+			assertTrue(((String) essr.evaluate()).equals("AutonomicC"));
+			assertTrue(((String) essrempty.evaluate()).equals(""));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test StringLength Expression
+	 */
+	public void testStringLength() {
+		String s1 = "\"AutonomicComputing\"";
+		String s2 = "\"StringLength\"";
+		String s3 = "\"PMAC1.2\"";
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		propertySensor3=new StringConstant(s3);
+
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			Expression e1 = new StringLength(v,true);
+
+			v.clear();
+			v.add(new StringConstant(s2));
+			Expression e2 = new StringLength(v,true);
+
+			v.clear();
+			v.add(new StringConstant(s3));
+			Expression e3 = new StringLength(v,true);
+
+			v.clear();
+			v.add(propertySensor1);
+			Expression eps1 = new StringLength(v,true);
+
+			v.clear();
+			v.add(propertySensor2);
+			Expression eps2 = new StringLength(v,true);
+
+			v.clear();
+			v.add(propertySensor3);
+			Expression eps3 = new StringLength(v,true);
+			s1 = s1.substring(1, s1.length()-1);
+			s2 = s2.substring(1, s2.length()-1);
+			s3 = s3.substring(1, s3.length()-1);
+
+			assertTrue(
+					new Integer(s1.length()).compareTo(e1.evaluate()) == 0);
+			assertTrue(
+					new Integer(s2.length()).compareTo(e2.evaluate()) == 0);
+			assertTrue(
+					new Integer(s3.length()).compareTo(e3.evaluate()) == 0);
+			assertTrue(
+					new Integer(s1.length()).compareTo(eps1.evaluate()) == 0);
+			assertTrue(
+					new Integer(s2.length()).compareTo(eps2.evaluate()) == 0);
+			assertTrue(
+					new Integer(s3.length()).compareTo(eps3.evaluate()) == 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test ReplaceSubstring Expression
+	 */
+	public void testReplaceSubstring() {
+		String s1 = "\"ThisIsADogThisIsAPenThisIsATelevisionSetThisIsAHouse.\"";
+		String s2 = "\"This\"";
+		String s3 = "\"That\"";
+		String s4 = "\"ThatIsADogThatIsAPenThatIsATelevisionSetThatIsAHouse.\"";
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		propertySensor3=new StringConstant(s3);
+
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			v.add(new StringConstant(s3));
+			Expression e1 = new ReplaceSubstring(v,true);
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(propertySensor2);
+			v.add(propertySensor3);
+			Expression eps1 = new ReplaceSubstring(v,true);
+			s4 = s4.substring(1, s4.length()-1);
+			assertTrue(s4.compareTo(e1.evaluate()) == 0);
+			assertTrue(s4.compareTo(eps1.evaluate()) == 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test StartsWith Expression
+	 */
+	public void testStartsWith() {
+		String s1 = "\"ThisIsADogThisIsAPenThisIsATelevisionSetThisIsAHouse.\"";
+		String s2 = "\"This\"";
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			Expression e1 = new StartsWith(v,true);
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(propertySensor2);
+			Expression eps1 = new StartsWith(v,true);
+
+			assertTrue(((Boolean) (e1.evaluate())).booleanValue());
+			assertTrue(((Boolean) (eps1.evaluate())).booleanValue());
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test Ends Expression
+	 */
+	public void testEndsWith() {
+		String s1 = "\"ThisIsADogThisIsAPenThisIsATelevisionSetThisIsAHouse.\"";
+		String s2 = "\"ThisIsAHouse.\"";
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			Expression e1 = new EndsWith(v,true);
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(propertySensor2);
+			Expression eps1 = new EndsWith(v,true);
+
+			assertTrue(((Boolean) (e1.evaluate())).booleanValue());
+			assertTrue(((Boolean) (eps1.evaluate())).booleanValue());
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test Concatenate Expression
+	 */
+	public void testConcatenate() {
+		String s1 = "\"ThisIsADog\"";
+		String s2 = "\"ThisIsAPen\"";
+		//String s3 = "ThisIsATelevisionSet";
+		//String s4 = "ThisIsAHouse.";
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			
+			Expression e1 = new Concatenate(v,true);
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(propertySensor2);
+			
+			Expression eps1 = new Concatenate(v,true);
+			s1 = s1.substring(1, s1.length()-1);
+			s2 = s2.substring(1, s2.length()-1);
+			assertTrue(e1.evaluate().equals(s1 + s2));
+			assertTrue(eps1.evaluate().equals(s1 + s2));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test Word Expression
+	 */
+	public void testWord() {
+		String s1 = "\"ThisIsADogThisIsAPenThisIsATelevisionSetThisIsAHouse\"";
+		String s2 = "\"This\"";
+		int n = 3;
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		propertySensor3=new IntegerConstant(1);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			v.add(new IntegerConstant(n));
+			Expression e1 = new Word(v,true);
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(propertySensor2);
+			v.add(propertySensor3);
+			Expression eps1 = new Word(v,true);
+
+			assertTrue(
+					(e1.evaluate()).equals(
+					"ThisIsADogThisIsAPenThisIsATelevisionSet"));
+			assertTrue((eps1.evaluate()).equals("ThisIsADog"));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test Contains Expression
+	 */
+	public void testContains() {
+		String s1 = "\"ThisIsADogThisIsAPenThisIsATelevisionSetThisIsAHouse\"";
+		String s2 = "\"ThisIsAPen\"";
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			Expression e1 = new Contains(v,true);
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(propertySensor2);
+			Expression eps1 = new Contains(v,true);
+
+			assertTrue(((Boolean) (e1.evaluate())).booleanValue());
+			assertTrue(((Boolean) (eps1.evaluate())).booleanValue());
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	   public void testToLower() {
+	    	String s1 = "\"HELLO\"";
+	        String s2 = "\"HellO\"";
+	        String s3 = "hello";
+
+	        //HashMap map = new HashMap();
+	        propertySensor1=new StringConstant(s1.toString());
+	        propertySensor2=new StringConstant(s2.toString());
+	        
+	        try {
+	            Vector v = new Vector();
+	            v.add(propertySensor1);
+	            Expression es1 = new ToLower(v,true);
+
+	            v.clear();
+	            v.add(propertySensor2);
+	            Expression es2 = new ToLower(v,true);
+
+	            
+	            
+	            String x=(String)es1.evaluate();
+	            assertTrue(x.equals(s3));
+	            x=(String)es2.evaluate();
+	            assertTrue(x.equals(s3));
+	                    
+	            
+	        } catch (SPLException e) {
+	            fail("Received evaluation exception " + e.getMessage());
+	        } catch (Exception e) {
+	            fail("Received expression exception " + e.getMessage());
+	        }
+	    }
+	   
+	   public void testToUpper() {
+	    	String s1 = "\"hello\"";
+	        String s2 = "\"HellO\"";
+	        String s3 = "HELLO";
+
+	        //HashMap map = new HashMap();
+	        propertySensor1=new StringConstant(s1.toString());
+	        propertySensor2=new StringConstant(s2.toString());
+	        
+	        try {
+	            Vector v = new Vector();
+	            v.add(propertySensor1);
+	            Expression es1 = new ToUpper(v,true);
+
+	            v.clear();
+	            v.add(propertySensor2);
+	            Expression es2 = new ToUpper(v,true);
+
+	            
+	            
+	            String x=(String)es1.evaluate();
+	            assertTrue(x.equals(s3));
+	            x=(String)es2.evaluate();
+	            assertTrue(x.equals(s3));
+	                    
+	            
+	        } catch (SPLException e) {
+	            fail("Received evaluation exception " + e.getMessage());
+	        } catch (Exception e) {
+	            fail("Received expression exception " + e.getMessage());
+	        }
+	    }
+	   
+	   public void testToString() {
+	    	propertySensor1=new IntegerConstant(845);
+	        propertySensor2=new BooleanConstant(true);
+	        
+	        try {
+	            Vector v = new Vector();
+	            v.add(propertySensor1);
+	            Expression es1 = new ToString(v,true);
+
+	            v.clear();
+	            v.add(propertySensor2);
+	            Expression es2 = new ToString(v,true);
+
+	            
+	            
+	            String x=(String)es1.evaluate();
+	            assertTrue(x.equals("845"));
+	            x=(String)es2.evaluate();
+	            assertTrue(x.equals("true"));
+	                    
+	            
+	        } catch (SPLException e) {
+	            fail("Received evaluation exception " + e.getMessage());
+	        } catch (Exception e) {
+	            fail("Received expression exception " + e.getMessage());
+	        }
+	    }
+}
\ No newline at end of file

Added: incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/TestMain.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/TestMain.java?rev=608716&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/TestMain.java
(added)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/TestMain.java
Thu Jan  3 18:47:48 2008
@@ -0,0 +1,70 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Prashant Baliga <prabalig@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.tests;
+
+import java.util.Enumeration;
+import java.util.logging.Logger;
+
+import org.apache.imperius.util.SPLLogger;
+
+import junit.framework.TestFailure;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+public class TestMain {
+	private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+	
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		TestSuite testsuite=new TestSuite();
+		//testsuite.addTestSuite(AbsTests.class);
+		//testsuite.addTestSuite(AdditionTests.class);
+		//testsuite.addTestSuite(AssignmentExpressionTests.class);
+		testsuite.addTestSuite(BooleanExpressionTest.class);
+		testsuite.addTestSuite(StringExpressionTest.class);
+		testsuite.addTestSuite(NumericExpressionTest.class);
+		testsuite.addTestSuite(NewExpressionTest.class);
+		testsuite.addTestSuite(CollectionExpressionsTest.class);
+		testsuite.addTestSuite(UtilityTest.class);
+		
+		TestResult result=new TestResult();
+		testsuite.run(result);
+		Enumeration enm=result.errors();
+		while(enm.hasMoreElements()){
+			TestFailure ob=(TestFailure)enm.nextElement();
+			System.out.println("Failed Test : "+ob.failedTest().toString()+" "+ob.trace());
+			logger.severe("Failed Test : "+ob.failedTest().toString()+" "+ob.trace());
+		}
+		Enumeration enm1=result.failures();
+		while(enm1.hasMoreElements()){
+			TestFailure ob=(TestFailure)enm1.nextElement();
+			System.out.println("Failed Test : "+ob.failedTest().toString()+" "+ob.trace());
+			logger.severe("Failed Test : "+ob.failedTest().toString()+" "+ob.trace());
+		}
+		
+		System.out.println("result errorCount "+result.errorCount()+ " result failureCount "+ result.failureCount()+
" result status "+result.wasSuccessful()+ result.errors()
+				);
+	}
+
+}

Added: incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/UtilityTest.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/UtilityTest.java?rev=608716&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/UtilityTest.java
(added)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/UtilityTest.java
Thu Jan  3 18:47:48 2008
@@ -0,0 +1,222 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Prashant Baliga <prabalig@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.spl.tests;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expressions.impl.*;
+import org.apache.imperius.spl.parser.util.ExpressionUtility;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.spl.parser.util.TypeResolver;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+
+
+public class UtilityTest extends TestCase {
+
+    static final String CMVC_ID_UtilityTest = "$Header: /cvsroot/cimsplpegasus/trunk/modules/imperius-splcore/src/com/ibm/ac/spl/tests/UtilityTest.java,v
1.2 2007/12/20 13:07:37 prabalig Exp $";
+    static final String VERSION_UtilityTest = "File version $Revision: 1.2 $, last changed
$Date: 2007/12/20 13:07:37 $";
+//    private static Logger logger = SPLLogger.getCIMSPLLogger().getLogger();
+    
+    static Expression propertySensor1 =null;
+    //new ConstantExpression("propertySensor1");
+static Expression propertySensor2 =null;
+    //new PropertySensor("propertySensor2");
+static  Expression propertySensor3 =null;
+    //new PropertySensor("propertySensor3");
+static  Expression propertySensor4 =null;
+    //new PropertySensor("propertySensor4");
+static  Expression propertySensor5 =null;
+    //new PropertySensor("propertySensor5");
+static  Expression propertySensor6 =null;
+    //new PropertySensor("propertySensor6");
+static  Expression propertySensor7 =null;
+    //new PropertySensor("propertySensor7");
+static  Expression propertySensor8 =null;
+    //new PropertySensor("propertySensor8");
+static  Expression propertySensor9 =null;
+    //new PropertySensor("propertySensor9");
+static  Expression propertySensor10 =null;
+    //new PropertySensor("propertySensor10");
+    public UtilityTest(String arg0) {
+        super(arg0);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(UtilityTest.class);
+        TestSetup wrapper = new TestSetup(suite) {
+
+            protected void setUp() throws Exception {
+                oneTimeSetUp();
+            }
+
+            protected void tearDown() throws Exception {
+                oneTimeTearDown();
+            }
+        };
+        return wrapper;
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+
+    protected static void oneTimeSetUp() throws Exception {
+    }
+
+    protected static void oneTimeTearDown() throws Exception {
+
+    }
+
+    public void testExpressionUtility() {
+        Byte o1 = new Byte((byte)8);
+        Byte o2 = new Byte((byte)9);
+        
+        try {
+            assertTrue(ExpressionUtility.compare(o1, o2)==-1);
+            assertTrue(ExpressionUtility.minus(o2, o1).intValue()==(int)1);
+            assertTrue(ExpressionUtility.multiplication(o1, o2).intValue()==72);
+            assertTrue(ExpressionUtility.plus(o1, o2).intValue()==17);
+            assertTrue(ExpressionUtility.division(o2, o1).doubleValue()==(double)1.125);
+            
+            String YEAR="1999";
+            String MONTH="06";
+            String DAY_OF_MONTH="23";
+            String HOUR_OF_DAY="11";
+            String MINUTE="34";
+            String SECOND="34";
+            String MILLISECOND="123456";
+            String sign="-";
+            String UTC="330";
+            String CIMDateString=YEAR+MONTH+DAY_OF_MONTH+HOUR_OF_DAY+MINUTE+SECOND+"."+MILLISECOND+sign+UTC;
+           //System.out.println("CIMDateString = "+CIMDateString);
+            
+            
+            String  GMT            = "GMT";
+            int     UTC_MULTIPLIER = 60000;
+            int zoneOffsetMinutes=Integer.parseInt(UTC);
+            int zoneOffsetMilliseconds=zoneOffsetMinutes * UTC_MULTIPLIER;
+            Calendar cal = Calendar.getInstance (TimeZone.getTimeZone (GMT));
+            
+//          CIM date format yyyymmddHHMMSS.mmmmmmsUUU
+            
+            cal.set(Calendar.YEAR, 1999);
+            cal.set(Calendar.MONTH, 06);
+            cal.set(Calendar.DAY_OF_MONTH, 23);
+            cal.set(Calendar.HOUR_OF_DAY,11);
+            cal.set(Calendar.MINUTE, 34);
+            cal.set(Calendar.SECOND, 34);
+            
+            cal.set(Calendar.MILLISECOND, 123);
+            
+            if(sign.equalsIgnoreCase("-")){
+                zoneOffsetMilliseconds=0-zoneOffsetMilliseconds;
+            }
+            
+            cal.set(Calendar.ZONE_OFFSET, zoneOffsetMilliseconds);
+            //System.out.println("created calendar");
+            DateTimeConstant dtc=new DateTimeConstant(CIMDateString);
+            Calendar cal1= (Calendar)dtc.evaluate();
+           //System.out.println("cal1.getTimeInMillis() "+cal1.getTime()+" "+cal1.getTimeInMillis());
+            
+           //System.out.println("cal.getTimeInMillis() "+cal.getTime()+" "+cal.getTimeInMillis());
+            
+          //  assertTrue(cal1.getTimeInMillis()==cal.getTimeInMillis());          
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testTypeResolver() {
+        Byte o1 = new Byte((byte)8);
+        Float o2 = new Float((float)8.22);
+        Integer o3 = new Integer((int)8.22);
+        Long o4 = new Long((long)8.22);
+        Double o5 = new Double((double)8.22);
+        Number[] num={o1,o2,o3,o4,o5};
+        ByteConstant n1=new ByteConstant(o1.byteValue());
+        FloatConstant n2=new FloatConstant(o2.floatValue());
+        IntegerConstant n3=new IntegerConstant(o3.intValue());
+        LongConstant n4=new LongConstant(o4.longValue());
+        ArrayList passedParams=new ArrayList();
+        passedParams.add(n1);
+        passedParams.add(n2);
+        passedParams.add(n3);
+        passedParams.add(n4);
+        ArrayList formalParams=new ArrayList();
+        formalParams.add(new TypeInfo(TypeConstants.byteType));
+        formalParams.add(new TypeInfo(TypeConstants.floatType));
+        formalParams.add(new TypeInfo(TypeConstants.intType));
+        formalParams.add(new TypeInfo(TypeConstants.longType));
+        
+        
+        
+        
+        try {
+        	TypeInfo flt = new TypeInfo(TypeConstants.floatType);
+        	TypeInfo dbl = new TypeInfo(TypeConstants.doubleType);
+        	TypeInfo intt = new TypeInfo(TypeConstants.intType);
+        	TypeInfo lg = new TypeInfo(TypeConstants.longType);
+        	TypeInfo str = new TypeInfo(TypeConstants.stringType);
+        	TypeInfo bo	 = new TypeInfo(TypeConstants.booleanType);
+        	TypeInfo cal = new TypeInfo(TypeConstants.dateTime);
+        	TypeInfo bt = new TypeInfo(TypeConstants.byteType);
+        	
+        	//System.out.println("TypeResolver.resolveType(flt, dbl).getType()="+TypeResolver.resolveType(flt,
dbl).getType());
+        	//System.out.println("TypeConstants.doubleType="+TypeConstants.doubleType);
+            assertTrue(TypeResolver.resolveType(flt, dbl).getType()==TypeConstants.doubleType);
+            assertTrue(TypeResolver.resolveType(num)==TypeConstants.doubleType);
+            assertTrue(TypeResolver.binaryNumericPromotionResolver(intt, lg).getType()==TypeConstants.longType);
+            assertFalse(TypeResolver.isTypeAssignableForEquality(bo, str));
+            assertFalse(TypeResolver.isTypeAssignableForRelation(bo, str));
+            assertFalse(TypeResolver.isNumeric(str));
+            assertTrue(TypeResolver.isString(str));
+            assertTrue(TypeResolver.isBoolean(bo));
+            assertTrue(TypeResolver.isCalendar(cal));
+            assertTrue(TypeResolver.validateActualParameterTypes(formalParams, passedParams));
+            assertTrue(TypeResolver.unaryNumericPromotionResolver(bt).getType()==TypeConstants.intType);
+            
+                        
+        } catch (SPLException e) {
+        	e.printStackTrace();
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+        	e.printStackTrace();
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+ 
+}
\ No newline at end of file



Mime
View raw message