Package org.springframework.expression

Examples of org.springframework.expression.EvaluationContext


    assertNull(state.lookupLocalVariable("goo"));
  }

  @Test
  public void testRootObjectConstructor() {
    EvaluationContext ctx = getContext();
    // TypedValue root = ctx.getRootObject();
    // supplied should override root on context
    ExpressionState state = new ExpressionState(ctx,new TypedValue("i am a string"));
    TypedValue stateRoot = state.getRootContextObject();
    assertEquals(String.class,stateRoot.getTypeDescriptor().getType());
View Full Code Here


  /**
   * @return a new ExpressionState
   */
  private ExpressionState getState() {
    EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    ExpressionState state = new ExpressionState(context);
    return state;
  }
View Full Code Here

  }
 
  @Test
  public void operatorVariants() throws Exception {
    SpelExpression expr = (SpelExpression)parser.parseExpression("#a < #b");
    EvaluationContext ctx = new StandardEvaluationContext();
    ctx.setVariable("a", (short)3);
    ctx.setVariable("b", (short)6);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("b", (byte)6);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)9);
    ctx.setVariable("b", (byte)6);
    assertFalse(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", 10L);
    ctx.setVariable("b", (short)30);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)3);
    ctx.setVariable("b", (short)30);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)3);
    ctx.setVariable("b", 30L);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)3);
    ctx.setVariable("b", 30f);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", new BigInteger("10"));
    ctx.setVariable("b", new BigInteger("20"));
    assertTrue(expr.getValue(ctx, Boolean.class));
  }
View Full Code Here

  @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()));
View Full Code Here

    assertEquals(-45, minusFortyFive);
  }

  @Test
  public void testComparison() throws Exception {
    EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    boolean trueValue = parser.parseExpression("T(java.util.Date) == Birthdate.Class").getValue(context,
      Boolean.class);
    assertTrue(trueValue);
  }
View Full Code Here

   * doesn't currently exist in the collection (address.crossStreets[0] below)
   */
  @Test
  public void initializingCollectionElementsOnWrite() throws Exception {
    TestPerson person = new TestPerson();
    EvaluationContext context = new StandardEvaluationContext(person);
    SpelParserConfiguration config = new SpelParserConfiguration(true, true);
    ExpressionParser parser = new SpelExpressionParser(config);
    Expression expression = parser.parseExpression("name");
    expression.setValue(context, "Oleg");
    assertEquals("Oleg", person.getName());
View Full Code Here

    assertNull(nullValue);
  }

  @Test
  public void testPropertyAccess() throws Exception {
    EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    int year = (Integer) parser.parseExpression("Birthdate.Year + 1900").getValue(context); // 1856
    assertEquals(1856,year);

    String city = (String) parser.parseExpression("placeOfBirth.City").getValue(context);
    assertEquals("SmilJan",city);
View Full Code Here

  @Test
  public void testReflectivePropertyResolver() throws Exception {
    ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
    Tester t = new Tester();
    t.setProperty("hello");
    EvaluationContext ctx = new StandardEvaluationContext(t);
    assertTrue(rpr.canRead(ctx, t, "property"));
    assertEquals("hello",rpr.read(ctx, t, "property").getValue());
    assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used

    assertTrue(rpr.canRead(ctx, t, "field"));
View Full Code Here

  @Test
  public void testOptimalReflectivePropertyResolver() throws Exception {
    ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
    Tester t = new Tester();
    t.setProperty("hello");
    EvaluationContext ctx = new StandardEvaluationContext(t);
//    assertTrue(rpr.canRead(ctx, t, "property"));
//    assertEquals("hello",rpr.read(ctx, t, "property").getValue());
//    assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used

    PropertyAccessor optA = rpr.createOptimalAccessor(ctx, t, "property");
View Full Code Here

  }

  @Test
  public void accessingNullPropertyViaReflection_SPR5663() throws AccessException {
    PropertyAccessor propertyAccessor = new ReflectivePropertyAccessor();
    EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    assertFalse(propertyAccessor.canRead(context, null, "abc"));
    assertFalse(propertyAccessor.canWrite(context, null, "abc"));
    try {
      propertyAccessor.read(context, null, "abc");
      fail("Should have failed with an AccessException");
View Full Code Here

TOP

Related Classes of org.springframework.expression.EvaluationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.