From 5d44043806605b1b829067331cdde5179bf47975 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 9 Mar 2010 21:51:46 +0000 Subject: [PATCH] Bug 48701 test cases git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@921145 13f79535-47bb-0310-9956-ffa450edef68 --- test/org/apache/jasper/compiler/TestGenerator.java | 116 +++++++++++++++++++++ test/webapp-3.0/WEB-INF/bugs.tld | 35 ++++++- test/webapp-3.0/bug48701-TVI-NFA.jsp | 20 ++++ test/webapp-3.0/bug48701-TVI-NG.jsp | 20 ++++ test/webapp-3.0/bug48701-UseBean.jsp | 19 ++++ test/webapp-3.0/bug48701-VI.jsp | 20 ++++ test/webapp-3.0/bug48701-fail.jsp | 19 ++++ 7 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 test/webapp-3.0/bug48701-TVI-NFA.jsp create mode 100644 test/webapp-3.0/bug48701-TVI-NG.jsp create mode 100644 test/webapp-3.0/bug48701-UseBean.jsp create mode 100644 test/webapp-3.0/bug48701-VI.jsp create mode 100644 test/webapp-3.0/bug48701-fail.jsp diff --git a/test/org/apache/jasper/compiler/TestGenerator.java b/test/org/apache/jasper/compiler/TestGenerator.java index d8c6070a6..ac0d630de 100644 --- a/test/org/apache/jasper/compiler/TestGenerator.java +++ b/test/org/apache/jasper/compiler/TestGenerator.java @@ -19,7 +19,15 @@ package org.apache.jasper.compiler; import java.io.File; import java.io.IOException; +import java.util.Date; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagData; +import javax.servlet.jsp.tagext.TagExtraInfo; +import javax.servlet.jsp.tagext.TagSupport; +import javax.servlet.jsp.tagext.VariableInfo; + +import org.apache.catalina.core.StandardContext; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; import org.apache.tomcat.util.buf.ByteChunk; @@ -75,6 +83,114 @@ public class TestGenerator extends TomcatBaseTest { assertNotNull(e); } + public void testBug48701Fail() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = + new File("test/webapp-3.0"); + // app dir is relative to server home + StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, + "/test", appDir.getAbsolutePath()); + + // This test needs the JSTL libraries + File lib = new File("webapps/examples/WEB-INF/lib"); + ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath()); + + tomcat.start(); + + Exception e = null; + try { + getUrl("http://localhost:" + getPort() + "/test/bug48701-fail.jsp"); + } catch (IOException ioe) { + e = ioe; + } + + // Failure is expected + assertNotNull(e); + } + + public void testBug48701UseBean() throws Exception { + testBug48701("bug48701-UseBean.jsp"); + } + + public void testBug48701VariableInfo() throws Exception { + testBug48701("bug48701-VI.jsp"); + } + + public void testBug48701TagVariableInfoNameGiven() throws Exception { + testBug48701("bug48701-TVI-NG.jsp"); + } + + public void testBug48701TagVariableInfoNameFromAttribute() throws Exception { + testBug48701("bug48701-TVI-NFA.jsp"); + } + + private void testBug48701(String jsp) throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = + new File("test/webapp-3.0"); + // app dir is relative to server home + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + + tomcat.start(); + + ByteChunk res = getUrl("http://localhost:" + getPort() + + "/test/" + jsp); + + String result = res.toString(); + assertEcho(result, "00-PASS"); + } + + public static class Bug48701 extends TagSupport { + + private static final long serialVersionUID = 1L; + + private String beanName = null; + + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + public String getBeanName() { + return beanName; + } + + @Override + public int doStartTag() throws JspException { + Bean bean = new Bean(); + bean.setTime((new Date()).toString()); + pageContext.setAttribute("now", bean); + return super.doStartTag(); + } + + + } + + public static class Bug48701TEI extends TagExtraInfo { + + @Override + public VariableInfo[] getVariableInfo(TagData data) { + return new VariableInfo[] { + new VariableInfo("now", Bean.class.getCanonicalName(), + true, VariableInfo.AT_END) + }; + } + + } + + public static class Bean { + private String time; + + public void setTime(String time) { + this.time = time; + } + + public String getTime() { + return time; + } + } + /** Assertion for text printed by tags:echo */ private static void assertEcho(String result, String expected) { assertTrue(result.indexOf("

" + expected + "

") > 0); diff --git a/test/webapp-3.0/WEB-INF/bugs.tld b/test/webapp-3.0/WEB-INF/bugs.tld index bcbeb4db1..42b711981 100644 --- a/test/webapp-3.0/WEB-INF/bugs.tld +++ b/test/webapp-3.0/WEB-INF/bugs.tld @@ -28,11 +28,44 @@ org.apache.jasper.compiler.TestScriptingVariabler$Bug48616aTag JSP - Bug48616b org.apache.jasper.compiler.TestScriptingVariabler$Bug48616bTag org.apache.jasper.compiler.TestScriptingVariabler$Bug48616bTei JSP + + + Bug48701a + org.apache.jasper.compiler.TestGenerator$Bug48701 + org.apache.jasper.compiler.TestGenerator$Bug48701TEI + empty + + + Bug48701b + org.apache.jasper.compiler.TestGenerator$Bug48701 + empty + + now + org.apache.jasper.compiler.TestGenerator.Bean + true + AT_END + + + + Bug48701c + org.apache.jasper.compiler.TestGenerator$Bug48701 + empty + + beanName + java.lang.String + + + beanName + org.apache.jasper.compiler.TestGenerator.Bean + true + AT_END + + + \ No newline at end of file diff --git a/test/webapp-3.0/bug48701-TVI-NFA.jsp b/test/webapp-3.0/bug48701-TVI-NFA.jsp new file mode 100644 index 000000000..dd00f5761 --- /dev/null +++ b/test/webapp-3.0/bug48701-TVI-NFA.jsp @@ -0,0 +1,20 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%@ taglib uri="http://tomcat.apache.org/bugs" prefix="bugs" %> + + +

00-PASS

diff --git a/test/webapp-3.0/bug48701-TVI-NG.jsp b/test/webapp-3.0/bug48701-TVI-NG.jsp new file mode 100644 index 000000000..2b4096213 --- /dev/null +++ b/test/webapp-3.0/bug48701-TVI-NG.jsp @@ -0,0 +1,20 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%@ taglib uri="http://tomcat.apache.org/bugs" prefix="bugs" %> + + +

00-PASS

diff --git a/test/webapp-3.0/bug48701-UseBean.jsp b/test/webapp-3.0/bug48701-UseBean.jsp new file mode 100644 index 000000000..a64214e61 --- /dev/null +++ b/test/webapp-3.0/bug48701-UseBean.jsp @@ -0,0 +1,19 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> + + +

00-PASS

\ No newline at end of file diff --git a/test/webapp-3.0/bug48701-VI.jsp b/test/webapp-3.0/bug48701-VI.jsp new file mode 100644 index 000000000..7f042cadb --- /dev/null +++ b/test/webapp-3.0/bug48701-VI.jsp @@ -0,0 +1,20 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%@ taglib uri="http://tomcat.apache.org/bugs" prefix="bugs" %> + + +

00-PASS

diff --git a/test/webapp-3.0/bug48701-fail.jsp b/test/webapp-3.0/bug48701-fail.jsp new file mode 100644 index 000000000..5b04d4a58 --- /dev/null +++ b/test/webapp-3.0/bug48701-fail.jsp @@ -0,0 +1,19 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + -- 2.11.0