Search in sources :

Example 96 with Expression

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

the class SpelCompilationPerformanceTests method compilingPropertyReferenceNestedMixedFieldGetter.

@Test
public void compilingPropertyReferenceNestedMixedFieldGetter() throws Exception {
    long interpretedTotal = 0, compiledTotal = 0, stime, etime;
    String interpretedResult = null, compiledResult = null;
    TestClass2 testdata = new TestClass2();
    Expression expression = parser.parseExpression("foo.baz.boo");
    // warmup
    for (int i = 0; i < count; i++) {
        expression.getValue(testdata, String.class);
    }
    log("timing interpreted: ");
    for (int i = 0; i < iterations; i++) {
        stime = System.currentTimeMillis();
        for (int j = 0; j < count; j++) {
            interpretedResult = expression.getValue(testdata, String.class);
        }
        etime = System.currentTimeMillis();
        long interpretedSpeed = (etime - stime);
        interpretedTotal += interpretedSpeed;
        log(interpretedSpeed + "ms ");
    }
    logln();
    compile(expression);
    log("timing compiled: ");
    expression.getValue(testdata, String.class);
    for (int i = 0; i < iterations; i++) {
        stime = System.currentTimeMillis();
        for (int j = 0; j < count; j++) {
            compiledResult = expression.getValue(testdata, String.class);
        }
        etime = System.currentTimeMillis();
        long compiledSpeed = (etime - stime);
        compiledTotal += compiledSpeed;
        log(compiledSpeed + "ms ");
    }
    logln();
    assertEquals(interpretedResult, compiledResult);
    reportPerformance("nested property reference (mixed field/getter)", interpretedTotal, compiledTotal);
}
Also used : Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 97 with Expression

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

the class SpelCompilationPerformanceTests method compilingPropertyReferenceField.

@Test
public void compilingPropertyReferenceField() throws Exception {
    long interpretedTotal = 0, compiledTotal = 0, stime, etime;
    String interpretedResult = null, compiledResult = null;
    TestClass2 testdata = new TestClass2();
    Expression expression = parser.parseExpression("name");
    // warmup
    for (int i = 0; i < count; i++) {
        expression.getValue(testdata, String.class);
    }
    log("timing interpreted: ");
    for (int i = 0; i < iterations; i++) {
        stime = System.currentTimeMillis();
        for (int j = 0; j < count; j++) {
            interpretedResult = expression.getValue(testdata, String.class);
        }
        etime = System.currentTimeMillis();
        long interpretedSpeed = (etime - stime);
        interpretedTotal += interpretedSpeed;
        log(interpretedSpeed + "ms ");
    }
    logln();
    compile(expression);
    log("timing compiled: ");
    expression.getValue(testdata, String.class);
    for (int i = 0; i < iterations; i++) {
        stime = System.currentTimeMillis();
        for (int j = 0; j < count; j++) {
            compiledResult = expression.getValue(testdata, String.class);
        }
        etime = System.currentTimeMillis();
        long compiledSpeed = (etime - stime);
        compiledTotal += compiledSpeed;
        log(compiledSpeed + "ms ");
    }
    logln();
    assertEquals(interpretedResult, compiledResult);
    reportPerformance("property reference (field)", interpretedTotal, compiledTotal);
}
Also used : Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 98 with Expression

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

the class SpelReproTests method SPR10328.

@Test
public void SPR10328() throws Exception {
    thrown.expect(SpelParseException.class);
    thrown.expectMessage("EL1071E: A required selection expression has not been specified");
    Expression exp = parser.parseExpression("$[]");
    exp.getValue(Arrays.asList("foo", "bar", "baz"));
}
Also used : SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 99 with Expression

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

the class SpelReproTests method SPR9486_floatEqFloat.

@Test
public void SPR9486_floatEqFloat() {
    Boolean expectedResult = 10.215f == 10.2109f;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.215f == 10.2109f");
    Boolean result = expression.getValue(context, null, Boolean.class);
    assertEquals(expectedResult, result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 100 with Expression

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

the class SpelReproTests method SPR10210.

@Test
public void SPR10210() throws Exception {
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setVariable("bridgeExample", new org.springframework.expression.spel.spr10210.D());
    Expression parseExpression = parser.parseExpression("#bridgeExample.bridgeMethod()");
    parseExpression.getValue(context);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Aggregations

Expression (org.springframework.expression.Expression)288 Test (org.junit.Test)228 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)172 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)155 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)114 ExpressionParser (org.springframework.expression.ExpressionParser)76 EvaluationContext (org.springframework.expression.EvaluationContext)52 ArrayList (java.util.ArrayList)32 CompoundExpression (org.springframework.expression.spel.ast.CompoundExpression)18 HashMap (java.util.HashMap)17 EvaluationException (org.springframework.expression.EvaluationException)17 Authentication (org.springframework.security.core.Authentication)16 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)14 List (java.util.List)13 Map (java.util.Map)13 ParseException (org.springframework.expression.ParseException)11 LinkedHashMap (java.util.LinkedHashMap)10 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)10 MethodInvocation (org.aopalliance.intercept.MethodInvocation)9 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)9