org.springframework.expression.spel.testresources.TestPerson Java Examples

The following examples show how to use org.springframework.expression.spel.testresources.TestPerson. 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: EvaluationTests.java    From java-technology-stack with MIT License 8 votes vote down vote up
/**
 * SPR-6984: attempting to index a collection on write using an index that
 * doesn't currently exist in the collection (address.crossStreets[0] below)
 */
@Test
public void initializingCollectionElementsOnWrite() {
	TestPerson person = new TestPerson();
	EvaluationContext context = new StandardEvaluationContext(person);
	SpelParserConfiguration config = new SpelParserConfiguration(true, true);
	ExpressionParser parser = new SpelExpressionParser(config);
	Expression e = parser.parseExpression("name");
	e.setValue(context, "Oleg");
	assertEquals("Oleg", person.getName());

	e = parser.parseExpression("address.street");
	e.setValue(context, "123 High St");
	assertEquals("123 High St", person.getAddress().getStreet());

	e = parser.parseExpression("address.crossStreets[0]");
	e.setValue(context, "Blah");
	assertEquals("Blah", person.getAddress().getCrossStreets().get(0));

	e = parser.parseExpression("address.crossStreets[3]");
	e.setValue(context, "Wibble");
	assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
	assertEquals("Wibble", person.getAddress().getCrossStreets().get(3));
}
 
Example #2
Source File: EvaluationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * SPR-6984: attempting to index a collection on write using an index that
 * doesn't currently exist in the collection (address.crossStreets[0] below)
 */
@Test
public void initializingCollectionElementsOnWrite() {
	TestPerson person = new TestPerson();
	EvaluationContext context = new StandardEvaluationContext(person);
	SpelParserConfiguration config = new SpelParserConfiguration(true, true);
	ExpressionParser parser = new SpelExpressionParser(config);
	Expression e = parser.parseExpression("name");
	e.setValue(context, "Oleg");
	assertEquals("Oleg", person.getName());

	e = parser.parseExpression("address.street");
	e.setValue(context, "123 High St");
	assertEquals("123 High St", person.getAddress().getStreet());

	e = parser.parseExpression("address.crossStreets[0]");
	e.setValue(context, "Blah");
	assertEquals("Blah", person.getAddress().getCrossStreets().get(0));

	e = parser.parseExpression("address.crossStreets[3]");
	e.setValue(context, "Wibble");
	assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
	assertEquals("Wibble", person.getAddress().getCrossStreets().get(3));
}
 
Example #3
Source File: EvaluationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * SPR-6984: attempting to index a collection on write using an index that
 * doesn't currently exist in the collection (address.crossStreets[0] below)
 */
@Test
public void initializingCollectionElementsOnWrite() throws Exception {
	TestPerson person = new TestPerson();
	EvaluationContext context = new StandardEvaluationContext(person);
	SpelParserConfiguration config = new SpelParserConfiguration(true, true);
	ExpressionParser parser = new SpelExpressionParser(config);
	Expression expression = parser.parseExpression("name");
	expression.setValue(context, "Oleg");
	assertEquals("Oleg", person.getName());

	expression = parser.parseExpression("address.street");
	expression.setValue(context, "123 High St");
	assertEquals("123 High St", person.getAddress().getStreet());

	expression = parser.parseExpression("address.crossStreets[0]");
	expression.setValue(context, "Blah");
	assertEquals("Blah", person.getAddress().getCrossStreets().get(0));

	expression = parser.parseExpression("address.crossStreets[3]");
	expression.setValue(context, "Wibble");
	assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
	assertEquals("Wibble", person.getAddress().getCrossStreets().get(3));
}