|
From: Michael R. <mr...@us...> - 2002-01-10 20:32:39
|
Update of /cvsroot/openorb/EvaluatorUtility/src/test/org/openorb/constraint/test
In directory usw-pr-cvs1:/tmp/cvs-serv7859/test/org/openorb/constraint/test
Added Files:
ConstraintEvaluatorTest.java DynamicValueTest.java
Log Message:
#501909: Moved the test case in the correct directory.
--- NEW FILE: ConstraintEvaluatorTest.java ---
/**
* Redistribution and use of this software and associated
* documentation ("Software"), with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright statements
* and notices. Redistributions must also contain a copy of this
* document.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio Inc. For written permission, please
* contact in...@ex....
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio Inc. Exolab is a registered trademark of
* Intalio Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Copyright 2000 (C) Intalio Inc. All Rights Reserved.
*/
package org.openorb.constraint.test;
/**
* This class provides a set of tests for the constraint evaluator.
*
* @author <a href="mailto:jd...@in...">Jerome Daniel <da...@in...></a>
*/
public class ConstraintEvaluatorTest
{
public static void main( String [] args )
{
// -- creates the ORB --
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init( args, null );
// -- tests a set of constraints --
test_constraint( "memory > 10000", orb, false );
test_constraint( "person.first_name == 'foo'", orb , true );
test_constraint( "person.old < ( 2 * 3 )", orb , false );
test_constraint( "person.old == 30", orb, true );
test_constraint( "( person.old == 30 ) or ( person.old < ( 2 * 3 ) )", orb, true );
test_constraint( "person.pair(position) > 40", orb, true);
test_constraint( "( person.value * 3 ) / 2 <= 150", orb, true );
test_constraint( "50 + ( -2 * 6 ) > 45", orb, false );
test_constraint( "$address ~ 'long'", orb, true );
test_constraint( "exist $.size", orb, true );
test_constraint( "'January' in third.seq", orb, true );
test_constraint( "third.months == March", orb, true );
test_constraint( "third.seq._length == 2 and ( third.seq[1] == 'February' )", orb, true );
test_constraint( "10e-3 * 2 + ( 2 + -6 ) > 0", orb, false );
test_constraint( "fourth.k.(5) < 10", orb, true );
test_constraint( "fourth.k._d == 5", orb, true );
test_constraint( "default fourth.k2._d", orb, true );
test_constraint( "fourth.k2.() >= 3.14", orb, true );
test_constraint( "fourth.seq[0](index) > 3", orb, true);
test_constraint( "fourth.seq[0].name == 'index'", orb, true);
}
/**
* This operation is used to evaluate a constraint
*/
private static void test_constraint( String constraint, org.omg.CORBA.ORB orb, boolean result )
{
// -- prepares the values --
org.omg.CORBA.Any member = orb.create_any();
member.insert_long(100);
org.openorb.constraint.Inside ins = new org.openorb.constraint.Inside( "long way", false );
org.openorb.constraint.ValuePair pair = new org.openorb.constraint.ValuePair( "position", 50 );
org.openorb.constraint.Person p = new org.openorb.constraint.Person( "foo", "bar", 30, member, pair );
org.openorb.constraint.Other o = new org.openorb.constraint.Other( 30, ins );
String [] tab = new String[2];
tab[0] = "January";
tab[1] = "February";
org.openorb.constraint.Third t = new org.openorb.constraint.Third( org.openorb.constraint.Months.March, tab );
org.openorb.constraint.K k = new org.openorb.constraint.K();
k.M(8);
org.openorb.constraint.K k2 = new org.openorb.constraint.K();
k2.D(3.14);
org.openorb.constraint.ValuePair [] pairSeq = new org.openorb.constraint.ValuePair[1];
pairSeq[0] = new org.openorb.constraint.ValuePair( "index", 5 );
org.openorb.constraint.Fourth f = new org.openorb.constraint.Fourth( k, k2, pairSeq );
org.omg.CORBA.Any any = orb.create_any();
org.omg.CORBA.Any any2 = orb.create_any();
org.omg.CORBA.Any any3 = orb.create_any();
org.omg.CORBA.Any any4 = orb.create_any();
org.omg.CORBA.Any any5 = orb.create_any();
any5.insert_long( 10 );
org.openorb.constraint.PersonHelper.insert( any, p );
org.openorb.constraint.OtherHelper.insert( any2, o );
org.openorb.constraint.ThirdHelper.insert( any3, t );
org.openorb.constraint.FourthHelper.insert( any4, f );
// -- creates the constraint --
org.openorb.constraint.Constraint c = null;
try
{
c = org.openorb.constraint.ConstraintEvaluator.create( constraint, orb );
}
catch ( org.openorb.constraint.InvalidConstraint ex )
{
System.out.println("This constraint contains an error : " + constraint );
return;
}
// -- evaluates the constraint --
try
{
c.addValue( "person", any );
c.addValue( "$", any2 );
c.addValue( "third", any3 );
c.addValue( "fourth", any4 );
c.addValue( "memory", any5 );
boolean b = (( Boolean ) c.evaluate() ).booleanValue();
System.out.println( constraint + " : " + b );
if ( b != result )
System.out.println("******* ERROR : expected result = " + result );
}
catch ( org.openorb.constraint.InvalidValue ex )
{
System.out.println("This contraint cannot be evaluated : " + constraint);
}
}
}
--- NEW FILE: DynamicValueTest.java ---
/**
* Redistribution and use of this software and associated
* documentation ("Software"), with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright statements
* and notices. Redistributions must also contain a copy of this
* document.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio Inc. For written permission, please
* contact in...@ex....
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio Inc. Exolab is a registered trademark of
* Intalio Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Copyright 2000 (C) Intalio Inc. All Rights Reserved.
*/
package org.openorb.constraint.test;
/**
* This class provides a set of tests for the identifier evaluator.
*
* @author <a href="mailto:jd...@in...">Jerome Daniel <da...@in...></a>
*/
public class DynamicValueTest
{
public DynamicValueTest()
{
}
public static void main( String [] args )
{
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init( args, null );
org.openorb.constraint.evaluator.IdentifierEvaluator eval = new org.openorb.constraint.evaluator.IdentifierEvaluator( orb );
org.omg.CORBA.Any member = orb.create_any();
member.insert_long(100);
org.openorb.constraint.Inside ins = new org.openorb.constraint.Inside( "long way", false );
org.openorb.constraint.ValuePair pair = new org.openorb.constraint.ValuePair( "position", 50 );
org.openorb.constraint.Person p = new org.openorb.constraint.Person( "foo", "bar", 30, member, pair );
org.openorb.constraint.Other o = new org.openorb.constraint.Other( 30, ins );
String [] tab = new String[2];
tab[0] = "January";
tab[1] = "February";
org.openorb.constraint.Third t = new org.openorb.constraint.Third( org.openorb.constraint.Months.March, tab );
org.openorb.constraint.K k = new org.openorb.constraint.K();
k.M(8);
org.openorb.constraint.K k2 = new org.openorb.constraint.K();
k2.D(3.14);
org.openorb.constraint.ValuePair [] pairSeq = new org.openorb.constraint.ValuePair[1];
pairSeq[0] = new org.openorb.constraint.ValuePair( "index", 5 );
org.openorb.constraint.Fourth f = new org.openorb.constraint.Fourth( k, k2, pairSeq );
org.omg.CORBA.Any any = orb.create_any();
org.omg.CORBA.Any any2 = orb.create_any();
org.omg.CORBA.Any any3 = orb.create_any();
org.omg.CORBA.Any any4 = orb.create_any();
org.openorb.constraint.PersonHelper.insert( any, p );
org.openorb.constraint.OtherHelper.insert( any2, o );
org.openorb.constraint.ThirdHelper.insert( any3, t );
org.openorb.constraint.FourthHelper.insert( any4, f );
org.openorb.constraint.evaluator.NamedValuePair [] pairs = new org.openorb.constraint.evaluator.NamedValuePair[ 4 ];
pairs[0] = new org.openorb.constraint.evaluator.NamedValuePair( "person", any );
pairs[1] = new org.openorb.constraint.evaluator.NamedValuePair( "$", any2 );
pairs[2] = new org.openorb.constraint.evaluator.NamedValuePair( "third", any3 );
pairs[3] = new org.openorb.constraint.evaluator.NamedValuePair( "fourth", any4 );
eval.setTopLevelValues( pairs );
System.out.println( "person.first_name = " + eval.getIdentifierValue("person.first_name") );
System.out.println( "person.last_name = " + eval.getIdentifierValue("person.last_name") );
System.out.println( "person.old = " + eval.getIdentifierValue("person.old") );
System.out.println( "person.value = " + eval.getIdentifierValue("person.value") );
System.out.println( "person.pair(position) = " + eval.getIdentifierValue("person.pair(position)") );
System.out.println( "$.size = " + eval.getIdentifierValue("$.size") );
System.out.println( "$address = " + eval.getIdentifierValue("$address") );
System.out.println( "$.0 = " + eval.getIdentifierValue("$.0") );
System.out.println( "$.1._type_id = " + eval.getIdentifierValue("$.1._type_id") );
System.out.println( "$.1._repos_id = " + eval.getIdentifierValue("$.1._repos_id") );
System.out.println( "third.seq[1] = " + eval.getIdentifierValue("third.seq[1]") );
System.out.println( "third.months = " + eval.getIdentifierValue("third.months") );
System.out.println( "fourth.k.M = " + eval.getIdentifierValue("fourth.k.M") );
System.out.println( "fourth.k.(5) = " + eval.getIdentifierValue("fourth.k.(5)") );
}
}
|