use of org.springframework.expression.ExpressionParser 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.ExpressionParser in project spring-framework by spring-projects.
the class EvaluationTests method increment02prefix.
@Test
public void increment02prefix() {
Spr9751 helper = new Spr9751();
StandardEvaluationContext ctx = new StandardEvaluationContext(helper);
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression e = null;
// BigDecimal
e = parser.parseExpression("++bd");
assertTrue(new BigDecimal("2").equals(helper.bd));
BigDecimal return_bd = e.getValue(ctx, BigDecimal.class);
assertTrue(new BigDecimal("3").equals(return_bd));
assertTrue(new BigDecimal("3").equals(helper.bd));
// double
e = parser.parseExpression("++ddd");
assertEquals(2.0d, helper.ddd, 0d);
double return_ddd = e.getValue(ctx, Double.TYPE);
assertEquals(3.0d, return_ddd, 0d);
assertEquals(3.0d, helper.ddd, 0d);
// float
e = parser.parseExpression("++fff");
assertEquals(3.0f, helper.fff, 0d);
float return_fff = e.getValue(ctx, Float.TYPE);
assertEquals(4.0f, return_fff, 0d);
assertEquals(4.0f, helper.fff, 0d);
// long
e = parser.parseExpression("++lll");
assertEquals(66666L, helper.lll);
long return_lll = e.getValue(ctx, Long.TYPE);
assertEquals(66667L, return_lll);
assertEquals(66667L, helper.lll);
// int
e = parser.parseExpression("++iii");
assertEquals(42, helper.iii);
int return_iii = e.getValue(ctx, Integer.TYPE);
assertEquals(43, return_iii);
assertEquals(43, helper.iii);
return_iii = e.getValue(ctx, Integer.TYPE);
assertEquals(44, return_iii);
assertEquals(44, helper.iii);
// short
e = parser.parseExpression("++sss");
assertEquals(15, helper.sss);
int return_sss = (Integer) e.getValue(ctx);
assertEquals(16, return_sss);
assertEquals(16, helper.sss);
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class EvaluationTests method increment01root.
// For now I am making #this not assignable
@Test
public void increment01root() {
Integer i = 42;
StandardEvaluationContext ctx = new StandardEvaluationContext(i);
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression e = parser.parseExpression("#this++");
assertEquals(42, i.intValue());
try {
e.getValue(ctx, Integer.class);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode());
}
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class EvaluationTests method collectionGrowingViaIndexer.
/**
* This test is checking that with the changes for 9751 that the refactoring in Indexer is
* coping correctly for references beyond collection boundaries.
*/
@Test
public void collectionGrowingViaIndexer() {
Spr9751 instance = new Spr9751();
// Add a new element to the list
StandardEvaluationContext ctx = new StandardEvaluationContext(instance);
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression e = parser.parseExpression("listOfStrings[++index3]='def'");
e.getValue(ctx);
assertEquals(2, instance.listOfStrings.size());
assertEquals("def", instance.listOfStrings.get(1));
// Check reference beyond end of collection
ctx = new StandardEvaluationContext(instance);
parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
e = parser.parseExpression("listOfStrings[0]");
String value = e.getValue(ctx, String.class);
assertEquals("abc", value);
e = parser.parseExpression("listOfStrings[1]");
value = e.getValue(ctx, String.class);
assertEquals("def", value);
e = parser.parseExpression("listOfStrings[2]");
value = e.getValue(ctx, String.class);
assertEquals("", value);
// Now turn off growing and reference off the end
ctx = new StandardEvaluationContext(instance);
parser = new SpelExpressionParser(new SpelParserConfiguration(false, false));
e = parser.parseExpression("listOfStrings[3]");
try {
e.getValue(ctx, String.class);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS, see.getMessageCode());
}
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class EvaluationTests method testCreateObjectsOnAttemptToReferenceNull.
// wibble2 should be null (cannot be initialized dynamically), there is no setter
@Test(expected = SpelEvaluationException.class)
public void testCreateObjectsOnAttemptToReferenceNull() throws Exception {
TestClass testClass = new TestClass();
StandardEvaluationContext ctx = new StandardEvaluationContext(testClass);
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Object o = null;
o = parser.parseExpression("wibble.bar").getValue(ctx);
assertEquals("hello", o);
o = parser.parseExpression("wibble").getValue(ctx);
assertNotNull(o);
o = parser.parseExpression("wibble2.bar").getValue(ctx);
}
Aggregations