Ejemplo n.º 1
0
  @Test
  public void testNoParams2() throws Exception {
    List list = new ArrayList();
    list.add(ExpressionFactory.matchExp("k1", new ExpressionParameter("test1")));
    list.add(ExpressionFactory.matchExp("k2", new ExpressionParameter("test2")));
    list.add(ExpressionFactory.matchExp("k3", new ExpressionParameter("test3")));
    list.add(ExpressionFactory.matchExp("k4", new ExpressionParameter("test4")));
    Expression e1 = ExpressionFactory.or(list);

    Map params = new HashMap();
    params.put("test2", "abc");
    params.put("test3", "xyz");
    Expression e2 = e1.params(params);

    // some expression nodes must be pruned
    assertNotNull(e2);

    assertEquals(2, e2.getOperandCount());

    Expression k2 = (Expression) e2.getOperand(0);
    assertEquals("abc", k2.getOperand(1));

    Expression k3 = (Expression) e2.getOperand(1);
    assertEquals("xyz", k3.getOperand(1));
  }
 public EnterExpression(Expression expression, int operand) {
   if (expression.isTerminal()) {
     finalExpression = expression.repeat(expression.getOperand());
     finalOperand = expression.getOperand();
   } else {
     finalExpression = expression.repeat(operand);
     finalOperand = operand;
   }
 }
Ejemplo n.º 3
0
  @Test
  public void testNoParams3_FromString() {
    Expression e1 =
        ExpressionFactory.exp("k1 = $test1 or k2 = $test2 or k3 = $test3 or k4 = $test4");

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("test4", "123");
    Expression e2 = e1.params(params);

    // some expression nodes must be pruned
    assertNotNull(e2);
    assertEquals(2, e2.getOperandCount());
    assertEquals("123", e2.getOperand(1));
    assertEquals("k4", ((Expression) e2.getOperand(0)).getOperand(0));
  }
Ejemplo n.º 4
0
  @Test
  public void testParams2_FromString() {
    Expression e1 = ExpressionFactory.exp("k1 like $test");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("test", "xyz");
    Expression e2 = e1.params(map, false);
    assertNotNull(e2);
    assertEquals(2, e2.getOperandCount());
    assertEquals(Expression.LIKE, e2.getType());
    assertEquals("xyz", e2.getOperand(1));
  }
Ejemplo n.º 5
0
  @Test
  public void testNoParams3() throws Exception {
    List list = new ArrayList();
    list.add(ExpressionFactory.matchExp("k1", new ExpressionParameter("test1")));
    list.add(ExpressionFactory.matchExp("k2", new ExpressionParameter("test2")));
    list.add(ExpressionFactory.matchExp("k3", new ExpressionParameter("test3")));
    list.add(ExpressionFactory.matchExp("k4", new ExpressionParameter("test4")));
    Expression e1 = ExpressionFactory.joinExp(Expression.OR, list);

    Map params = new HashMap();
    params.put("test4", "123");
    Expression e2 = e1.params(params, true);

    // some expression nodes must be pruned
    assertNotNull(e2);
    assertTrue("List expression: " + e2, !(e2 instanceof ASTList));

    assertEquals(2, e2.getOperandCount());
    assertEquals("123", e2.getOperand(1));
    assertEquals("k4", ((Expression) e2.getOperand(0)).getOperand(0));
  }
Ejemplo n.º 6
0
  @Test
  public void testParams2() throws Exception {
    Expression e1 = ExpressionFactory.likeExp("k1", new ExpressionParameter("test"));

    Map map = new HashMap();
    map.put("test", "xyz");
    Expression e2 = e1.params(map, false);
    assertNotNull(e2);
    assertEquals(2, e2.getOperandCount());
    assertEquals(Expression.LIKE, e2.getType());
    assertEquals("xyz", e2.getOperand(1));
  }