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

The following examples show how to use org.springframework.expression.spel.testresources.Inventor. 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: SpelDocumentationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testRootObject() throws Exception {
	GregorianCalendar c = new GregorianCalendar();
	c.set(1856, 7, 9);

	//  The constructor arguments are name, birthday, and nationaltiy.
	Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");

	ExpressionParser parser = new SpelExpressionParser();
	Expression exp = parser.parseExpression("name");

	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setRootObject(tesla);

	String name = (String) exp.getValue(context);
	assertEquals("Nikola Tesla",name);
}
 
Example #2
Source File: ExpressionStateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testRootContextObject() {
	ExpressionState state = getState();
	assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());

	// although the root object is being set on the evaluation context, the value in the 'state' remains what it was when constructed
	((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
	assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());
	// assertEquals(null, state.getRootContextObject().getValue());

	state = new ExpressionState(new StandardEvaluationContext());
	assertEquals(TypedValue.NULL,state.getRootContextObject());


	((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null);
	assertEquals(null,state.getRootContextObject().getValue());
}
 
Example #3
Source File: SpelDocumentationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());

}
 
Example #4
Source File: SpelDocumentationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testRootObject() throws Exception {
	GregorianCalendar c = new GregorianCalendar();
	c.set(1856, 7, 9);

	//  The constructor arguments are name, birthday, and nationaltiy.
	Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");

	ExpressionParser parser = new SpelExpressionParser();
	Expression exp = parser.parseExpression("name");

	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setRootObject(tesla);

	String name = (String) exp.getValue(context);
	assertEquals("Nikola Tesla",name);
}
 
Example #5
Source File: ExpressionStateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testRootContextObject() {
	ExpressionState state = getState();
	assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass());

	// although the root object is being set on the evaluation context, the value in the 'state' remains what it was when constructed
	((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
	assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass());
	// assertEquals(null, state.getRootContextObject().getValue());

	state = new ExpressionState(new StandardEvaluationContext());
	assertEquals(TypedValue.NULL, state.getRootContextObject());


	((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
	assertEquals(null, state.getRootContextObject().getValue());
}
 
Example #6
Source File: SpelDocumentationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());

}
 
Example #7
Source File: SpelDocumentationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testRootObject() throws Exception {
	GregorianCalendar c = new GregorianCalendar();
	c.set(1856, 7, 9);

	//  The constructor arguments are name, birthday, and nationaltiy.
	Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");

	ExpressionParser parser = new SpelExpressionParser();
	Expression exp = parser.parseExpression("name");

	StandardEvaluationContext context = new StandardEvaluationContext();
	context.setRootObject(tesla);

	String name = (String) exp.getValue(context);
	assertEquals("Nikola Tesla",name);
}
 
Example #8
Source File: SpelDocumentationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());

}
 
Example #9
Source File: ExpressionStateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testRootContextObject() {
	ExpressionState state = getState();
	assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass());

	// although the root object is being set on the evaluation context, the value in the 'state' remains what it was when constructed
	((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
	assertEquals(Inventor.class, state.getRootContextObject().getValue().getClass());
	// assertEquals(null, state.getRootContextObject().getValue());

	state = new ExpressionState(new StandardEvaluationContext());
	assertEquals(TypedValue.NULL, state.getRootContextObject());


	((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
	assertEquals(null, state.getRootContextObject().getValue());
}
 
Example #10
Source File: SpelDocumentationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #11
Source File: TestScenarioCreator.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example #12
Source File: SpelDocumentationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testSelection() throws Exception {
	StandardEvaluationContext societyContext = new StandardEvaluationContext();
	societyContext.setRootObject(new IEEE());
	List<Inventor> list = (List<Inventor>) parser.parseExpression("Members2.?[nationality == 'Serbian']").getValue(societyContext);
	assertEquals(1,list.size());
	assertEquals("Nikola Tesla",list.get(0).getName());
}
 
Example #13
Source File: SpelDocumentationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #14
Source File: SpelDocumentationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: SpelDocumentationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #16
Source File: SpelDocumentationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #17
Source File: TestScenarioCreator.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: SpelDocumentationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testSelection() throws Exception {
	StandardEvaluationContext societyContext = new StandardEvaluationContext();
	societyContext.setRootObject(new IEEE());
	List<Inventor> list = (List<Inventor>) parser.parseExpression("Members2.?[nationality == 'Serbian']").getValue(societyContext);
	assertEquals(1,list.size());
	assertEquals("Nikola Tesla",list.get(0).getName());
}
 
Example #19
Source File: SpelDocumentationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #20
Source File: SpelDocumentationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #21
Source File: SpelDocumentationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #22
Source File: SpelDocumentationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}
 
Example #23
Source File: SpelDocumentationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testSelection() throws Exception {
	StandardEvaluationContext societyContext = new StandardEvaluationContext();
	societyContext.setRootObject(new IEEE());
	List<Inventor> list = (List<Inventor>) parser.parseExpression("Members2.?[nationality == 'Serbian']").getValue(societyContext);
	assertEquals(1,list.size());
	assertEquals("Nikola Tesla",list.get(0).getName());
}
 
Example #24
Source File: TestScenarioCreator.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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);
}