Package org.apache.imperius.spl.tests

Source Code of org.apache.imperius.spl.tests.UtilityTest

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License. 
*/
//

/**
* @author Prashant Baliga <prabalig@in.ibm.com>
*
*/


package org.apache.imperius.spl.tests;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.TimeZone;

import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.imperius.spl.core.Expression;
import org.apache.imperius.spl.core.TypeConstants;
import org.apache.imperius.spl.core.TypeInfo;
import org.apache.imperius.spl.parser.exceptions.SPLException;
import org.apache.imperius.spl.parser.expressions.impl.ByteConstant;
import org.apache.imperius.spl.parser.expressions.impl.DateTimeConstant;
import org.apache.imperius.spl.parser.expressions.impl.FloatConstant;
import org.apache.imperius.spl.parser.expressions.impl.IntegerConstant;
import org.apache.imperius.spl.parser.expressions.impl.LongConstant;
import org.apache.imperius.spl.parser.util.ExpressionUtility;
import org.apache.imperius.spl.parser.util.TypeInfoImpl;
import org.apache.imperius.spl.parser.util.TypeResolver;





public class UtilityTest extends TestCase {

    static final String CMVC_ID_UtilityTest = "$Header: /cvsroot/cimsplpegasus/trunk/modules/imperius-splcore/src/com/ibm/ac/spl/tests/UtilityTest.java,v 1.2 2007/12/20 13:07:37 prabalig Exp $";
    static final String VERSION_UtilityTest = "File version $Revision: 1.2 $, last changed $Date: 2007/12/20 13:07:37 $";
//    private static Logger logger = SPLLogger.getCIMSPLLogger().getLogger();
   
    static Expression propertySensor1 =null;
    //new ConstantExpression("propertySensor1");
static Expression propertySensor2 =null;
    //new PropertySensor("propertySensor2");
static  Expression propertySensor3 =null;
    //new PropertySensor("propertySensor3");
static  Expression propertySensor4 =null;
    //new PropertySensor("propertySensor4");
static  Expression propertySensor5 =null;
    //new PropertySensor("propertySensor5");
static  Expression propertySensor6 =null;
    //new PropertySensor("propertySensor6");
static  Expression propertySensor7 =null;
    //new PropertySensor("propertySensor7");
static  Expression propertySensor8 =null;
    //new PropertySensor("propertySensor8");
static  Expression propertySensor9 =null;
    //new PropertySensor("propertySensor9");
static  Expression propertySensor10 =null;
    //new PropertySensor("propertySensor10");
    public UtilityTest(String arg0) {
        super(arg0);
    }

    public static Test suite() {
        TestSuite suite = new TestSuite(UtilityTest.class);
        TestSetup wrapper = new TestSetup(suite) {

            protected void setUp() throws Exception {
                oneTimeSetUp();
            }

            protected void tearDown() throws Exception {
                oneTimeTearDown();
            }
        };
        return wrapper;
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }

    protected static void oneTimeSetUp() throws Exception {
    }

    protected static void oneTimeTearDown() throws Exception {

    }

    public void testExpressionUtility() {
        Byte o1 = new Byte((byte)8);
        Byte o2 = new Byte((byte)9);
       
        try {
            assertTrue(ExpressionUtility.compare(o1, o2)==-1);
            assertTrue(ExpressionUtility.minus(o2, o1).intValue()==(int)1);
            assertTrue(ExpressionUtility.multiplication(o1, o2).intValue()==72);
            assertTrue(ExpressionUtility.plus(o1, o2).intValue()==17);
            assertTrue(ExpressionUtility.division(o2, o1).doubleValue()==(double)1.125);
           
            String YEAR="1999";
            String MONTH="06";
            String DAY_OF_MONTH="23";
            String HOUR_OF_DAY="11";
            String MINUTE="34";
            String SECOND="34";
            String MILLISECOND="123456";
            String sign="-";
            String UTC="330";
            String CIMDateString=YEAR+MONTH+DAY_OF_MONTH+HOUR_OF_DAY+MINUTE+SECOND+"."+MILLISECOND+sign+UTC;
           //System.out.println("CIMDateString = "+CIMDateString);
           
           
            String  GMT            = "GMT";
            int     UTC_MULTIPLIER = 60000;
            int zoneOffsetMinutes=Integer.parseInt(UTC);
            int zoneOffsetMilliseconds=zoneOffsetMinutes * UTC_MULTIPLIER;
            Calendar cal = Calendar.getInstance (TimeZone.getTimeZone (GMT));
           
//          CIM date format yyyymmddHHMMSS.mmmmmmsUUU
           
            cal.set(Calendar.YEAR, 1999);
            cal.set(Calendar.MONTH, 06);
            cal.set(Calendar.DAY_OF_MONTH, 23);
            cal.set(Calendar.HOUR_OF_DAY,11);
            cal.set(Calendar.MINUTE, 34);
            cal.set(Calendar.SECOND, 34);
           
            cal.set(Calendar.MILLISECOND, 123);
           
            if(sign.equalsIgnoreCase("-")){
                zoneOffsetMilliseconds=0-zoneOffsetMilliseconds;
            }
           
            cal.set(Calendar.ZONE_OFFSET, zoneOffsetMilliseconds);
            //System.out.println("created calendar");
            DateTimeConstant dtc=new DateTimeConstant(CIMDateString);
            Calendar cal1= (Calendar)dtc.evaluate();
           //System.out.println("cal1.getTimeInMillis() "+cal1.getTime()+" "+cal1.getTimeInMillis());
           
           //System.out.println("cal.getTimeInMillis() "+cal.getTime()+" "+cal.getTimeInMillis());
           
          //  assertTrue(cal1.getTimeInMillis()==cal.getTimeInMillis());         
           
        } catch (SPLException e) {
            fail("Received evaluation exception " + e.getMessage());
        } catch (Exception e) {
            fail("Received expression exception " + e.getMessage());
        }
    }
   
