use of org.springframework.expression.spel.testresources.Inventor in project spring-framework by spring-projects.
the class TestScenarioCreator method setupRootContextObject.
/**
* Create the root context object, an Inventor instance. Non-qualified property
* and method references will be resolved against this context object.
* @param testContext the evaluation context in which to set the root object
*/
private static void setupRootContextObject(StandardEvaluationContext testContext) {
GregorianCalendar c = new GregorianCalendar();
c.set(1856, 7, 9);
Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
tesla.setPlaceOfBirth(new PlaceOfBirth("SmilJan"));
tesla.setInventions(new String[] { "Telephone repeater", "Rotating magnetic field principle", "Polyphase alternating-current system", "Induction motor", "Alternating-current power transmission", "Tesla coil transformer", "Wireless communication", "Radio", "Fluorescent lights" });
testContext.setRootObject(tesla);
}
use of org.springframework.expression.spel.testresources.Inventor in project spring-framework by spring-projects.
the class SpelDocumentationTests method testDictionaryAccess.
@Test
public void testDictionaryAccess() throws Exception {
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
// Officer's Dictionary
Inventor pupin = parser.parseExpression("officers['president']").getValue(societyContext, Inventor.class);
assertNotNull(pupin);
// evaluates to "Idvor"
String city = parser.parseExpression("officers['president'].PlaceOfBirth.city").getValue(societyContext, String.class);
assertNotNull(city);
// setting values
Inventor i = parser.parseExpression("officers['advisors'][0]").getValue(societyContext, Inventor.class);
assertEquals("Nikola Tesla", i.getName());
parser.parseExpression("officers['advisors'][0].PlaceOfBirth.Country").setValue(societyContext, "Croatia");
Inventor i2 = parser.parseExpression("reverse[0]['advisors'][0]").getValue(societyContext, Inventor.class);
assertEquals("Nikola Tesla", i2.getName());
}
use of org.springframework.expression.spel.testresources.Inventor in project spring-framework by spring-projects.
the class SpelDocumentationTests method testVariables.
// 7.5.8
@Test
public void testVariables() throws Exception {
Inventor tesla = new Inventor("Nikola Tesla", "Serbian");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("newName", "Mike Tesla");
context.setRootObject(tesla);
parser.parseExpression("foo = #newName").getValue(context);
assertEquals("Mike Tesla", tesla.getFoo());
}
use of org.springframework.expression.spel.testresources.Inventor in project spring-framework by spring-projects.
the class SpelDocumentationTests method testConstructors.
// 7.5.7
@Test
public void testConstructors() throws Exception {
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
Inventor einstein = parser.parseExpression("new org.springframework.expression.spel.testresources.Inventor('Albert Einstein',new java.util.Date(), 'German')").getValue(Inventor.class);
assertEquals("Albert Einstein", einstein.getName());
//create new inventor instance within add method of List
parser.parseExpression("Members2.add(new org.springframework.expression.spel.testresources.Inventor('Albert Einstein', 'German'))").getValue(societyContext);
}
use of org.springframework.expression.spel.testresources.Inventor in project spring-framework by spring-projects.
the class SpelDocumentationTests method testAssignment.
// 7.5.5
@Test
public void testAssignment() throws Exception {
Inventor inventor = new Inventor();
StandardEvaluationContext inventorContext = new StandardEvaluationContext();
inventorContext.setRootObject(inventor);
parser.parseExpression("foo").setValue(inventorContext, "Alexander Seovic2");
assertEquals("Alexander Seovic2", parser.parseExpression("foo").getValue(inventorContext, String.class));
// alternatively
String aleks = parser.parseExpression("foo = 'Alexandar Seovic'").getValue(inventorContext, String.class);
assertEquals("Alexandar Seovic", parser.parseExpression("foo").getValue(inventorContext, String.class));
assertEquals("Alexandar Seovic", aleks);
}
Aggregations