@Override public Optional<TestOutcome> loadReportFrom(final File reportFile) { try( InputStream input = new FileInputStream(reportFile); InputStreamReader reader = new InputStreamReader(input, encoding); ) { XStream xstream = new XStream(); xstream.alias("acceptance-test-run", TestOutcome.class); xstream.registerConverter(usingXmlConverter()); return Optional.of((TestOutcome) xstream.fromXML(reader)); } catch (CannotResolveClassException e) { LOGGER.warn("Tried to load a file that is not a thucydides report: " + reportFile); return Optional.empty(); } catch (FileNotFoundException e) { LOGGER.warn("Tried to load a file that is not a thucydides report: " + reportFile); return Optional.empty(); } catch (IOException e) { LOGGER.warn("Could not load a report for some reason" + e.getMessage()); return Optional.empty(); } }
public Optional<TestOutcome> loadReportFrom(final File reportFile) { InputStream input = null; InputStreamReader reader = null; try { XStream xstream = new XStream(); xstream.alias("acceptance-test-run", TestOutcome.class); xstream.registerConverter(usingXmlConverter()); input = new FileInputStream(reportFile); reader = new InputStreamReader(input, Charset.forName("UTF-8")); return Optional.of((TestOutcome) xstream.fromXML(reader)); } catch (CannotResolveClassException e) { LOGGER.warn("Tried to load a file that is not a thucydides report: " + reportFile); return Optional.absent(); } catch (FileNotFoundException e) { LOGGER.warn("Tried to load a file that is not a thucydides report: " + reportFile); return Optional.absent(); } finally { try { reader.close(); input.close(); } catch (IOException ignored) {} } }
public Optional<TestOutcome> loadReportFrom(final File reportFile) { InputStream input = null; InputStreamReader reader = null; try { XStream xstream = new XStream(); xstream.alias("acceptance-test-run", TestOutcome.class); xstream.registerConverter(usingXmlConverter()); input = new FileInputStream(reportFile); reader = new InputStreamReader(input, Charset.forName("UTF-8")); return Optional.of((TestOutcome) xstream.fromXML(reader)); } catch (CannotResolveClassException e) { LOGGER.warn("Tried to load a file that is not a thucydides report: " + reportFile); return Optional.absent(); } catch (FileNotFoundException e) { LOGGER.warn("Tried to load a file that is not a thucydides report: " + reportFile); return Optional.absent(); } finally { try { reader.close(); input.close(); } catch (IOException ignored) {} } }
/** * Generate an XML report for a given test run. */ public File generateReportFor(final TestOutcome testOutcome, final TestOutcomes allTestOutcomes) throws IOException { TestOutcome storedTestOutcome = testOutcome.withQualifier(qualifier); Preconditions.checkNotNull(outputDirectory); XStream xstream = new XStream(); xstream.alias("acceptance-test-run", TestOutcome.class); xstream.registerConverter(usingXmlConverter()); String reportFilename = reportFor(storedTestOutcome); OutputStream outputStream = null; OutputStreamWriter writer = null; File report = new File(getOutputDirectory(), reportFilename); LOGGER.info("Generating XML report for {} to file {}", testOutcome.getTitle(), report.getAbsolutePath()); try { outputStream = new FileOutputStream(report); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xstream.toXML(storedTestOutcome, writer); LOGGER.info("XML report generated ({} bytes) {}",report.getAbsolutePath(),report.length()); } catch(IOException failedToWriteReport) { throw failedToWriteReport; } finally { writer.flush(); writer.close(); outputStream.close(); } return report; }
/** * Generate an XML report for a given test run. */ public File generateReportFor(final TestOutcome testOutcome, final TestOutcomes allTestOutcomes) throws IOException { TestOutcome storedTestOutcome = testOutcome.withQualifier(qualifier); Preconditions.checkNotNull(outputDirectory); XStream xstream = new XStream(); xstream.alias("acceptance-test-run", TestOutcome.class); xstream.registerConverter(usingXmlConverter()); String reportFilename = reportFor(storedTestOutcome); OutputStream outputStream = null; OutputStreamWriter writer = null; File report = new File(getOutputDirectory(), reportFilename); LOGGER.info("Generating XML report for {} to file {}", testOutcome.getTitle(), report.getAbsolutePath()); try { outputStream = new FileOutputStream(report); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xstream.toXML(storedTestOutcome, writer); LOGGER.info("XML report generated ({} bytes) {}",report.getAbsolutePath(),report.length()); } catch(IOException failedToWriteReport) { throw failedToWriteReport; } finally { writer.flush(); writer.close(); outputStream.close(); } return report; }
/** * Generate an XML report for a given test run. */ @Override public File generateReportFor(final TestOutcome testOutcome) throws IOException { TestOutcome storedTestOutcome = testOutcome.withQualifier(qualifier); Preconditions.checkNotNull(outputDirectory); XStream xstream = new XStream(); xstream.alias("acceptance-test-run", TestOutcome.class); xstream.registerConverter(usingXmlConverter()); String reportFilename = reportFor(storedTestOutcome); String unique = UUID.randomUUID().toString(); File temporary = new File(getOutputDirectory(), reportFilename.concat(unique)); File report = new File(getOutputDirectory(), reportFilename); report.createNewFile(); LOGGER.debug("Generating XML report for {} to file {} (using temp file {})", testOutcome.getTitle(), report.getAbsolutePath(), temporary.getAbsolutePath()); try( OutputStream outputStream = new FileOutputStream(temporary); OutputStreamWriter writer = new OutputStreamWriter(outputStream, encoding)) { xstream.toXML(storedTestOutcome, writer); writer.flush(); LOGGER.debug("XML report generated ({} bytes) {}", report.getAbsolutePath(), report.length()); } SafelyMoveFiles.withMaxRetriesOf(3).from(temporary.toPath()).to(report.toPath()); return report; }