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 [3/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/CalendarExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java?rev=608716&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java (added)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java Thu Jan  3 18:47:48 2008
@@ -0,0 +1,683 @@
+/*
+ * 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.Calendar;
+import java.util.GregorianCalendar;
+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.TimeZoneExpression;
+import org.apache.imperius.spl.parser.expressions.impl.DateTime;
+import org.apache.imperius.spl.parser.expressions.impl.DateTimeConstant;
+import org.apache.imperius.spl.parser.expressions.impl.GetDayOfMonth;
+import org.apache.imperius.spl.parser.expressions.impl.GetDayOfWeek;
+import org.apache.imperius.spl.parser.expressions.impl.GetDayOfWeekInMonth;
+import org.apache.imperius.spl.parser.expressions.impl.GetDayOfYear;
+import org.apache.imperius.spl.parser.expressions.impl.GetHour12;
+import org.apache.imperius.spl.parser.expressions.impl.GetHour24;
+import org.apache.imperius.spl.parser.expressions.impl.GetMillisecond;
+import org.apache.imperius.spl.parser.expressions.impl.GetMinute;
+import org.apache.imperius.spl.parser.expressions.impl.GetMonth;
+import org.apache.imperius.spl.parser.expressions.impl.GetSecond;
+import org.apache.imperius.spl.parser.expressions.impl.GetWeekOfMonth;
+import org.apache.imperius.spl.parser.expressions.impl.GetWeekOfYear;
+import org.apache.imperius.spl.parser.expressions.impl.GetYear;
+import org.apache.imperius.spl.parser.expressions.impl.IsAfter;
+import org.apache.imperius.spl.parser.expressions.impl.IsBefore;
+import org.apache.imperius.spl.parser.expressions.impl.IsWithin;
+import org.apache.imperius.spl.parser.expressions.impl.StringConstant;
+import org.apache.imperius.spl.parser.expressions.impl.ToMilliseconds;
+import org.apache.imperius.spl.parser.util.ExpressionUtility;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+//import org.apache.imperius.spl.parser.expressions.impl.TimeConstant;
+
+public class CalendarExpressionTest extends TestCase {
+
+    static final String CMVC_ID_CalendarExpressionTest = "$Header: /cvsroot/cimsplpegasus/trunk/modules/imperius-splcore/src/com/ibm/ac/spl/tests/CalendarExpressionTest.java,v 1.2 2007/12/20 13:07:37 prabalig Exp $";
+    static final String VERSION_CalendarExpressionTest = "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 CalendarExpressionTest(String arg0) {
+		super(arg0);
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(CalendarExpressionTest.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 DateTime
+	 */
+	public void testDateTime() 
+	{
+	/*	//String isodate = "20040615T163709.463+01:30";
+		String date = "20070615164020.000000-300";
+		try {
+			DateTime dt = new DateTime(date);
+			
+			assertTrue(dt.getDay() == 15);
+			assertTrue(dt.getHour() == 16);
+			assertTrue(dt.getMillis() == 0);
+			assertTrue(dt.getMinute() == 40);
+			assertTrue(dt.getMonth() == 6);
+			assertTrue(dt.getSecond() == 20);
+			assertTrue(dt.getTimeZoneMinuteOffset() == -300);
+			assertTrue(dt.getYear() == 2007);
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}*/
+	}
+
+	/*
+	 * This will test GetDayOfMonth
+	 */
+	public void testGetDayOfMonth() {
+		
+		
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			Vector v = new Vector();
+			v.add(tdc);
+			GetDayOfMonth gdom = new GetDayOfMonth(v,true);
+
+			assertTrue(
+				((Integer) gdom.evaluate()).compareTo(
+					new Integer(c.get(Calendar.DAY_OF_MONTH)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetDayOfWeek
+	 */
+	public void testGetDayOfWeek() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetDayOfWeek gdow = new GetDayOfWeek(v,true);
+
+			assertTrue(
+				((Integer) gdow.evaluate()).compareTo(
+					new Integer(c.get(Calendar.DAY_OF_WEEK)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetDayOfWeek
+	 */
+	public void testGetDayOfWeekInMonth() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetDayOfWeekInMonth gdowim = new GetDayOfWeekInMonth(v,true);
+
+			assertTrue(
+				((Integer) gdowim.evaluate()).compareTo(
+					new Integer(c.get(Calendar.DAY_OF_WEEK_IN_MONTH)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetDayOfYear
+	 */
+	public void testGetDayOfYear() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+		
+			Vector v = new Vector();
+			v.add(tdc);
+			GetDayOfYear gdoy = new GetDayOfYear(v,true);
+
+			assertTrue(
+				((Integer) gdoy.evaluate()).compareTo(
+					new Integer(c.get(Calendar.DAY_OF_YEAR)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetHour
+	 */
+	public void testGetHour() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetHour12 gh = new GetHour12(v,true);
+
+			assertTrue(
+				((Integer) gh.evaluate()).compareTo(
+					new Integer(c.get(Calendar.HOUR)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetHourOfDay
+	 */
+	public void testGetHourOfDay() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetHour24 ghod = new GetHour24(v,true);
+
+			assertTrue(
+				((Integer) ghod.evaluate()).compareTo(
+					new Integer(c.get(Calendar.HOUR_OF_DAY)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetMillisecond
+	 */
+	public void testGetGetMillisecond() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetMillisecond gm = new GetMillisecond(v,true);
+
+			assertTrue(
+				((Integer) gm.evaluate()).compareTo(
+					new Integer(c.get(Calendar.MILLISECOND)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetMinute
+	 */
+	public void testGetMinute() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetMinute gm = new GetMinute(v,true);
+
+			assertTrue(
+				((Integer) gm.evaluate()).compareTo(
+					new Integer(c.get(Calendar.MINUTE)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetMonth
+	 */
+	public void testGetMonth() {
+		
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetMonth gm = new GetMonth(v,true);
+			//			//System.out.println("gm.evaluate() = " + gm.evaluate());
+			//			//System.out.println("c.get(Calendar.MONTH) = " + c.get(Calendar.MONTH));
+
+						assertTrue(((Integer)gm.evaluate()).compareTo(new Integer(c.get(Calendar.MONTH))) == 0);			
+			//		} catch (SPLException e) {
+			//			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetSecond
+	 */
+	public void testGetSecond() {
+		
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetSecond gs = new GetSecond(v,true);
+
+			assertTrue(
+				((Integer) gs.evaluate()).compareTo(
+					new Integer(c.get(Calendar.SECOND)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetWeekOfMonth
+	 */
+	public void testGetWeekOfMonth() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+		
+			Vector v = new Vector();
+			v.add(tdc);
+			GetWeekOfMonth gwom = new GetWeekOfMonth(v,true);
+
+			assertTrue(
+				((Integer) gwom.evaluate()).compareTo(
+					new Integer(c.get(Calendar.WEEK_OF_MONTH)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetWeekOfYear
+	 */
+	public void testGetWeekOfYear() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetWeekOfYear gwoy = new GetWeekOfYear(v,true);
+
+			assertTrue(
+				((Integer) gwoy.evaluate()).compareTo(
+					new Integer(c.get(Calendar.WEEK_OF_YEAR)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test GetYear
+	 */
+	public void testGetYear() {
+		
+
+		try {
+			Calendar c = new GregorianCalendar();
+			DateTimeConstant tdc = new DateTimeConstant(c);
+			
+			Vector v = new Vector();
+			v.add(tdc);
+			GetYear gy = new GetYear(v,true);
+
+			assertTrue(
+				((Integer) gy.evaluate()).compareTo(
+					new Integer(c.get(Calendar.YEAR)))
+					== 0);
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/**
+	 * This will test TImeConstant
+	 */
+	/*public void testTimeConstant() {
+		String isodate = "20040615T163709.463+01:30";
+		//HashMap map = new HashMap();
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			DateTime dt = new DateTime(isodate);
+			StringConstant sc = new StringConstant("local'");
+			Vector v = new Vector();
+			v.add(sc);
+			TimeZoneExpression tz = new TimeZoneExpression(v,true);
+
+			TimeConstant tc = new TimeConstant(dt, true, true, tz);
+			Calendar calendar = (Calendar) tc.evaluate();
+
+			//System.out.println("year = " + calendar.get(Calendar.YEAR));
+			//System.out.println("month = " + calendar.get(Calendar.MONTH));
+			//System.out.println("day = " + calendar.get(Calendar.DAY_OF_WEEK));
+			//System.out.println("hour = " + calendar.get(Calendar.HOUR));
+			//System.out.println("minute = " + calendar.get(Calendar.MINUTE));
+			//System.out.println("second = " + calendar.get(Calendar.SECOND));
+			//System.out.println("millisecond = " + calendar.get(Calendar.MILLISECOND));
+		} catch (SPLException e) {
+			fail("Received expression exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}*/
+
+	/*
+	 * This will test IsBefore().
+	 */
+	public void testIsBefore() {
+		Calendar c1 = Calendar.getInstance();
+		try {
+			Thread.sleep(1000);
+		} catch (InterruptedException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		Calendar c2 = Calendar.getInstance();
+		
+		
+		//HashMap map = new HashMap();
+		//map.put("propertySensor1", c1);
+		//map.put("propertySensor2", c2);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			DateTimeConstant tdc1 = new DateTimeConstant(c1);
+			DateTimeConstant tdc2 = new DateTimeConstant(c2);
+			Vector v = new Vector();
+			v.add(tdc1);
+			v.add(tdc2);
+			Expression e = new IsBefore(v,true);
+			
+			/*v.clear();
+			v.add(propertySensor1);
+			v.add(tdc2);
+			Expression eps = new IsBefore(v,true);*/
+
+			assertTrue(((Boolean)e.evaluate()).booleanValue());
+			//assertTrue(((Boolean)eps.evaluate()).booleanValue());
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test IsAfter().
+	 */
+	public void testIsAfter() {
+		Calendar c1 = Calendar.getInstance();
+		try {
+			Thread.sleep(1000);
+		} catch (InterruptedException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		Calendar c2 = Calendar.getInstance();
+		
+	
+		//HashMap map = new HashMap();
+		//map.put("propertySensor1", c1);
+		//map.put("propertySensor2", c2);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			DateTimeConstant tdc1 = new DateTimeConstant(c1);
+			DateTimeConstant tdc2 = new DateTimeConstant(c2);
+			Vector v = new Vector();
+			v.add(tdc2);
+			v.add(tdc1);
+			Expression e = new IsAfter(v,true);
+			
+			/*v.clear();
+			v.add(propertySensor2);
+			v.add(propertySensor1);
+			Expression eps = new IsAfter(v,true);*/
+
+			assertTrue(((Boolean)e.evaluate()).booleanValue());
+			//assertTrue(((Boolean)eps.evaluate()).booleanValue());
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	/*
+	 * This will test IsWithin().
+	 */
+	public void testIsWithin() {
+		Calendar c1 = Calendar.getInstance();
+
+		try {
+			Thread.sleep(1000);
+		} catch (InterruptedException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		Calendar c2 = Calendar.getInstance();
+
+		try {
+			Thread.sleep(500);
+		} catch (InterruptedException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		
+		Calendar c3 = Calendar.getInstance();
+
+		
+		//HashMap map = new HashMap();
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			DateTimeConstant tdc1 = new DateTimeConstant(c1);
+			DateTimeConstant tdc2 = new DateTimeConstant(c2);
+			DateTimeConstant tdc3 = new DateTimeConstant(c3);
+
+			Vector v = new Vector();
+			v.add(tdc2);
+			v.add(tdc1);
+			v.add(tdc3);
+			Expression e = new IsWithin(v,true);
+			
+			assertTrue(((Boolean)e.evaluate()).booleanValue());
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+
+	   public void testToMilliseconds() {
+		   
+		   Calendar c1 = Calendar.getInstance();
+
+	    	
+	        
+	        try {
+	        	propertySensor1=new DateTimeConstant(c1);
+	            Vector v = new Vector();
+	            v.add(propertySensor1);
+	            Expression es1 = new ToMilliseconds(v,true);
+ 
+	            
+	            Long x=(Long)es1.evaluate();
+	           //System.out.println("x, c1 "+x.longValue()+ " "+c1.getTimeInMillis());
+	            assertTrue(x.longValue()==c1.getTimeInMillis());
+	                     
+	            
+	        } catch (SPLException e) {
+	            fail("Received evaluation exception " + e.getMessage());
+	        } catch (Exception e) {
+	            fail("Received expression exception " + e.getMessage());
+	        }
+	    }
+	
+	/*
+	 * This will test Belongs().
+	 */
+	/*public void testBelongs() {
+		StringConstant s = new StringConstant("Zero");
+		StringConstant s0 = new StringConstant("Zero");
+		StringConstant s1 = new StringConstant("One");
+		StringConstant s2 = new StringConstant("Two");
+		StringConstant s3 = new StringConstant("Three");
+
+		//HashMap map = new HashMap();
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Vector v = new Vector();
+			Vector c = new Vector();
+		
+			c.add(s0);
+			c.add(s1);
+			c.add(s2);
+			c.add(s3);
+			Expression ec = new CollectionConstant(c);
+
+			v.add(s);
+			v.add(ec);
+			
+			Expression e = new Belongs(v,true);
+
+			assertTrue(((Boolean)e.evaluate()).booleanValue());
+		} 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/CollectionExpressionsTest.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CollectionExpressionsTest.java?rev=608716&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CollectionExpressionsTest.java (added)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CollectionExpressionsTest.java Thu Jan  3 18:47:48 2008
@@ -0,0 +1,955 @@
+/*
+ * 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.List;
+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.expression.primary.BasicCollectionExpression;
+import org.apache.imperius.spl.parser.expressions.impl.AllInCollection;
+import org.apache.imperius.spl.parser.expressions.impl.AnyInCollection;
+import org.apache.imperius.spl.parser.expressions.impl.ApplyToCollection;
+import org.apache.imperius.spl.parser.expressions.impl.AvrgInCollection;
+import org.apache.imperius.spl.parser.expressions.impl.BooleanConstant;
+import org.apache.imperius.spl.parser.expressions.impl.ByteConstant;
+import org.apache.imperius.spl.parser.expressions.impl.CollectionSize;
+import org.apache.imperius.spl.parser.expressions.impl.EqCollections;
+import org.apache.imperius.spl.parser.expressions.impl.FloatConstant;
+import org.apache.imperius.spl.parser.expressions.impl.InCollection;
+import org.apache.imperius.spl.parser.expressions.impl.MaxInCollection;
+import org.apache.imperius.spl.parser.expressions.impl.MedianInCollection;
+import org.apache.imperius.spl.parser.expressions.impl.MinInCollection;
+import org.apache.imperius.spl.parser.expressions.impl.SdInCollection;
+import org.apache.imperius.spl.parser.expressions.impl.StringConstant;
+import org.apache.imperius.spl.parser.expressions.impl.SubCollection;
+import org.apache.imperius.spl.parser.expressions.impl.Sum;
+import org.apache.imperius.spl.parser.expressions.impl.Union;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+
+public class CollectionExpressionsTest  extends TestCase 
+{
+	
+    static final String CMVC_ID_NumericExpressionTest = "$Header: /cvsroot/cimsplpegasus/trunk/modules/imperius-splcore/src/com/ibm/ac/spl/tests/CollectionExpressionsTest.java,v 1.2 2007/12/20 13:07:37 prabalig Exp $";
+    static final String VERSION_NumericExpressionTest = "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 CollectionExpressionsTest(String arg0) {
+        super(arg0);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(CollectionExpressionsTest.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 testAllInCollection() {
+    	propertySensor1 = new ByteConstant((byte)1);
+    	propertySensor2 = new ByteConstant((byte)2);
+    	propertySensor3 = new ByteConstant((byte)3);
+    	propertySensor4 = new ByteConstant((byte)4);
+    	propertySensor5 = new ByteConstant((byte)5);
+    	propertySensor6 = new ByteConstant((byte)6);
+    	propertySensor7 = new ByteConstant((byte)7);
+    	propertySensor8 = new ByteConstant((byte)8);
+    	
+    	StringConstant stringLOR = new StringConstant("\"OR\"");
+    	StringConstant stringLAND = new StringConstant("\"AND\"");
+    	StringConstant stringBXOR = new StringConstant("\"XOR\"");
+    	StringConstant stringNOT_EQUAL = new StringConstant("\"NOT_EQUAL\"");
+    	StringConstant stringEQUAL = new StringConstant("\"EQUAL\"");
+    	StringConstant stringLT = new StringConstant("\"LESS\"");
+    	StringConstant stringGT = new StringConstant("\"GREATER\"");
+    	StringConstant stringLE = new StringConstant("\"LESS_OR_EQUAL\"");
+    	StringConstant stringGE = new StringConstant("\"GREATER_OR_EQUAL\"");
+    	
+    	
+		
+		
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(new ByteConstant((byte)0));
+            v.add(stringGT);
+            v.add(collection);
+            Expression es1 = new AllInCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)10));
+            v.add(stringLT);
+            v.add(collection);
+            Expression es2 = new AllInCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)8));
+            v.add(stringLE);
+            v.add(collection);
+            Expression es3 = new AllInCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)1));
+            v.add(stringGE);
+            v.add(collection);
+            Expression es4 = new AllInCollection(v,true);
+            v.clear();
+            
+            
+
+
+            assertTrue(((Boolean)es1.evaluate()).booleanValue());
+            assertTrue(((Boolean)es2.evaluate()).booleanValue());
+            assertTrue(((Boolean)es3.evaluate()).booleanValue());
+            assertTrue(((Boolean)es4.evaluate()).booleanValue());
+            
+            
+            
+            propertySensor1 = new BooleanConstant(true);
+        	propertySensor2 = new BooleanConstant(true);
+        	propertySensor3 = new BooleanConstant(true);
+        	propertySensor4 = new BooleanConstant(true);
+        	
+        	
+        	vbytes.clear();
+        	
+        	vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            
+            
+            collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(new BooleanConstant(false));
+            v.add(stringLOR);
+            v.add(collection);
+            Expression es5 = new AllInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(true));
+            v.add(stringLAND);
+            v.add(collection);
+            Expression es6 = new AllInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(false));
+            v.add(stringBXOR);
+            v.add(collection);
+            Expression es7 = new AllInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(false));
+            v.add(stringNOT_EQUAL);
+            v.add(collection);
+            Expression es8 = new AllInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(true));
+            v.add(stringEQUAL);
+            v.add(collection);
+            Expression es9 = new AllInCollection(v,true);
+            v.clear();
+            
+            
+
+
+            assertTrue(((Boolean)es5.evaluate()).booleanValue());
+            assertTrue(((Boolean)es6.evaluate()).booleanValue());
+            assertTrue(((Boolean)es7.evaluate()).booleanValue());
+            assertTrue(((Boolean)es8.evaluate()).booleanValue());
+            assertTrue(((Boolean)es9.evaluate()).booleanValue());
+            
+            
+            
+            
+        } catch (SPLException e) {
+        	e.printStackTrace();
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+        	e.printStackTrace();
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testAnyInCollection() {
+    	propertySensor1 = new ByteConstant((byte)1);
+    	propertySensor2 = new ByteConstant((byte)2);
+    	propertySensor3 = new ByteConstant((byte)3);
+    	propertySensor4 = new ByteConstant((byte)4);
+    	propertySensor5 = new ByteConstant((byte)5);
+    	propertySensor6 = new ByteConstant((byte)6);
+    	propertySensor7 = new ByteConstant((byte)7);
+    	propertySensor8 = new ByteConstant((byte)8);
+    	
+    	StringConstant stringLOR = new StringConstant("\"OR\"");
+    	StringConstant stringLAND = new StringConstant("\"AND\"");
+    	StringConstant stringBXOR = new StringConstant("\"XOR\"");
+    	StringConstant stringNOT_EQUAL = new StringConstant("\"NOT_EQUAL\"");
+    	StringConstant stringEQUAL = new StringConstant("\"EQUAL\"");
+    	StringConstant stringLT = new StringConstant("\"LESS\"");
+    	StringConstant stringGT = new StringConstant("\"GREATER\"");
+    	StringConstant stringLE = new StringConstant("\"LESS_OR_EQUAL\"");
+    	StringConstant stringGE = new StringConstant("\"GREATER_OR_EQUAL\"");
+    	
+		
+
+		
+		
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(new ByteConstant((byte)6));
+            v.add(stringGT);
+            v.add(collection);
+            Expression es1 = new AnyInCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)2));
+            v.add(stringLT);
+            v.add(collection);
+            Expression es2 = new AnyInCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)3));
+            v.add(stringLE);
+            v.add(collection);
+            Expression es3 = new AnyInCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)4));
+            v.add(stringGE);
+            v.add(collection);
+            Expression es4 = new AnyInCollection(v,true);
+            v.clear();
+            
+            
+
+
+            assertTrue(((Boolean)es1.evaluate()).booleanValue());
+            assertTrue(((Boolean)es2.evaluate()).booleanValue());
+            assertTrue(((Boolean)es3.evaluate()).booleanValue());
+            assertTrue(((Boolean)es4.evaluate()).booleanValue());
+            
+            
+            
+            propertySensor1 = new BooleanConstant(true);
+        	propertySensor2 = new BooleanConstant(true);
+        	propertySensor3 = new BooleanConstant(true);
+        	propertySensor4 = new BooleanConstant(true);
+        	
+        	
+        	vbytes.clear();
+        	
+        	vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            
+            
+            collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(new BooleanConstant(false));
+            v.add(stringLOR);
+            v.add(collection);
+            Expression es5 = new AnyInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(true));
+            v.add(stringLAND);
+            v.add(collection);
+            Expression es6 = new AnyInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(false));
+            v.add(stringBXOR);
+            v.add(collection);
+            Expression es7 = new AnyInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(false));
+            v.add(stringNOT_EQUAL);
+            v.add(collection);
+            Expression es8 = new AnyInCollection(v,true);
+            v.clear();
+            
+            v.add(new BooleanConstant(true));
+            v.add(stringEQUAL);
+            v.add(collection);
+            Expression es9 = new AnyInCollection(v,true);
+            v.clear();
+            
+            
+
+
+            assertTrue(((Boolean)es5.evaluate()).booleanValue());
+            assertTrue(((Boolean)es6.evaluate()).booleanValue());
+            assertTrue(((Boolean)es7.evaluate()).booleanValue());
+            assertTrue(((Boolean)es8.evaluate()).booleanValue());
+            assertTrue(((Boolean)es9.evaluate()).booleanValue());
+            
+            
+            
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testApplyToCollection() {
+    	propertySensor8 = new ByteConstant((byte)8);
+    	
+    	StringConstant stringPLUS = new StringConstant("\"PLUS\"");
+    	StringConstant stringMINUS = new StringConstant("\"MINUS\"");
+    	StringConstant stringSTAR = new StringConstant("\"MULTIPLY\"");
+    	StringConstant stringDIV = new StringConstant("\"DIVIDE\"");
+		
+
+		
+		
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor8);
+            vbytes.add(propertySensor8);
+            vbytes.add(propertySensor8);
+            vbytes.add(propertySensor8);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(new ByteConstant((byte)10));
+            v.add(stringPLUS);
+            v.add(collection);
+            Expression es1 = new ApplyToCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)4));
+            v.add(stringMINUS);
+            v.add(collection);
+            Expression es2 = new ApplyToCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)2));
+            v.add(stringSTAR);
+            v.add(collection);
+            Expression es3 = new ApplyToCollection(v,true);
+            v.clear();
+            
+            v.add(new ByteConstant((byte)2));
+            v.add(stringDIV);
+            v.add(collection);
+            Expression es4 = new ApplyToCollection(v,true);
+            v.clear();
+            
+            List resultarr1=(List)es1.evaluate();
+            for(int i=0;i<resultarr1.size();i++){
+            	//System.out.println(((Number)resultarr1.get(i)).intValue());
+            	assertTrue(((Number)resultarr1.get(i)).intValue()==18);
+
+            }
+            
+            List resultarr2=(List)es2.evaluate();
+            for(int i=0;i<resultarr2.size();i++){
+            	//System.out.println(((Number)resultarr2.get(i)).intValue());
+            	assertTrue(((Number)resultarr2.get(i)).intValue()==4);
+
+            }
+            
+            List resultarr3=(List)es3.evaluate();
+            for(int i=0;i<resultarr3.size();i++){
+            	//System.out.println(((Number)resultarr3.get(i)).intValue());
+            	assertTrue(((Number)resultarr3.get(i)).intValue()==16);
+
+            }
+            
+            List resultarr4=(List)es4.evaluate();
+            for(int i=0;i<resultarr4.size();i++){
+            	//System.out.println(((Number)resultarr4.get(i)).intValue());
+            	assertTrue(((Number)resultarr4.get(i)).intValue()==4);
+
+            }
+            
+            
+        } catch (SPLException e) {
+        	e.printStackTrace();
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+        	e.printStackTrace();
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testAvrgInCollection() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            Expression es1 = new AvrgInCollection(v,true);
+            v.clear();
+            double n=((Number)es1.evaluate()).doubleValue();
+           //System.out.println(n);
+            assertTrue(n>9.94 && n<9.95);
+
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testEqCollection() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            Expression collection1 = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            v.add(collection1);
+            Expression es1 = new EqCollections(v,true);
+            v.clear();
+            assertTrue(((Boolean)es1.evaluate()).booleanValue());
+
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testMaxInCollection() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            Expression es1 = new MaxInCollection(v,true);
+            v.clear();
+            assertTrue(((Number)es1.evaluate()).floatValue()==(float)88.44);
+
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testMinInCollection() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            Expression es1 = new MinInCollection(v,true);
+            v.clear();
+            assertTrue(((Number)es1.evaluate()).floatValue()==(float)-7.77);
+
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testSum() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            Expression es1 = new Sum(v,true);
+            v.clear();
+            assertTrue(((Number)es1.evaluate()).floatValue()==(float)79.560005);
+
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testInCollection() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(propertySensor3);
+            v.add(collection);
+            Expression es1 = new InCollection(v,true);
+            v.clear();
+            assertTrue(((Boolean)es1.evaluate()).booleanValue());
+            
+            v.add(propertySensor8);
+            v.add(collection);
+            Expression es2 = new InCollection(v,true);
+            v.clear();
+            assertFalse(((Boolean)es2.evaluate()).booleanValue());
+
+            
+        } catch (SPLException e) {
+        	e.printStackTrace();
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+        	e.printStackTrace();
+            
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testSubCollection() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            vbytes.add(propertySensor8);
+            
+            
+            Expression collection1 = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            v.add(collection1);
+            Expression es1 = new SubCollection(v,true);
+            v.clear();
+            assertTrue(((Boolean)es1.evaluate()).booleanValue());
+
+            
+        } catch (SPLException e) {
+        	e.printStackTrace();
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+        	e.printStackTrace();
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testUnion() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            Vector vbytes1 = new Vector();
+            
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            vbytes1.add(propertySensor5);
+            vbytes1.add(propertySensor6);
+            vbytes1.add(propertySensor7);
+            vbytes1.add(propertySensor8);
+            
+            
+            Expression collection1 = new BasicCollectionExpression(vbytes1,null);
+            
+            v.add(collection);
+            v.add(collection1);
+            Expression es1 = new Union(v,true);
+            v.clear();
+            List resultList=(List)es1.evaluate();
+//            System.out.println("list "+ resultList.toString());
+            assertTrue(((Number)resultList.get(0)).floatValue()==(float)1.11);
+            assertTrue(((Number)resultList.get(1)).floatValue()==(float)2.22);
+            assertTrue(((Number)resultList.get(2)).floatValue()==(float)3.33);
+            assertTrue(((Number)resultList.get(3)).floatValue()==(float)4.44);
+            assertTrue(((Number)resultList.get(4)).floatValue()==(float)-5.55);
+            assertTrue(((Number)resultList.get(5)).floatValue()==(float)-6.66);
+            assertTrue(((Number)resultList.get(6)).floatValue()==(float)-7.77);
+            assertTrue(((Number)resultList.get(7)).floatValue()==(float)88.44);
+            
+            
+        } catch (SPLException e) {
+        	e.printStackTrace();
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+        	e.printStackTrace();
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testCollectionSize() {
+    	propertySensor1 = new FloatConstant((float)1.11);
+    	propertySensor2 = new FloatConstant((float)2.22);
+    	propertySensor3 = new FloatConstant((float)3.33);
+    	propertySensor4 = new FloatConstant((float)4.44);
+    	propertySensor5 = new FloatConstant((float)-5.55);
+    	propertySensor6 = new FloatConstant((float)-6.66);
+    	propertySensor7 = new FloatConstant((float)-7.77);
+    	propertySensor8 = new FloatConstant((float)88.44);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+            vbytes.add(propertySensor6);
+            vbytes.add(propertySensor7);
+            
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            Expression es1 = new CollectionSize(v,true);
+            v.clear();
+            assertTrue(((Number)es1.evaluate()).intValue()==7);
+            
+            
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testMedianInCollection() {
+    	propertySensor1 = new FloatConstant((float)6);
+    	propertySensor2 = new FloatConstant((float)9.7);
+    	propertySensor3 = new FloatConstant((float)14.8);
+    	propertySensor4 = new FloatConstant((float)22.4);
+    	propertySensor5 = new FloatConstant((float)-9.8);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+             
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            Expression es1 = new MedianInCollection(v,true);
+            v.clear();
+            assertTrue(((Number)es1.evaluate()).floatValue()==(float)9.7);
+            
+            
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+    
+    public void testSdInCollection() {
+    	propertySensor1 = new FloatConstant((float)2);
+    	propertySensor2 = new FloatConstant((float)4);
+    	propertySensor3 = new FloatConstant((float)1);
+    	propertySensor4 = new FloatConstant((float)6);
+    	propertySensor5 = new FloatConstant((float)7);
+    	
+    	
+    	
+        try {
+            Vector v = new Vector();
+            Vector vbytes = new Vector();
+            
+            vbytes.add(propertySensor1);
+            vbytes.add(propertySensor2);
+            vbytes.add(propertySensor3);
+            vbytes.add(propertySensor4);
+            vbytes.add(propertySensor5);
+             
+            
+            Expression collection = new BasicCollectionExpression(vbytes,null);
+            
+            v.add(collection);
+            Expression es1 = new SdInCollection(v,true);
+            v.clear();
+           //System.out.println(((Number)es1.evaluate()).floatValue());
+            assertTrue(((Number)es1.evaluate()).floatValue()==(float)2.2803508501982757e+000);
+            
+            
+            
+        } catch (SPLException e) {
+            fail("Received evaluation exception " + e.getMessage());
+        } catch (Exception e) {
+            fail("Received expression exception " + e.getMessage());
+        }
+    }
+}
+
+

Added: incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NewExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NewExpressionTest.java?rev=608716&view=auto
==============================================================================
--- incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NewExpressionTest.java (added)
+++ incubator/imperius/trunk/modules/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/NewExpressionTest.java Thu Jan  3 18:47:48 2008
@@ -0,0 +1,627 @@
+/*
+ * 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.Calendar;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expression.primary.BasicCollectionExpression;
+import org.apache.imperius.spl.parser.expressions.impl.*;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+public class NewExpressionTest extends TestCase {
+
+    static final String CMVC_ID_NewExpressionTest = "$Header: /cvsroot/cimsplpegasus/trunk/modules/imperius-splcore/src/com/ibm/ac/spl/tests/NewExpressionTest.java,v 1.2 2007/12/20 13:07:37 prabalig Exp $";
+    static final String VERSION_NewExpressionTest = "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");
+
+	public NewExpressionTest(String arg0) {
+		super(arg0);
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(NewExpressionTest.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 ContainsOnlyDigits Expression
+	 */
+	public void testContainsOnlyDigits() {
+		String s1 = "\"containsNoDigits\"";
+		String s2 = "\"30 Sawmill River Rd, Hawthorne, NY 10532\"";
+		String s3 = "\"18007778888\"";
+		String s4 = "\"\"";
+		String s5 = "\"@#$%^&*(){}|\"";
+
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		propertySensor3=new StringConstant(s3);
+		propertySensor4=new StringConstant(s4);
+		propertySensor5=new StringConstant(s5);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Expression exp;
+			
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor1);
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+			
+			v.clear();
+			v.add(new StringConstant(s2));
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor2);
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(new StringConstant(s3));
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(propertySensor3);
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+			
+			v.clear();
+			v.add(new StringConstant(s4));
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(propertySensor4);
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(new StringConstant(s5));
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor5);
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	/**
+	 * This will test ContainsOnlyLetters Expression
+	 */	
+	public void testContainsOnlyLetters() {
+		String s1 = "\"containsNoDigits\"";
+		String s2 = "\"30 Sawmill River Rd, Hawthorne, NY 10532\"";
+		String s3 = "\"1 800 777 8888\"";
+		String s4 = "\"\"";
+		String s5 = "\"@#$%^&*(){}|\"";
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		propertySensor3=new StringConstant(s3);
+		propertySensor4=new StringConstant(s4);
+		propertySensor5=new StringConstant(s5);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Expression exp;
+			
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			exp = new ContainsOnlyLetters(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(propertySensor1);
+			exp = new ContainsOnlyLetters(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(new StringConstant(s2));
+			exp = new ContainsOnlyLetters(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor2);
+			exp = new ContainsOnlyLetters(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(new StringConstant(s3));
+			exp = new ContainsOnlyLetters(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor3);
+			exp = new ContainsOnlyLetters(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+			
+			v.clear();
+			v.add(new StringConstant(s4));
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(propertySensor4);
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(new StringConstant(s5));
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor5);
+			exp = new ContainsOnlyDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	/**
+	 * This will test ContainsOnlyLettersOrDigits Expression
+	 */
+	public void testContainsOnlyLettersOrDigits() {
+		String s1 = "\"containsDigitsAndLetters12345\"";
+		String s2 = "\"30 Sawmill River Rd, Hawthorne, NY 10532\"";
+		String s3 = "\"TollFree18007778888\"";
+		String s4 = "\"\"";
+		String s5 = "\"@#$%^&*(){}|\"";
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		propertySensor3=new StringConstant(s3);
+		propertySensor4=new StringConstant(s4);
+		propertySensor5=new StringConstant(s5);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Expression exp;
+
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(propertySensor1);
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(new StringConstant(s2));
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor2);
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(new StringConstant(s3));
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(propertySensor3);
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+			
+			v.clear();
+			v.add(new StringConstant(s4));
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(propertySensor4);
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(new StringConstant(s5));
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+
+			v.clear();
+			v.add(propertySensor5);
+			exp = new ContainsOnlyLettersOrDigits(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.FALSE));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+		
+	}
+	
+	/**
+	 * This will test Like Expression
+	 */	
+	public void testMatchesRegExp() {
+		String s1 = "\"aaaaab\"";
+		String s2 = "\"a*b\"";
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		propertySensor2=new StringConstant(s2);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Expression exp;
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			exp = new MatchesRegExp(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+
+			v.clear();
+			v.add(new StringConstant(s1));
+			v.add(new StringConstant(s2));
+			exp = new MatchesRegExp(v,true);
+			assertTrue(exp.evaluate().equals(Boolean.TRUE));
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+		
+	}
+	
+	/**
+	 * This will test Substring Expression
+	 */
+	public void testSubstring() {
+		String s1 = "\"containsDigitsAndLetters12345\"";
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			Expression exp;
+
+			Vector v = new Vector();
+			v.add(new StringConstant(s1));
+			v.add(new IntegerConstant(8));
+			exp = new Substring(v,true);
+			assertTrue(exp.evaluate().equals("DigitsAndLetters12345"));
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(new IntegerConstant(8));
+			exp = new Substring(v,true);
+			assertTrue(exp.evaluate().equals("DigitsAndLetters12345"));
+
+			v.clear();
+			v.add(new StringConstant(s1));
+			v.add(new IntegerConstant(8));
+			v.add(new IntegerConstant(24));
+			exp = new Substring(v,true);
+			assertTrue(exp.evaluate().equals("DigitsAndLetters"));
+
+			v.clear();
+			v.add(propertySensor1);
+			v.add(new IntegerConstant(8));
+			v.add(new IntegerConstant(24));
+			exp = new Substring(v,true);
+			assertTrue(exp.evaluate().equals("DigitsAndLetters"));
+		} catch (SPLException e) {
+			e.printStackTrace();
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testStringConstant() {
+		String s1 = "\"Test String\"";
+		String s2 = "Test String";
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new StringConstant(s1);
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.stringType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((String)propertySensor1.evaluate()).equals(s2));
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testIntegerConstant() {
+		Integer s1 = new Integer(1);
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new IntegerConstant(s1.intValue());
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.intType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Integer)propertySensor1.evaluate()).intValue()==s1.intValue());
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testFloatConstant() {
+		Float s1 = new Float(1.23);
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new FloatConstant(s1.floatValue());
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.floatType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Float)propertySensor1.evaluate()).floatValue()==s1.floatValue());
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testLongConstant() {
+		Long s1 = new Long(65000);
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new LongConstant(s1.longValue());
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.longType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Long)propertySensor1.evaluate()).longValue()==s1.longValue());
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testDoubleConstant() {
+		Double s1 = new Double(65000.65);
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new DoubleConstant(s1.doubleValue());
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.doubleType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Double)propertySensor1.evaluate()).doubleValue()==s1.doubleValue());
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testBooleanConstant() {
+		Boolean s1 = new Boolean(true);
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new BooleanConstant(s1.booleanValue());
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.booleanType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Boolean)propertySensor1.evaluate()).booleanValue()==s1.booleanValue());
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testCharConstant() {
+		Character s1 = new Character('a');
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new CharConstant(s1.charValue());
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.charType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Character)propertySensor1.evaluate()).equals(s1));
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testShortConstant() {
+		Short s1 = new Short((short)23);
+		
+		//HashMap map = new HashMap();
+		propertySensor1=new ShortConstant(s1.shortValue());
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.shortType);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Short)propertySensor1.evaluate()).shortValue()==s1.shortValue());
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testDateTimeConstant() {
+		Calendar c1=Calendar.getInstance();
+		//HashMap map = new HashMap();
+		
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			propertySensor1=new DateTimeConstant(c1);
+			assertTrue(propertySensor1.getType().getType()== TypeConstants.dateTime);
+			assertFalse(propertySensor1.isArray());
+			assertTrue(((Calendar)propertySensor1.evaluate())==c1);
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+	
+	public void testBasicCollectionExpression() {
+		int c1=10;
+		//HashMap map = new HashMap();
+		propertySensor1=new IntegerConstant(c1);
+		propertySensor2=new IntegerConstant(c1);
+		propertySensor3=new IntegerConstant(c1);
+		propertySensor4=new IntegerConstant(c1);
+		propertySensor5=new IntegerConstant(c1);
+		
+		
+		
+		//SensorLookup lookup = new SensorLookupImpl(map);
+
+		try {
+			SPLSymbolTable t =new SPLSymbolTable();
+			Vector v = new Vector();
+			v.add(propertySensor1);
+			v.add(propertySensor2);
+			v.add(propertySensor3);
+			v.add(propertySensor4);
+			v.add(propertySensor5);
+			Expression e1=new BasicCollectionExpression(v,t);
+			assertTrue(e1.getType().getType()== TypeConstants.intType);
+			assertTrue(e1.isArray());
+			
+			
+			List resultList=(List)e1.evaluate();
+			for(int i=0;i<resultList.size();i++)
+			{
+				assertTrue(((Integer)resultList.get(i)).intValue()==c1);
+			}
+			
+		} catch (SPLException e) {
+			fail("Received evaluation exception " + e.getMessage());
+		} catch (Exception e) {
+			fail("Received expression exception " + e.getMessage());
+		}
+	}
+}
\ No newline at end of file



Mime
View raw message