From: Laramie Crocker Date: Fri, 20 May 2011 11:07:25 +0000 (+0000) Subject: CSPACE-4027 removed the pesky dev-master.xml so inadvertant checkins can not happen... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=05743a02507fc699d6f2ff6de2073a2664f55bfb;p=tmp%2Fjakarta-migration.git CSPACE-4027 removed the pesky dev-master.xml so inadvertant checkins can not happen, and modified XmlReplayDevTest to quit nicely if not dev-master.mxl not found. Also moved common prettyPrint code into common.XmlTools. Added XmlReplayReport and supporting files to spit out friendly html version of test results. --- diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java index 463cf0437..15e224137 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java @@ -4,7 +4,9 @@ import org.apache.commons.cli.*; import org.apache.commons.io.FileUtils; import org.apache.commons.jexl2.JexlEngine; +import org.collectionspace.services.common.api.FileTools; import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.common.service.ServiceBindingType; import org.dom4j.*; import org.dom4j.io.SAXReader; @@ -21,6 +23,7 @@ public class XmlReplay { public XmlReplay(String basedir){ this.basedir = basedir; this.serviceResultsMap = createResultsMap(); + this.reportsList = new ArrayList(); } public static final String DEFAULT_CONTROL = "xml-replay-control.xml"; @@ -80,6 +83,10 @@ public class XmlReplay { return new HashMap(); } + private List reportsList; + public List getReportsList(){ + return reportsList; + } public String toString(){ return "XmlReplay{"+this.basedir+", "+this.defaultAuthsMap+", "+this.dump+'}'; @@ -87,8 +94,30 @@ public class XmlReplay { // ============== METHODS =========================================================== + /** Optional information method: call this method after instantiating this class using the constructor XmlReplay(String), which sets the basedir. Then you + * pass in your relative masterFilename to that basedir to this method, which will return true if the file is readable, valid xml, etc. + * Do this in preference to just seeing if File.exists(), because there are rules to finding the file relative to the maven test dir, yada, yada. + * This method makes it easy to have a development test file that you don't check in, so that dev tests can be missing gracefully, etc. + */ + public boolean masterConfigFileExists(String masterFilename){ + try { + org.dom4j.Document doc = openMasterConfigFile(masterFilename); + if (doc == null){ + return false; + } + return true; + } catch (Throwable t){ + return false; + } + } + public org.dom4j.Document openMasterConfigFile(String masterFilename) throws FileNotFoundException { - org.dom4j.Document document = getDocument(Tools.glue(basedir, "/", masterFilename)); //will check full path first, then checks relative to PWD. + String fullPath = Tools.glue(basedir, "/", masterFilename); + File f = new File(fullPath); + if (!f.exists()){ + return null; + } + org.dom4j.Document document = getDocument(fullPath); //will check full path first, then checks relative to PWD. if (document == null){ throw new FileNotFoundException("XmlReplay master control file ("+masterFilename+") not found in basedir: "+basedir+". Exiting test."); } @@ -100,6 +129,9 @@ public class XmlReplay { */ public org.dom4j.Document readOptionsFromMasterConfigFile(String masterFilename) throws FileNotFoundException { org.dom4j.Document document = openMasterConfigFile(masterFilename); + if (document == null){ + throw new FileNotFoundException(masterFilename); + } protoHostPort = document.selectSingleNode("/xmlReplayMaster/protoHostPort").getText().trim(); AuthsMap authsMap = readAuths(document); setDefaultAuthsMap(authsMap); @@ -122,6 +154,9 @@ public class XmlReplay { } else { document = openMasterConfigFile(masterFilename); } + if (document==null){ + throw new FileNotFoundException(masterFilename); + } String controlFile, testGroup, test; List runNodes; runNodes = document.selectNodes("/xmlReplayMaster/run"); @@ -141,7 +176,16 @@ public class XmlReplay { //Now run *that* instance. List results = replay.runTests(testGroup, test); list.add(results); + this.reportsList.addAll(replay.getReportsList()); //Add all the reports from the inner replay, to our master replay's reportsList, to generate the index.html file. } + StringBuffer sb = new StringBuffer(XmlReplayReport.HTML_PAGE_START); + String dateStr = Tools.nowLocale(); + sb.append("
XmlReplay run "+dateStr+" master: "+masterFilename+"
"); + for (String oneToc: this.reportsList){ + sb.append(oneToc).append("
"); + } + sb.append(XmlReplayReport.HTML_PAGE_END); + FileTools.saveFile(getReportsDir(this.basedir),"index."+masterFilename+".html", sb.toString(), false); return list; } @@ -155,7 +199,8 @@ public class XmlReplay { this.autoDeletePOSTS, dump, this.protoHostPort, - this.defaultAuthsMap); + this.defaultAuthsMap, + this.reportsList); return result; } @@ -169,7 +214,8 @@ public class XmlReplay { this.autoDeletePOSTS, dump, this.protoHostPort, - this.defaultAuthsMap); + this.defaultAuthsMap, + this.reportsList); if (result.size()>1){ throw new IndexOutOfBoundsException("Multiple ("+result.size()+") tests with ID='"+testID+"' were found within test group '"+testGroupID+"', but there should only be one test per ID attribute."); } @@ -352,7 +398,7 @@ public class XmlReplay { document = reader.read(xmlFileName); } catch (DocumentException e) { System.out.println("ERROR reading document: "+e); - e.printStackTrace(); + //e.printStackTrace(); } return document; } @@ -417,13 +463,16 @@ public class XmlReplay { boolean param_autoDeletePOSTS, Dump dump, String protoHostPortParam, - AuthsMap defaultAuths) + AuthsMap defaultAuths, + List reportsList) throws Exception { //Internally, we maintain two collections of ServiceResult: // the first is the return value of this method. // the second is the serviceResultsMap, which is used for keeping track of CSIDs created by POSTs, for later reference by DELETE, etc. List results = new ArrayList(); + XmlReplayReport report = new XmlReplayReport(); + String controlFile = Tools.glue(xmlReplayBaseDir, "/", controlFileName); org.dom4j.Document document; document = getDocument(controlFile); //will check full path first, then checks relative to PWD. @@ -449,7 +498,9 @@ public class XmlReplay { } else { authsMapINFO = "Using AuthsMap from control file: "+authsMap; } - System.out.println("========================================================================" + + report.addTestGroup(testGroupID, controlFileName); //controlFileName is just the short name, without the full path. + String xmlReplayHeader = "========================================================================" +"\r\nXmlReplay running:" +"\r\n controlFile: "+ (new File(controlFile).getCanonicalPath()) +"\r\n protoHostPort: "+protoHostPort @@ -459,7 +510,10 @@ public class XmlReplay { +"\r\n param_autoDeletePOSTS: "+param_autoDeletePOSTS +"\r\n Dump info: "+dump +"\r\n========================================================================" - +"\r\n"); + +"\r\n"; + report.addRunInfo(xmlReplayHeader); + + System.out.println(xmlReplayHeader); String autoDeletePOSTS = ""; List testgroupNodes; @@ -631,6 +685,8 @@ public class XmlReplay { String serviceResultRow = serviceResult.dump(dump.dumpServiceResult, hasError)+"; time:"+(System.currentTimeMillis()-startTime); String leader = (dump.dumpServiceResult == ServiceResult.DUMP_OPTIONS.detailed) ? "XmlReplay:"+testIDLabel+": ": ""; + report.addTestResult(serviceResult); + if ( (dump.dumpServiceResult == ServiceResult.DUMP_OPTIONS.detailed) || (dump.dumpServiceResult == ServiceResult.DUMP_OPTIONS.full) ){ System.out.println("\r\n#---------------------#"); @@ -664,9 +720,28 @@ public class XmlReplay { autoDelete(serviceResultsMap, "default"); } } + + //=== Now spit out the HTML report file === + File m = new File(controlFileName); + String localName = m.getName();//don't instantiate, just use File to extract file name without directory. + String reportName = localName+'-'+testGroupID+".html"; + File resultFile = FileTools.saveFile(getReportsDir(xmlReplayBaseDir), reportName, report.getPage(), true); + if (resultFile!=null) { + System.out.println("XmlReplay summary reports saved to directory: "+resultFile.getParent()); + System.out.println("XmlReplay summary report: "+resultFile.getCanonicalPath()); + String toc = report.getTOC(reportName); + reportsList.add(toc); + } + //================================ + return results; } + //todo: move from xmlReplayBaseDir to "target/xmlReplayReports" dir. + public static String getReportsDir(String basename){ + return Tools.glue(basename,"/","TEST-REPORTS"); + } + //======================== MAIN =================================================================== private static Options createOptions() { @@ -775,7 +850,9 @@ public class XmlReplay { } else { Dump dump = getDumpConfig(); dump.payloads = Tools.isTrue(dumpResults); - runXmlReplayFile(xmlReplayBaseDirResolved, controlFilename, testGroupID, testID, createResultsMap(), bAutoDeletePOSTS, dump, "", null); + List reportsList = new ArrayList(); + runXmlReplayFile(xmlReplayBaseDirResolved, controlFilename, testGroupID, testID, createResultsMap(), bAutoDeletePOSTS, dump, "", null, reportsList); + System.out.println("DEPRECATED: reportsList is generated, but not dumped: "+reportsList.toString()); } } catch (ParseException exp) { // oops, something went wrong diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayReport.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayReport.java new file mode 100644 index 000000000..4783b049c --- /dev/null +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayReport.java @@ -0,0 +1,207 @@ +package org.collectionspace.services.IntegrationTests.xmlreplay; + +import org.collectionspace.services.common.XmlTools; +import org.collectionspace.services.common.api.Tools; +import org.dom4j.Document; +import org.dom4j.DocumentHelper; + +import java.util.ArrayList; +import java.util.List; + +/** Format a report based on XmlReplay ServiceResult object from a test group. + * @author laramie + */ +public class XmlReplayReport { + public static final String HTML_PAGE_START = "" + +""; + protected static final String HTML_PAGE_END = ""; + protected static final String TOPLINKS = "Show All Payloads" + "Hide All Payloads"; + + protected static final String HTML_TEST_START = "
"; + protected static final String HTML_TEST_END = "
"; + + protected static final String GROUP_START = "
"; + protected static final String GROUP_END = "
"; + + protected static final String RUNINFO_START = "
"; + protected static final String RUNINFO_END = "
"; + + + protected static final String DIV_END = ""; + + protected static final String PRE_START = "
";
+    protected static final String PRE_END = "
"; + protected static final String BR = "
\r\n"; + + protected static final String DETAIL_START = "\r\n
\r\n"; + protected static final String DETAIL_LINESEP = "
"; + protected static final String DETAIL_END = "
"; + + private static final String SP = "   "; + + + protected static String formatCollapse(String myDivID, String linkText){ + return ""+linkText+"" + + BR + + "