1 16 17 package org.springframework.web.jsf; 18 19 import javax.faces.context.FacesContext; 20 import javax.faces.el.EvaluationException; 21 import javax.faces.el.VariableResolver; 22 23 import junit.framework.TestCase; 24 25 import org.springframework.beans.TestBean; 26 import org.springframework.web.context.WebApplicationContext; 27 import org.springframework.web.context.support.StaticWebApplicationContext; 28 29 33 public class DelegatingVariableResolverTests extends TestCase { 34 35 public void testDelegatingVariableResolver() { 36 final StaticWebApplicationContext wac = new StaticWebApplicationContext(); 37 wac.registerSingleton("bean1", TestBean.class, null); 38 wac.registerSingleton("var1", TestBean.class, null); 39 wac.refresh(); 40 TestBean bean1 = (TestBean) wac.getBean("bean1"); 41 42 DelegatingVariableResolver resolver = new DelegatingVariableResolver(new OriginalVariableResolver()) { 45 protected WebApplicationContext getWebApplicationContext(FacesContext facesContext) { 46 return wac; 47 } 48 }; 49 assertEquals("val1", resolver.resolveVariable(null, "var1")); 50 assertEquals(bean1, resolver.resolveVariable(null, "bean1")); 51 } 52 53 54 private static class OriginalVariableResolver extends VariableResolver { 55 56 public Object resolveVariable(FacesContext facesContext, String name) throws EvaluationException { 57 if ("var1".equals(name)) { 58 return "val1"; 59 } 60 return null; 61 } 62 } 63 64 } 65 | Popular Tags |