org.springframework.expression.spel.standard.SpelCompiler Java Examples

The following examples show how to use org.springframework.expression.spel.standard.SpelCompiler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpelCompilationCoverageTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void booleanLiteral() throws Exception {
	expression = parser.parseExpression("true");
	boolean resultI = expression.getValue(1,Boolean.TYPE);
	assertEquals(true,resultI);
	assertTrue(SpelCompiler.compile(expression));
	boolean resultC = expression.getValue(1,Boolean.TYPE);
	assertEquals(true,resultC);

	expression = parser.parseExpression("false");
	resultI = expression.getValue(1,Boolean.TYPE);
	assertEquals(false,resultI);
	assertTrue(SpelCompiler.compile(expression));
	resultC = expression.getValue(1,Boolean.TYPE);
	assertEquals(false,resultC);
}
 
Example #2
Source File: MapAccessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void mapAccessorCompilable() {
	Map<String, Object> testMap = getSimpleTestMap();
	StandardEvaluationContext sec = new StandardEvaluationContext();
	sec.addPropertyAccessor(new MapAccessor());
	SpelExpressionParser sep = new SpelExpressionParser();

	// basic
	Expression ex = sep.parseExpression("foo");
	assertEquals("bar",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("bar",ex.getValue(sec,testMap));

	// compound expression
	ex = sep.parseExpression("foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("BAR",ex.getValue(sec,testMap));

	// nested map
	Map<String,Map<String,Object>> nestedMap = getNestedTestMap();
	ex = sep.parseExpression("aaa.foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,nestedMap));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("BAR",ex.getValue(sec,nestedMap));

	// avoiding inserting checkcast because first part of expression returns a Map
	ex = sep.parseExpression("getMap().foo");
	MapGetter mapGetter = new MapGetter();
	assertEquals("bar",ex.getValue(sec,mapGetter));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("bar",ex.getValue(sec,mapGetter));
}
 
Example #3
Source File: MapAccessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void mapAccessorCompilable() {
	Map<String, Object> testMap = getSimpleTestMap();
	StandardEvaluationContext sec = new StandardEvaluationContext();
	sec.addPropertyAccessor(new MapAccessor());
	SpelExpressionParser sep = new SpelExpressionParser();

	// basic
	Expression ex = sep.parseExpression("foo");
	assertEquals("bar",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("bar",ex.getValue(sec,testMap));

	// compound expression
	ex = sep.parseExpression("foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("BAR",ex.getValue(sec,testMap));

	// nested map
	Map<String,Map<String,Object>> nestedMap = getNestedTestMap();
	ex = sep.parseExpression("aaa.foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,nestedMap));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("BAR",ex.getValue(sec,nestedMap));

	// avoiding inserting checkcast because first part of expression returns a Map
	ex = sep.parseExpression("getMap().foo");
	MapGetter mapGetter = new MapGetter();
	assertEquals("bar",ex.getValue(sec,mapGetter));
	assertTrue(SpelCompiler.compile(ex));
	assertEquals("bar",ex.getValue(sec,mapGetter));
}
 
Example #4
Source File: MapAccessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void mapAccessorCompilable() {
	Map<String, Object> testMap = getSimpleTestMap();
	StandardEvaluationContext sec = new StandardEvaluationContext();		
	sec.addPropertyAccessor(new MapAccessor());
	SpelExpressionParser sep = new SpelExpressionParser();
	
	// basic
	Expression ex = sep.parseExpression("foo");
	assertEquals("bar",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("bar",ex.getValue(sec,testMap));

	// compound expression
	ex = sep.parseExpression("foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,testMap));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("BAR",ex.getValue(sec,testMap));
	
	// nested map
	Map<String,Map<String,Object>> nestedMap = getNestedTestMap();
	ex = sep.parseExpression("aaa.foo.toUpperCase()");
	assertEquals("BAR",ex.getValue(sec,nestedMap));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("BAR",ex.getValue(sec,nestedMap));
	
	// avoiding inserting checkcast because first part of expression returns a Map
	ex = sep.parseExpression("getMap().foo");
	MapGetter mapGetter = new MapGetter();
	assertEquals("bar",ex.getValue(sec,mapGetter));
	assertTrue(SpelCompiler.compile(ex));		
	assertEquals("bar",ex.getValue(sec,mapGetter));
}
 
Example #5
Source File: SpelCompilationPerformanceTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void compile(Expression expression) {
	assertTrue(SpelCompiler.compile(expression));
}
 
Example #6
Source File: SpelCompilationPerformanceTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void compile(Expression expression) {
	assertTrue(SpelCompiler.compile(expression));
}
 
Example #7
Source File: SpelCompilationPerformanceTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void compile(Expression expression) {
	assertTrue(SpelCompiler.compile(expression));
}
 
Example #8
Source File: SpelCompilationCoverageTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void assertCanCompile(Expression expression) {
	assertTrue(SpelCompiler.compile(expression));
}
 
Example #9
Source File: SpelCompilationCoverageTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void assertCantCompile(Expression expression) {
	assertFalse(SpelCompiler.compile(expression));
}