Спасибо за ссылку.
Но проблема в том что у меня есть класс который генерит тег :
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86.
public class Pie3DTag extends TagSupport{
private Vector datasetValues;
private String title;
public void setDatasetValues(Vector pDatasetValues) {
this .datasetValues = pDatasetValues;
}
public Vector getDatasetValues() {
return this .datasetValues;
}
public void setTitle(String pTitle) {
this .title = pTitle;
}
public String getTitle() {
return this .title;
}
// Get pie with necessary properties
public pieApp getPie() {
Iterator iterator = getDatasetValues().iterator();
//int value = 0;
String stringOfValues = "";
while (iterator.hasNext()) {
int value = ((Integer)iterator.next()).intValue();
stringOfValues = stringOfValues + new String( String.valueOf(value) + ",");
}
pieApp pie3D = new pieApp();
pie3D.loadProperties(pageContext.getServletContext().getRealPath("/WEB-INF/classes/style.properties"));
pie3D.setProperty("dataset0yValues",stringOfValues);
pie3D.setProperty("writeDirectory", pageContext.getServletContext().getRealPath(pie3D.getProperty("writeDirectory")));
pie3D.setProperty("readDirectory", pageContext.getServletContext().getRealPath(pie3D.getProperty("readDirectory")));
return pie3D;
}
// Out pie
public void outPie(pieApp pPie3D) {
String fileName = "";
String linkMap = "";
try {
linkMap = pPie3D.getLinkMap();
fileName = pPie3D.getProperty("readDirectory") + "\\" +pPie3D.getFileName();
} catch(Exception e) {
System.out.println("Error in Pie3DTag" + e.getMessage());
}
JspWriter out = pageContext.getOut();
try {
out.println("<jtidy:tidy>");
out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#DCDCDC\" >");
out.println("<tr>");
out.println("<td>");
out.println(linkMap);
out.println("<img src=\"" + fileName + "\"");
out.println("BORDER=\"0\" USEMAP=\"#pieMap\"/>");
out.println("</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td align=\"center\" >");
out.println(getTitle());
out.println("</td>");
out.println("</tr>");
out.println("</table>");
out.println("</jtidy:tidy>");
} catch (IOException ioe) {
System.out.println("Error in Pie3DTag" + ioe.getMessage());
}
}
// Start Tag
public int doStartTag() throws JspException {
pieApp pie3D = getPie();
outPie(pie3D);
return EVAL_BODY_INCLUDE;
}
// End Tag
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
}
Вот класс которій проводит тест :
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64.
public class Pie3DTagTestCactus extends JspTestCase {
private Pie3DTag tag;
public Pie3DTagTestCactus(String name) {
super (name);
}
public void setUp() throws Exception {
tag = new Pie3DTag();
tag.setPageContext( this .pageContext);
}
public void testTag() {
Vector dataset = new Vector();
dataset.add( 0 , new Integer( 110 ));
dataset.add( 1 , new Integer( 65 ));
dataset.add( 2 , new Integer( 60 ));
dataset.add( 3 , new Integer( 90 ));
tag.setDatasetValues(dataset);
tag.setTitle("My title");
try {
assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
} catch (JspException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
public void endTag(WebResponse response) throws IOException, ParserConfigurationException, SAXException, TransformerException {
String outputXhtml = response.getText();
//String outputXhtml = "<solar-system><planet name='Earth' position='3' supportsLife='yes'/>"
// + "<planet name='Venus' position='4'/></solar-system>";
try {
// validate xhtml
//XMLUnit.buildControlDocument(outputXhtml);
System.out.println(outputXhtml);
XMLAssert.assertXpathExists("//planet[@name='Earth']", outputXhtml);
/*
XMLAssert.assertXpathEvaluatesTo("0", "//table/@border", outputXhtml);
XMLAssert.assertXpathExists("//table/tr/td", outputXhtml);
System.out.println("//table/tr[1]/td");
XMLAssert.assertXpathExists("//table/tr[1]/td", outputXhtml);
System.out.println("//table/tr[2]/td/font");
XMLAssert.assertXpathExists("//table/tr[2]/td/font", outputXhtml);
XMLAssert.assertXpathEvaluatesTo("65", "//table/tr[2]/td/font/b", outputXhtml);
System.out.println("//table/tr[2]/td/font/font");
*/
//XMLAssert.assertXpathExists("//table/tr[2]/td//font", outputXhtml);
//XMLAssert.assertXpathEvaluatesTo("My title", "//table/tr[2]/td/font/b/font", outputXhtml);
}
catch (SAXException e) {
fail("Wrong XHTML code: " + e);
System.out.println(e.getMessage());
}
}
}
страничка JSP :
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.
<%@ taglib uri="/WEB-INF/chart.tld" prefix="chart" %>
<%@ taglib uri="/WEB-INF/jtidysamples-taglib-11.tld" prefix="jtidy" %>
<%@ page import = "javachart.servlet.*"%>
<html>
<head><title>Antialiased Pie Chart Example</title></head>
<body bgcolor="white">
<jsp:useBean id="dataset" class ="java.util.Vector" scope="page" />
<%
dataset.add( 0 , new Integer( 110 ));
dataset.add( 1 , new Integer( 65 ));
dataset.add( 2 , new Integer( 60 ));
dataset.add( 3 , new Integer( 90 ));
String title = "<font size=\"5\" color=\"#CD853F\" face=\"Arial\"><B>" + "65 " + "</B></font>" +
"<font size=\"2\" color=\"#A9A9A9\" face=\"Arial\">" + "Title" + "</font>";
%>
<chart:pie3D datasetValues="<%=dataset%>" title="<%=title%>" />
</body>
</html>
Но нужно провести CactusTest с использованием XMLUnit но он валиться
так как linkMap генерит
1. 2. 3. 4. 5. 6.
<map name="pieMap">
<area shape="poly" coords="185, 37, 182, 35, 179, 32, 176, 29, 172, 27, 168, 24, 164, 22, 160, 20, 155, 18, 150, 16, 145, 15, 140, 13, 134, 12, 129, 11, 123, 10, 117, 9, 112, 9, 106, 9, 100, 9, 95, 9, 89, 9, 83, 9, 77, 10, 72, 11, 66, 12, 61, 13, 56, 15, 50, 16, 46, 18, 41, 20, 36, 22, 32, 24, 28, 26, 22, 31, 100, 58" alt="value: 110" title="value: 110" href="1.html">
<area shape="poly" coords="22, 31, 19, 34, 16, 37, 13, 40, 11, 43, 10, 46, 8, 49, 7, 52, 7, 55, 7, 58, 7, 60, 7, 63, 8, 66, 9, 69, 11, 72, 13, 75, 15, 78, 18, 81, 21, 84, 24, 86, 27, 89, 100, 58" alt="value: 65" title="value: 65" href="2.html">
<area shape="poly" coords="27, 89, 31, 91, 35, 94, 40, 96, 44, 98, 49, 99, 54, 101, 60, 103, 65, 104, 71, 105, 76, 106, 82, 107, 88, 107, 94, 107, 100, 107, 104, 107, 110, 107, 116, 107, 124, 106, 100, 58" alt="value: 60" title="value: 60" href="3.html">
<area shape="poly" coords="124, 106, 129, 105, 135, 104, 140, 103, 146, 101, 151, 99, 156, 98, 160, 96, 165, 94, 169, 91, 173, 89, 176, 86, 179, 84, 182, 81, 185, 78, 187, 75, 189, 72, 191, 69, 192, 66, 193, 63, 193, 60, 193, 58, 193, 55, 193, 52, 192, 49, 190, 46, 189, 43, 185, 37, 100, 58" alt="value: 90" title="value: 90" href="4.html">
</MAP>
Ошибка в том что тег area должен заканчиваться на "/>", а при генерации
генериться ">", и из-за этого я не могу проводить ни каких тестов(так бы я сам исправил ">" на "/>", но оно генериться). Вот я и хочу прикрутить JTidy , но он что не поднялся.
Может кто знает почему он не поднялся,
или как можна решить эту проблему по другому.
|