private void save(ProgressSnapshot snapshot) throws FileNotFoundException { XStream xstream = new XStream(); File snapshotFile = new File(getDirectory(), progressPrefix() + snapshot.getTime().getMillis()); OutputStream out = null; Writer writer = null; try { out = new FileOutputStream(snapshotFile); writer = new OutputStreamWriter(out, Charset.forName("UTF-8")); xstream.toXML(snapshot, writer); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { close(writer); close(out); } }
private TestHistory(final String projectName, final EnvironmentVariables environmentVariables, final File baseDirectory, final DateProvider dateProvider) { this.environmentVariables = environmentVariables; this.projectName = projectName; dataDirectory = (baseDirectory != null) ? baseDirectory : new File(getBaseDirectoryPath()); this.dateProvider = dateProvider; }
public void clearHistory() { File[] historyFiles = getHistoryFiles(); for(File historyFile : historyFiles) { historyFile.delete(); } }
private void save(TestResultSnapshot snapshot) throws FileNotFoundException { XStream xstream = new XStream(); File snapshotFile = new File(getDirectory(), outcomesPrefix() + snapshot.getTime().getMillis()); OutputStream out = null; Writer writer = null; try { out = new FileOutputStream(snapshotFile); writer = new OutputStreamWriter(out, Charset.forName("UTF-8")); xstream.toXML(snapshot, writer); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { close(writer); close(out); } }
public void updateData(TestOutcomes testOutcomes) { int totalStepCount = testOutcomes.getStepCount(); int passingSteps = testOutcomes.getPassingTests().getStepCount(); int failingSteps = testOutcomes.getFailingTests().getStepCount(); int skippedSteps = totalStepCount - passingSteps - failingSteps; String buildId = getEnvironmentVariables().getValue(BUILD_ID, "MANUAL"); TestResultSnapshot newSnapshot = new TestResultSnapshot(totalStepCount, passingSteps, failingSteps, skippedSteps, buildId); try { save(newSnapshot); } catch (FileNotFoundException e) { throw new IllegalArgumentException("Unable to store history data", e); } }
public List<TestResultSnapshot> getHistory() { File[] historyFiles = getOutcomeFiles(); List<TestResultSnapshot> resultSnapshots = new ArrayList<TestResultSnapshot>(); XStream xstream = new XStream(); for (File historyFile : historyFiles) { TestResultSnapshot snapshot = null; InputStream inputStream = null; Reader reader = null; try { inputStream = new FileInputStream(historyFile); reader = new InputStreamReader(inputStream, Charset.forName("UTF-8")); snapshot = (TestResultSnapshot) xstream.fromXML(reader); } catch (FileNotFoundException e) { throw new IllegalArgumentException("Unable to read history data in " + historyFile, e); } catch (StreamException streamException) { throw new IllegalArgumentException("Unable to parse history data in " + historyFile, streamException); } finally { close(reader); close(inputStream); } resultSnapshots.add(snapshot); } Collections.sort(resultSnapshots); return resultSnapshots; }
public List<ProgressSnapshot> getProgress() { File[] historyFiles = getProgressFiles(); List<ProgressSnapshot> resultSnapshots = new ArrayList<ProgressSnapshot>(); XStream xstream = new XStream(); for (File historyFile : historyFiles) { ProgressSnapshot snapshot = null; InputStream inputStream = null; Reader reader = null; try { inputStream = new FileInputStream(historyFile); reader = new InputStreamReader(inputStream, Charset.forName("UTF-8")); snapshot = (ProgressSnapshot) xstream.fromXML(reader); } catch (FileNotFoundException e) { throw new IllegalArgumentException("Unable to read history data in " + historyFile, e); } catch (StreamException streamException) { throw new IllegalArgumentException("Unable to parse history data in " + historyFile, streamException); } finally { close(reader); close(inputStream); } resultSnapshots.add(snapshot); } Collections.sort(resultSnapshots); return resultSnapshots; }
private File[] getProgressFiles() { return getDirectory().listFiles(new FilenameFilter() { public boolean accept(File directory, String filename) { return filename.startsWith(progressPrefix()); } }); }
protected TestHistory getTestHistory() { if (testHistory == null) { testHistory = new TestHistory(getProjectName()); } return testHistory; }
public void clearHistory() { getTestHistory().clearHistory(); }
private void generateHistoryReportFor(TestOutcomes testOutcomes) throws IOException { List<TestResultSnapshot> history = getTestHistory().getHistory(); Map<String, Object> context = buildContext(testOutcomes, reportNameProvider); context.put("history", history); context.put("rowcount", history.size()); addFormattersToContext(context); String htmlContents = mergeTemplate(HISTORY_TEMPLATE_PATH).usingContext(context); LOGGER.debug("Writing history page"); writeReportToOutputDirectory("history.html", htmlContents); }
public File generateReportFor(final RequirementsOutcomes requirementsOutcomes, final TestOutcomes testOutcomes, final String filename) throws IOException { Preconditions.checkNotNull(getOutputDirectory()); Map<String,Object> context = new HashMap<String,Object>(); context.put("progress", getEstimatedDeliveryDate(testHistory.getProgress())); context.put("requirements", requirementsOutcomes); context.put("testOutcomes", requirementsOutcomes.getTestOutcomes()); context.put("allTestOutcomes", testOutcomes); context.put("reportName", new ReportNameProvider()); context.put("absoluteReportName", new ReportNameProvider()); context.put("timestamp", timestampFrom(testOutcomes)); addFormattersToContext(context); String htmlContents = mergeTemplate(DEFAULT_PROGRESS_REPORT).usingContext(context); copyResourcesToOutputDirectory(); return writeReportToOutputDirectory(filename, htmlContents); }
public void updateProgressHistory(RequirementsOutcomes requirementsOutcome) { String requirementType = requirementsOutcome.getType(); int totalRequirements = requirementsOutcome.getRequirementCount(); int completedRequirements = requirementsOutcome.getCompletedRequirementsCount(); int failingRequirements = requirementsOutcome.getFailingRequirementsCount(); String buildId = getEnvironmentVariables().getValue(BUILD_ID, "MANUAL"); ProgressSnapshot newSnapshot = ProgressSnapshot.forRequirementType(requirementType) .atTime(dateProvider.getCurrentTime()) .with(completedRequirements).completed() .and(failingRequirements).failed() .outOf(totalRequirements) .forBuild(buildId); try { save(newSnapshot); } catch (FileNotFoundException e) { throw new IllegalArgumentException("Unable to store history data", e); } }
private File[] getHistoryFiles() { return getDirectory().listFiles(new FilenameFilter() { public boolean accept(File directory, String filename) { return filename.startsWith(outcomesPrefix()) || filename.startsWith(progressPrefix()); } }); }
public HtmlAggregateStoryReporter(final String projectName, final String relativeLink) { this(projectName, relativeLink, Injectors.getInjector().getInstance(IssueTracking.class), new TestHistory(projectName), Injectors.getInjector().getInstance(RequirementsService.class), Injectors.getInjector().getProvider(EnvironmentVariables.class).get() ); }
private File[] getOutcomeFiles() { return getDirectory().listFiles(new FilenameFilter() { public boolean accept(File directory, String filename) { return filename.startsWith(outcomesPrefix()); } }); }