use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class ExpressionStateTests method testNoVariableInteference.
@Test
public void testNoVariableInteference() {
ExpressionState state = getState();
TypedValue typedValue = state.lookupVariable("foo");
assertEquals(TypedValue.NULL, typedValue);
state.setLocalVariable("foo", 34);
typedValue = state.lookupVariable("foo");
assertEquals(TypedValue.NULL, typedValue);
state.setVariable("goo", "hello");
assertNull(state.lookupLocalVariable("goo"));
}
use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class ExpressionStateTests method testActiveContextObject.
@Test
public void testActiveContextObject() {
ExpressionState state = getState();
assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue());
try {
state.popActiveContextObject();
fail("stack should be empty...");
} catch (EmptyStackException ese) {
// success
}
state.pushActiveContextObject(new TypedValue(34));
assertEquals(34, state.getActiveContextObject().getValue());
state.pushActiveContextObject(new TypedValue("hello"));
assertEquals("hello", state.getActiveContextObject().getValue());
state.popActiveContextObject();
assertEquals(34, state.getActiveContextObject().getValue());
state.popActiveContextObject();
assertEquals(state.getRootContextObject().getValue(), state.getActiveContextObject().getValue());
state = new ExpressionState(new StandardEvaluationContext());
assertEquals(TypedValue.NULL, state.getActiveContextObject());
}
use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class ExpressionStateTests method testTypeConversion.
@Test
public void testTypeConversion() throws EvaluationException {
ExpressionState state = getState();
String s = (String) state.convertValue(34, TypeDescriptor.valueOf(String.class));
assertEquals("34", s);
s = (String) state.convertValue(new TypedValue(34), TypeDescriptor.valueOf(String.class));
assertEquals("34", s);
}
use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method selectionWithArray.
@Test
public void selectionWithArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertTrue(value.getClass().isArray());
TypedValue typedValue = new TypedValue(value);
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
Integer[] array = (Integer[]) value;
assertEquals(5, array.length);
assertEquals(new Integer(0), array[0]);
assertEquals(new Integer(1), array[1]);
assertEquals(new Integer(2), array[2]);
assertEquals(new Integer(3), array[3]);
assertEquals(new Integer(4), array[4]);
}
use of org.springframework.expression.TypedValue in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method selectionWithPrimitiveArray.
@Test
public void selectionWithPrimitiveArray() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("ints.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
Object value = expression.getValue(context);
assertTrue(value.getClass().isArray());
TypedValue typedValue = new TypedValue(value);
assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
Integer[] array = (Integer[]) value;
assertEquals(5, array.length);
assertEquals(new Integer(0), array[0]);
assertEquals(new Integer(1), array[1]);
assertEquals(new Integer(2), array[2]);
assertEquals(new Integer(3), array[3]);
assertEquals(new Integer(4), array[4]);
}
Aggregations