@Test public void shouldRedirectToJUL() throws Exception { final MemoryLogHandler memoryLogHandler = registerMemoryLogHandler(); File inputFile = classpath.getResource("documentwithnotexistingfile.adoc"); String renderContent = asciidoctor.convertFile(inputFile, options() .inPlace(true) .safe(SafeMode.SERVER) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap()); File expectedFile = new File(inputFile.getParent(), "documentwithnotexistingfile.html"); expectedFile.delete(); assertEquals(4, memoryLogHandler.getLogRecords().size()); assertThat(memoryLogHandler.getLogRecords().get(0).getMessage(), both(containsString("include file not found")) .and(containsString("documentwithnotexistingfile.adoc: line 3"))); }
@Test public void shouldNotifyLogHandlerService() throws Exception { File inputFile = classpath.getResource("documentwithnotexistingfile.adoc"); String renderContent = asciidoctor.convertFile(inputFile, options() .inPlace(true) .safe(SafeMode.SERVER) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap()); File expectedFile = new File(inputFile.getParent(), "documentwithnotexistingfile.html"); expectedFile.delete(); final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords(); for (LogRecord logRecord : logRecords) { System.err.println(">> " + logRecord.getMessage()); } assertThat(logRecords, hasSize(4)); assertThat(logRecords.get(0).getMessage(), containsString("include file not found")); final Cursor cursor = logRecords.get(0).getCursor(); assertThat(cursor.getDir().replace('\\', '/'), is(inputFile.getParent().replace('\\', '/'))); assertThat(cursor.getFile(), is(inputFile.getName())); assertThat(cursor.getLineNumber(), is(3)); for (LogRecord logRecord: logRecords) { assertThat(logRecord.getCursor(), not(Matchers.nullValue())); assertThat(logRecord.getCursor().getFile(), not(Matchers.nullValue())); assertThat(logRecord.getCursor().getDir(), not(Matchers.nullValue())); } }
.safe(SafeMode.SERVER) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap()); .safe(SafeMode.SERVER) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap());
.safe(SafeMode.SERVER) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap()); .safe(SafeMode.SERVER) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap());
.safe(SafeMode.SERVER) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap());
@Test @Ignore("Until logging of invalid refs is enabled by default") public void shouldLogInvalidRefs() throws Exception { final List<LogRecord> logRecords = new ArrayList<>(); final LogHandler logHandler = new LogHandler() { @Override public void log(LogRecord logRecord) { logRecords.add(logRecord); } }; asciidoctor.registerLogHandler(logHandler); File inputFile = classpath.getResource("documentwithinvalidrefs.adoc"); String renderContent = asciidoctor.convertFile(inputFile, options() .inPlace(true) .safe(SafeMode.SERVER) .toFile(false) .attributes( AttributesBuilder.attributes().allowUriRead(true)) .asMap()); assertThat(logRecords, hasSize(1)); assertThat(logRecords.get(0).getMessage(), containsString("invalid reference: invalidref")); final Cursor cursor = logRecords.get(0).getCursor(); assertThat(cursor, is(nullValue())); }