[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/tagTests JspTagTest.java,1.27,1.28
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-09-01 21:53:40
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests In directory sc8-pr-cvs1:/tmp/cvs-serv10193 Modified Files: JspTagTest.java Log Message: Incorporated test cases from bug #772700 Jsp Tags are not parsed correctly when in quoted attributes. This should be resolved when the lexer package is integrated. Commented out the one that fails. Index: JspTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/JspTagTest.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** JspTagTest.java 24 Aug 2003 21:59:44 -0000 1.27 --- JspTagTest.java 1 Sep 2003 21:53:33 -0000 1.28 *************** *** 38,180 **** { ! public JspTagTest(String name) { ! super(name); ! } ! /** ! * Check if the JSP Tag is being correctly recognized. ! * Our test html is : <BR> ! * <%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %><BR> ! * <jsp:useBean id="transfer" scope="session" class="com.bank.PageBean"/><BR> ! * <%<BR> ! * org.apache.struts.util.BeanUtils.populate(transfer, request);<BR> ! * if(request.getParameter("marker") == null)<BR> ! * // initialize a pseudo-property<BR> ! * transfer.set("days", java.util.Arrays.asList(<BR> ! * new String[] {"1", "2", "3", "4", "31"}));<BR> ! * else <BR> ! * if(transfer.validate(request))<BR> ! * %><jsp:forward page="transferConfirm.jsp"/><% ! * %> ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testJspTag() throws ParserException ! { ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! "<jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/>\n"+ ! "<%\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " %><jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>\n"); ! Parser.setLineSeparator("\r\n"); ! // Register the Jsp Scanner ! parser.addScanner(new JspScanner("-j")); ! parseAndAssertNodeCount(5); ! // The first node should be an HTMLJspTag ! assertTrue("Node 1 should be an HTMLJspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertStringEquals("Contents of the tag","@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" ",tag.getText()); ! ! // The second node should be a normal tag ! assertTrue("Node 2 should be an Tag",node[1] instanceof Tag); ! Tag htag = (Tag)node[1]; ! assertStringEquals("Contents of the tag","jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"",htag.getText()); ! assertStringEquals("html","<JSP:USEBEAN ID=\"transfer\" SCOPE=\"session\" CLASS=\"com.bank.PageBean\"/>",htag.toHtml()); ! // The third node should be an HTMLJspTag ! assertTrue("Node 3 should be an HTMLJspTag",node[2] instanceof JspTag); ! JspTag tag2 = (JspTag)node[2]; ! String expected = "\r\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\r\n"+ ! " if(request.getParameter(\"marker\") == null)\r\n"+ ! " // initialize a pseudo-property\r\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\r\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\r\n"+ ! " else \r\n"+ ! " if(transfer.validate(request))\r\n"+ ! " "; ! assertEquals("Contents of the tag",expected,tag2.getText()); ! ! } ! ! /** ! * Check if the JSP Tag is being correctly recognized. ! * Our test html is : <BR> ! * <%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %><BR> ! * <jsp:useBean id="transfer" scope="session" class="com.bank.PageBean"/><BR> ! * <%<BR> ! * org.apache.struts.util.BeanUtils.populate(transfer, request);<BR> ! * if(request.getParameter("marker") == null)<BR> ! * // initialize a pseudo-property<BR> ! * transfer.set("days", java.util.Arrays.asList(<BR> ! * new String[] {"1", "2", "3", "4", "31"}));<BR> ! * else <BR> ! * if(transfer.validate(request))<BR> ! * %><jsp:forward page="transferConfirm.jsp"/><% ! * %> ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testToHTML() throws ParserException ! { ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! "<jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/>\n"+ ! "<%\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " %><jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>\n"); ! Parser.setLineSeparator("\r\n"); ! // Register the Jsp Scanner ! parser.addScanner(new JspScanner("-j")); ! parseAndAssertNodeCount(5); ! // The first node should be an HTMLJspTag ! assertTrue("Node 1 should be an HTMLJspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertEquals("Raw String of the first JSP tag","<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>",tag.toHtml()); ! ! ! // The third node should be an HTMLJspTag ! assertTrue("Node 2 should be an HTMLJspTag",node[2] instanceof JspTag); ! JspTag tag2 = (JspTag)node[2]; ! String expected = "<%\r\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\r\n"+ ! " if(request.getParameter(\"marker\") == null)\r\n"+ ! " // initialize a pseudo-property\r\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\r\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\r\n"+ ! " else \r\n"+ ! " if(transfer.validate(request))\r\n"+ ! " %>"; ! assertEquals("Raw String of the second JSP tag",expected,tag2.toHtml()); ! assertTrue("Node 4 should be an HTMLJspTag",node[4] instanceof JspTag); ! JspTag tag4 = (JspTag)node[4]; ! expected = "<%\r\n"+ ! "%>"; ! assertEquals("Raw String of the fourth JSP tag",expected,tag4.toHtml()); ! ! } ! public void testSpecialCharacters() throws ParserException { ! StringBuffer sb1 = new StringBuffer(); ! sb1.append("<% for (i=0;i<j;i++);%>"); ! createParser(sb1.toString()); ! ! // Register the jsp scanner ! parser.addScanner(new JspScanner("-j")); ! parseAndAssertNodeCount(1); ! //assertTrue("Node should be a jsp tag",node[1] instanceof HTMLJspTag); ! JspTag jspTag = (JspTag)node[0]; ! assertEquals("jsp toHTML()","<% for (i=0;i<j;i++);%>",jspTag.toHtml()); ! } } --- 38,212 ---- { ! public JspTagTest(String name) { ! super(name); ! } ! /** ! * Check if the JSP Tag is being correctly recognized. ! * Our test html is : <BR> ! * <%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %><BR> ! * <jsp:useBean id="transfer" scope="session" class="com.bank.PageBean"/><BR> ! * <%<BR> ! * org.apache.struts.util.BeanUtils.populate(transfer, request);<BR> ! * if(request.getParameter("marker") == null)<BR> ! * // initialize a pseudo-property<BR> ! * transfer.set("days", java.util.Arrays.asList(<BR> ! * new String[] {"1", "2", "3", "4", "31"}));<BR> ! * else <BR> ! * if(transfer.validate(request))<BR> ! * %><jsp:forward page="transferConfirm.jsp"/><% ! * %> ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testJspTag() throws ParserException ! { ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! "<jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/>\n"+ ! "<%\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " %><jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>\n"); ! Parser.setLineSeparator("\r\n"); ! // Register the Jsp Scanner ! parser.addScanner(new JspScanner("-j")); ! parseAndAssertNodeCount(5); ! // The first node should be an HTMLJspTag ! assertTrue("Node 1 should be an HTMLJspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertStringEquals("Contents of the tag","@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" ",tag.getText()); ! ! // The second node should be a normal tag ! assertTrue("Node 2 should be an Tag",node[1] instanceof Tag); ! Tag htag = (Tag)node[1]; ! assertStringEquals("Contents of the tag","jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"",htag.getText()); ! assertStringEquals("html","<JSP:USEBEAN ID=\"transfer\" SCOPE=\"session\" CLASS=\"com.bank.PageBean\"/>",htag.toHtml()); ! // The third node should be an HTMLJspTag ! assertTrue("Node 3 should be an HTMLJspTag",node[2] instanceof JspTag); ! JspTag tag2 = (JspTag)node[2]; ! String expected = "\r\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\r\n"+ ! " if(request.getParameter(\"marker\") == null)\r\n"+ ! " // initialize a pseudo-property\r\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\r\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\r\n"+ ! " else \r\n"+ ! " if(transfer.validate(request))\r\n"+ ! " "; ! assertEquals("Contents of the tag",expected,tag2.getText()); ! ! } ! ! /** ! * Check if the JSP Tag is being correctly recognized. ! * Our test html is : <BR> ! * <%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %><BR> ! * <jsp:useBean id="transfer" scope="session" class="com.bank.PageBean"/><BR> ! * <%<BR> ! * org.apache.struts.util.BeanUtils.populate(transfer, request);<BR> ! * if(request.getParameter("marker") == null)<BR> ! * // initialize a pseudo-property<BR> ! * transfer.set("days", java.util.Arrays.asList(<BR> ! * new String[] {"1", "2", "3", "4", "31"}));<BR> ! * else <BR> ! * if(transfer.validate(request))<BR> ! * %><jsp:forward page="transferConfirm.jsp"/><% ! * %> ! * Creation date: (6/17/2001 4:01:06 PM) ! */ ! public void testToHTML() throws ParserException ! { ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! "<jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/>\n"+ ! "<%\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " %><jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>\n"); ! Parser.setLineSeparator("\r\n"); ! // Register the Jsp Scanner ! parser.addScanner(new JspScanner("-j")); ! parseAndAssertNodeCount(5); ! // The first node should be an HTMLJspTag ! assertTrue("Node 1 should be an HTMLJspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertEquals("Raw String of the first JSP tag","<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>",tag.toHtml()); ! ! ! // The third node should be an HTMLJspTag ! assertTrue("Node 2 should be an HTMLJspTag",node[2] instanceof JspTag); ! JspTag tag2 = (JspTag)node[2]; ! String expected = "<%\r\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\r\n"+ ! " if(request.getParameter(\"marker\") == null)\r\n"+ ! " // initialize a pseudo-property\r\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\r\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\r\n"+ ! " else \r\n"+ ! " if(transfer.validate(request))\r\n"+ ! " %>"; ! assertEquals("Raw String of the second JSP tag",expected,tag2.toHtml()); ! assertTrue("Node 4 should be an HTMLJspTag",node[4] instanceof JspTag); ! JspTag tag4 = (JspTag)node[4]; ! expected = "<%\r\n"+ ! "%>"; ! assertEquals("Raw String of the fourth JSP tag",expected,tag4.toHtml()); ! ! } ! public void testSpecialCharacters() throws ParserException { ! StringBuffer sb1 = new StringBuffer(); ! sb1.append("<% for (i=0;i<j;i++);%>"); ! createParser(sb1.toString()); ! ! // Register the jsp scanner ! parser.addScanner(new JspScanner("-j")); ! parseAndAssertNodeCount(1); ! //assertTrue("Node should be a jsp tag",node[1] instanceof HTMLJspTag); ! JspTag jspTag = (JspTag)node[0]; ! assertEquals("jsp toHTML()","<% for (i=0;i<j;i++);%>",jspTag.toHtml()); ! } ! ! ! /** ! * See bug #772700 Jsp Tags are not parsed correctly when in quoted attributes. ! */ ! public void testJspTagsInUnQuotedAttribes() throws ParserException { ! // this test should pass when none of the attibutes are quoted ! testJspTagsInAttributes("<img alt=<%=altText1%> src=<%=imgUrl1%> border=<%=borderToggle%>>"); ! } ! ! /** ! * See bug #772700 Jsp Tags are not parsed correctly when in quoted attributes. ! */ ! // public void testJspTagsInQuotedAttribes() throws ParserException { ! // // this test seems to mess up.... ! // testJspTagsInAttributes("<img alt=\"<%=altText1%>\" src=\"<%=imgUrl1%>\" border=\"<%=borderToggle%>\">"); ! // } ! ! private void testJspTagsInAttributes(String html) throws ParserException { ! createParser(html); ! parser.addScanner(new JspScanner()); ! parseAndAssertNodeCount(7); ! ! assertTrue("Should be a Jsp tag but was "+node[1].getClass().getName(),node[1] instanceof JspTag); ! assertTrue("Should be a Jsp tag but was "+node[3].getClass().getName(),node[3] instanceof JspTag); ! assertTrue("Should be a Jsp tag but was "+node[5].getClass().getName(),node[5] instanceof JspTag); ! ! assertTrue("Text Should be '<%=altText1%>'but was '" + node[1].toHtml() + "'" ,node[1].toHtml().equals("<%=altText1%>")); ! assertTrue("Text Should be '<%=imgUrl1%>' but was '" + node[3].toHtml() + "'" ,node[3].toHtml().equals("<%=imgUrl1%>")); ! assertTrue("Text Should be '<%=borderToggle%>' but was '" + node[5].toHtml() + "'" ,node[5].toHtml().equals("<%=borderToggle%>")); ! ! } } |