Methods Summary |
---|
private void | addResultsToDocument(java.lang.String status, java.util.Vector resultVector)This api adds each result to the document tree based on the status.
for (int i = 0; i < resultVector.size(); i++) {
Enumeration en;
Result r = (Result) resultVector.get(i);
String moduleName = r.getModuleName();
if (status == FAILED) {
en = r.getErrorDetails().elements();
} else if (status == WARNING) {
en = r.getWarningDetails().elements();
} else if (status == PASSED)
en = r.getGoodDetails().elements();
else
en = r.getNaDetails().elements();
createNode(moduleName, status);
addToDocument(moduleName, status, r, en);
}
|
private void | addToDocument(java.lang.String moduleName, java.lang.String status, Result r, java.util.Enumeration en)This method adds the result value to the appropriate location in the DOM
tree.
if (r == null) return;
NodeList nodeList;
//this nodeList is the list of nodes below the moduleNode
nodeList =
document.getElementsByTagName(moduleName).item(0)
.getChildNodes();
Element statusNode = null;
for (int j = 0; j < nodeList.getLength(); j++) {
if (((Element) nodeList.item(j)).getTagName().equals(status)) {
statusNode = (Element) nodeList.item(j);
break;
}
}
// now get the stuff and write out from result object r
Element test = document.createElement(TEST);
Element testName = getTextNode(TEST_NAME, r.getTestName());
Element testAssertion = getTextNode(TEST_ASSERTION, r.getAssertion());
// loop thru Details vector
String string = "";
while (en.hasMoreElements()) {
string = string + (String) en.nextElement() + "\n"; // NOI18N
}
Element testDescr = getTextNode(TEST_DESC, string);
test.appendChild(testName);
test.appendChild(testAssertion);
test.appendChild(testDescr);
statusNode.appendChild(test);
|
private void | createDOMTree()create the new Document tree with root node
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
document = builder.newDocument();
rootNode = document.createElement(STATIC_VER);
document.appendChild(rootNode);
|
private void | createNode(java.lang.String moduleName, java.lang.String status)This method is responsible for creating nodes in the DOM tree like
where moduleName is ejb and status is failed.
NodeList nodeList;
Element moduleNode;
nodeList = document.getElementsByTagName(moduleName);
if (nodeList.getLength() == 0) {
moduleNode = document.createElement(moduleName);
rootNode.appendChild(moduleNode);
} else {
moduleNode = (Element) nodeList.item(0); //there is only 1 node with tag of moduleNode value
}
nodeList = moduleNode.getChildNodes();
Element statusNode = null;
if (nodeList.getLength() == 0) {
statusNode = document.createElement(status);
moduleNode.appendChild(statusNode);
} else {
for (int j = 0; j < nodeList.getLength(); j++) {
if (((Element) nodeList.item(j)).getTagName().equals(status)) {
statusNode = (Element) nodeList.item(j);
break;
}
}
if (statusNode == null) {
statusNode = document.createElement(status);
moduleNode.appendChild(statusNode);
}
}
|
private void | createResultsDocument(int reportLevel)This api initializes the document object and calls generate apis to add results
to the document. Finally failureCount() api is called to add the error, failure
and warning counts to the document.
createDOMTree();
if (reportLevel != VerifierConstants.FAIL)
addResultsToDocument(WARNING, resultMgr.getWarningResults());
if (reportLevel == VerifierConstants.ALL) {
addResultsToDocument(PASSED, resultMgr.getOkayResults());
addResultsToDocument(NOTAPPLICABLE, resultMgr.getNaResults());
}
addResultsToDocument(FAILED, resultMgr.getFailedResults());
Vector error = resultMgr.getError();
if (!error.isEmpty()) {
for (int i = 0; i < error.size(); i++) {
LogRecord lr = (LogRecord) error.get(i);
generateErrors(lr);
}
}
failureCount();
|
private java.io.File | extractResultsFileToTmpDir(java.lang.String jarFile)
File tmpJarFile = null;
String fullFilename;
tmpJarFile = new File(jarFile);
fullFilename = tmpJarFile.getAbsolutePath();
if (new File(fullFilename).getParent() != null) {
(new File(new File(fullFilename).getParent())).mkdirs();
}
return tmpJarFile;
|
private void | failureCount()
int failedCount = resultMgr.getFailedCount();
int warningCount = resultMgr.getWarningCount();
int errorCount = resultMgr.getErrorCount();
Element failureNode = null;
NodeList nodeList = document.getElementsByTagName(FAILCOUNT);
if (nodeList.getLength() == 0) {
failureNode = document.createElement(FAILCOUNT);
rootNode.appendChild(failureNode);
} else {
failureNode = (Element) nodeList.item(0);
}
nodeList = failureNode.getChildNodes();//document.getElementsByTagName(FAILED);
Element failed_count = null;
Element warning_count = null;
Element error_count = null;
if (nodeList.getLength() == 0) {
failed_count =
getTextNode(FAILNUMBER,
new Integer(failedCount).toString());
failureNode.appendChild(failed_count);
warning_count =
getTextNode(WARNINGNUMBER,
new Integer((warningCount)).toString());
failureNode.appendChild(warning_count);
error_count =
getTextNode(ERRORNUMBER,
new Integer(errorCount).toString());
failureNode.appendChild(error_count);
} else {
for (int j = 0; j < nodeList.getLength(); j++) {
if (((Element) nodeList.item(j)).getTagName().equals(
FAILNUMBER)) {
failed_count = (Element) nodeList.item(j);
(failed_count.getFirstChild()).setNodeValue(
new Integer(failedCount).toString());
}
if (((Element) nodeList.item(j)).getTagName().equals(
WARNINGNUMBER)) {
warning_count = (Element) nodeList.item(j);
(warning_count.getFirstChild()).setNodeValue(
new Integer(warningCount).toString());
}
if (((Element) nodeList.item(j)).getTagName().equals(
ERRORNUMBER)) {
error_count = (Element) nodeList.item(j);
(error_count.getFirstChild()).setNodeValue(
new Integer(errorCount).toString());
}
}
if (failed_count == null) {
failed_count =
getTextNode(FAILNUMBER,
new Integer(failedCount).toString());
failureNode.appendChild(failed_count);
}
if (warning_count == null) {
warning_count =
getTextNode(WARNINGNUMBER,
new Integer(warningCount).toString());
failureNode.appendChild(warning_count);
}
if (error_count == null) {
error_count =
getTextNode(ERRORNUMBER,
new Integer(errorCount).toString());
failureNode.appendChild(error_count);
}
}
|
public void | generateAllReports()This api is called from verfier framework to generate the final report
try {
createResultsDocument(frameworkContext.getReportLevel());
writeToXmlFile();
writeToTxtFile();
writeToConsole();
} catch (IOException e) {
throw e;
}
|
private void | generateErrors(java.util.logging.LogRecord record)This api is used to add the error logs into the document.
Element errorNode = null;
//start adding nodes to document
//check if the node already exists. If not, add it.
NodeList nodeList = document.getElementsByTagName(ERROR);
if (nodeList.getLength() == 0) {
errorNode = document.createElement(ERROR);
rootNode.appendChild(errorNode);
} else {
errorNode = (Element) nodeList.item(0); //there is only 1 node with tag of errorNode value
}
Element excepName = getTextNode(ERROR_NAME, record.getMessage());
errorNode.appendChild(excepName);
if (record.getThrown() != null) {
Element excepDescr = getTextNode(ERROR_DESC,
writeStackTraceToFile(record.getThrown()));
errorNode.appendChild(excepDescr);
}
|
private void | generateText(org.w3c.dom.Document xmlResult, java.io.File stylesheet, java.io.OutputStream output)Transforms the xml report to txt report.
// Produce Output:
FileOutputStream fos = null;
try {
StreamSource styleSource;
Transformer transformer;
TransformerFactory tFactory = TransformerFactory.newInstance();
if (stylesheet != null) {
FileInputStream fis = new FileInputStream(stylesheet);
styleSource = new StreamSource(fis);
transformer = tFactory.newTransformer(styleSource);
} else {
transformer = tFactory.newTransformer();
}
DOMSource source = new DOMSource(xmlResult);
StreamResult streamResult = new StreamResult(output);
transformer.transform(source, streamResult);
} catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
} finally {
try {
if(fos != null)
fos.close();
} catch (Exception e) {}
}
|
private java.io.File | getLocalizedXSLFile()
String xslHome = System.getProperty(Constants.VERIFIER_XSL);
if (xslHome == null) {
xslHome = System.getProperty(Constants.INSTALL_ROOT) +
File.separator +
"lib" + // NOI18N
File.separator +
"verifier"; // NOI18N
}
Locale locale = Locale.getDefault();
// check first with the language and country
String xslFileName = xslHome + File.separator + XSL_FILE + "_" + locale.toString() + ".xsl"; // NOI18N
File xslFile = new File(xslFileName);
if (xslFile.exists()) {
return xslFile;
}
// check now with the language
xslFileName = xslHome + File.separator + XSL_FILE + "_" + locale.getLanguage() + ".xsl"; // NOI18N
xslFile = new File(xslFileName);
if (xslFile.exists()) {
return xslFile;
}
// just take the english version now...
xslFileName = xslHome + File.separator + XSL_FILE + ".xsl"; // NOI18N
xslFile = new File(xslFileName);
return xslFile;
|
private org.w3c.dom.Element | getTextNode(java.lang.String tag, java.lang.String text)Convenience for creating a node text.
Element element = document.createElement(tag);
element.appendChild(document.createTextNode(text));
return element;
|
private java.lang.String | writeStackTraceToFile(java.lang.Throwable e)returns the error description for writing to the final report.
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return sw.toString();
|
private void | writeToConsole()writes the final output report file to the console.
if (frameworkContext.isUsingGui())
return;
if (frameworkContext.isBackend()) {
logger.log(Level.SEVERE, textResult);
} else {
logger.log(Level.INFO, getClass().getName() + ".resultSummary",
new Object[]{new Integer(resultMgr.getFailedCount()),
new Integer(resultMgr.getWarningCount()),
new Integer(resultMgr.getErrorCount())});
}
if((resultMgr.getFailedCount() + resultMgr.getWarningCount()
+ resultMgr.getErrorCount()) != 0
|| frameworkContext.getReportLevel() == VerifierConstants.ALL)
logger.log(Level.INFO, getClass().getName() +
".LookInResultsTestAssertions", // NOI18N
new Object[]{outputFileStr + ".txt"}); // NOI18N
else
logger.log(Level.INFO, getClass().getName() +
".LookInResultsTestAssertions1"); // NOI18N
|
private void | writeToTxtFile()writes the final result report to output txt file
File xslFile = getLocalizedXSLFile();
Document dynamicDocument = document;
ByteArrayOutputStream output = new ByteArrayOutputStream();
generateText(dynamicDocument, xslFile, output);
textResult = output.toString("UTF-8");
// dump to text file.
File outputFile = extractResultsFileToTmpDir(outputFileStr + ".txt"); // NOI18N
OutputStreamWriter fw = new OutputStreamWriter(
new FileOutputStream(outputFile));
fw.write(textResult);
fw.close();
|
private void | writeToXmlFile()wites the final result report to the output xml file
FileOutputStream fos = null;
try {
File outputFile = extractResultsFileToTmpDir(
outputFileStr + ".xml"); // NOI18N
DOMSource domSource = new DOMSource(document);
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // NOI18N
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); // NOI18N
String encoding = System.getProperty("file.encoding");
transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
fos = new FileOutputStream(outputFile);
transformer.transform(domSource, new StreamResult(fos));
} catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
} finally {
try {
if(fos != null)
fos.close();
} catch (Exception e){}
}
|