Tabnine Logo
SpelExpressionParser.parseExpression
Code IndexAdd Tabnine to your IDE (free)

How to use
parseExpression
method
in
org.springframework.expression.spel.standard.SpelExpressionParser

Best Java code snippets using org.springframework.expression.spel.standard.SpelExpressionParser.parseExpression (Showing top 20 results out of 1,188)

origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
@Test
public void testListsOfMap() {
  listOfMapsNotGeneric = new ArrayList();
  Map map = new HashMap();
  map.put("fruit", "apple");
  listOfMapsNotGeneric.add(map);
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("listOfMapsNotGeneric[0]['fruit']");
  assertEquals("apple", expression.getValue(this, String.class));
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
@Test
public void testListOfScalar() {
  listOfScalarNotGeneric = new ArrayList(1);
  listOfScalarNotGeneric.add("5");
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("listOfScalarNotGeneric[0]");
  assertEquals(new Integer(5), expression.getValue(this, Integer.class));
}
origin: spring-projects/spring-framework

@Test
public void SPR10486() {
  SpelExpressionParser parser = new SpelExpressionParser();
  StandardEvaluationContext context = new StandardEvaluationContext();
  Spr10486 rootObject = new Spr10486();
  Expression classNameExpression = parser.parseExpression("class.name");
  Expression nameExpression = parser.parseExpression("name");
  assertThat(classNameExpression.getValue(context, rootObject), equalTo((Object) Spr10486.class.getName()));
  assertThat(nameExpression.getValue(context, rootObject), equalTo((Object) "name"));
}
origin: spring-projects/spring-framework

@Test
public void testParsingSimpleTemplateExpression02() throws Exception {
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expr = parser.parseExpression("hello ${'to'} you", DEFAULT_TEMPLATE_PARSER_CONTEXT);
  Object o = expr.getValue();
  assertEquals("hello to you", o.toString());
}
origin: spring-projects/spring-framework

@Test
public void testParsingSimpleTemplateExpression01() throws Exception {
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expr = parser.parseExpression("hello ${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
  Object o = expr.getValue();
  assertEquals("hello world", o.toString());
}
origin: spring-projects/spring-framework

@Test
public void props() {
  Properties props = new Properties();
  props.setProperty("x", "1");
  props.setProperty("y", "2");
  props.setProperty("z", "3");
  Expression expression = parser.parseExpression("foo(#props)");
  StandardEvaluationContext context = new StandardEvaluationContext();
  context.setVariable("props", props);
  String result = expression.getValue(context, new TestBean(), String.class);
  assertEquals("123", result);
}
origin: spring-projects/spring-framework

@Test
public void indexIntoGenericPropertyContainingList() {
  List<String> property = new ArrayList<>();
  property.add("bar");
  this.property = property;
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("property");
  assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
  assertEquals(property, expression.getValue(this));
  expression = parser.parseExpression("property[0]");
  assertEquals("bar", expression.getValue(this));
}
origin: spring-projects/spring-framework

@Test
public void withReturnValue() {
  EvaluationContext context = createEvaluationContext("theResult");
  Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
  assertThat(value, equalTo("theResult"));
}
origin: spring-projects/spring-framework

@Test
public void withNullReturn() {
  EvaluationContext context = createEvaluationContext(null);
  Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
  assertThat(value, nullValue());
}
origin: spring-projects/spring-framework

@Test
public void withoutReturnValue() {
  EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT);
  Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
  assertThat(value, nullValue());
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
@Test
public void resolveMapKeyValueTypes() {
  mapNotGeneric = new HashMap();
  mapNotGeneric.put("baseAmount", 3.11);
  mapNotGeneric.put("bonusAmount", 7.17);
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("mapNotGeneric");
  assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(this).toString());
}
origin: spring-projects/spring-framework

@Test
public void SPR12502() {
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("#root.getClass().getName()");
  assertEquals(UnnamedUser.class.getName(), expression.getValue(new UnnamedUser()));
  assertEquals(NamedUser.class.getName(), expression.getValue(new NamedUser()));
}
origin: spring-projects/spring-framework

@Test
public void indexIntoGenericPropertyContainingArray() {
  String[] property = new String[] { "bar" };
  this.property = property;
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("property");
  assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.String[]", expression.getValueTypeDescriptor(this).toString());
  assertEquals(property, expression.getValue(this));
  expression = parser.parseExpression("property[0]");
  assertEquals("bar", expression.getValue(this));
}
origin: spring-projects/spring-framework

@Test
public void SPR12803() {
  StandardEvaluationContext sec = new StandardEvaluationContext();
  sec.setVariable("iterable", Collections.emptyList());
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("T(org.springframework.expression.spel.SpelReproTests.FooLists).newArrayList(#iterable)");
  assertTrue(expression.getValue(sec) instanceof ArrayList);
}
origin: spring-projects/spring-framework

@Test
public void resolveBeanReference() {
  StaticApplicationContext applicationContext = new StaticApplicationContext();
  BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
  applicationContext.registerBeanDefinition("myBean", beanDefinition);
  applicationContext.refresh();
  EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT, applicationContext);
  Object value = new SpelExpressionParser().parseExpression("@myBean.class.getName()").getValue(context);
  assertThat(value, is(String.class.getName()));
}
origin: spring-projects/spring-framework

