AsciidocConfluenceConverter { public ConfluencePublisherMetadata convert(AsciidocPagesStructureProvider asciidocPagesStructureProvider, Path buildFolder, Map<String, Object> userAttributes) { return convert(asciidocPagesStructureProvider, new NoOpPageTitlePostProcessor(), buildFolder, userAttributes); } AsciidocConfluenceConverter(String spaceKey, String ancestorId); ConfluencePublisherMetadata convert(AsciidocPagesStructureProvider asciidocPagesStructureProvider, Path buildFolder, Map<String, Object> userAttributes); ConfluencePublisherMetadata convert(AsciidocPagesStructureProvider asciidocPagesStructureProvider, PageTitlePostProcessor pageTitlePostProcessor, Path buildFolder, Map<String, Object> userAttributes);  }
@Test public void convertAndBuildConfluencePages_withThreeLevelAdocStructure_convertsTemplatesAndReturnsMetadata() throws Exception { Path documentationRootFolder = Paths.get(DOCUMENTATION_LOCATION).toAbsolutePath(); Path buildFolder = this.temporaryFolder.newFolder().toPath().toAbsolutePath(); Map<String, Object> userAttributes = new HashMap<>(); userAttributes.put("name", "Rick and Morty"); userAttributes.put("genre", "science fiction"); AsciidocPagesStructureProvider asciidocPagesStructureProvider = new FolderBasedAsciidocPagesStructureProvider(documentationRootFolder, UTF_8); AsciidocConfluenceConverter asciidocConfluenceConverter = new AsciidocConfluenceConverter("~personalSpace", "1234"); ConfluencePublisherMetadata confluencePublisherMetadata = asciidocConfluenceConverter.convert(asciidocPagesStructureProvider, buildFolder, userAttributes); assertThat(confluencePublisherMetadata.getSpaceKey(), is("~personalSpace")); assertThat(confluencePublisherMetadata.getAncestorId(), is("1234")); assertThat(confluencePublisherMetadata.getPages().size(), is(1)); ConfluencePageMetadata indexPageMetadata = confluencePublisherMetadata.getPages().get(0); assertThat(indexPageMetadata.getTitle(), is("Test Document")); assertThat(indexPageMetadata.getAttachments().size(), is(0)); assertThat(indexPageMetadata.getChildren().size(), is(1)); assertThat(indexPageMetadata.getLabels().size(), is(0)); ConfluencePageMetadata subPageMetadata = indexPageMetadata.getChildren().get(0); assertThat(subPageMetadata.getTitle(), is("Sub Page")); assertThat(subPageMetadata.getAttachments().size(), is(2)); assertThat(subPageMetadata.getChildren().size(), is(1)); assertThat(subPageMetadata.getLabels().size(), is(0)); ConfluencePageMetadata subSubPageMetadata = subPageMetadata.getChildren().get(0); assertThat(subSubPageMetadata.getTitle(), is("Sub Sub Page")); assertThat(subSubPageMetadata.getAttachments().size(), is(0)); assertThat(subSubPageMetadata.getLabels().size(), is(1)); assertContentFilePath(indexPageMetadata, targetFilePath(buildFolder, documentationRootFolder, "index.adoc", "index.html")); assertContentFilePath(subPageMetadata, targetFilePath(buildFolder, documentationRootFolder, "index/sub-page.adoc", "sub-page.html")); assertContentFilePath(subSubPageMetadata, targetFilePath(buildFolder, documentationRootFolder, "index/sub-page/sub-sub-page.adoc", "sub-sub-page.html")); assertAttachmentFilePath(subPageMetadata, "attachmentOne.txt", targetFilePath(buildFolder, documentationRootFolder, "index/sub-page.adoc", "attachmentOne.txt")); assertAttachmentFilePath(subPageMetadata, "embedded-diagram.png", targetFilePath(buildFolder, documentationRootFolder, "index/sub-page.adoc", "embedded-diagram.png")); }
@Test public void convertAndBuildConfluencePages_withPageReferencingNonExistingAttachment_throwsException() throws Exception { Path documentationRootFolder = Paths.get("src/test/resources/non-existing-attachment").toAbsolutePath(); Path buildFolder = this.temporaryFolder.newFolder().toPath().toAbsolutePath(); AsciidocPagesStructureProvider asciidocPagesStructureProvider = new FolderBasedAsciidocPagesStructureProvider(documentationRootFolder, UTF_8); this.expectedException.expect(RuntimeException.class); this.expectedException.expectMessage("Attachment 'non-existing-attachment.png' does not exist"); AsciidocConfluenceConverter asciidocConfluenceConverter = new AsciidocConfluenceConverter("~personalSpace", "1234"); asciidocConfluenceConverter.convert(asciidocPagesStructureProvider, buildFolder, emptyMap()); }
@Test public void convertAndBuildConfluencePages_withPageTitlePostProcessor_convertsTemplatesAndReturnsMetadata() throws Exception { Path documentationRootFolder = Paths.get(DOCUMENTATION_LOCATION).toAbsolutePath(); Path buildFolder = this.temporaryFolder.newFolder().toPath().toAbsolutePath(); AsciidocPagesStructureProvider asciidocPagesStructureProvider = new FolderBasedAsciidocPagesStructureProvider(documentationRootFolder, UTF_8); PageTitlePostProcessor pageTitlePostProcessor = new PrefixAndSuffixPageTitlePostProcessor("(Doc) ", " (1.0)"); AsciidocConfluenceConverter asciidocConfluenceConverter = new AsciidocConfluenceConverter("~personalSpace", "1234"); ConfluencePublisherMetadata confluencePublisherMetadata = asciidocConfluenceConverter.convert(asciidocPagesStructureProvider, pageTitlePostProcessor, buildFolder, emptyMap()); assertThat(confluencePublisherMetadata.getSpaceKey(), is("~personalSpace")); assertThat(confluencePublisherMetadata.getAncestorId(), is("1234")); assertThat(confluencePublisherMetadata.getPages().size(), is(1)); ConfluencePageMetadata indexPageMetadata = confluencePublisherMetadata.getPages().get(0); assertThat(indexPageMetadata.getTitle(), is("(Doc) Test Document (1.0)")); }
@Test public void convertAndBuildConfluencePages_withTemplates_extractsTemplatesFromClassPathToTargetFolder() throws Exception { Path documentationRootFolder = this.temporaryFolder.newFolder().toPath().toAbsolutePath(); Path buildFolder = this.temporaryFolder.newFolder().toPath().toAbsolutePath(); AsciidocPagesStructureProvider asciidocPagesStructureProvider = new FolderBasedAsciidocPagesStructureProvider(documentationRootFolder, UTF_8); AsciidocConfluenceConverter asciidocConfluenceConverter = new AsciidocConfluenceConverter("~personalSpace", "1234"); asciidocConfluenceConverter.convert(asciidocPagesStructureProvider, buildFolder, emptyMap()); assertThat(exists(buildFolder.resolve("templates").resolve("helpers.rb")), is(true)); }