Skip to content

Commit

Permalink
Merge 5b10f7c into 760e9b0
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloren committed Feb 27, 2019
2 parents 760e9b0 + 5b10f7c commit c0dc240
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ public void publish() {
startPublishingUnderAncestorId(this.metadata.getPages(), this.metadata.getSpaceKey(), this.metadata.getAncestorId());
break;
case REPLACE_ANCESTOR:
ConfluencePageMetadata rootPageMetaData = singleRootPageMetadata(this.metadata);

if (rootPageMetaData != null) {
updatePage(this.metadata.getAncestorId(), null, rootPageMetaData);
startPublishingUnderAncestorId(rootPageMetaData.getChildren(), this.metadata.getSpaceKey(), this.metadata.getAncestorId());
}
startPublishingReplacingAncestorId(this.metadata, this.metadata.getSpaceKey(), this.metadata.getAncestorId());
break;
default:
throw new IllegalArgumentException("Invalid publishing strategy '" + this.publishingStrategy + "'");
Expand All @@ -112,13 +107,27 @@ private static ConfluencePageMetadata singleRootPageMetadata(ConfluencePublisher
return null;
}

private void startPublishingReplacingAncestorId(ConfluencePublisherMetadata metadata, String spaceKey, String ancestorId) {
ConfluencePageMetadata rootPage = singleRootPageMetadata(metadata);

if (rootPage != null) {
updatePage(ancestorId, null, rootPage);

deleteConfluenceAttachmentsNotPresentUnderPage(ancestorId, rootPage.getAttachments());
addAttachments(ancestorId, rootPage.getAttachments());

startPublishingUnderAncestorId(rootPage.getChildren(), spaceKey, ancestorId);
}
}

private void startPublishingUnderAncestorId(List<ConfluencePageMetadata> pages, String spaceKey, String ancestorId) {
deleteConfluencePagesNotPresentUnderAncestor(pages, ancestorId);
pages.forEach(page -> {
String contentId = addOrUpdatePageUnderAncestor(spaceKey, ancestorId, page);

deleteConfluenceAttachmentsNotPresentUnderPage(contentId, page.getAttachments());
addAttachments(contentId, page.getAttachments());

startPublishingUnderAncestorId(page.getChildren(), spaceKey, contentId);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,39 @@ public void publish_metadataWithExistingPageWithSameContentButDifferentTitleAndR
verifyNoMoreInteractions(confluencePublisherListenerMock);
}

@Test
public void publish_metadataWithExistingPageAndNewAttachments_sendsUpdateAndAddAttachmentRequests() {
// arrange
ConfluencePage existingPage = new ConfluencePage("72189173", "Existing Page (Old Title)", "<h1>Some Confluence Content</h1>", 1);

ConfluenceRestClient confluenceRestClientMock = mock(ConfluenceRestClient.class);
when(confluenceRestClientMock.getPageWithContentAndVersionById("72189173")).thenReturn(existingPage);
when(confluenceRestClientMock.getPropertyByKey("72189173", CONTENT_HASH_PROPERTY_KEY)).thenReturn(SOME_CONFLUENCE_CONTENT_SHA256_HASH);
when(confluenceRestClientMock.getAttachmentByFileName("72189173", "attachmentOne.txt"))
.thenThrow(new NotFoundException());
when(confluenceRestClientMock.getAttachmentByFileName("72189173", "attachmentTwo.txt"))
.thenReturn(new ConfluenceAttachment("att2", "attachmentOne.txt", "/download/attachmentOne.txt", 1));
when(confluenceRestClientMock.getAttachmentContent("/download/attachmentOne.txt"))
.thenReturn(new ByteArrayInputStream("Old content".getBytes()));

ConfluencePublisherListener confluencePublisherListenerMock = mock(ConfluencePublisherListener.class);

ConfluencePublisher confluencePublisher = confluencePublisher("root-ancestor-id-page-with-attachments", REPLACE_ANCESTOR, confluenceRestClientMock, confluencePublisherListenerMock, null);

// act
confluencePublisher.publish();

// assert
verify(confluenceRestClientMock, never()).addPageUnderAncestor(any(), any(), any(), any(), any());
verify(confluenceRestClientMock, times(1)).updatePage(eq("72189173"), eq(null), eq("Some Confluence Content"), eq("<h1>Some Confluence Content</h1>"), eq(2), eq(null));
verify(confluenceRestClientMock).addAttachment(eq("72189173"), eq("attachmentOne.txt"), any(InputStream.class));
verify(confluenceRestClientMock).updateAttachmentContent(eq("72189173"), eq("att2"), any(InputStream.class));

verify(confluencePublisherListenerMock, times(1)).pageUpdated(existingPage, new ConfluencePage("72189173", "Some Confluence Content", "<h1>Some Confluence Content</h1>", 2));
verify(confluencePublisherListenerMock, times(1)).publishCompleted();
verifyNoMoreInteractions(confluencePublisherListenerMock);
}

@Test
public void publish_metadataWithExistingPageAndAttachmentWithDifferentAttachmentContentUnderRootSpace_sendsUpdateAttachmentRequest() {
// arrange
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<module>asciidoc-confluence-publisher-client</module>
<module>asciidoc-confluence-publisher-converter</module>
<module>asciidoc-confluence-publisher-doc</module>
<module>asciidoc-confluence-publisher-docker</module>
<!--<module>asciidoc-confluence-publisher-docker</module>-->
<module>asciidoc-confluence-publisher-maven-plugin</module>
</modules>

Expand Down

0 comments on commit c0dc240

Please sign in to comment.