package org.apache.jasper.compiler; import static org.junit.Assert.*; import java.io.File; import javax.servlet.ServletContext; import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; import org.apache.jasper.JspCompilationContext; import org.junit.Test; public class TestELInterpreterFactory extends TomcatBaseTest { public static class SimpleELInterpreter implements ELInterpreter { @Override public String interpreterCall(JspCompilationContext context, boolean isTagFile, String expression, Class expectedType, String fnmapvar, boolean xmlEscape) { return expression; } } @Test public void testBug54239() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ServletContext context = ctx.getServletContext(); ELInterpreter interpreter = ELInterpreterFactory.getELInterpreter(context); assertNotNull(interpreter); assertTrue(interpreter instanceof ELInterpreterFactory.DefaultELInterpreter); context.removeAttribute(ELInterpreter.class.getName()); System.setProperty(ELInterpreter.class.getName(), SimpleELInterpreter.class.getName()); interpreter = ELInterpreterFactory.getELInterpreter(context); assertNotNull(interpreter); assertTrue(interpreter instanceof SimpleELInterpreter); context.removeAttribute(ELInterpreter.class.getName()); context.setAttribute(ELInterpreter.class.getName(), SimpleELInterpreter.class.getName()); interpreter = ELInterpreterFactory.getELInterpreter(context); assertNotNull(interpreter); assertTrue(interpreter instanceof SimpleELInterpreter); context.removeAttribute(ELInterpreter.class.getName()); SimpleELInterpreter simpleInterpreter = new SimpleELInterpreter(); context.setAttribute(ELInterpreter.class.getName(), simpleInterpreter); interpreter = ELInterpreterFactory.getELInterpreter(context); assertNotNull(interpreter); assertTrue(interpreter instanceof SimpleELInterpreter); assertTrue(interpreter == simpleInterpreter); context.removeAttribute(ELInterpreter.class.getName()); context.setInitParameter(ELInterpreter.class.getName(), SimpleELInterpreter.class.getName()); interpreter = ELInterpreterFactory.getELInterpreter(context); assertNotNull(interpreter); assertTrue(interpreter instanceof SimpleELInterpreter); context.removeAttribute(ELInterpreter.class.getName()); } }