Java Code Examples for org.springframework.expression.EvaluationException#printStackTrace()
The following examples show how to use
org.springframework.expression.EvaluationException#printStackTrace() .
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: EvaluationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException { ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); Expression e = parser.parseExpression("list[0]"); TestClass testClass = new TestClass(); Object o = e.getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.list.size()); try { o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass)); fail(); } catch (EvaluationException ee) { ee.printStackTrace(); // success! } o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.getFoo().size()); }
Example 2
Source File: ScenariosForSpringSecurity.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testScenario01_Roles() throws Exception { try { SpelExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext ctx = new StandardEvaluationContext(); Expression expr = parser.parseRaw("hasAnyRole('MANAGER','TELLER')"); ctx.setRootObject(new Person("Ben")); Boolean value = expr.getValue(ctx,Boolean.class); assertFalse(value); ctx.setRootObject(new Manager("Luke")); value = expr.getValue(ctx,Boolean.class); assertTrue(value); } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected SpelException: " + ee.getMessage()); } }
Example 3
Source File: EvaluationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException { ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); Expression e = parser.parseExpression("list[0]"); TestClass testClass = new TestClass(); Object o = e.getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.list.size()); try { o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass)); fail(); } catch (EvaluationException ee) { ee.printStackTrace(); // success! } o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.getFoo().size()); }
Example 4
Source File: ScenariosForSpringSecurity.java From java-technology-stack with MIT License | 6 votes |
@Test public void testScenario01_Roles() throws Exception { try { SpelExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext ctx = new StandardEvaluationContext(); Expression expr = parser.parseRaw("hasAnyRole('MANAGER','TELLER')"); ctx.setRootObject(new Person("Ben")); Boolean value = expr.getValue(ctx,Boolean.class); assertFalse(value); ctx.setRootObject(new Manager("Luke")); value = expr.getValue(ctx,Boolean.class); assertTrue(value); } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected SpelException: " + ee.getMessage()); } }
Example 5
Source File: EvaluationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException { ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); Expression expression = parser.parseExpression("list[0]"); TestClass testClass = new TestClass(); Object o = null; o = expression.getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.list.size()); try { o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass)); fail(); } catch (EvaluationException ee) { ee.printStackTrace(); // success! } o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.getFoo().size()); }
Example 6
Source File: ScenariosForSpringSecurity.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testScenario01_Roles() throws Exception { try { SpelExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext ctx = new StandardEvaluationContext(); Expression expr = parser.parseRaw("hasAnyRole('MANAGER','TELLER')"); ctx.setRootObject(new Person("Ben")); Boolean value = expr.getValue(ctx,Boolean.class); assertFalse(value); ctx.setRootObject(new Manager("Luke")); value = expr.getValue(ctx,Boolean.class); assertTrue(value); } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected SpelException: " + ee.getMessage()); } }
Example 7
Source File: SetValueTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
protected void setValue(String expression, Object value) { try { Expression e = parser.parseExpression(expression); if (e == null) { fail("Parser returned null for expression"); } if (DEBUG) { SpelUtilities.printAbstractSyntaxTree(System.out, e); } StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext(); assertTrue("Expression is not writeable but should be", e.isWritable(lContext)); e.setValue(lContext, value); assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass())); } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected Exception: " + ee.getMessage()); } catch (ParseException pe) { pe.printStackTrace(); fail("Unexpected Exception: " + pe.getMessage()); } }
Example 8
Source File: ExpressionLanguageScenarioTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Scenario: using the standard infrastructure and running simple expression evaluation. */ @Test public void testScenario_UsingStandardInfrastructure() { try { // Create a parser SpelExpressionParser parser = new SpelExpressionParser(); // Parse an expression Expression expr = parser.parseRaw("new String('hello world')"); // Evaluate it using a 'standard' context Object value = expr.getValue(); // They are reusable value = expr.getValue(); assertEquals("hello world", value); assertEquals(String.class, value.getClass()); } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected Exception: " + ee.getMessage()); } catch (ParseException pe) { pe.printStackTrace(); fail("Unexpected Exception: " + pe.getMessage()); } }
Example 9
Source File: ExpressionLanguageScenarioTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Scenario: using your own java methods and calling them from the expression */ @Test public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException { try { // Create a parser SpelExpressionParser parser = new SpelExpressionParser(); // Use the standard evaluation context StandardEvaluationContext ctx = new StandardEvaluationContext(); ctx.registerFunction("repeat",ExpressionLanguageScenarioTests.class.getDeclaredMethod("repeat",String.class)); Expression expr = parser.parseRaw("#repeat('hello')"); Object value = expr.getValue(ctx); assertEquals("hellohello", value); } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected Exception: " + ee.getMessage()); } catch (ParseException pe) { pe.printStackTrace(); fail("Unexpected Exception: " + pe.getMessage()); } }
Example 10
Source File: SetValueTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * For use when coercion is happening during a setValue(). The expectedValue should be * the coerced form of the value. */ protected void setValue(String expression, Object value, Object expectedValue) { try { Expression e = parser.parseExpression(expression); if (e == null) { fail("Parser returned null for expression"); } if (DEBUG) { SpelUtilities.printAbstractSyntaxTree(System.out, e); } StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext(); assertTrue("Expression is not writeable but should be", e.isWritable(lContext)); e.setValue(lContext, value); Object a = expectedValue; Object b = e.getValue(lContext); if (!a.equals(b)) { fail("Not the same: ["+a+"] type="+a.getClass()+" ["+b+"] type="+b.getClass()); // assertEquals("Retrieved value was not equal to set value", expectedValue, e.getValue(lContext)); } } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected Exception: " + ee.getMessage()); } catch (ParseException pe) { pe.printStackTrace(); fail("Unexpected Exception: " + pe.getMessage()); } }