Java Code Examples for org.springframework.expression.spel.standard.SpelExpression#getValue()

The following examples show how to use org.springframework.expression.spel.standard.SpelExpression#getValue() . 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: SpelReproTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_1() {
	StandardEvaluationContext context = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ls.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(context);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example 2
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void greaterThanWithNulls_SPR7840() throws Exception {
	List<D> list = new ArrayList<D>();
	list.add(new D("aaa"));
	list.add(new D("bbb"));
	list.add(new D(null));
	list.add(new D("ccc"));
	list.add(new D(null));
	list.add(new D("zzz"));

	StandardEvaluationContext ctx = new StandardEvaluationContext(list);
	SpelExpressionParser parser = new SpelExpressionParser();

	String el1 = "#root.?[a < 'hhh']";
	SpelExpression exp = parser.parseRaw(el1);
	Object value = exp.getValue(ctx);
	assertEquals("[D(aaa), D(bbb), D(null), D(ccc), D(null)]", value.toString());

	String el2 = "#root.?[a > 'hhh']";
	SpelExpression exp2 = parser.parseRaw(el2);
	Object value2 = exp2.getValue(ctx);
	assertEquals("[D(zzz)]", value2.toString());

	// trim out the nulls first
	String el3 = "#root.?[a!=null].?[a < 'hhh']";
	SpelExpression exp3 = parser.parseRaw(el3);
	Object value3 = exp3.getValue(ctx);
	assertEquals("[D(aaa), D(bbb), D(ccc)]", value3.toString());
}
 
