use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.
the class TestStaticSymbolMappingVisitor method testVisitUpdate2.
public void testVisitUpdate2() {
Update update = new Update();
update.setGroup(exampleGroup(true, 0));
// $NON-NLS-1$
update.addChange(exampleElement(true, 0), new Constant("abc"));
// $NON-NLS-1$
update.addChange(exampleElement(true, 1), new Constant("abc"));
// $NON-NLS-1$
update.setCriteria(new CompareCriteria(exampleElement(true, 2), CompareCriteria.LT, new Constant("xyz")));
helpTest(update, getSymbolMap());
}
use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.
the class TestStaticSymbolMappingVisitor method testVisitCompareCriteria.
// ################################## ACTUAL TESTS ################################
public void testVisitCompareCriteria() {
CompareCriteria cc = new CompareCriteria(exampleElement(true, 0), CompareCriteria.EQ, exampleElement(true, 1));
helpTest(cc, getSymbolMap());
}
use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.
the class TestSearchedCaseExpression method testSetWhen.
public void testSetWhen() {
SearchedCaseExpression caseExpr = example(4);
// Both are nulls
try {
caseExpr.setWhen(null, null);
// $NON-NLS-1$
fail("Setting WHEN and THEN to null should have failed.");
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenCriteria(caseExpr, 4);
TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
}
try {
caseExpr.setWhen(getWhenCriteria(2), null);
// $NON-NLS-1$
fail("Setting THEN to null should have failed.");
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenCriteria(caseExpr, 4);
TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
}
try {
caseExpr.setWhen(null, TestCaseExpression.getThenExpressions(2));
// $NON-NLS-1$
fail("Setting WHEN to null should have failed.");
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenCriteria(caseExpr, 4);
TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
}
try {
caseExpr.setWhen(getWhenCriteria(0), TestCaseExpression.getThenExpressions(0));
// $NON-NLS-1$
fail("Setting WHEN and THEN to empty lists should have failed.");
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenCriteria(caseExpr, 4);
TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
}
try {
caseExpr.setWhen(TestCaseExpression.getWhenExpressions(3), TestCaseExpression.getThenExpressions(3));
// $NON-NLS-1$
fail("Setting WHEN non Criteria types should have failed.");
} catch (IllegalArgumentException e) {
// There should be no side-effects of an illegal argument
helpTestWhenCriteria(caseExpr, 4);
TestCaseExpression.helpTestThenExpressions(caseExpr, 4);
}
caseExpr.setWhen(getWhenCriteria(3), getWhenCriteria(3));
ArrayList whens = new ArrayList();
// $NON-NLS-1$
whens.add(new CompareCriteria(new ElementSymbol("abc"), CompareCriteria.EQ, new Constant(new Integer(20000))));
// $NON-NLS-1$
whens.add(new CompareCriteria(new ElementSymbol("xyz"), CompareCriteria.EQ, new Constant(new Integer(30000))));
ArrayList thens = new ArrayList();
thens.add(new Constant(new Integer(20000)));
thens.add(new Constant(new Integer(30000)));
caseExpr.setWhen(whens, thens);
assertEquals(2, caseExpr.getWhenCount());
// $NON-NLS-1$
assertEquals(new CompareCriteria(new ElementSymbol("abc"), CompareCriteria.EQ, new Constant(new Integer(20000))), caseExpr.getWhenCriteria(0));
// $NON-NLS-1$
assertEquals(new CompareCriteria(new ElementSymbol("xyz"), CompareCriteria.EQ, new Constant(new Integer(30000))), caseExpr.getWhenCriteria(1));
assertEquals(new Constant(new Integer(20000)), caseExpr.getThenExpression(0));
assertEquals(new Constant(new Integer(30000)), caseExpr.getThenExpression(1));
}
use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.
the class TestExpressionMappingVisitor method testCompareCriteria2.
@Test
public void testCompareCriteria2() {
// $NON-NLS-1$
ElementSymbol e1 = new ElementSymbol("e1");
// $NON-NLS-1$
Function f = new Function("+", new Expression[] { new Constant(new Integer(2)), new Constant(new Integer(5)) });
Map<Expression, Expression> map = new HashMap<Expression, Expression>();
map.put(e1, f);
// $NON-NLS-1$
CompareCriteria before = new CompareCriteria(new Constant("xyz"), CompareCriteria.EQ, e1);
// $NON-NLS-1$
CompareCriteria after = new CompareCriteria(new Constant("xyz"), CompareCriteria.EQ, f);
helpTest(before, map, after);
}
use of org.teiid.query.sql.lang.CompareCriteria in project teiid by teiid.
the class TestExpressionMappingVisitor method testCaseExpression2.
@Test
public void testCaseExpression2() {
// $NON-NLS-1$
ElementSymbol x = new ElementSymbol("x");
// $NON-NLS-1$
ElementSymbol y = new ElementSymbol("y");
HashMap<Expression, Expression> map = new HashMap<Expression, Expression>();
map.put(x, y);
ArrayList<Expression> whens = new ArrayList<Expression>(), thens = new ArrayList<Expression>();
whens.add(new CompareCriteria(y, CompareCriteria.EQ, new Constant(new Integer(0))));
thens.add(new Constant(new Integer(0)));
whens.add(new CompareCriteria(y, CompareCriteria.EQ, new Constant(new Integer(1))));
thens.add(new Constant(new Integer(1)));
whens.add(new CompareCriteria(y, CompareCriteria.EQ, new Constant(new Integer(2))));
thens.add(new Constant(new Integer(2)));
SearchedCaseExpression mapped = new SearchedCaseExpression(whens, thens);
mapped.setElseExpression(new Constant(new Integer(9999)));
helpTest(TestSearchedCaseExpression.example(3), map, mapped);
}
Aggregations