@Test public void testPreserveSheetPRWhenDocumentIsOnContext() throws Exception { DocumentModelBridge document = mockDocument(DOCUMENT_REFERENCE); DocumentModelBridge sheet = mockDocument(SHEET_REFERENCE); setCurrentDocument(document); SheetManager sheetManager = this.mocker.getInstance(SheetManager.class); when(sheetManager.getSheets(document, "view")).thenReturn(Collections.singletonList(SHEET_REFERENCE)); DocumentModelBridge originalSecurityDoc = mock(DocumentModelBridge.class, "sdoc"); when(this.modelBridge.setSecurityDocument(sheet)).thenReturn(originalSecurityDoc); XDOM output = new XDOM(Collections.<Block>emptyList()); DocumentDisplayer documentDisplayer = this.mocker.getInstance(DocumentDisplayer.class); when(documentDisplayer.display(eq(sheet), any(DocumentDisplayerParameters.class))).thenReturn(output); assertSame(output, this.mocker.getComponentUnderTest().display(document, new DocumentDisplayerParameters())); verify(this.modelBridge).setSecurityDocument(originalSecurityDoc); }
@Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { XDOM xdom = null; if (isSheetExpected(document, parameters)) { Map<String, Object> backupObjects = null; EntityReference currentWikiReference = null; try { if (!modelBridge.isCurrentDocument(document)) { backupObjects = modelBridge.pushDocumentInContext(document); currentWikiReference = modelContext.getCurrentEntityReference(); modelContext.setCurrentEntityReference(document.getDocumentReference().getWikiReference()); } xdom = maybeDisplayWithSheet(document, parameters); } finally { if (backupObjects != null) { documentAccessBridge.popDocumentFromContext(backupObjects); modelContext.setCurrentEntityReference(currentWikiReference); } } } return xdom != null ? xdom : documentDisplayer.display(document, parameters); }
SheetDocumentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { XDOM xdom = null; if (isSheetExpected(document, parameters)) { Map<String, Object> backupObjects = null; EntityReference currentWikiReference = null; try { if (!modelBridge.isCurrentDocument(document)) { backupObjects = modelBridge.pushDocumentInContext(document); currentWikiReference = modelContext.getCurrentEntityReference(); modelContext.setCurrentEntityReference(document.getDocumentReference().getWikiReference()); } xdom = maybeDisplayWithSheet(document, parameters); } finally { if (backupObjects != null) { documentAccessBridge.popDocumentFromContext(backupObjects); modelContext.setCurrentEntityReference(currentWikiReference); } } } return xdom != null ? xdom : documentDisplayer.display(document, parameters); } }
SheetDocumentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { XDOM xdom = null; if (isSheetExpected(document, parameters)) { Map<String, Object> backupObjects = null; EntityReference currentWikiReference = null; try { if (!modelBridge.isCurrentDocument(document)) { backupObjects = modelBridge.pushDocumentInContext(document); currentWikiReference = modelContext.getCurrentEntityReference(); modelContext.setCurrentEntityReference(document.getDocumentReference().getWikiReference()); } xdom = maybeDisplayWithSheet(document, parameters); } finally { if (backupObjects != null) { documentAccessBridge.popDocumentFromContext(backupObjects); modelContext.setCurrentEntityReference(currentWikiReference); } } } return xdom != null ? xdom : documentDisplayer.display(document, parameters); }  }
SheetDocumentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { XDOM xdom = null; if (isSheetExpected(document, parameters)) { Map<String, Object> backupObjects = null; EntityReference currentWikiReference = null; try { if (!modelBridge.isCurrentDocument(document)) { backupObjects = modelBridge.pushDocumentInContext(document); currentWikiReference = modelContext.getCurrentEntityReference(); modelContext.setCurrentEntityReference(document.getDocumentReference().getWikiReference()); } xdom = maybeDisplayWithSheet(document, parameters); } finally { if (backupObjects != null) { documentAccessBridge.popDocumentFromContext(backupObjects); modelContext.setCurrentEntityReference(currentWikiReference); } } } return xdom != null ? xdom : documentDisplayer.display(document, parameters); }  @Override XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters); }
SheetDocumentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { XDOM xdom = null; if (isSheetExpected(document, parameters)) { Map<String, Object> backupObjects = null; EntityReference currentWikiReference = null; try { if (!modelBridge.isCurrentDocument(document)) { backupObjects = modelBridge.pushDocumentInContext(document); currentWikiReference = modelContext.getCurrentEntityReference(); modelContext.setCurrentEntityReference(document.getDocumentReference().getWikiReference()); } xdom = maybeDisplayWithSheet(document, parameters); } finally { if (backupObjects != null) { documentAccessBridge.popDocumentFromContext(backupObjects); modelContext.setCurrentEntityReference(currentWikiReference); } } } return xdom != null ? xdom : documentDisplayer.display(document, parameters); }  @Override XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters);  }