Java Code Examples for org.springframework.expression.spel.standard.SpelExpression

The following examples show how to use org.springframework.expression.spel.standard.SpelExpression. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: ParsingTests.java    License: MIT License 6 votes vote down vote up
/**
 * Parse the supplied expression and then create a string representation of the resultant AST, it should be the
 * expected value.
 *
 * @param expression the expression to parse
 * @param expectedStringFormOfAST the expected string form of the AST
 */
public void parseCheck(String expression, String expectedStringFormOfAST) {
	try {
		SpelExpression e = parser.parseRaw(expression);
		if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
			SpelUtilities.printAbstractSyntaxTree(System.err, e);
		}
		if (e == null) {
			fail("Parsed exception was null");
		}
		assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
	}
	catch (ParseException ee) {
		ee.printStackTrace();
		fail("Unexpected Exception: " + ee.getMessage());
	}
}
 
Example 2
Source Project: java-technology-stack   Source File: ParsingTests.java    License: MIT License 6 votes vote down vote up
/**
 * Parse the supplied expression and then create a string representation of the resultant AST, it should be the
 * expected value.
 *
 * @param expression the expression to parse
 * @param expectedStringFormOfAST the expected string form of the AST
 */
public void parseCheck(String expression, String expectedStringFormOfAST) {
	try {
		SpelExpression e = parser.parseRaw(expression);
		if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
			SpelUtilities.printAbstractSyntaxTree(System.err, e);
		}
		if (e == null) {
			fail("Parsed exception was null");
		}
		assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
	}
	catch (ParseException ee) {
		ee.printStackTrace();
		fail("Unexpected Exception: " + ee.getMessage());
	}
}
 
Example 3
Source Project: spring4-understanding   Source File: ParsingTests.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parse the supplied expression and then create a string representation of the resultant AST, it should be the
 * expected value.
 *
 * @param expression the expression to parse
 * @param expectedStringFormOfAST the expected string form of the AST
 */
public void parseCheck(String expression, String expectedStringFormOfAST) {
	try {
		SpelExpression e = parser.parseRaw(expression);
		if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
			SpelUtilities.printAbstractSyntaxTree(System.err, e);
		}
		if (e == null) {
			fail("Parsed exception was null");
		}
		assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
	} catch (ParseException ee) {
		ee.printStackTrace();
		fail("Unexpected Exception: " + ee.getMessage());
	}
}
 
Example 4
Source Project: spring-data-keyvalue   Source File: SpelCriteriaAccessor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public SpelCriteria resolve(KeyValueQuery<?> query) {

	if (query.getCriteria() == null) {
		return null;
	}

	if (query.getCriteria() instanceof SpelExpression) {
		return new SpelCriteria((SpelExpression) query.getCriteria());
	}

	if (query.getCriteria() instanceof String) {
		return new SpelCriteria(parser.parseRaw((String) query.getCriteria()));
	}

	if (query.getCriteria() instanceof SpelCriteria) {
		return (SpelCriteria) query.getCriteria();
	}

	throw new IllegalArgumentException("Cannot create SpelCriteria for " + query.getCriteria());
}
 
Example 5
private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args)
		throws NoSuchMethodException, SecurityException {

	Class<?>[] argTypes = new Class<?>[args.length];
	if (!ObjectUtils.isEmpty(args)) {

		for (int i = 0; i < args.length; i++) {
			argTypes[i] = args[i].getClass();
		}
	}

	Method method = PersonRepository.class.getMethod(methodName, argTypes);
	doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);

	PartTree partTree = new PartTree(method.getName(), method.getReturnType());
	SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(
			new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args));

	KeyValueQuery<SpelExpression> q = creator.createQuery();
	q.getCriteria().setEvaluationContext(
			SimpleEvaluationContext.forReadOnlyDataBinding().withRootObject(args).withInstanceMethods().build());

	return q;
}
 
Example 6
Source Project: spring-analysis-note   Source File: ListTests.java    License: MIT License 5 votes vote down vote up
private void checkConstantList(String expressionText, boolean expectedToBeConstant) {
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
	SpelNode node = expression.getAST();
	assertTrue(node instanceof InlineList);
	InlineList inlineList = (InlineList) node;
	if (expectedToBeConstant) {
		assertTrue(inlineList.isConstant());
	}
	else {
		assertFalse(inlineList.isConstant());
	}
}
 
Example 7
Source Project: spring-analysis-note   Source File: EvaluationTests.java    License: 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 8
Source Project: spring-analysis-note   Source File: EvaluationTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testTypeReferencesAndQualifiedIdentifierCaching() {
	SpelExpression e = (SpelExpression) parser.parseExpression("T(java.lang.String)");
	assertFalse(e.isWritable(new StandardEvaluationContext()));
	assertEquals("T(java.lang.String)", e.toStringAST());
	assertEquals(String.class, e.getValue(Class.class));
	// use cached QualifiedIdentifier:
	assertEquals("T(java.lang.String)", e.toStringAST());
	assertEquals(String.class, e.getValue(Class.class));
}
 
