use of org.springframework.expression.spel.standard.SpelExpressionParser in project pinpoint by naver.
the class HbaseApiMetaDataDaoTest method getApiMetaDataCachable.
@Test
public void getApiMetaDataCachable() {
// cacheable key - spring expression language
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("agentId", "foo");
context.setVariable("time", (long) 1);
context.setVariable("apiId", (int) 2);
String key = (String) parser.parseExpression(HbaseApiMetaDataDao.SPEL_KEY).getValue(context);
assertEquals("foo.1.2", key);
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-boot by spring-projects.
the class BindingPreparationTests method testExpressionLists.
@Test
@Ignore("Work in progress")
public void testExpressionLists() throws Exception {
TargetWithNestedMapOfListOfString target = new TargetWithNestedMapOfListOfString();
LinkedHashMap<String, List<String>> map = new LinkedHashMap<>();
// map.put("foo", Arrays.asList("bar"));
target.setNested(map);
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(target);
context.addPropertyAccessor(new MapAccessor());
Expression expression = parser.parseExpression("nested.foo");
assertThat(expression.getValue(context)).isNotNull();
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class ExpressionEvaluatorTests method unavailableReturnValue.
@Test
public void unavailableReturnValue() throws Exception {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.RESULT_UNAVAILABLE);
try {
new SpelExpressionParser().parseExpression("#result").getValue(context);
fail("Should have failed to parse expression, result not available");
} catch (VariableNotAvailableException e) {
assertEquals("wrong variable name", "result", e.getName());
}
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class MapAccessorTests method mapAccessorCompilable.
@Test
public void mapAccessorCompilable() {
Map<String, Object> testMap = getSimpleTestMap();
StandardEvaluationContext sec = new StandardEvaluationContext();
sec.addPropertyAccessor(new MapAccessor());
SpelExpressionParser sep = new SpelExpressionParser();
// basic
Expression ex = sep.parseExpression("foo");
assertEquals("bar", ex.getValue(sec, testMap));
assertTrue(SpelCompiler.compile(ex));
assertEquals("bar", ex.getValue(sec, testMap));
// compound expression
ex = sep.parseExpression("foo.toUpperCase()");
assertEquals("BAR", ex.getValue(sec, testMap));
assertTrue(SpelCompiler.compile(ex));
assertEquals("BAR", ex.getValue(sec, testMap));
// nested map
Map<String, Map<String, Object>> nestedMap = getNestedTestMap();
ex = sep.parseExpression("aaa.foo.toUpperCase()");
assertEquals("BAR", ex.getValue(sec, nestedMap));
assertTrue(SpelCompiler.compile(ex));
assertEquals("BAR", ex.getValue(sec, nestedMap));
// avoiding inserting checkcast because first part of expression returns a Map
ex = sep.parseExpression("getMap().foo");
MapGetter mapGetter = new MapGetter();
assertEquals("bar", ex.getValue(sec, mapGetter));
assertTrue(SpelCompiler.compile(ex));
assertEquals("bar", ex.getValue(sec, mapGetter));
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class ArrayConstructorTests method evaluateArrayBuildingExpression.
private String evaluateArrayBuildingExpression(String expression, String expectedToString) {
SpelExpressionParser parser = new SpelExpressionParser();
Expression e = parser.parseExpression(expression);
Object o = e.getValue();
assertNotNull(o);
assertTrue(o.getClass().isArray());
StringBuilder s = new StringBuilder();
s.append('[');
if (o instanceof int[]) {
int[] array = (int[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else if (o instanceof boolean[]) {
boolean[] array = (boolean[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else if (o instanceof char[]) {
char[] array = (char[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else if (o instanceof long[]) {
long[] array = (long[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else if (o instanceof short[]) {
short[] array = (short[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else if (o instanceof double[]) {
double[] array = (double[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else if (o instanceof float[]) {
float[] array = (float[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else if (o instanceof byte[]) {
byte[] array = (byte[]) o;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
s.append(',');
}
s.append(array[i]);
}
} else {
fail("Not supported " + o.getClass());
}
s.append(']');
assertEquals(expectedToString, s.toString());
return s.toString();
}
Aggregations