Example 3
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_3() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ms.![key.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(ctx);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example 4
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_2() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "as.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	Object[] value = (Object[]) exp.getValue(ctx);
	// value is array containing [true,false]
	assertEquals(Boolean.class, value[0].getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
	assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
 
Example 5
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_1() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ls.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(ctx);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example 6
Source File: EvaluationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructorInvocation06() throws Exception {
	// repeated evaluation to drive use of cached executor
	SpelExpression expr = (SpelExpression) parser.parseExpression("new String('wibble')");
	String newString = expr.getValue(String.class);
	assertEquals("wibble", newString);
	newString = expr.getValue(String.class);
	assertEquals("wibble", newString);

	// not writable
	assertFalse(expr.isWritable(new StandardEvaluationContext()));

	// ast
	assertEquals("new String('wibble')", expr.toStringAST());
}
 
Example 7
Source File: SpelReproTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void reservedWordProperties_SPR9862() {
	StandardEvaluationContext context = new StandardEvaluationContext();
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
	Object value = expression.getValue(context);
	assertEquals(value, Reserver.CONST);
}
 
Example 8
Source File: SpelReproTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void greaterThanWithNulls_SPR7840() {
	List<D> list = new ArrayList<>();
	list.add(new D("aaa"));
	list.add(new D("bbb"));
	list.add(new D(null));
	list.add(new D("ccc"));
	list.add(new D(null));
	list.add(new D("zzz"));

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

	String el1 = "#root.?[a < 'hhh']";
	SpelExpression exp = parser.parseRaw(el1);
	Object value = exp.getValue(context);
	assertEquals("[D(aaa), D(bbb), D(null), D(ccc), D(null)]", value.toString());

	String el2 = "#root.?[a > 'hhh']";
	SpelExpression exp2 = parser.parseRaw(el2);
	Object value2 = exp2.getValue(context);
	assertEquals("[D(zzz)]", value2.toString());

	// trim out the nulls first
	String el3 = "#root.?[a!=null].?[a < 'hhh']";
	SpelExpression exp3 = parser.parseRaw(el3);
	Object value3 = exp3.getValue(context);
	assertEquals("[D(aaa), D(bbb), D(ccc)]", value3.toString());
}
 
Example 9
Source File: SpelReproTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_3() {
	StandardEvaluationContext context = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ms.![key.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(context);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example 10
Source File: SpelReproTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_2() {
	StandardEvaluationContext context = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "as.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	Object[] value = (Object[]) exp.getValue(context);
	// value is array containing [true,false]
	assertEquals(Boolean.class, value[0].getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
	assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
 
Example 11
Source File: SpelReproTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_1() {
	StandardEvaluationContext context = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ls.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(context);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example 12
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void reservedWordProperties_9862() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext();
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
	Object value = expression.getValue(ctx);
	assertEquals(value, Reserver.CONST);
}
 
Example 13
Source File: SpelReproTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void reservedWordProperties_SPR9862() {
	StandardEvaluationContext context = new StandardEvaluationContext();
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
	Object value = expression.getValue(context);
	assertEquals(value, Reserver.CONST);
}
 
Example 14
Source File: SpelReproTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void greaterThanWithNulls_SPR7840() {
	List<D> list = new ArrayList<>();
	list.add(new D("aaa"));
	list.add(new D("bbb"));
	list.add(new D(null));
	list.add(new D("ccc"));
	list.add(new D(null));
	list.add(new D("zzz"));

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

	String el1 = "#root.?[a < 'hhh']";
	SpelExpression exp = parser.parseRaw(el1);
	Object value = exp.getValue(context);
	assertEquals("[D(aaa), D(bbb), D(null), D(ccc), D(null)]", value.toString());

	String el2 = "#root.?[a > 'hhh']";
	SpelExpression exp2 = parser.parseRaw(el2);
	Object value2 = exp2.getValue(context);
	assertEquals("[D(zzz)]", value2.toString());

	// trim out the nulls first
	String el3 = "#root.?[a!=null].?[a < 'hhh']";
	SpelExpression exp3 = parser.parseRaw(el3);
	Object value3 = exp3.getValue(context);
	assertEquals("[D(aaa), D(bbb), D(ccc)]", value3.toString());
}
 
Example 15
Source File: SpelReproTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_3() {
	StandardEvaluationContext context = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ms.![key.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(context);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example 16
Source File: SpelReproTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_2() {
	StandardEvaluationContext context = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "as.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	Object[] value = (Object[]) exp.getValue(context);
	// value is array containing [true,false]
	assertEquals(Boolean.class, value[0].getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
	assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
 
Example 17
Source File: EvaluationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testConstructorInvocation06() {
	// repeated evaluation to drive use of cached executor
	SpelExpression e = (SpelExpression) parser.parseExpression("new String('wibble')");
	String newString = e.getValue(String.class);
	assertEquals("wibble", newString);
	newString = e.getValue(String.class);
	assertEquals("wibble", newString);

	// not writable
	assertFalse(e.isWritable(new StandardEvaluationContext()));

	// ast
	assertEquals("new String('wibble')", e.toStringAST());
}
 
Example 18
Source File: SpelReproTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void reservedWords_SPR8228() {

	// "DIV","EQ","GE","GT","LE","LT","MOD","NE","NOT"
	@SuppressWarnings("unused")
	class Reserver {
		public Reserver getReserver() {
			return this;
		}
		public String NE = "abc";
		public String ne = "def";

		public int DIV = 1;
		public int div = 3;

		public Map<String, String> m = new HashMap<>();

		Reserver() {
			m.put("NE", "xyz");
		}
	}

	StandardEvaluationContext context = new StandardEvaluationContext(new Reserver());
	SpelExpressionParser parser = new SpelExpressionParser();
	String ex = "getReserver().NE";
	SpelExpression exp = parser.parseRaw(ex);
	String value = (String) exp.getValue(context);
	assertEquals("abc", value);

	ex = "getReserver().ne";
	exp = parser.parseRaw(ex);
	value = (String) exp.getValue(context);
	assertEquals("def", value);

	ex = "getReserver().m[NE]";
	exp = parser.parseRaw(ex);
	value = (String) exp.getValue(context);
	assertEquals("xyz", value);

	ex = "getReserver().DIV";
	exp = parser.parseRaw(ex);
	assertEquals(1, exp.getValue(context));

	ex = "getReserver().div";
	exp = parser.parseRaw(ex);
	assertEquals(3, exp.getValue(context));

	exp = parser.parseRaw("NE");
	assertEquals("abc", exp.getValue(context));
}
 
Example 19
Source File: SpelReproTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void reservedWords_SPR8228() {

	// "DIV","EQ","GE","GT","LE","LT","MOD","NE","NOT"
	@SuppressWarnings("unused")
	class Reserver {
		public Reserver getReserver() {
			return this;
		}
		public String NE = "abc";
		public String ne = "def";

		public int DIV = 1;
		public int div = 3;

		public Map<String, String> m = new HashMap<>();

		Reserver() {
			m.put("NE", "xyz");
		}
	}

	StandardEvaluationContext context = new StandardEvaluationContext(new Reserver());
	SpelExpressionParser parser = new SpelExpressionParser();
	String ex = "getReserver().NE";
	SpelExpression exp = parser.parseRaw(ex);
	String value = (String) exp.getValue(context);
	assertEquals("abc", value);

	ex = "getReserver().ne";
	exp = parser.parseRaw(ex);
	value = (String) exp.getValue(context);
	assertEquals("def", value);

	ex = "getReserver().m[NE]";
	exp = parser.parseRaw(ex);
	value = (String) exp.getValue(context);
	assertEquals("xyz", value);

	ex = "getReserver().DIV";
	exp = parser.parseRaw(ex);
	assertEquals(1, exp.getValue(context));

	ex = "getReserver().div";
	exp = parser.parseRaw(ex);
	assertEquals(3, exp.getValue(context));

	exp = parser.parseRaw("NE");
	assertEquals("abc", exp.getValue(context));
}
 
Example 20
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void reservedWords_8228() throws Exception {
	// "DIV","EQ","GE","GT","LE","LT","MOD","NE","NOT"
	@SuppressWarnings("unused")
	class Reserver {
		public Reserver getReserver() {
			return this;
		}
		public String NE = "abc";
		public String ne = "def";

		public int DIV = 1;
		public int div = 3;

		public Map<String, String> m = new HashMap<String, String>();

		Reserver() {
			m.put("NE", "xyz");
		}
	}

	StandardEvaluationContext ctx = new StandardEvaluationContext(new Reserver());
	SpelExpressionParser parser = new SpelExpressionParser();
	String ex = "getReserver().NE";
	SpelExpression exp = parser.parseRaw(ex);
	String value = (String) exp.getValue(ctx);
	assertEquals("abc", value);

	ex = "getReserver().ne";
	exp = parser.parseRaw(ex);
	value = (String) exp.getValue(ctx);
	assertEquals("def", value);

	ex = "getReserver().m[NE]";
	exp = parser.parseRaw(ex);
	value = (String) exp.getValue(ctx);
	assertEquals("xyz", value);

	ex = "getReserver().DIV";
	exp = parser.parseRaw(ex);
	assertEquals(1, exp.getValue(ctx));

	ex = "getReserver().div";
	exp = parser.parseRaw(ex);
	assertEquals(3, exp.getValue(ctx));

	exp = parser.parseRaw("NE");
	assertEquals("abc", exp.getValue(ctx));
}