@Test
public void setPropertyContainingMapAutoGrow() {
  SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, false));
  Expression expression = parser.parseExpression("parameterizedMap");
  assertEquals("java.util.Map<java.lang.Integer, java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
  assertEquals(property, expression.getValue(this));
  expression = parser.parseExpression("parameterizedMap['9']");
  assertEquals(null, expression.getValue(this));
  expression.setValue(this, "37");
  assertEquals(37, expression.getValue(this));
}
origin: spring-projects/spring-framework

@Test
public void shouldAlwaysUsePropertyAccessorFromEvaluationContext() {
  SpelExpressionParser parser = new SpelExpressionParser();
  Expression expression = parser.parseExpression("name");
  StandardEvaluationContext context = new StandardEvaluationContext();
  context.addPropertyAccessor(new ConfigurablePropertyAccessor(Collections.singletonMap("name", "Ollie")));
  assertEquals("Ollie", expression.getValue(context));
  context = new StandardEvaluationContext();
  context.addPropertyAccessor(new ConfigurablePropertyAccessor(Collections.singletonMap("name", "Jens")));
  assertEquals("Jens", expression.getValue(context));
}
origin: spring-projects/spring-framework

@Test
public void SPR11142() {
  SpelExpressionParser parser = new SpelExpressionParser();
  StandardEvaluationContext context = new StandardEvaluationContext();
  Spr11142 rootObject = new Spr11142();
  Expression expression = parser.parseExpression("something");
  thrown.expect(SpelEvaluationException.class);
  thrown.expectMessage("'something' cannot be found");
  expression.getValue(context, rootObject);
}
origin: spring-projects/spring-framework

@Test
public void unavailableReturnValue() {
  EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.RESULT_UNAVAILABLE);
  try {
    new SpelExpressionParser().parseExpression("#result").getValue(context);
    fail("Should have failed to parse expression, result not available");
  }
  catch (VariableNotAvailableException e) {
    assertEquals("wrong variable name", "result", e.getName());
  }
}
origin: spring-projects/spring-framework

@Test
public void testRogueTrailingDotCausesNPE_SPR6866() {
  try {
    new SpelExpressionParser().parseExpression("placeOfBirth.foo.");
    fail("Should have failed to parse");
  }
  catch (SpelParseException ex) {
    assertEquals(SpelMessage.OOD, ex.getMessageCode());
    assertEquals(16, ex.getPosition());
  }
}
org.springframework.expression.spel.standardSpelExpressionParserparseExpression

Popular methods of SpelExpressionParser

  • <init>
    Create a parser with the specified configuration.
  • parseRaw
  • doParseExpression

Popular in Java

  • Making http requests using okhttp
  • setContentView (Activity)
  • getSystemService (Context)
  • getSharedPreferences (Context)
  • Kernel (java.awt.image)
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • JComboBox (javax.swing)
  • JFrame (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now