    public void testTypeResolver() {
        Byte o1 = new Byte((byte)8);
        Float o2 = new Float((float)8.22);
        Integer o3 = new Integer((int)8.22);
        Long o4 = new Long((long)8.22);
        Double o5 = new Double((double)8.22);
        Number[] num={o1,o2,o3,o4,o5};
        ByteConstant n1=new ByteConstant(o1.byteValue());
        FloatConstant n2=new FloatConstant(o2.floatValue());
        IntegerConstant n3=new IntegerConstant(o3.intValue());
        LongConstant n4=new LongConstant(o4.longValue());
        ArrayList passedParams=new ArrayList();
        passedParams.add(n1);
        passedParams.add(n2);
        passedParams.add(n3);
        passedParams.add(n4);
        ArrayList formalParams=new ArrayList();
        formalParams.add(new TypeInfoImpl(TypeConstants.byteType));
        formalParams.add(new TypeInfoImpl(TypeConstants.floatType));
        formalParams.add(new TypeInfoImpl(TypeConstants.intType));
        formalParams.add(new TypeInfoImpl(TypeConstants.longType));
       
       
       
       
        try {
          TypeInfo flt = new TypeInfoImpl(TypeConstants.floatType);
          TypeInfo dbl = new TypeInfoImpl(TypeConstants.doubleType);
          TypeInfo intt = new TypeInfoImpl(TypeConstants.intType);
          TypeInfo lg = new TypeInfoImpl(TypeConstants.longType);
          TypeInfo str = new TypeInfoImpl(TypeConstants.stringType);
          TypeInfo bo   = new TypeInfoImpl(TypeConstants.booleanType);
          TypeInfo cal = new TypeInfoImpl(TypeConstants.dateTime);
          TypeInfo bt = new TypeInfoImpl(TypeConstants.byteType);
         
          //System.out.println("TypeResolver.resolveType(flt, dbl).getType()="+TypeResolver.resolveType(flt, dbl).getType());
          //System.out.println("TypeConstants.doubleType="+TypeConstants.doubleType);
            assertTrue(TypeResolver.resolveType(flt, dbl).getType()==TypeConstants.doubleType);
            assertTrue(TypeResolver.resolveType(num)==TypeConstants.doubleType);
            assertTrue(TypeResolver.binaryNumericPromotionResolver(intt, lg).getType()==TypeConstants.longType);
            assertFalse(TypeResolver.isTypeAssignableForEquality(bo, str));
            assertFalse(TypeResolver.isTypeAssignableForRelation(bo, str));
            assertFalse(TypeResolver.isNumeric(str));
            assertTrue(TypeResolver.isString(str));
            assertTrue(TypeResolver.isBoolean(bo));
            assertTrue(TypeResolver.isCalendar(cal));
            assertTrue(TypeResolver.validateActualParameterTypes(formalParams, passedParams));
            assertTrue(TypeResolver.unaryNumericPromotionResolver(bt).getType()==TypeConstants.intType);
           
                       
        } catch (SPLException e) {
          e.printStackTrace();
            fail("Received evaluation exception " + e.getMessage());
        } catch (Exception e) {
          e.printStackTrace();
            fail("Received expression exception " + e.getMessage());
        }
    }
   
}
TOP

Related Classes of org.apache.imperius.spl.tests.UtilityTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.