Search in sources :

Example 1 with LiteralExpression

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

the class LiteralExpressionTests method testSetValue.

@Test
public void testSetValue() {
    try {
        LiteralExpression lEx = new LiteralExpression("somevalue");
        lEx.setValue(new StandardEvaluationContext(), "flibble");
        fail("Should have got an exception that the value cannot be set");
    } catch (EvaluationException ee) {
        // success, not allowed - whilst here, check the expression value in the exception
        assertEquals(ee.getExpressionString(), "somevalue");
    }
    try {
        LiteralExpression lEx = new LiteralExpression("somevalue");
        lEx.setValue(new Rooty(), "flibble");
        fail("Should have got an exception that the value cannot be set");
    } catch (EvaluationException ee) {
        // success, not allowed - whilst here, check the expression value in the exception
        assertEquals(ee.getExpressionString(), "somevalue");
    }
    try {
        LiteralExpression lEx = new LiteralExpression("somevalue");
        lEx.setValue(new StandardEvaluationContext(), new Rooty(), "flibble");
        fail("Should have got an exception that the value cannot be set");
    } catch (EvaluationException ee) {
        // success, not allowed - whilst here, check the expression value in the exception
        assertEquals(ee.getExpressionString(), "somevalue");
    }
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) LiteralExpression(org.springframework.expression.common.LiteralExpression) EvaluationException(org.springframework.expression.EvaluationException) Test(org.junit.Test)

Example 2 with LiteralExpression

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

the class LiteralExpressionTests method testGetValueType.

@Test
public void testGetValueType() throws Exception {
    LiteralExpression lEx = new LiteralExpression("somevalue");
    assertEquals(String.class, lEx.getValueType());
    assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext()));
    assertEquals(String.class, lEx.getValueType(new Rooty()));
    assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext(), new Rooty()));
    assertEquals(String.class, lEx.getValueTypeDescriptor().getType());
    assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType());
    assertEquals(String.class, lEx.getValueTypeDescriptor(new Rooty()).getType());
    assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType());
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) LiteralExpression(org.springframework.expression.common.LiteralExpression) Test(org.junit.Test)

Example 3 with LiteralExpression

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

the class LiteralExpressionTests method testGetValue.

@Test
public void testGetValue() throws Exception {
    LiteralExpression lEx = new LiteralExpression("somevalue");
    checkString("somevalue", lEx.getValue());
    checkString("somevalue", lEx.getValue(String.class));
    EvaluationContext ctx = new StandardEvaluationContext();
    checkString("somevalue", lEx.getValue(ctx));
    checkString("somevalue", lEx.getValue(ctx, String.class));
    checkString("somevalue", lEx.getValue(new Rooty()));
    checkString("somevalue", lEx.getValue(new Rooty(), String.class));
    checkString("somevalue", lEx.getValue(ctx, new Rooty()));
    checkString("somevalue", lEx.getValue(ctx, new Rooty(), String.class));
    assertEquals("somevalue", lEx.getExpressionString());
    assertFalse(lEx.isWritable(new StandardEvaluationContext()));
    assertFalse(lEx.isWritable(new Rooty()));
    assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty()));
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) LiteralExpression(org.springframework.expression.common.LiteralExpression) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) EvaluationContext(org.springframework.expression.EvaluationContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 LiteralExpression (org.springframework.expression.common.LiteralExpression)3 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)3 EvaluationContext (org.springframework.expression.EvaluationContext)1 EvaluationException (org.springframework.expression.EvaluationException)1