Examples of StandardEvaluationContext


Examples of org.springframework.expression.spel.support.StandardEvaluationContext

import org.springframework.expression.spel.support.StandardEvaluationContext;

public class SPELTest {
  @Test
  public void test() {
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setRootObject(new Object());
    context.addMethodResolver(new ConditionEvalMethodResolver());
    ExpressionParser parser = new SpelExpressionParser();

    Expression exp = parser.parseExpression("test('test') or paet(true)");
    System.out.println(exp.getValue(context));
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

  public MapExpressionMethods(EvaluationContext evaluationContext) {
    if (evaluationContext instanceof StandardEvaluationContext) {
      // we were given a context, so don't register anything
      context = (StandardEvaluationContext) evaluationContext;
    } else {
      context = new StandardEvaluationContext();
      context.addMethodResolver(new PartitionKeyMethodResolver());
      context.addPropertyAccessor(new MapAccessor());
    }
  }
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

    Message<String> message = MessageBuilder.withPayload("jee").copyHeaders(headers).build();
    String nowYYYYMM = new SimpleDateFormat("yyyy/MM").format(new Date());
    String nowYYYY = new SimpleDateFormat("yyyy").format(new Date());

    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    MessagePartitionKeyMethodResolver resolver = new MessagePartitionKeyMethodResolver();
    MessagePartitionKeyPropertyAccessor accessor = new MessagePartitionKeyPropertyAccessor();
    context.addMethodResolver(resolver);
    context.addPropertyAccessor(accessor);

    assertThat(parser.parseExpression("dateFormat('yyyy/MM')").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("dateFormat('yyyy/MM', headers[timestamp])").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("dateFormat('yyyy/MM', timestamp)").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("dateFormat('yyyy/MM', T(java.lang.System).currentTimeMillis())").getValue(context, message, String.class), is(nowYYYYMM));
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

  @Test
  public void testPerfWithResolverAndAccessor() {
    Message<String> message = MessageBuilder.withPayload("jee").build();

    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    PartitionKeyMethodResolver resolver = new PartitionKeyMethodResolver();
    MessagePartitionKeyPropertyAccessor accessor = new MessagePartitionKeyPropertyAccessor();
    context.addMethodResolver(resolver);
    context.addPropertyAccessor(accessor);

    Expression expression1 = parser.parseExpression("payload");
    Expression expression2 = parser.parseExpression("timestamp");
    for (int i = 0; i<1000000; i++) {
      expression1.getValue(context, message, String.class);
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

  @Test
  public void testPerfWithNativeSpel() {
    Message<String> message = MessageBuilder.withPayload("jee").build();

    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();

    Expression expression1 = parser.parseExpression("payload");
    Expression expression2 = parser.parseExpression("headers.timestamp");
    for (int i = 0; i<1000000; i++) {
      expression1.getValue(context, message, String.class);
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

  public MessageExpressionMethods(EvaluationContext evaluationContext) {
    if (evaluationContext instanceof StandardEvaluationContext) {
      // we were given a context, so don't register anything
      context = (StandardEvaluationContext) evaluationContext;
    } else {
      context = new StandardEvaluationContext();
      context.addMethodResolver(new MessagePartitionKeyMethodResolver());
      context.addPropertyAccessor(new MessagePartitionKeyPropertyAccessor());
    }
  }
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

*/
public class HashMethodExecutorTests {

  @Test
  public void testPositiveValues() throws Exception {
    StandardEvaluationContext context = new StandardEvaluationContext();
    HashMethodExecutor executor = new HashMethodExecutor();
    TypedValue value = executor.execute(context, new Object(), 3, 2);
    assertThat((String) value.getValue(), is("1_hash"));
    value = executor.execute(context, new Object(), 4, 2);
    assertThat((String) value.getValue(), is("0_hash"));
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

    assertThat((String) value.getValue(), is("8_hash"));
  }

  @Test
  public void testNegativeValues() throws Exception {
    StandardEvaluationContext context = new StandardEvaluationContext();
    HashMethodExecutor executor = new HashMethodExecutor();
    TypedValue value = executor.execute(context, new Object(), -3, -2);
    assertThat((String) value.getValue(), is("1_hash"));
  }
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

    assertThat((String) value.getValue(), is("1_hash"));
  }

  @Test
  public void testEqualValues() throws Exception {
    StandardEvaluationContext context = new StandardEvaluationContext();
    HashMethodExecutor executor = new HashMethodExecutor();
    TypedValue value = executor.execute(context, new Object(), -3, -3);
    assertThat((String) value.getValue(), is("0_hash"));
    value = executor.execute(context, new Object(), -1, -1);
    assertThat((String) value.getValue(), is("0_hash"));
View Full Code Here

Examples of org.springframework.expression.spel.support.StandardEvaluationContext

    assertThat((String) value.getValue(), is("0_hash"));
  }

  @Test(expected=AccessException.class)
  public void testZeros() throws Exception {
    StandardEvaluationContext context = new StandardEvaluationContext();
    HashMethodExecutor executor = new HashMethodExecutor();
    executor.execute(context, new Object(), 0, 0);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.