Beispiel #1
0
  @Test
  public void testEmbeddedExpressionsAndQuotes() {
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("x", "abc");
    attributes.put("a", "abc");

    verifyEquals("${x:equals(${a})}", attributes, true);

    Query.validateExpression("${x:equals('${a}')}", false);
    assertEquals("true", Query.evaluateExpressions("${x:equals('${a}')}", attributes, null));

    Query.validateExpression("${x:equals(\"${a}\")}", false);
    assertEquals("true", Query.evaluateExpressions("${x:equals(\"${a}\")}", attributes, null));
  }
Beispiel #2
0
 @Test
 public void testNewLinesAndTabsInQuery() {
   final String query = "${ abc:equals('abc'):or( \n\t${xx:isNull()}\n) }";
   assertEquals(ResultType.BOOLEAN, Query.getResultType(query));
   Query.validateExpression(query, false);
   assertEquals("true", Query.evaluateExpressions(query));
 }
Beispiel #3
0
  @Test
  public void testIsValidExpression() {
    Query.validateExpression("${abc:substring(${xyz:length()})}", false);
    Query.isValidExpression("${now():format('yyyy-MM-dd')}");

    try {
      Query.validateExpression("$${attr}", false);
      Assert.fail("invalid query validated");
    } catch (final AttributeExpressionLanguageParsingException e) {
    }

    Query.validateExpression("$${attr}", true);

    Query.validateExpression(
        "${filename:startsWith('T8MTXBC')\n"
            + ":or( ${filename:startsWith('C4QXABC')} )\n"
            + ":or( ${filename:startsWith('U6CXEBC')} )"
            + ":or( ${filename:startsWith('KYM3ABC')} )}",
        false);
  }
Beispiel #4
0
  @Test
  public void testCompileEmbedded() {
    final String expression = "${x:equals( ${y} )}";
    final Query query = Query.compile(expression);
    final Tree tree = query.getTree();
    System.out.println(printTree(tree));

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("x", "x");
    attributes.put("y", "x");
    final String result = Query.evaluateExpressions(expression, attributes, null);
    assertEquals("true", result);

    Query.validateExpression(expression, false);
  }
Beispiel #5
0
  private void verifyEquals(
      final String expression, final Map<String, String> attributes, final Object expectedResult) {
    Query.validateExpression(expression, false);
    assertEquals(
        String.valueOf(expectedResult), Query.evaluateExpressions(expression, attributes, null));

    Query query = Query.compile(expression);
    QueryResult<?> result = query.evaluate(attributes);

    if (expectedResult instanceof Number) {
      assertEquals(ResultType.NUMBER, result.getResultType());
    } else if (expectedResult instanceof Boolean) {
      assertEquals(ResultType.BOOLEAN, result.getResultType());
    } else {
      assertEquals(ResultType.STRING, result.getResultType());
    }

    assertEquals(expectedResult, result.getValue());
  }