Bug 48701 test cases
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 9 Mar 2010 21:51:46 +0000 (21:51 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 9 Mar 2010 21:51:46 +0000 (21:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@921145 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/jasper/compiler/TestGenerator.java
test/webapp-3.0/WEB-INF/bugs.tld
test/webapp-3.0/bug48701-TVI-NFA.jsp [new file with mode: 0644]
test/webapp-3.0/bug48701-TVI-NG.jsp [new file with mode: 0644]
test/webapp-3.0/bug48701-UseBean.jsp [new file with mode: 0644]
test/webapp-3.0/bug48701-VI.jsp [new file with mode: 0644]
test/webapp-3.0/bug48701-fail.jsp [new file with mode: 0644]

index d8c6070..ac0d630 100644 (file)
@@ -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("<p>" + expected + "</p>") > 0);
index bcbeb4d..42b7119 100644 (file)
     <tag-class>org.apache.jasper.compiler.TestScriptingVariabler$Bug48616aTag</tag-class>
     <body-content>JSP</body-content>
   </tag>
-
   <tag>
     <name>Bug48616b</name>
     <tag-class>org.apache.jasper.compiler.TestScriptingVariabler$Bug48616bTag</tag-class>
     <tei-class>org.apache.jasper.compiler.TestScriptingVariabler$Bug48616bTei</tei-class>
     <body-content>JSP</body-content>
   </tag>
+  
+  <tag>
+    <name>Bug48701a</name>
+    <tag-class>org.apache.jasper.compiler.TestGenerator$Bug48701</tag-class>
+    <tei-class>org.apache.jasper.compiler.TestGenerator$Bug48701TEI</tei-class>
+    <body-content>empty</body-content>
+  </tag>
+  <tag>
+    <name>Bug48701b</name>
+    <tag-class>org.apache.jasper.compiler.TestGenerator$Bug48701</tag-class>
+    <body-content>empty</body-content>
+    <variable>
+      <name-given>now</name-given>
+      <variable-class>org.apache.jasper.compiler.TestGenerator.Bean</variable-class>
+      <declare>true</declare>
+      <scope>AT_END</scope>
+    </variable>
+  </tag>
+  <tag>
+    <name>Bug48701c</name>
+    <tag-class>org.apache.jasper.compiler.TestGenerator$Bug48701</tag-class>
+    <body-content>empty</body-content>
+    <attribute>
+      <name>beanName</name>
+      <type>java.lang.String</type>
+    </attribute>
+    <variable>
+      <name-from-attribute>beanName</name-from-attribute>
+      <variable-class>org.apache.jasper.compiler.TestGenerator.Bean</variable-class>
+      <declare>true</declare>
+      <scope>AT_END</scope>
+    </variable>
+  </tag>
+  
 </taglib>
\ 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 (file)
index 0000000..dd00f57
--- /dev/null
@@ -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" %>
+<bugs:Bug48701c beanName="now" />
+<jsp:getProperty name="now" property="time" />
+<p>00-PASS</p>
diff --git a/test/webapp-3.0/bug48701-TVI-NG.jsp b/test/webapp-3.0/bug48701-TVI-NG.jsp
new file mode 100644 (file)
index 0000000..2b40962
--- /dev/null
@@ -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" %>
+<bugs:Bug48701b/>
+<jsp:getProperty name="now" property="time" />
+<p>00-PASS</p>
diff --git a/test/webapp-3.0/bug48701-UseBean.jsp b/test/webapp-3.0/bug48701-UseBean.jsp
new file mode 100644 (file)
index 0000000..a64214e
--- /dev/null
@@ -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.
+--%>
+<jsp:useBean id="now" class="java.util.Date" />
+<jsp:getProperty name="now" property="time" />
+<p>00-PASS</p>
\ 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 (file)
index 0000000..7f042ca
--- /dev/null
@@ -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" %>
+<bugs:Bug48701a/>
+<jsp:getProperty name="now" property="time" />
+<p>00-PASS</p>
diff --git a/test/webapp-3.0/bug48701-fail.jsp b/test/webapp-3.0/bug48701-fail.jsp
new file mode 100644 (file)
index 0000000..5b04d4a
--- /dev/null
@@ -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" %>
+<c:set var="now" value='<%= new java.util.Date() %>' />
+<jsp:getProperty name="now" property="time" />