public void testGetWhenExpression() { helpTestWhenExpressions(example(3), 3); }
public void testGetThenExpression() { helpTestThenExpressions(example(3), 3); }
@Test public void testCaseExpression1() { helpTest(TestCaseExpression.example(2), "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 ELSE 9999 END"); //$NON-NLS-1$ }
public void testGetElseExpression() { CaseExpression expr = example(3); assertEquals(new Constant(new Integer(9999)), expr.getElseExpression()); }
@Test public void testCaseExpression3() { CaseExpression example = TestCaseExpression.example(3, 0, true); helpTest(example, "CASE x WHEN null THEN 0 WHEN 'b' THEN 1 WHEN 'c' THEN 2 ELSE 9999 END"); //$NON-NLS-1$ }
@Test public void testCaseExpression1() { ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ ElementSymbol y = new ElementSymbol("y"); //$NON-NLS-1$ Constant a = new Constant(String.valueOf('a')); Constant z = new Constant(String.valueOf('z')); HashMap<Expression, Expression> map = new HashMap<Expression, Expression>(); map.put(x, y); map.put(a, z); ArrayList<Expression> whens = new ArrayList<Expression>(), thens = new ArrayList<Expression>(); whens.add(new Constant(String.valueOf('z'))); thens.add(new Constant(new Integer(0))); whens.add(new Constant(String.valueOf('b'))); thens.add(new Constant(new Integer(1))); whens.add(new Constant(String.valueOf('c'))); thens.add(new Constant(new Integer(2))); CaseExpression mapped = new CaseExpression(y, whens, thens); mapped.setElseExpression(new Constant(new Integer(9999))); helpTest(TestCaseExpression.example(3), map, mapped); }
@Test public void testCaseExpression4() { CaseExpression example = TestCaseExpression.example(3, 2, true); example.setElseExpression(null); helpTest(example, "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 WHEN null THEN 2 END"); //$NON-NLS-1$ }
@Test public void testCaseExpression2() { CaseExpression example = TestCaseExpression.example(2); example.setElseExpression(null); helpTest(example, "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 END"); //$NON-NLS-1$ }
public void testGetWhen() { CaseExpression expr = example(3); assertNotNull(expr.getWhen()); assertEquals(3, expr.getWhen().size()); try { expr.getWhen().add(new Object()); fail("Should not be modifiable"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { } }
public void testGetThen() { CaseExpression expr = example(3); assertNotNull(expr.getThen()); assertEquals(3, expr.getThen().size()); try { expr.getThen().add(new Object()); fail("Should not be modifiable"); //$NON-NLS-1$ } catch (UnsupportedOperationException e) { } }
public void testSetElseExpression() { CaseExpression expr = example(3); expr.setElseExpression(new Constant(new Integer(1000))); assertEquals(new Constant(new Integer(1000)), expr.getElseExpression()); expr.setElseExpression(null); assertNull(expr.getElseExpression()); }
@Test public void testCaseExpression1() { CaseExpression expr = TestCaseExpression.example(4); Select select = new Select(); select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$ select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$ // The parser hard-codes the name "expr" select.addSymbol(expr); //$NON-NLS-1$ From from = new From(); from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$ Query q = new Query(); q.setSelect(select); q.setFrom(from); String query = new StringBuffer("SELECT y, z, ") //$NON-NLS-1$ .append("CASE x") //$NON-NLS-1$ .append(" WHEN 'a' THEN 0") //$NON-NLS-1$ .append(" WHEN 'b' THEN 1") //$NON-NLS-1$ .append(" WHEN 'c' THEN 2") //$NON-NLS-1$ .append(" WHEN 'd' THEN 3") //$NON-NLS-1$ .append(" ELSE 9999") //$NON-NLS-1$ .append(" END") //$NON-NLS-1$ .append(" FROM m.g").toString(); //$NON-NLS-1$ helpTest(query, query, q); }
public void testGetType() { CaseExpression expr = example(4); assertNull(expr.getType()); expr.setType(Integer.class); assertEquals(Integer.class, expr.getType()); }
@Test public void testCaseExpression2() { CaseExpression expr = TestCaseExpression.example(4); expr.setElseExpression(null); Select select = new Select(); select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$ select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$ // The parser hard-codes the name "expr" select.addSymbol(expr); //$NON-NLS-1$ From from = new From(); from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$ Query q = new Query(); q.setSelect(select); q.setFrom(from); String query = new StringBuffer("SELECT y, z, ") //$NON-NLS-1$ .append("CASE x") //$NON-NLS-1$ .append(" WHEN 'a' THEN 0") //$NON-NLS-1$ .append(" WHEN 'b' THEN 1") //$NON-NLS-1$ .append(" WHEN 'c' THEN 2") //$NON-NLS-1$ .append(" WHEN 'd' THEN 3") //$NON-NLS-1$ .append(" END") //$NON-NLS-1$ .append(" FROM m.g").toString(); //$NON-NLS-1$ helpTest(query, query, q); }
@Test public void testCaseExpression1() { CaseExpression expr = TestCaseExpression.example(3); expr.setExpression(new Constant("a")); //$NON-NLS-1$ helpTestEval(expr, null, null, null, null, new Integer(0)); expr.setExpression(new Constant("b")); //$NON-NLS-1$ helpTestEval(expr, null, null, null, null, new Integer(1)); expr.setExpression(new Constant("c")); //$NON-NLS-1$ helpTestEval(expr, null, null, null, null, new Integer(2)); expr.setExpression(new Constant("d")); //$NON-NLS-1$ helpTestEval(expr, null, null, null, null, new Integer(9999)); }
public void testEquals() { CaseExpression sc1 = example(3); assertTrue(sc1.equals(sc1)); assertTrue(sc1.equals(sc1.clone())); assertTrue(sc1.clone().equals(sc1)); assertTrue(sc1.equals(example(3))); CaseExpression sc2 = example(4); assertFalse(sc1.equals(sc2)); assertFalse(sc2.equals(sc1)); CaseExpression sc3 = example(3); sc3.setElseExpression(new ElementSymbol("y")); //$NON-NLS-1$ assertFalse(sc1.equals(sc3)); assertFalse(sc3.equals(sc1)); CaseExpression sc4 = example(3); sc4.setExpression(new ElementSymbol("y")); //$NON-NLS-1$ assertFalse(sc1.equals(sc4)); assertFalse(sc4.equals(sc1)); } }
public void testSetExpression() { CaseExpression caseExpr = example(1); ElementSymbol y = new ElementSymbol("y"); //$NON-NLS-1$ caseExpr.setExpression(y); assertEquals(y, caseExpr.getExpression()); try { caseExpr.setExpression(null); fail("Setting the expression to null should fail."); //$NON-NLS-1$ } catch (IllegalArgumentException e) { // There should be no side-effects of an illegal argument assertEquals(y, caseExpr.getExpression()); } }
public void testSetWhen() { CaseExpression caseExpr = example(4);