public Collection<String> getSitesForTestSession(TestSession testSession) throws Exception { Set<String> sites = new HashSet<>(); List<LogMapDTO> logMapDTOs = getLogsForTestSession(testSession); for (LogMapDTO logMapDTO : logMapDTOs) { Map<String, LogFileContentDTO> map = logMapDTO.getLogFileContentMap(); for (LogFileContentDTO logFileContentDTO : map.values()) { String site = logFileContentDTO.getSiteName(); if (site != null && !site.equals("")) sites.add(site); } } return sites; }
public boolean isTls() { return logMapDTO != null && logMapDTO.isTls(); }
private LogMapDTO buildLogMap(File testDir, TestInstance testInstance) throws Exception { LogMapDTO lm = new LogMapDTO(); if (f.isFile() && f.getName().equals("log.xml")) { LogFileContentDTO ll = new LogFileContentBuilder().build(f); lm.add(f.getName(), ll); } else if (f.isDirectory()) { File logfile = new File(f, "log.xml"); if (logfile.exists()) { LogFileContentDTO ll = new LogFileContentBuilder().build(logfile); lm.add(f.getName(), ll); try { LogFileContentDTO ll = new LogFileContentBuilder().build(lfx); lm.add(sectionName, ll); } catch (Exception e)
@Override public void logOut(TestInstance id, LogMapDTO log, File logDir) throws XdsException { logger.debug("Writing logs " + log.getKeys() + " to " + logFile(id, logDir)); FileOutputStream fos; ObjectOutputStream out = null; try { fos = new FileOutputStream(logFile(id, logDir)); out = new ObjectOutputStream(fos); out.writeObject(log); } catch (IOException e) { throw new XdsInternalException("Cannot write transaction log file", e); } finally { try { out.close(); } catch (IOException e) { // throw new XdsInternalException("Cannot write transaction log file", e); } } }
static public TestLogs build(LogMapDTO logMapDTO) throws Exception { TestLogs logs = new TestLogs(); for (LogMapItemDTO item : logMapDTO.getItems()) { LogFileContentDTO logFile = item.getLog(); for (TestStepLogContentDTO stepLog : logFile.getStepLogs()) { TestLog testLog = new TestLog(); String stepName = stepLog.getId(); logs.logs.add(testLog); testLog.stepName = stepName; testLog.endpoint = stepLog.getEndpoint(); testLog.inHeader = formatXmlToHtml(stepLog.getInHeader()); testLog.inputMetadata = formatXmlToHtml(stepLog.getInputMetadata()); testLog.outHeader = formatXmlToHtml(stepLog.getOutHeader()); testLog.result = formatXmlToHtml(stepLog.getResult()); testLog.status = stepLog.getStatus(); testLog.assignedIds = stepLog.getAssignedIds(); testLog.assignedUids = stepLog.getAssignedUids(); testLog.errors = listAsString(stepLog.getErrors()); testLog.log = formatXmlToHtml(stepLog.getRoot()); } } return logs; }
/** * Return LogMapDTO, the collection of information from the log.xml files generated by * the running of one or more tests. * @return LogMapDTO * @throws Exception - No tests have been specified, no logs can be found, or the log files cannot * be parsed. */ public LogMapDTO getLogMap() throws Exception { LogMapDTO lm = new LogMapDTO(); if (testLogDetails == null) throw new Exception("Xdstest2#getLogMap: testSpecs is null"); for (TestLogDetails testSpec : testLogDetails) { for (String section : testSpec.getTestPlanLogs().keySet()) { LogFileContentDTO testLog = testSpec.getTestPlanLogs().get(section); if (testLog == null) { if (section.equals("THIS")) continue; throw new Exception("Xdstest2#getLogMap: cannot find testlog for section " + section); } lm.add(testLog.getTestAttribute(), testLog); } } return lm; }
public LogMapDTO logIn(TestInstance id) throws Exception { FileInputStream fis = null; ObjectInputStream in = null; try { fis = new FileInputStream(logFile(id)); in = new ObjectInputStream(fis); LogMapDTO map = (LogMapDTO) in.readObject(); getLogger().debug("restoring log " + map.getKeys() + " from " + logDir); return map; } catch (ClassNotFoundException e) { getLogger().debug("attempting to restore log " + "from " + logDir); throw new XdsInternalException("Cannot create model of type LogMapDTO - class not found",e); } finally { in.close(); } }
public void logOut(TestInstance id, LogMapDTO log) throws XdsException { getLogger().debug("Writing log " + log.getKeys() + " to " + logDir); FileOutputStream fos = null; ObjectOutputStream out = null; try { fos = new FileOutputStream(logFile(id)); out = new ObjectOutputStream(fos); out.writeObject(log); } catch (IOException e) { throw new XdsInternalException("Cannot write transaction log file", e); } finally { try { out.close(); } catch (IOException e) { throw new XdsInternalException("Cannot write transaction log file", e); } } }
/** * Validate testSession and site exist and that either the testSession is empty or it contains * only test results for that site. * @param testSession * @param siteName * @return status */ public ConformanceSessionValidationStatus validateConformanceSession(TestSession testSession, String siteName) throws Exception { List<LogMapDTO> logMapDTOs = getLogsForTestSession(testSession); if (siteName == null || siteName.equals("")) return new ConformanceSessionValidationStatus(); Set<String> badSites = new HashSet<>(); for (LogMapDTO logMapDTO : logMapDTOs) { Map<String, LogFileContentDTO> map = logMapDTO.getLogFileContentMap(); for (LogFileContentDTO logFileContentDTO : map.values()) { String site = logFileContentDTO.getSiteName(); if (site == null || site.equals("")) continue; if (!site.equals(siteName)) { badSites.add(site); } } } if (badSites.size() == 0) return new ConformanceSessionValidationStatus(); StringBuilder buf = new StringBuilder(); buf.append("Test Session ").append(testSession).append(" already has results for these sites: ").append(badSites.toString() + " you cannot use it to test " + siteName); return new ConformanceSessionValidationStatus(false, buf.toString()); }
@Override public LogMapDTO logIn(TestInstance id, File logDir) throws Exception { logger.debug("Reading log from " + logFile(id, logDir)); FileInputStream fis = null; ObjectInputStream in = null; try { fis = new FileInputStream(logFile(id, logDir)); in = new ObjectInputStream(fis); LogMapDTO map = (LogMapDTO) in.readObject(); logger.debug("restoring log " + map.getKeys() + " from " + logFile(id, logDir)); return map; } catch (ClassNotFoundException e) { logger.debug("attempting to restore log " + "from " + logFile(id, logDir)); throw new XdsInternalException("Cannot create model of type LogMapDTO - class not found", e); } catch (Exception e) { logger.error(ExceptionUtil.here("Cannot load " + logFile(id, logDir))); throw e; } finally { if (in != null) in.close(); } }
for (String section : lm.getLogFileContentMap().keySet()) { LogFileContentDTO ll = lm.getLogFileContentMap().get(section); testLogDetails.addTestPlanLog(section, ll);