[webbeans-commits] Webbeans SVN: r1402 - tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Feb 3 23:09:41 EST 2009
Author: shane.bryzak at jboss.com
Date: 2009-02-03 23:09:41 -0500 (Tue, 03 Feb 2009)
New Revision: 1402
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditParser.java
Modified:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java
Log:
refactored, report improvements
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditParser.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditParser.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditParser.java 2009-02-04 04:09:41 UTC (rev 1402)
@@ -0,0 +1,138 @@
+package org.jboss.webbeans.tck.impl.report;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Parsing utilities for tck-audit.xml
+ *
+ * @author Shane Bryzak
+ *
+ */
+public class AuditParser
+{
+ private String version;
+
+ private Map<String,List<AuditAssertion>> assertions = new HashMap<String,List<AuditAssertion>>();
+
+ private Map<String,String> titles = new HashMap<String,String>();
+
+ private InputStream source;
+
+ public AuditParser(InputStream source)
+ {
+ this.source = source;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public String getSectionTitle(String sectionId)
+ {
+ return titles.get(sectionId);
+ }
+
+ public Map<String,List<AuditAssertion>> getAssertions()
+ {
+ return assertions;
+ }
+
+ /**
+ * Returns a sorted list of assertions for the specified section ID
+ *
+ * @param sectionId
+ * @return
+ */
+ public List<AuditAssertion> getAssertionsForSection(String sectionId)
+ {
+ List<AuditAssertion> sectionAssertions = new ArrayList<AuditAssertion>(assertions.get(sectionId));
+ Collections.sort(sectionAssertions);
+ return sectionAssertions;
+ }
+
+ /**
+ * Load the spec assertions defined in tck-audit.xml
+ */
+ public void parse() throws Exception
+ {
+ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
+ Document doc = builder.parse(source);
+ NodeList sectionNodes = doc.getDocumentElement().getChildNodes();
+
+ version = doc.getDocumentElement().getAttribute("version");
+
+ for (int i = 0; i < sectionNodes.getLength(); i++)
+ {
+ if (sectionNodes.item(i) instanceof Element &&
+ "section".equals(sectionNodes.item(i).getNodeName()))
+ {
+ processSectionNode((Element) sectionNodes.item(i));
+ }
+ }
+ }
+
+ private void processSectionNode(Element node)
+ {
+ String sectionId = node.getAttribute("id");
+ titles.put(sectionId, node.getAttribute("title"));
+
+ NodeList assertionNodes = node.getChildNodes();
+
+ for (int i = 0; i < assertionNodes.getLength(); i++)
+ {
+ if (assertionNodes.item(i) instanceof Element &&
+ "assertion".equals(assertionNodes.item(i).getNodeName()))
+ {
+ processAssertionNode(sectionId, (Element) assertionNodes.item(i));
+ }
+ }
+ }
+
+ private void processAssertionNode(String sectionId, Element node)
+ {
+ List<AuditAssertion> value = assertions.get(sectionId);
+ if (value == null)
+ {
+ value = new ArrayList<AuditAssertion>();
+ assertions.put(sectionId, value);
+ }
+
+ String text = null;
+ String note = null;
+
+ for (int i = 0; i < node.getChildNodes().getLength(); i++)
+ {
+ Node child = node.getChildNodes().item(i);
+
+ if (child instanceof Element)
+ {
+ if ("text".equals(child.getNodeName()))
+ {
+ text = child.getTextContent();
+ }
+ else if ("note".equals(child.getNodeName()))
+ {
+ note = child.getTextContent();
+ }
+ }
+ }
+
+ value.add(new AuditAssertion(node.getAttribute("section"),
+ node.getAttribute("id"), text, note));
+ }
+}
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java 2009-02-04 00:24:32 UTC (rev 1401)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java 2009-02-04 04:09:41 UTC (rev 1402)
@@ -1,29 +1,18 @@
package org.jboss.webbeans.tck.impl.report;
-import com.sun.mirror.util.DeclarationVisitors;
-
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import org.jboss.webbeans.tck.SpecAssertion;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import com.sun.mirror.apt.AnnotationProcessor;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
import com.sun.mirror.declaration.Declaration;
import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.util.DeclarationVisitors;
import com.sun.mirror.util.SimpleDeclarationVisitor;
/**
@@ -37,15 +26,14 @@
private static final String REPORT_FILE_NAME = "coverage.html";
private static final String AUDIT_FILE_NAME = "tck-audit.xml";
-
- private Map<String,List<AuditAssertion>> assertions = new HashMap<String,List<AuditAssertion>>();
- private Map<String,String> sections = new HashMap<String,String>();
-
+
private final AnnotationProcessorEnvironment env;
private final File baseDir;
private final List<SpecReference> references = new ArrayList<SpecReference>();
+ private AuditParser auditParser;
+
public CoverageProcessor(AnnotationProcessorEnvironment env)
{
this.env = env;
@@ -55,7 +43,8 @@
try
{
- loadAssertions();
+ auditParser = new AuditParser(new FileInputStream(AUDIT_FILE_NAME));
+ auditParser.parse();
}
catch (Exception ex)
{
@@ -63,76 +52,6 @@
ex.getClass().getName() + " - " + ex.getMessage(), ex);
}
}
-
- /**
- * Load the spec assertions defined in tck-audit.xml
- */
- private void loadAssertions() throws Exception
- {
- DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-
- Document doc = builder.parse(new FileInputStream(AUDIT_FILE_NAME));
- NodeList sectionNodes = doc.getDocumentElement().getChildNodes();
-
- for (int i = 0; i < sectionNodes.getLength(); i++)
- {
- if (sectionNodes.item(i) instanceof Element &&
- "section".equals(sectionNodes.item(i).getNodeName()))
- {
- processSectionNode((Element) sectionNodes.item(i));
- }
- }
- }
-
- private void processSectionNode(Element node)
- {
- String sectionId = node.getAttribute("id");
- sections.put(sectionId, node.getAttribute("title"));
-
- NodeList assertionNodes = node.getChildNodes();
-
- for (int i = 0; i < assertionNodes.getLength(); i++)
- {
- if (assertionNodes.item(i) instanceof Element &&
- "assertion".equals(assertionNodes.item(i).getNodeName()))
- {
- processAssertionNode(sectionId, (Element) assertionNodes.item(i));
- }
- }
- }
-
- private void processAssertionNode(String sectionId, Element node)
- {
- List<AuditAssertion> value = assertions.get(sectionId);
- if (value == null)
- {
- value = new ArrayList<AuditAssertion>();
- assertions.put(sectionId, value);
- }
-
- String text = null;
- String note = null;
-
- for (int i = 0; i < node.getChildNodes().getLength(); i++)
- {
- Node child = node.getChildNodes().item(i);
-
- if (child instanceof Element)
- {
- if ("text".equals(child.getNodeName()))
- {
- text = child.getTextContent();
- }
- else if ("note".equals(child.getNodeName()))
- {
- note = child.getTextContent();
- }
- }
- }
-
- value.add(new AuditAssertion(node.getAttribute("section"),
- node.getAttribute("id"), text, note));
- }
public void process()
{
@@ -145,20 +64,7 @@
new CreateReferenceVisitor(), DeclarationVisitors.NO_OP));
}
- CoverageReport report = new CoverageReport(references, assertions, sections);
-
- try
- {
- File reportFile = new File(baseDir, REPORT_FILE_NAME);
- FileOutputStream out = new FileOutputStream(reportFile);
- report.generate(out);
- out.flush();
- out.close();
- }
- catch (IOException ex)
- {
- throw new RuntimeException("Error generating report file", ex);
- }
+ new CoverageReport(references, auditParser).writeToFile(new File(baseDir, REPORT_FILE_NAME));
}
private class CreateReferenceVisitor extends SimpleDeclarationVisitor
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java 2009-02-04 00:24:32 UTC (rev 1401)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java 2009-02-04 04:09:41 UTC (rev 1402)
@@ -1,5 +1,7 @@
package org.jboss.webbeans.tck.impl.report;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -15,23 +17,14 @@
*/
public class CoverageReport
{
- /**
+ /*
* References to the spec assertions made by the tck tests
*/
private final Map<String,List<SpecReference>> references;
- /**
- * Assertions, mapped by section id
- */
- private final Map<String,List<AuditAssertion>> assertions;
+ private AuditParser auditParser;
- /*
- * Section titles
- */
- private final Map<String,String> sections;
-
- public CoverageReport(List<SpecReference> references, Map<String,List<AuditAssertion>> assertions,
- Map<String,String> sections)
+ public CoverageReport(List<SpecReference> references, AuditParser auditParser)
{
this.references = new HashMap<String,List<SpecReference>>();
@@ -45,14 +38,14 @@
this.references.get(ref.getSection()).add(ref);
}
- this.assertions = assertions;
- this.sections = sections;
+ this.auditParser = auditParser;
}
public void generate(OutputStream out) throws IOException
{
writeHeader(out);
- writeBody(out);
+ writeCoverage(out);
+ writeUnmatched(out);
writeFooter(out);
}
@@ -62,8 +55,9 @@
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n");
- sb.append("\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
- sb.append("<html><head><title>JSR-299 TCK Coverage Report</title>\n");
+ sb.append("\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n");
+ sb.append("<html>\n");
+ sb.append("<head><title>JSR-299 TCK Coverage Report</title>\n");
sb.append("<style type=\"text/css\">\n");
sb.append(" .code {\n");
@@ -74,40 +68,60 @@
sb.append(" height: 100%; }\n");
sb.append(" .results {\n");
sb.append(" margin-left: 50px; }\n");
- sb.append(" #pass {\n");
+ sb.append(" .description {\n");
+ sb.append(" margin-top: 2px;\n");
+ sb.append(" margin-bottom: 2px; }\n");
+ sb.append(" .sectionHeader {\n");
+ sb.append(" font-weight: bold; }\n");
+ sb.append(" .noCoverage {\n");
+ sb.append(" margin-top: 2px;\n");
+ sb.append(" margin-bottom: 2px;\n");
+ sb.append(" font-weight: bold;\n");
+ sb.append(" font-style: italic;\n");
+ sb.append(" color: #ff0000; }\n");
+ sb.append(" .coverageHeader {\n");
+ sb.append(" font-weight: bold;\n");
+ sb.append(" text-decoration: underline;\n");
+ sb.append(" margin-top: 2px;\n");
+ sb.append(" margin-bottom: 2px; }\n");
+ sb.append(" .pass {\n");
+ sb.append(" background-color: #dfd; }\n");
+ sb.append(" .fail {\n");
sb.append(" background-color: #fdd; }\n");
- sb.append(" #fail {\n");
- sb.append(" background-color: #dfd; }\n");
sb.append("</style>\n");
sb.append("</head><body>");
- sb.append("<h1>JSR-299 TCK Coverage</h1>");
+ sb.append("<h1>JSR-299 TCK Coverage</h1>");
+ sb.append("<h2>");
+ sb.append(auditParser.getVersion());
+ sb.append("</h2>\n");
out.write(sb.toString().getBytes());
}
- private void writeBody(OutputStream out) throws IOException
+ private void writeCoverage(OutputStream out) throws IOException
{
- List<String> keys = new ArrayList<String>(sections.keySet());
- Collections.sort(keys);
+ List<String> sectionIds = new ArrayList<String>(auditParser.getAssertions().keySet());
+ Collections.sort(sectionIds);
- for (String key : keys)
+ for (String sectionId : sectionIds)
{
- out.write(("<h2>Section " + key + " - " + sections.get(key) + "</h2>\n").getBytes());
+ out.write(("<div class=\"sectionHeader\">Section " + sectionId + " - " + auditParser.getSectionTitle(sectionId) +
+ "</div>\n").getBytes());
- List<AuditAssertion> sectionAssertions = assertions.get(key);
+ List<AuditAssertion> sectionAssertions = auditParser.getAssertionsForSection(sectionId);
if (sectionAssertions != null && !sectionAssertions.isEmpty())
- {
- Collections.sort(sectionAssertions);
-
+ {
StringBuilder sb = new StringBuilder();
for (AuditAssertion assertion : sectionAssertions)
{
- sb.append(" <div class=\"assertion\">\n");
+ List<SpecReference> coverage = getCoverageForAssertion(sectionId, assertion.getId());
+ sb.append(" <div class=\"" + (coverage.isEmpty() ? "fail" : "pass") + "\">\n");
+
sb.append(" <span class=\"code\">");
sb.append(assertion.getId());
sb.append(")");
@@ -119,11 +133,15 @@
sb.append("</p>\n");
sb.append(" <div class=\"coverage\">\n");
- sb.append(" <h4>Coverage</h4>\n");
+ sb.append(" <p class=\"coverageHeader\">Coverage</p>\n");
- if (references.get(key) != null)
+ if (coverage.isEmpty())
{
- for (SpecReference ref : references.get(key))
+ sb.append(" <p class=\"noCoverage\">No tests exist for this assertion</p>\n");
+ }
+ else
+ {
+ for (SpecReference ref : coverage)
{
sb.append(" <p>");
sb.append(ref.getClassName());
@@ -134,17 +152,66 @@
}
}
- sb.append(" </div>\n </div>\n");
+ sb.append(" </div>\n </div>\n</div>");
}
out.write(sb.toString().getBytes());
}
}
}
+
+ private void writeUnmatched(OutputStream out) throws IOException
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("<h3>Unmatched tests</h3>\n");
+ sb.append("<p>The following tests do not match any known assertions</p>");
+
+ sb.append("<table>\n");
+ sb.append(" <tr><th>Section</th><th>Assertion</th><th>Test Class</th><th>Test Method</th></tr>\n");
+
+
+ sb.append("</table>");
+
+ out.write(sb.toString().getBytes());
+ }
+
+ private List<SpecReference> getCoverageForAssertion(String sectionId, String assertionId)
+ {
+ List<SpecReference> refs = new ArrayList<SpecReference>();
+
+ if (references.containsKey(sectionId))
+ {
+ for (SpecReference ref : references.get(sectionId))
+ {
+ if (ref.getAssertion().equals(assertionId))
+ {
+ refs.add(ref);
+ }
+ }
+ }
+
+ return refs;
+ }
private void writeFooter(OutputStream out) throws IOException
{
out.write("</table>".getBytes());
out.write("</body></html>".getBytes());
}
+
+ public void writeToFile(File file)
+ {
+ try
+ {
+ FileOutputStream out = new FileOutputStream(file);
+ generate(out);
+ out.flush();
+ out.close();
+ }
+ catch (IOException ex)
+ {
+ throw new RuntimeException("Error generating report file", ex);
+ }
+ }
}
More information about the weld-commits
mailing list