public static BinaryOperatorWithParameterTest getNumericParameterDivideTestWithBracketsAfterComparison() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Divide with parameter test with brackets after comparison"); String parameterName = "amountToDivide"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionBuilder.fromConstant(new Integer(20000), builder) .greaterThan( ExpressionMath.divide( builder.get("salary"), (builder.getParameter(parameterName)))); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE 20000 > (emp.salary / ?1)"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); return theTest; }
public static BinaryOperatorWithParameterTest getNumericParameterDivideTest() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Divide with parameter test"); String parameterName = "amountToDivide"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionMath.divide(builder.get("salary"), (builder.getParameter(parameterName))) .lessThanEqual(20000); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.salary / ?1 <= 20000"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); return theTest; }
public static BinaryOperatorWithParameterTest getNumericParameterMultiplyTestWithBracketsBeforeComparison() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Multiply with parameter test with brackets before comparison"); String parameterName = "amountToMultiply"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionMath.multiply(builder.get("salary"), (builder.getParameter(parameterName))) .lessThanEqual(100000); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE (emp.salary * ?1) <= 100000"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); return theTest; }
public static BinaryOperatorWithParameterTest getNumericTwoParameterMultipleOperatorsWithBracketsAroundMultiply() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Multiple operators with two parameters with brackets around multiply"); String parameterNameForDivide = "amountToDivide"; String parameterNameForMultiply = "amountToMultiply"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterNameForDivide); theTest.getExpressionParameters().add(parameterNameForMultiply); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder .get("salary") .greaterThan( ExpressionMath.subtract( ExpressionMath.add( ExpressionBuilder.fromConstant(new Integer(50000), builder), 10000), ExpressionMath.divide( ExpressionBuilder.fromConstant(new Integer(10000), builder), ExpressionMath.multiply( builder.getParameter(parameterNameForMultiply), builder.getParameter(parameterNameForDivide))))); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.salary > (50000 + 10000 - 10000 / (?1 * ?2))"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); myArgumentNames.add("2"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); theTest.getArguments().addElement(new Integer(5)); return theTest; }
public static BinaryOperatorWithParameterTest getNumericTwoParameterMultipleOperatorsWithBracketsAroundPlusMinus() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Multiple operators with two parameters with brackets around plus/minus"); String parameterNameForDivide = "amountToDivide"; String parameterNameForMultiply = "amountToMultiply"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterNameForDivide); theTest.getExpressionParameters().add(parameterNameForMultiply); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionMath.multiply( ExpressionMath.divide( ExpressionMath.subtract(ExpressionMath.add(builder.get("salary"), 10), 20), builder.getParameter(parameterNameForDivide)), builder.getParameter(parameterNameForMultiply)) .greaterThanEqual(70000); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE (emp.salary + 10 - 20) / ?1 * ?2 >= 70000"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); myArgumentNames.add("2"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); theTest.getArguments().addElement(new Integer(3)); return theTest; }
public static BinaryOperatorWithParameterTest getNumericParameterLessThanEqualTest() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Less than equal to with parameter test"); String parameterName = "id"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.get("id").lessThanEqual(builder.getParameter(parameterName)); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE "; ejbqlString = ejbqlString + "emp.id <= ?1 "; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); return theTest; }
public static TestSuite getParameterBinaryOperatorTests() { TestSuite theSuite = new TestSuite(); theSuite.setName("Parameter Binary Operator Test Suite"); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterGreaterThanTest()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterGreaterThanEqualTest()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterLessThanTest()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterLessThanEqualTest()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterPlusTest()); theSuite.addTest( BinaryOperatorWithParameterTest.getNumericParameterPlusTestWithBracketsBeforeComparison()); theSuite.addTest( BinaryOperatorWithParameterTest.getNumericParameterPlusTestWithBracketsAfterComparison()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterMinusTest()); theSuite.addTest( BinaryOperatorWithParameterTest.getNumericParameterMinusTestWithBracketsBeforeComparison()); theSuite.addTest( BinaryOperatorWithParameterTest.getNumericParameterMinusTestWithBracketsAfterComparison()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterMultiplyTest()); theSuite.addTest( BinaryOperatorWithParameterTest .getNumericParameterMultiplyTestWithBracketsBeforeComparison()); theSuite.addTest( BinaryOperatorWithParameterTest .getNumericParameterMultiplyTestWithBracketsAfterComparison()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericParameterDivideTest()); theSuite.addTest( BinaryOperatorWithParameterTest .getNumericParameterDivideTestWithBracketsBeforeComparison()); theSuite.addTest( BinaryOperatorWithParameterTest.getNumericParameterDivideTestWithBracketsAfterComparison()); theSuite.addTest(BinaryOperatorWithParameterTest.getNumericTwoParameterMultipleOperators()); theSuite.addTest( BinaryOperatorWithParameterTest .getNumericTwoParameterMultipleOperatorsWithBracketsAroundPlusMinus()); theSuite.addTest( BinaryOperatorWithParameterTest .getNumericTwoParameterMultipleOperatorsWithBracketsAroundMultiply()); return theSuite; }