use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class DefaultWikiComponentManagerEventListenerTest method onDocumentDeleted.
@Test
public void onDocumentDeleted() throws Exception {
DocumentModelBridge componentDocument = mock(DocumentModelBridge.class);
when(componentDocument.getDocumentReference()).thenReturn(DOC_REFERENCE);
mocker.getComponentUnderTest().onEvent(new DocumentDeletedEvent(DOC_REFERENCE), componentDocument, null);
verify(this.wikiComponentManagerEventListenerHelper, times(1)).unregisterComponents(DOC_REFERENCE);
}
use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class DefaultWikiComponentManagerEventListenerTest method onDocumentCreatedOrUpdated.
private void onDocumentCreatedOrUpdated(Event event) throws Exception {
DocumentModelBridge componentDocument = mock(DocumentModelBridge.class);
when(componentDocument.getDocumentReference()).thenReturn(DOC_REFERENCE);
/**
* Here, {@link WikiComponentManagerEventListenerHelper#registerComponentList(List)} is called two times
* because we have to "initialize" the tested event listener with an ApplicationReadyEvent() before sending
* our custom event. Therefore, the tested WikiComponent will be registered two times.
*/
mocker.getComponentUnderTest().onEvent(new ApplicationReadyEvent(), null, null);
mocker.getComponentUnderTest().onEvent(event, componentDocument, null);
}
use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class SheetScriptServiceTest method bindClassSheetClonesDocument.
/**
* Tests that {@link SheetScriptService#bindClassSheet(Document, DocumentReference)} clones the document first to
* follow the practice from {@link Document}. This is required in order to not modify the cached document.
*
* @throws Exception if the test fails to lookup the class sheet binder
*/
@Test
public void bindClassSheetClonesDocument() throws Exception {
DocumentReference classReference = new DocumentReference("wiki", "Space", "MyClass");
final XWikiDocument classDocument = new XWikiDocument(classReference);
classDocument.setSyntax(Syntax.PLAIN_1_0);
Document classDocumentApi = new Document(classDocument, null);
final DocumentReference sheetReference = new DocumentReference("MySheet", classReference.getLastSpaceReference());
when(this.mockClassSheetBinder.bind(argThat(new ArgumentMatcher<DocumentModelBridge>() {
@Override
public boolean matches(DocumentModelBridge argument) {
return classDocument.equals(argument) && classDocument != argument;
}
}), same(sheetReference))).thenReturn(true);
Assert.assertTrue(this.sheetScriptService.bindClassSheet(classDocumentApi, sheetReference));
}
use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockitoComponentManager componentManager) throws Exception {
ModelContext modelContext = componentManager.registerMockComponent(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
// Document Access Bridge mock
DocumentAccessBridge dab = componentManager.registerMockComponent(DocumentAccessBridge.class);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
DocumentReference currentDocumentReference = new DocumentReference("currentwiki", "currentspace", "currentpage");
DocumentModelBridge document = Mockito.mock(DocumentModelBridge.class);
when(dab.getDocumentURL(new DocumentReference("currentWiki", "space", "page"), "temp", null, null)).thenReturn("temppath");
when(dab.getCurrentDocumentReference()).thenReturn(currentDocumentReference);
when(dab.exists(documentReference)).thenReturn(true);
when(dab.getDocumentInstance(documentReference)).thenReturn(document);
when(dab.getCurrentUserReference()).thenReturn(null);
DocumentDisplayer displayer = componentManager.registerMockComponent(DocumentDisplayer.class);
Parser parser = componentManager.getInstance(Parser.class, Syntax.XWIKI_2_0.toIdString());
final XDOM xdom = parser.parse(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(WIKI_CONTENT_FILE)));
when(displayer.display(eq(document), any(DocumentDisplayerParameters.class))).thenReturn(xdom);
AuthorizationManager authorizationManager = componentManager.registerMockComponent(AuthorizationManager.class);
when(authorizationManager.hasAccess(Right.VIEW, null, documentReference)).thenReturn(true);
componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "current");
componentManager.registerMockComponent(SpaceReferenceResolver.TYPE_STRING, "current");
}
use of org.xwiki.bridge.DocumentModelBridge in project xwiki-platform by xwiki.
the class DocumentTitleDisplayerTest method whenSettingTheContextDocumentTheContextWikiIsAlsoSet.
@Test
public void whenSettingTheContextDocumentTheContextWikiIsAlsoSet() throws Exception {
EntityReferenceProvider defaultEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class);
when(defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new EntityReference("Page", EntityType.DOCUMENT));
DocumentModelBridge document = mock(DocumentModelBridge.class);
DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Space"), "Page");
when(document.getDocumentReference()).thenReturn(documentReference);
when(document.getTitle()).thenReturn("title");
XDOM titleXDOM = new XDOM(Arrays.asList(new WordBlock("title")));
Parser plainTextParser = this.mocker.getInstance(Parser.class, "plain/1.0");
when(plainTextParser.parse(any(StringReader.class))).thenReturn(titleXDOM);
ModelContext modelContext = this.mocker.getInstance(ModelContext.class);
WikiReference currentWikiReference = new WikiReference("currentWiki");
when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference);
AuthorizationManager authorizationManager = this.mocker.getInstance(AuthorizationManager.class);
when(authorizationManager.hasAccess(eq(Right.SCRIPT), any(), any())).thenReturn(true);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentDisplayerParameters params = new DocumentDisplayerParameters();
params.setTitleDisplayed(true);
params.setExecutionContextIsolated(true);
this.mocker.getComponentUnderTest().display(document, params);
// Check that the context is set.
verify(dab).pushDocumentInContext(any(), eq(documentReference));
verify(modelContext).setCurrentEntityReference(documentReference.getWikiReference());
// Check that the context is restored.
verify(dab).popDocumentFromContext(any());
verify(modelContext).setCurrentEntityReference(currentWikiReference);
}
Aggregations