public Optional<TestOutcome> loadReportFrom(final File reportFile) { try(BufferedInputStream report = new BufferedInputStream(new FileInputStream(reportFile))) { TestOutcome fromJson = jsonConverter.fromJson(report); return Optional.of(fromJson); // } catch (JsonMappingException mappingException) { // throw new RuntimeException("Error loading JSON test outcomes", mappingException); } catch (Throwable e) { LOGGER.warn("this file was not a valid JSON Thucydides test report: " + reportFile.getName() + System.lineSeparator() + e.getMessage()); return Optional.absent(); } }
public String toJson() { JSONConverter jsonConverter = Injectors.getInjector().getInstance(JSONConverter.class); try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { jsonConverter.toJson(this, outputStream); return outputStream.toString(); } catch (IOException e) { return ""; } }
public String toJson() { JSONConverter jsonConverter = Injectors.getInjector().getInstance(JSONConverter.class); try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { jsonConverter.toJson(this, outputStream); return outputStream.toString(); } catch (IOException e) { return ""; } }
@Override public File generateReportFor(TestOutcome testOutcome, TestOutcomes allTestOutcomes) throws IOException { TestOutcome storedTestOutcome = testOutcome.withQualifier(qualifier); Preconditions.checkNotNull(outputDirectory); String reportFilename = reportFor(storedTestOutcome); File report = new File(getOutputDirectory(), reportFilename); try(OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(report))){ jsonConverter.toJson(storedTestOutcome, outputStream); } return report; }
public Optional<TestOutcome> loadReportFrom(final File reportFile) { try(BufferedInputStream report = new BufferedInputStream(new FileInputStream(reportFile))) { TestOutcome fromJson = jsonConverter.fromJson(report); return Optional.of(fromJson); } catch (Throwable e) { LOGGER.warn("this file was not a valid JSON Serenity test report: " + reportFile.getName() + System.lineSeparator(), e); return Optional.absent(); } }
@Override public File generateReportFor(TestOutcome testOutcome, TestOutcomes allTestOutcomes) throws IOException { TestOutcome storedTestOutcome = testOutcome.withQualifier(qualifier); Preconditions.checkNotNull(outputDirectory); String reportFilename = reportFor(storedTestOutcome); File report = new File(getOutputDirectory(), reportFilename); try(OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(report))){ jsonConverter.toJson(storedTestOutcome, outputStream); } return report; }
@Override public Optional<TestOutcome> loadReportFrom(final File reportFile) { if (!reportFile.getName().toLowerCase().endsWith(".json")) { return Optional.empty(); } try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(reportFile), encoding))) { return jsonConverter.fromJson(in); } catch (Throwable e) { LOGGER.warn("This file was not a valid JSON Serenity test report: " + reportFile.getName() + System.lineSeparator() + e.getMessage()); return Optional.empty(); } }
public String toJson() { JSONConverter jsonConverter = Injectors.getInjector().getInstance(JSONConverter.class); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { jsonConverter.toJson(this, outputStream); return outputStream.toString(Charset.defaultCharset()); } catch (IOException e) { LOGGER.error("serialization error for testOutcome with name \"" + this.getName() + "\"", e); return ""; } }
@Override public File generateReportFor(TestOutcome testOutcome) throws IOException { TestOutcome storedTestOutcome = testOutcome.withQualifier(qualifier); Preconditions.checkNotNull(outputDirectory); 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 JSON report for {} to file {} (using temp file {})", testOutcome.getTitle(), report.getAbsolutePath(), temporary.getAbsolutePath()); try(OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(temporary))){ jsonConverter.toJson(storedTestOutcome, outputStream); outputStream.flush(); } SafelyMoveFiles.withMaxRetriesOf(3).from(temporary.toPath()).to(report.toPath()); return report; }