private ReportGenerator reportGenerator() throws IOException { FileReportGenerator generator = new FileReportGenerator(createOutputDirectory()); generator.adjustReportFilesExtensions(isOptionSpecified(RUNNER_SUITE_OPTION) || ! isOutputSpecified()); generator.setReportClass(isOptionSpecified("xml") ? XmlReport.class : PlainReport.class); return generator; }
private void downloadSpecification(Repository repository, String spec) throws MojoExecutionException { try { FileReportGenerator generator = new FileReportGenerator(new File(specsDirectory, repository.getName())); generator.adjustReportFilesExtensions(true); Document doc = repository.getDocumentRepository().loadDocument(spec); Report report = generator.openReport(spec); report.generate(doc); generator.closeReport(report); countDownload(repository, spec); } catch (Exception e) { throw new MojoExecutionException(format("Error downloading specification document %s from %s", spec, repository .getName()), e); } }
private String outputNameOf(Report report) { String name = report.getName(); StringBuilder nameBuilder = new StringBuilder(name); if (automaticExtension && ! name.endsWith(extensionOf(report))) { nameBuilder.append(extensionOf(report)); } return URIUtil.escapeFileSystemForbiddenCharacters(nameBuilder.toString()); }
private FileReportGenerator createDefaultReportGenerator() throws ClassNotFoundException { Class< ? extends Report> loadedReportClass = loadReportClass(); FileReportGenerator reportGenerator = new FileReportGenerator(outputDirectory); reportGenerator.setReportClass(loadedReportClass); return reportGenerator; }
private void setupGenerator(FileReportGenerator generator) { generator.adjustReportFilesExtensions(true); generator.setReportClass(PlainReport.class); }
@Before public void setup() throws Exception { outputDir = TestFileUtils.createTempReportsDirectory(); specificationDirectory = new File(URLDecoder.decode(getResourcePath("/"), "UTF-8")); input = "/specs/ognl"; suiteoutput = new File(URLDecoder.decode(outputDir.getAbsolutePath(), "UTF-8") + "/ognl"); suiteoutput.mkdir(); repo = new FileSystemRepository(specificationDirectory); generator = new FileReportGenerator(suiteoutput); setupGenerator(generator); monitors = new CompositeSpecificationRunnerMonitor(); monitors.add(log); recorder = new RecorderMonitor(); monitors.add(recorder); }
@Test public void testEscapeDoubleQuoteCharactersWhenWrittingFile() { try { PlainReport report = new PlainReport( "LivingDoc Confluence_LIVINGDOC_Action Access Resolution \"quote\"_report.xml"); FileReportGenerator reportGenerator = new FileReportGenerator(new File(tempDirectory)); reportGenerator.closeReport(report); } catch (Exception e) { fail("Unable to write the report on file system : " + e.getMessage()); } } }
private SpecificationRunner buildSuiteRunner() throws ClassNotFoundException { // One of the biggest differences between the suite and the document // runner is the report generation. The suite itself generates no // reports. It delegates the report generation to the underlying // document runner. Therefore we've to create separate report // generators. FileReportGenerator reportGenerator = createDefaultReportGenerator(); reportGenerator.adjustReportFilesExtensions(true); String[] sectionsArray = sections.toArray(new String[sections.size()]); SystemUnderDevelopment systemUnderDevelopment = instantiateSystemUnderDevelopment(); DocumentRepository repository = instantiateDocumentRepository(); Class< ? extends InterpreterSelector> selectorClass = loadInterpreterSelectorClass(); SuiteRunner runner = new SuiteRunner(); runner.setRepository(repository); runner.setSystemUnderDevelopment(systemUnderDevelopment); runner.setReportGenerator(reportGenerator); runner.setInterpreterSelector(selectorClass); runner.setSections(sectionsArray); runner.setMonitor(compositeMonitor); runner.setLazy(lazy); return runner; }
@Override public void closeReport(Report report) throws IOException { Writer out = null; try { File reportFile = new File(reportsDirectory, outputNameOf(report)); reportFile.getParentFile().mkdirs(); out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(reportFile.getAbsolutePath()), "UTF-8")); report.printTo(out); out.flush(); } finally { IOUtils.closeQuietly(out); } }
private void setupGenerator(FileReportGenerator generator) { generator.adjustReportFilesExtensions(true); generator.setReportClass(PlainReport.class); }
@Before public void setup() throws UnsupportedEncodingException { outputDir = TestFileUtils.createTempReportsDirectory(); specificationDirectory = new File(URLDecoder.decode(getResourcePath("/"), "UTF-8")); input = "/specs/WithImports"; suiteoutput = new File(URLDecoder.decode(outputDir.getAbsolutePath(), "UTF-8") + "/Seeds"); suiteoutput.mkdir(); repo = new FileSystemRepository(specificationDirectory); generator = new FileReportGenerator(suiteoutput); setupGenerator(generator); monitors = new CompositeSpecificationRunnerMonitor(); monitors.add(log); recorder = new RecorderMonitor(); monitors.add(recorder); }
@Test public void testCallsBackOnSystemUnderDevelopmentOnStartAndEndOfDocumentExecution() { DocumentRunner runner = new DocumentRunner(); FakeSystemUnderDevelopment sud = new FakeSystemUnderDevelopment(); runner.setInterpreterSelector(LivingDocInterpreterSelector.class); runner.setSystemUnderDevelopment(sud); runner.setSections(); runner.setReportGenerator(new FileReportGenerator(specificationDirectory)); runner.setRepository(new FileSystemRepository(specificationDirectory)); runner.run("specs/ABankSample.html", "specs/ABankSample.out.html"); assertTrue(sud.onStartDocumentHasBeenCalled); assertTrue(sud.onEndDocumentHasBeenCalled); }
private void testInterpreter(Class<? extends Interpreter> interpreterType, int expectedRightCount) { DocumentRunner runner = new DocumentRunner(); RecorderMonitor recorderMonitor = new RecorderMonitor(); runner.setInterpreterSelector(LivingDocInterpreterSelector.class); runner.setSystemUnderDevelopment(new DefaultSystemUnderDevelopment()); runner.setSections(); runner.setReportGenerator(new FileReportGenerator(specificationDirectory)); runner.setRepository(new FileSystemRepository(specificationDirectory)); runner.setMonitor(recorderMonitor); runner.run("specs/"+interpreterType.getSimpleName()+".html", "specs/"+interpreterType.getSimpleName()+".out.html"); assertNotNull(recorderMonitor.getStatistics()); assertEquals(0, recorderMonitor.getStatistics().exceptionCount()); assertEquals(0,recorderMonitor.getStatistics().ignoredCount()); assertEquals(0,recorderMonitor.getStatistics().wrongCount()); assertEquals(expectedRightCount, recorderMonitor.getStatistics().rightCount()); }