Search in sources :

Example 1 with ExpressionException

use of org.springframework.expression.ExpressionException in project spring-framework by spring-projects.

the class SpelReproTests method checkTemplateParsingError.

private void checkTemplateParsingError(String expression, ParserContext context, String expectedMessage) throws Exception {
    SpelExpressionParser parser = new SpelExpressionParser();
    try {
        parser.parseExpression(expression, context);
        fail("Should have failed with message: " + expectedMessage);
    } catch (Exception ex) {
        String message = ex.getMessage();
        if (ex instanceof ExpressionException) {
            message = ((ExpressionException) ex).getSimpleMessage();
        }
        if (!message.equals(expectedMessage)) {
            ex.printStackTrace();
        }
        assertThat(expectedMessage, equalTo(message));
    }
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) ExpressionException(org.springframework.expression.ExpressionException) EvaluationException(org.springframework.expression.EvaluationException) ExpectedException(org.junit.rules.ExpectedException) AccessException(org.springframework.expression.AccessException) ExpressionException(org.springframework.expression.ExpressionException)

Example 2 with ExpressionException

use of org.springframework.expression.ExpressionException in project spring-framework by spring-projects.

the class SpelParserTests method exceptions.

@Test
public void exceptions() {
    ExpressionException exprEx = new ExpressionException("test");
    assertEquals("test", exprEx.getSimpleMessage());
    assertEquals("test", exprEx.toDetailedString());
    assertEquals("test", exprEx.getMessage());
    exprEx = new ExpressionException("wibble", "test");
    assertEquals("test", exprEx.getSimpleMessage());
    assertEquals("Expression [wibble]: test", exprEx.toDetailedString());
    assertEquals("Expression [wibble]: test", exprEx.getMessage());
    exprEx = new ExpressionException("wibble", 3, "test");
    assertEquals("test", exprEx.getSimpleMessage());
    assertEquals("Expression [wibble] @3: test", exprEx.toDetailedString());
    assertEquals("Expression [wibble] @3: test", exprEx.getMessage());
}
Also used : ExpressionException(org.springframework.expression.ExpressionException) Test(org.junit.Test)

Aggregations

ExpressionException (org.springframework.expression.ExpressionException)2 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 AccessException (org.springframework.expression.AccessException)1 EvaluationException (org.springframework.expression.EvaluationException)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1