Commit f6448165 authored by wwalkowski's avatar wwalkowski

No commit message

No commit message
parent d01d53f5
/* $Id: ExtractDLNAResults.java 38705 2012-10-12 22:01:05Z wwalkowski $ */
/*
* Copyright (C) 2012 CableLabs
*/
package parser;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.*;
import java.util.HashMap;
import java.util.Vector;
public class ExtractDLNAResults
{
private HashMap<String, Vector<Rec>> map = new HashMap<String, Vector<Rec>>();
public static class Rec
{
private String status;
private String time;
private String assertion;
private String comment;
public Rec ( String s, String t, String a, String c )
{
status = s.replace("\t", " ").replace("\"", "'");
time = t.replace("\t", " ").replace("\"", "'");
assertion = a.replace("\t", " ").replace("\"", "'");
comment = c.replace("\t", " ").replace("\"", "'");
}
public String toString()
{
return status + ",\"" + comment + "\",\"" + assertion + "\"," + time;
}
}
public static void main ( String[] args )
{
int exitValue = SharedConstants.successValue;
ExtractDLNAResults ex = new ExtractDLNAResults();
try
{
ex.execute();
}
catch ( Exception e )
{
exitValue = SharedConstants.failValue;
}
System.exit ( exitValue );
}
/*
* Process the result file
*/
public void execute()
throws Exception
{
Utilities ut = new Utilities();
File file = new File ( SharedConstants.dlnaCttParserLogFile );
file.delete();
File inputFile = new File ( SharedConstants.dlnaInputResultsFile );
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
Document doc = null;
dbFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = null;
try
{
dBuilder = dbFactory.newDocumentBuilder();
}
catch ( ParserConfigurationException e )
{
e.printStackTrace();
log ( "Parser Configuration Exception\r\n" + ut.getExceptionString(e) );
throw new Exception();
}
try
{
doc = dBuilder.parse(inputFile);
}
catch ( SAXException e )
{
e.printStackTrace();
log ( "SAX Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
catch ( IOException e )
{
e.printStackTrace();
log ( "IO Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
doc.getDocumentElement().normalize();
// Get the Root Element
Element rootNode = doc.getDocumentElement();
// Burrow until we find a result
NodeList nList = rootNode.getChildNodes();
Node testRunParent = null;
for ( int i = 0; i < nList.getLength(); i++ )
{
testRunParent = nList.item(i);
if ( testRunParent.getNodeName().trim().equals("testRun") )
break;
}
NodeList testCases = testRunParent.getChildNodes();
for ( int i = 0; i < testCases.getLength(); i++ )
{
if ( testCases.item(i).getNodeName().trim().equals("testCase") )
processTestCase ( testCases.item(i) );
}
// Loop through all status types to count first
MyFileWriter countFile = new MyFileWriter ( ut.getCountFileName() );
MyFileWriter resultsFile = new MyFileWriter ( ut.getResultsFileName() );
int total = 0;
try
{
for ( String s : map.keySet() )
{
countFile.write ( s + "\t" + map.get(s).size() );
total += map.get(s).size();
}
countFile.write ( "-----------------------" );
countFile.write ( "Total\t" + total );
countFile.write ( "\r\n\r\nThese files are in SVN located at: \r\n" +
"https://community.cablelabs.com/svn/oc/ocap_ri/trunk/ri/QA/dlna_ctt/MarketDMS%20Automated%20Results" );
countFile.close();
}
catch ( IOException e )
{
e.printStackTrace();
log ( "IO Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
try
{
// Now loop through again to display
for ( String s : map.keySet() )
{
for ( Rec r : map.get(s) )
{
resultsFile.write ( r.toString() );
}
}
resultsFile.close();
}
catch ( IOException e )
{
e.printStackTrace();
log ( "IO Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
}
/*
* Process an individual test case
*/
private void processTestCase ( Node testCase )
{
NodeList child = testCase.getChildNodes();
for ( int i = 0; i < child.getLength(); i++ )
{
if ( child.item(i).getNodeName().equals("result"))
processResult ( child.item(i) );
}
}
/*
* Process the result from an individual test case
*/
private void processResult ( Node result )
{
NodeList child = result.getChildNodes();
NamedNodeMap attrs = result.getAttributes();
String status = "not set";
String assertion = "not set";
String comment = "not set";
String time = "not set";
for ( int j = 0; j < attrs.getLength(); j++ )
{
Node attr = attrs.item(j);
String attrName = attr.getNodeName();
if ( attrName.equals("stamp") )
time = attr.getNodeValue();
if ( attrName.equals("test") )
status = attr.getNodeValue();
}
for ( int i = 0; i < child.getLength(); i++ )
{
if ( !child.item(i).getNodeName().equals("#text") )
{
if ( child.item(i).getNodeName().equals("comment") )
comment = child.item(i).getTextContent().replace("\r\n", " ").replace("\n", " ");
if ( child.item(i).getNodeName().equals("assertion") )
assertion = child.item(i).getTextContent();
}
}
Rec rec = new Rec ( status, time, assertion, comment );
Vector<Rec> results = map.get(rec.status);
if ( results == null )
{
results = new Vector<Rec>();
map.put ( rec.status, results );
}
results.add(rec);
}
private void log ( String message )
{
MyFileWriter mfw = new MyFileWriter ( SharedConstants.dlnaCttParserLogFile );
try
{
mfw.write(message);
}
catch ( IOException e )
{
// There's not much we can do with this. It will be called by a bash script
// and we are inside the logging message, so dump to screen in case this
// is being run manually.
e.printStackTrace();
}
mfw.close();
}
}
/* $Id: ExtractDLNAResults.java 38705 2012-10-12 22:01:05Z wwalkowski $ */
/*
* Copyright (C) 2012 CableLabs
*/
package parser;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.*;
import java.util.HashMap;
import java.util.Vector;
public class ExtractUPnPResults
{
private HashMap<String, Vector<Rec>> map = new HashMap<String, Vector<Rec>>();
public static class Rec
{
private String status;
private String time;
private String assertion;
// private String significance;
public Rec ( String s, String t, String a/*, String sig*/ )
{
status = s.replace("\t", " ").replace("\"", "'");
time = t.replace("\t", " ").replace("\"", "'");
assertion = a.replace("\t", " ").replace("\"", "'");
// significance = sig.replace("\t", " ").replace("\"", "'");
}
public String toString()
{
// return status + ",\"" + significance + "\",\"" + assertion + "\"," + time;
return status + ",\"" + assertion + "\"," + time;
}
}
public static void main ( String[] args )
{
int exitValue = SharedConstants.successValue;
ExtractUPnPResults ex = new ExtractUPnPResults();
try
{
ex.execute();
}
catch ( Exception e )
{
exitValue = SharedConstants.failValue;
}
System.exit ( exitValue );
}
/*
* Process the result file
*/
public void execute()
throws Exception
{
Utilities ut = new Utilities();
File file = new File ( SharedConstants.upnpCttParserLogFile );
file.delete();
File inputFile = new File ( SharedConstants.upnpInputResultsFile );
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
Document doc = null;
dbFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = null;
try
{
dBuilder = dbFactory.newDocumentBuilder();
}
catch ( ParserConfigurationException e )
{
e.printStackTrace();
log ( "Parser Configuration Exception\r\n" + ut.getExceptionString(e) );
throw new Exception();
}
try
{
doc = dBuilder.parse(inputFile);
}
catch ( SAXException e )
{
e.printStackTrace();
log ( "SAX Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
catch ( IOException e )
{
e.printStackTrace();
log ( "IO Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
doc.getDocumentElement().normalize();
// Get the Root Element
Element rootNode = doc.getDocumentElement();
// Burrow until we find a result
NodeList nList = rootNode.getChildNodes();
Node testRunParent = null;
for ( int i = 0; i < nList.getLength(); i++ )
{
testRunParent = nList.item(i);
if ( testRunParent.getNodeName().trim().equals("TestRun") )
break;
}
NodeList testCases = testRunParent.getChildNodes();
for ( int i = 0; i < testCases.getLength(); i++ )
{
if ( testCases.item(i).getNodeName().trim().equals("TestCase") )
processTestCase ( testCases.item(i) );
}
// Loop through all status types to count first
MyFileWriter countFile = new MyFileWriter ( ut.getCountFileName() );
MyFileWriter resultsFile = new MyFileWriter ( ut.getResultsFileName() );
int total = 0;
try
{
for ( String s : map.keySet() )
{
countFile.write ( s + "\t" + map.get(s).size() );
total += map.get(s).size();
}
countFile.write ( "-----------------------" );
countFile.write ( "Total\t" + total );
countFile.write ( "\r\n\r\nThese files are in SVN located at: \r\n" +
"https://community.cablelabs.com/svn/oc/ocap_ri/trunk/ri/QA/upnp_ctt/MarketDMS%20Automated%20Results" );
countFile.close();
}
catch ( IOException e )
{
e.printStackTrace();
log ( "IO Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
try
{
// Now loop through again to display
for ( String s : map.keySet() )
{
for ( Rec r : map.get(s) )
{
resultsFile.write ( r.toString() );
}
}
resultsFile.close();
}
catch ( IOException e )
{
e.printStackTrace();
log ( "IO Exception\r\n" + new Utilities().getExceptionString(e) );
throw new Exception();
}
}
/*
* Process an individual test case
*/
private void processTestCase ( Node testCase )
{
NamedNodeMap attrs = testCase.getAttributes();
// String significance = "not set";
String time = "not set";
String assertion = "not set";
String result = "not set";
// Get name and time from attributes
for ( int j = 0; j < attrs.getLength(); j++ )
{
Node attr = attrs.item(j);
String attrName = attr.getNodeName();
if ( attrName.equals("name") )
assertion = attr.getNodeValue();
if ( attrName.equals("startTime") )
time = attr.getNodeValue();
// if ( attrName.equals("significance") )
// significance = attr.getNodeValue();
}
NodeList child = testCase.getChildNodes();
for ( int i = 0; i < child.getLength(); i++ )
{
if ( child.item(i).getNodeName().equals("Result"))
{
result = child.item(i).getTextContent();
break;
}
}
System.out.println( "assertion : " + assertion );
System.out.println( "time : " + time );
// System.out.println( "significance: " + significance );
System.out.println( "result : " + result );
Rec rec = new Rec ( result, time, assertion/*, significance*/ );
Vector<Rec> results = map.get(rec.status);
if ( results == null )
{
results = new Vector<Rec>();
map.put ( rec.status, results );
}
results.add ( rec );
}
private void log ( String message )
{
MyFileWriter mfw = new MyFileWriter ( SharedConstants.dlnaCttParserLogFile );
try
{
mfw.write(message);
}
catch ( IOException e )
{
// There's not much we can do with this. It will be called by a bash script
// and we are inside the logging message, so dump to screen in case this
// is being run manually.
e.printStackTrace();
}
mfw.close();
}
}
package parser;
import java.io.*;
public class MyFileWriter
{
private String filename;
private boolean isOpened = false;
private boolean appendData = false;
private BufferedWriter out = null;
public MyFileWriter ( String fn )
{
filename = fn;
}
public void write ( String line )
throws IOException
{
if ( !isOpened )
{
out = new BufferedWriter ( new FileWriter ( filename, appendData ) );
isOpened = true;
}
out.append ( line + "\r\n");
}
public void close()
{
try
{
if ( out != null )
out.close();
}
catch ( IOException e )
{
e.printStackTrace();
System.out.println ( "MyFileWriter.close() - IOException closing file: " + filename );
}
}
}
/* $Id: SharedConstants.java 39188 2012-11-06 17:56:39Z wwalkowski $ */
/*
* Copyright (C) 2012 CableLabs
*/
package parser;
public interface SharedConstants
{
// Log files
public static final String dlnaCttParserLogFile = "C:\\dlnaCttParserLog.txt";
public static final String upnpCttParserLogFile = "C:\\upnpCttParserLog.txt";
// Used to reference DLNA CTT results
public static final String dlnaInputResultsFile = "C:\\dlnaCttTestResults.trf";
public static final String upnpInputResultsFile = "C:\\upnpCttTestResults.uctt";
// Values used in System.exit() calls that signal the controlling
// bash script success or failure.
public static final int successValue = 0;
public static final int failValue = 1;
}
package parser;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import java.io.*;
public class Utilities
{
private static final String outputResultsFile = "C:\\outputResults";
private static final String outputCountFile = "C:\\outputCount";
public static void main(String[] args)
{
System.out.println ( "time: " + new Utilities().getTimeStamp() );
}
public String getCountFileName()
{
// return dlnaOutputCountFile + "_" + getTimeStamp() + ".txt";
return outputCountFile + ".txt";
}
public String getResultsFileName()
{
// return dlnaOutputResultsFile + "_" + getTimeStamp() + ".csv";
return outputResultsFile + ".csv";
}
public String getTimeStamp()
{
TimeZone tz_gmt = TimeZone.getDefault();
// SimpleDateFormat sdf = new SimpleDateFormat ( "EEE-MMM/d-HH:mm:ss" );
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy_MM_d_HH_mm_ss" );
sdf.setTimeZone(tz_gmt);