1 16 17 package org.springframework.web.util; 18 19 import javax.servlet.jsp.PageContext ; 20 21 import junit.framework.TestCase; 22 23 import org.springframework.mock.web.MockPageContext; 24 25 29 public class ExpressionEvaluationUtilsTests extends TestCase { 30 31 public void testIsExpressionLanguage() { 32 String expr = "${bla}"; 34 assertTrue(ExpressionEvaluationUtils.isExpressionLanguage(expr)); 35 36 expr = "bla${bla}"; 38 assertTrue(ExpressionEvaluationUtils.isExpressionLanguage(expr)); 39 40 expr = "bla{bla"; 42 assertFalse(ExpressionEvaluationUtils.isExpressionLanguage(expr)); 43 44 expr = "bla$b{"; 46 assertFalse(ExpressionEvaluationUtils.isExpressionLanguage(expr)); 47 48 } 50 51 public void testEvaluate() throws Exception { 52 PageContext ctx = new MockPageContext(); 53 54 ctx.setAttribute("bla", "blie"); 55 String expr = "${bla}"; 56 57 Object o = ExpressionEvaluationUtils.evaluate("test", expr, String .class, ctx); 58 assertEquals(o, "blie"); 59 60 assertEquals(new String ("test"), 61 ExpressionEvaluationUtils.evaluate("test", "test", Float .class, ctx)); 62 } 63 64 public void testEvaluateString() throws Exception { 65 PageContext ctx = new MockPageContext(); 66 67 ctx.setAttribute("bla", "blie"); 68 String expr = "${bla}"; 69 Object o = ExpressionEvaluationUtils.evaluateString("test", expr, ctx); 70 assertEquals(o, "blie"); 71 72 assertEquals("blie", ExpressionEvaluationUtils.evaluateString("test", "blie", ctx)); 73 } 74 75 public void testEvaluateInteger() throws Exception { 76 PageContext ctx = new MockPageContext(); 77 78 ctx.setAttribute("bla", new Integer (1)); 79 String expr = "${bla}"; 80 81 int i = ExpressionEvaluationUtils.evaluateInteger("test", expr, ctx); 82 assertEquals(i, 1); 83 84 assertEquals(21, ExpressionEvaluationUtils.evaluateInteger("test", "21", ctx)); 85 } 86 87 public void testEvaluateBoolean() throws Exception { 88 PageContext ctx = new MockPageContext(); 89 90 ctx.setAttribute("bla", new Boolean (true)); 91 String expr = "${bla}"; 92 93 boolean b = ExpressionEvaluationUtils.evaluateBoolean("test", expr, ctx); 94 assertEquals(b, true); 95 96 assertEquals(true, ExpressionEvaluationUtils.evaluateBoolean("test", "true", ctx)); 97 } 98 99 } 100 | Popular Tags |