incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r611261 [37/43] - in /incubator/imperius/trunk: ./ imperius-javaspl/ imperius-javaspl/src/main/java/org/apache/imperius/javaspl/ imperius-splcore/ imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/ imperius-splcore/src...
Date Fri, 11 Jan 2008 18:57:14 GMT
Propchange: incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/BooleanExpressionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java
(original)
+++ incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java
Fri Jan 11 10:56:30 2008
@@ -1,683 +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());
-		}
-	}
-	*/
+/*
+ * 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());
+		}
+	}
+	*/
 }

Propchange: incubator/imperius/trunk/imperius-splcore/src/test/java/org/apache/imperius/spl/tests/CalendarExpressionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message