Adding <c:catch> JSTL test cases
This commit is contained in:
parent
0476d4d28d
commit
06cb0ca897
|
@ -43,3 +43,7 @@ bin/
|
|||
|
||||
# merge tooling
|
||||
*.orig
|
||||
|
||||
# test generated content
|
||||
*/src/test/*/WEB-INF/lib/test*.jar
|
||||
|
||||
|
|
|
@ -20,19 +20,7 @@ package org.eclipse.jetty.jstl;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tomcat.InstanceManager;
|
||||
import org.apache.tomcat.SimpleInstanceManager;
|
||||
import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
|
||||
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
|
||||
import org.eclipse.jetty.jsp.JettyJspServlet;
|
||||
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,19 +25,21 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.JAR;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.SimpleRequest;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
public class JstlTest
|
||||
{
|
||||
private static Server server;
|
||||
|
@ -54,6 +56,14 @@ public class JstlTest
|
|||
|
||||
// Setup WebAppContext
|
||||
File testWebAppDir = MavenTestingUtils.getProjectDir("src/test/webapp");
|
||||
|
||||
// Prepare WebApp libs
|
||||
File libDir = new File(testWebAppDir, "WEB-INF/lib");
|
||||
FS.ensureDirExists(libDir);
|
||||
File testTagLibDir = MavenTestingUtils.getProjectDir("src/test/taglibjar");
|
||||
JAR.create(testTagLibDir,new File(libDir, "testtaglib.jar"));
|
||||
|
||||
// Configure WebAppContext
|
||||
|
||||
Configuration.ClassList classlist = Configuration.ClassList
|
||||
.setServerDefault(server);
|
||||
|
@ -61,7 +71,6 @@ public class JstlTest
|
|||
classlist.addBefore(
|
||||
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
|
||||
"org.eclipse.jetty.annotations.AnnotationConfiguration");
|
||||
|
||||
|
||||
WebAppContext context = new WebAppContext();
|
||||
context.setContextPath("/");
|
||||
|
@ -99,8 +108,28 @@ public class JstlTest
|
|||
assertThat("Response should be JSP processed", resp, not(containsString("<c:url")));
|
||||
assertThat("Response", resp, containsString("[c:url value] = /ref.jsp;jsessionid="));
|
||||
assertThat("Response", resp, containsString("[c:url param] = ref.jsp;key=value;jsessionid="));
|
||||
|
||||
System.err.println("Response:");
|
||||
System.err.println(resp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCatchBasic() throws IOException
|
||||
{
|
||||
SimpleRequest req = new SimpleRequest(baseUri);
|
||||
String resp = req.getString("/catch-basic.jsp");
|
||||
assertThat("Response should be JSP processed", resp, not(containsString("<c:catch")));
|
||||
assertThat("Response", resp, containsString("[c:catch] exception : " + JspException.class.getName()));
|
||||
assertThat("Response", resp, containsString("[c:catch] exception.message : In <parseNumber>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testCatchTaglib() throws IOException
|
||||
{
|
||||
SimpleRequest req = new SimpleRequest(baseUri);
|
||||
String resp = req.getString("/catch-taglib.jsp");
|
||||
System.out.println("resp = " + resp);
|
||||
assertThat("Response should be JSP processed", resp, not(containsString("<c:catch")));
|
||||
assertThat("Response should be JSP processed", resp, not(containsString("<jtest:errortest")));
|
||||
assertThat("Response", resp, containsString("[jtest:errorhandler] exception : "));
|
||||
assertThat("Response", resp, containsString("[jtest:errorhandler] exception.message : "));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
|
||||
version="2.0">
|
||||
|
||||
<description>eclipse jetty test taglib</description>
|
||||
<tlib-version>1.0</tlib-version>
|
||||
|
||||
<short-name>jtest</short-name>
|
||||
<uri>org.eclipse.jetty.jstl.jtest</uri>
|
||||
|
||||
<tag-file>
|
||||
<name>errortest</name>
|
||||
<path>/META-INF/tags/errortest.tag</path>
|
||||
</tag-file>
|
||||
|
||||
<tag-file>
|
||||
<name>errorhandler</name>
|
||||
<path>/META-INF/tags/errorhandler.tag</path>
|
||||
</tag-file>
|
||||
</taglib>
|
|
@ -0,0 +1,13 @@
|
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
|
||||
<c:catch var="error">
|
||||
<jsp:doBody />
|
||||
</c:catch>
|
||||
|
||||
<c:if test="${error != null}">
|
||||
[jtest:errorhandler] exception : ${error}
|
||||
[jtest:errorhandler] exception.message : ${error.message}
|
||||
</c:if>
|
||||
<c:if test="${error == null}">
|
||||
[jtest:errorhandler] exception is null
|
||||
</c:if>
|
|
@ -0,0 +1,3 @@
|
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
|
||||
<c:out value="content from jtest:errortest tag"/>
|
|
@ -0,0 +1,16 @@
|
|||
<%@ page contentType="text/plain; charset=UTF-8" %>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
|
||||
Title: JSTL c:catch test
|
||||
|
||||
<c:catch var ="catchException">
|
||||
<fmt:parseNumber var="parsedNum" value="aaa" />
|
||||
</c:catch>
|
||||
|
||||
<c:if test = "${catchException != null}">
|
||||
[c:catch] exception : ${catchException}
|
||||
[c:catch] exception.message : ${catchException.message}
|
||||
</c:if>
|
||||
<c:if test = "${catchException == null}">
|
||||
[c:catch] exception is null
|
||||
</c:if>
|
|
@ -0,0 +1,11 @@
|
|||
<%@ page contentType="text/plain; charset=UTF-8" %>
|
||||
<%@ taglib uri="org.eclipse.jetty.jstl.jtest" prefix="jtest" %>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
|
||||
Title: JSTL c:catch test
|
||||
|
||||
<jtest:errortest>
|
||||
<fmt:parseNumber var="parsedNum" value="aaa" />
|
||||
</jtest:errortest>
|
||||
|
||||
parsedNum = <c:out value="${parsedNum}"/>
|
Loading…
Reference in New Issue