Refine search
@Test(expected = SpelEvaluationException.class) public void spelExpressionListIndexAccessNullVariables() { ExpressionParser parser = new SpelExpressionParser(); Expression spelExpression = parser.parseExpression("#aList[0] eq 'one'"); spelExpression.getValue(); }
@Test public void testOtherOperators() throws Exception { // evaluates to false boolean falseValue = parser.parseExpression("'xyz' instanceof T(int)").getValue(Boolean.class); assertFalse(falseValue); // evaluates to true boolean trueValue = parser.parseExpression("'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class); assertTrue(trueValue); //evaluates to false falseValue = parser.parseExpression("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class); assertFalse(falseValue); }
@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); }
@Test public void SPR16123() { ExpressionParser parser = new SpelExpressionParser(); parser.parseExpression("simpleProperty").setValue(new BooleanHolder(), null); try { parser.parseExpression("primitiveProperty").setValue(new BooleanHolder(), null); fail("Should have thrown EvaluationException"); } catch (EvaluationException ex) { // expected } }
@Test public void SPR10091_primitiveTestValueType() { ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder()); Class<?> valueType = parser.parseExpression("primitiveProperty").getValueType(evaluationContext); assertNotNull(valueType); }
@Test public void testSelectionAST() throws Exception { SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.^[true]"); assertEquals("'abc'.^[true]", expr.toStringAST()); expr = (SpelExpression) parser.parseExpression("'abc'.?[true]"); assertEquals("'abc'.?[true]", expr.toStringAST()); expr = (SpelExpression) parser.parseExpression("'abc'.$[true]"); assertEquals("'abc'.$[true]", expr.toStringAST()); }
@Test public void testTernaryOperator04() { Expression e = parser.parseExpression("1>2?3:4"); assertFalse(e.isWritable(context)); }
@Test public void testRelationalOperators() throws Exception { boolean result = parser.parseExpression("2 == 2").getValue(Boolean.class); assertTrue(result); // evaluates to false result = parser.parseExpression("2 < -5.0").getValue(Boolean.class); assertFalse(result); // evaluates to true result = parser.parseExpression("'black' < 'block'").getValue(Boolean.class); assertTrue(result); }
@Test public void testSetParameterizedList() throws Exception { StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext(); Expression e = parser.parseExpression("listOfInteger.size()"); assertEquals(0,e.getValue(context,Integer.class).intValue()); context.setTypeConverter(new TypeConvertorUsingConversionService()); // Assign a List<String> to the List<Integer> field - the component elements should be converted parser.parseExpression("listOfInteger").setValue(context,listOfString); assertEquals(3,e.getValue(context,Integer.class).intValue()); // size now 3 Class<?> clazz = parser.parseExpression("listOfInteger[1].getClass()").getValue(context, Class.class); // element type correctly Integer assertEquals(Integer.class,clazz); }
@Test public void SPR10091_simpleTestValueType() { ExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder()); Class<?> valueType = parser.parseExpression("simpleProperty").getValueType(evaluationContext); assertNotNull(valueType); }
@Test public void testNotWritable() throws Exception { SpelExpression expr = (SpelExpression)parser.parseExpression("37"); assertFalse(expr.isWritable(new StandardEvaluationContext())); expr = (SpelExpression)parser.parseExpression("37L"); assertFalse(expr.isWritable(new StandardEvaluationContext())); expr = (SpelExpression)parser.parseExpression("true"); assertFalse(expr.isWritable(new StandardEvaluationContext())); } }
@Test(expected = SpelEvaluationException.class) public void spelExpressionListNullVariables() { ExpressionParser parser = new SpelExpressionParser(); Expression spelExpression = parser.parseExpression("#aList.contains('one')"); spelExpression.getValue(); }
@Test public void testTypes() throws Exception { Class<?> dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class); assertEquals(Date.class, dateClass); boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class); assertTrue(trueValue); }
@Test public void testCachedExecutionForParameters() { Expression expression = this.parser.parseExpression("echo(#var)"); assertMethodExecution(expression, 42, "int: 42"); assertMethodExecution(expression, 42, "int: 42"); assertMethodExecution(expression, "Deep Thought", "String: Deep Thought"); assertMethodExecution(expression, 42, "int: 42"); }
@Test(expected = SpelEvaluationException.class) public void spelExpressionArrayIndexAccessNullVariables() { ExpressionParser parser = new SpelExpressionParser(); Expression spelExpression = parser.parseExpression("#anArray[0] eq 1"); spelExpression.getValue(); }
@Test public void SPR10125() { StandardEvaluationContext context = new StandardEvaluationContext(); String fromInterface = parser.parseExpression("T(" + StaticFinalImpl1.class.getName() + ").VALUE").getValue( context, String.class); assertThat(fromInterface, is("interfaceValue")); String fromClass = parser.parseExpression("T(" + StaticFinalImpl2.class.getName() + ").VALUE").getValue( context, String.class); assertThat(fromClass, is("interfaceValue")); }
@Test(expected = SpelEvaluationException.class) public void spelExpressionMapNullVariables() { ExpressionParser parser = new SpelExpressionParser(); Expression spelExpression = parser.parseExpression("#aMap.containsKey('one')"); spelExpression.getValue(); }
@Test public void testResolvingString() { Class<?> stringClass = parser.parseExpression("T(String)").getValue(Class.class); assertEquals(String.class, stringClass); }
@Test(expected = SpelEvaluationException.class) public void spelExpressionMapIndexAccessNullVariables() { ExpressionParser parser = new SpelExpressionParser(); Expression spelExpression = parser.parseExpression("#aMap['one'] eq 1"); spelExpression.getValue(); }
@Test public void testParsingNormalExpressionThroughTemplateParser() throws Exception { Expression expr = parser.parseExpression("1+2+3"); assertEquals(6, expr.getValue()); }