/** * Call setValue() but expect it to fail. */ protected void setValueExpectError(String expression, Object value) { try { Expression e = parser.parseExpression(expression); if (e == null) { fail("Parser returned null for expression"); } if (DEBUG) { SpelUtilities.printAbstractSyntaxTree(System.out, e); } StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext(); e.setValue(lContext, value); fail("expected an error"); } catch (ParseException pe) { pe.printStackTrace(); fail("Unexpected Exception: " + pe.getMessage()); } catch (EvaluationException ee) { // success! } }
/** * Parse the supplied expression and then create a string representation of the resultant AST, it should be the * expected value. * * @param expression the expression to parse * @param expectedStringFormOfAST the expected string form of the AST */ public void parseCheck(String expression, String expectedStringFormOfAST) { try { SpelExpression e = parser.parseRaw(expression); if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) { SpelUtilities.printAbstractSyntaxTree(System.err, e); } if (e == null) { fail("Parsed exception was null"); } assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST()); } catch (ParseException ee) { ee.printStackTrace(); fail("Unexpected Exception: " + ee.getMessage()); } }
/** * check filter and generate more friendly message than CT normally does * * @param partitionFilter */ private void checkSpelFilter(String partitionFilter) { LOG.info("Located partition filter expression: {}", partitionFilter); try { expressionParser.parse(partitionFilter); } catch (ParseException e) { System.out.println("WARNING: There was a problem parsing your expression. Check above to see what was " + "resolved from the YML file to see if it is what you expect."); System.out.println("Perhaps you are inadvertently creating a YAML comment with '#{ #'?"); e.printStackTrace(System.out); return; } } }
/** * check filter and generate more friendly message than CT normally does * * @param partitionFilter */ private void checkSpelFilter(String partitionFilter) { LOG.info("Located partition filter expression: {}", partitionFilter); try { expressionParser.parse(partitionFilter); } catch (ParseException e) { System.out.println("WARNING: There was a problem parsing your expression. Check above to see what was " + "resolved from the YML file to see if it is what you expect."); System.out.println("Perhaps you are inadvertently creating a YAML comment with '#{ #'?"); e.printStackTrace(System.out); return; } } }