Example 9
Source Project: spring-analysis-note   Source File: EvaluationTests.java    License: MIT License 5 votes vote down vote up
@Test
public void operatorVariants() {
	SpelExpression e = (SpelExpression)parser.parseExpression("#a < #b");
	EvaluationContext ctx = new StandardEvaluationContext();
	ctx.setVariable("a", (short) 3);
	ctx.setVariable("b", (short) 6);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("b", (byte) 6);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 9);
	ctx.setVariable("b", (byte) 6);
	assertFalse(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", 10L);
	ctx.setVariable("b", (short) 30);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 3);
	ctx.setVariable("b", (short) 30);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 3);
	ctx.setVariable("b", 30L);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 3);
	ctx.setVariable("b", 30f);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", new BigInteger("10"));
	ctx.setVariable("b", new BigInteger("20"));
	assertTrue(e.getValue(ctx, Boolean.class));
}
 
Example 10
Source Project: spring-analysis-note   Source File: OperatorTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testOperatorNames() throws Exception {
	Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
	assertEquals("==",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
	assertEquals("!=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
	assertEquals("/",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
	assertEquals("+",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
	assertEquals("-",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3<4"));
	assertEquals("<",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
	assertEquals("<=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
	assertEquals("*",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
	assertEquals("%",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
	assertEquals(">=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
	assertEquals("between",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
	assertEquals("^",node.getOperatorName());
}
 
Example 11
Source Project: spring-analysis-note   Source File: MapTests.java    License: MIT License 5 votes vote down vote up
private void checkConstantMap(String expressionText, boolean expectedToBeConstant) {
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
	SpelNode node = expression.getAST();
	assertTrue(node instanceof InlineMap);
	InlineMap inlineMap = (InlineMap) node;
	if (expectedToBeConstant) {
		assertTrue(inlineMap.isConstant());
	}
	else {
		assertFalse(inlineMap.isConstant());
	}
}
 
Example 12
Source Project: spring-analysis-note   Source File: ReflectionHelperTests.java    License: MIT License 5 votes vote down vote up
@Test
	public void testUtilities() throws ParseException {
		SpelExpression expr = (SpelExpression)parser.parseExpression("3+4+5+6+7-2");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream(baos);
		SpelUtilities.printAbstractSyntaxTree(ps, expr);
		ps.flush();
		String s = baos.toString();
//		===> Expression '3+4+5+6+7-2' - AST start
//		OperatorMinus  value:(((((3 + 4) + 5) + 6) + 7) - 2)  #children:2
//		  OperatorPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2
//		    OperatorPlus  value:(((3 + 4) + 5) + 6)  #children:2
//		      OperatorPlus  value:((3 + 4) + 5)  #children:2
//		        OperatorPlus  value:(3 + 4)  #children:2
//		          CompoundExpression  value:3
//		            IntLiteral  value:3
//		          CompoundExpression  value:4
//		            IntLiteral  value:4
//		        CompoundExpression  value:5
//		          IntLiteral  value:5
//		      CompoundExpression  value:6
//		        IntLiteral  value:6
//		    CompoundExpression  value:7
//		      IntLiteral  value:7
//		  CompoundExpression  value:2
//		    IntLiteral  value:2
//		===> Expression '3+4+5+6+7-2' - AST end
		assertTrue(s.contains("===> Expression '3+4+5+6+7-2' - AST start"));
		assertTrue(s.contains(" OpPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2"));
	}
 
Example 13
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: 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 14
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: 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 15
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: 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 Project: spring-analysis-note   Source File: SpelReproTests.java    License: 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 17
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: 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 18
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: MIT License 5 votes vote down vote up
@Test
public void array() {
	ExpressionParser parser = new SpelExpressionParser();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Expression expression = null;
	Object result = null;

	expression = parser.parseExpression("new java.lang.Long[0].class");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

	expression = parser.parseExpression("T(java.lang.Long[])");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

	expression = parser.parseExpression("T(java.lang.String[][][])");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [[[Ljava.lang.String;", result.toString());
	assertEquals("T(java.lang.String[][][])", ((SpelExpression) expression).toStringAST());

	expression = parser.parseExpression("new int[0].class");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [I", result.toString());

	expression = parser.parseExpression("T(int[][])");
	result = expression.getValue(context, "");
	assertEquals("class [[I", result.toString());
}
 
Example 19
Source Project: java-technology-stack   Source File: ListTests.java    License: MIT License 5 votes vote down vote up
private void checkConstantList(String expressionText, boolean expectedToBeConstant) {
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
	SpelNode node = expression.getAST();
	assertTrue(node instanceof InlineList);
	InlineList inlineList = (InlineList) node;
	if (expectedToBeConstant) {
		assertTrue(inlineList.isConstant());
	}
	else {
		assertFalse(inlineList.isConstant());
	}
}
 
Example 20
Source Project: java-technology-stack   Source File: EvaluationTests.java    License: 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 21
Source Project: java-technology-stack   Source File: EvaluationTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testTypeReferencesAndQualifiedIdentifierCaching() {
	SpelExpression e = (SpelExpression) parser.parseExpression("T(java.lang.String)");
	assertFalse(e.isWritable(new StandardEvaluationContext()));
	assertEquals("T(java.lang.String)", e.toStringAST());
	assertEquals(String.class, e.getValue(Class.class));
	// use cached QualifiedIdentifier:
	assertEquals("T(java.lang.String)", e.toStringAST());
	assertEquals(String.class, e.getValue(Class.class));
}
 
Example 22
Source Project: java-technology-stack   Source File: EvaluationTests.java    License: MIT License 5 votes vote down vote up
@Test
public void operatorVariants() {
	SpelExpression e = (SpelExpression)parser.parseExpression("#a < #b");
	EvaluationContext ctx = new StandardEvaluationContext();
	ctx.setVariable("a", (short) 3);
	ctx.setVariable("b", (short) 6);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("b", (byte) 6);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 9);
	ctx.setVariable("b", (byte) 6);
	assertFalse(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", 10L);
	ctx.setVariable("b", (short) 30);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 3);
	ctx.setVariable("b", (short) 30);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 3);
	ctx.setVariable("b", 30L);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte) 3);
	ctx.setVariable("b", 30f);
	assertTrue(e.getValue(ctx, Boolean.class));
	ctx.setVariable("a", new BigInteger("10"));
	ctx.setVariable("b", new BigInteger("20"));
	assertTrue(e.getValue(ctx, Boolean.class));
}
 
Example 23
Source Project: java-technology-stack   Source File: OperatorTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testOperatorNames() throws Exception {
	Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
	assertEquals("==",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
	assertEquals("!=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
	assertEquals("/",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
	assertEquals("+",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
	assertEquals("-",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3<4"));
	assertEquals("<",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
	assertEquals("<=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
	assertEquals("*",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
	assertEquals("%",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
	assertEquals(">=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
	assertEquals("between",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
	assertEquals("^",node.getOperatorName());
}
 
Example 24
Source Project: java-technology-stack   Source File: MapTests.java    License: MIT License 5 votes vote down vote up
private void checkConstantMap(String expressionText, boolean expectedToBeConstant) {
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
	SpelNode node = expression.getAST();
	assertTrue(node instanceof InlineMap);
	InlineMap inlineMap = (InlineMap) node;
	if (expectedToBeConstant) {
		assertTrue(inlineMap.isConstant());
	}
	else {
		assertFalse(inlineMap.isConstant());
	}
}
 
Example 25
Source Project: java-technology-stack   Source File: ReflectionHelperTests.java    License: MIT License 5 votes vote down vote up
@Test
	public void testUtilities() throws ParseException {
		SpelExpression expr = (SpelExpression)parser.parseExpression("3+4+5+6+7-2");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream(baos);
		SpelUtilities.printAbstractSyntaxTree(ps, expr);
		ps.flush();
		String s = baos.toString();
//		===> Expression '3+4+5+6+7-2' - AST start
//		OperatorMinus  value:(((((3 + 4) + 5) + 6) + 7) - 2)  #children:2
//		  OperatorPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2
//		    OperatorPlus  value:(((3 + 4) + 5) + 6)  #children:2
//		      OperatorPlus  value:((3 + 4) + 5)  #children:2
//		        OperatorPlus  value:(3 + 4)  #children:2
//		          CompoundExpression  value:3
//		            IntLiteral  value:3
//		          CompoundExpression  value:4
//		            IntLiteral  value:4
//		        CompoundExpression  value:5
//		          IntLiteral  value:5
//		      CompoundExpression  value:6
//		        IntLiteral  value:6
//		    CompoundExpression  value:7
//		      IntLiteral  value:7
//		  CompoundExpression  value:2
//		    IntLiteral  value:2
//		===> Expression '3+4+5+6+7-2' - AST end
		assertTrue(s.contains("===> Expression '3+4+5+6+7-2' - AST start"));
		assertTrue(s.contains(" OpPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2"));
	}
 
Example 26
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: 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 27
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: 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 28
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: 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 29
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: 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 30
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: 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);
}