예제 #1
0
  /** Tests how parameter substitution algorithm works on an expression with no parameters. */
  @Test
  public void testInParameter() throws Exception {
    Expression inExp = ExpressionFactory.exp("k1 in $test");
    Expression e1 = ExpressionFactory.exp("k1 in ('a', 'b')");

    Expression transformed =
        inExp.params(Collections.singletonMap("test", new Object[] {"a", "b"}));
    TstTraversalHandler.compareExps(e1, transformed);

    // just in case manually check params
    DataObject o1 = new CayenneDataObject();
    o1.writePropertyDirectly("k1", "a");
    assertTrue(transformed.match(o1));

    DataObject o2 = new CayenneDataObject();
    o2.writePropertyDirectly("k1", "x");
    assertFalse(transformed.match(o2));
  }
예제 #2
0
  @Test
  public void testInParameter_AsValues() throws Exception {
    Expression inExp = ExpressionFactory.exp("k1 in ($ap, $bp)");

    String e1String = "k1 in (\"a\", \"b\")";
    Expression e1 = ExpressionFactory.exp(e1String);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("ap", "a");
    params.put("bp", "b");
    Expression transformed = inExp.params(params);
    TstTraversalHandler.compareExps(e1, transformed);

    assertEquals(e1String, transformed.toString());

    // just in case manually check params
    DataObject o1 = new CayenneDataObject();
    o1.writePropertyDirectly("k1", "a");
    assertTrue(transformed.match(o1));

    DataObject o2 = new CayenneDataObject();
    o2.writePropertyDirectly("k1", "x");
    assertFalse(transformed.match(o2));
  }