use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class DocumentTableBlockDataSourceTest method isDefinedChartSourceTheCurrentDocumentWhenReferenceNotNullAndMatching.
@Test
public void isDefinedChartSourceTheCurrentDocumentWhenReferenceNotNullAndMatching() throws Exception {
DocumentAccessBridge dab = this.componentManager.getInstance(DocumentAccessBridge.class);
DocumentReference currentReference = new DocumentReference("currentwiki", "currentspace", "currentpage");
when(dab.getCurrentDocumentReference()).thenReturn(currentReference);
DocumentReferenceResolver<String> resolver = this.componentManager.getInstance(DocumentReferenceResolver.TYPE_STRING);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
when(resolver.resolve("wiki:space.page", currentReference)).thenReturn(documentReference);
MacroBlock currentMacroBlock = mock(MacroBlock.class);
MetaDataBlock metaDataBlock = new MetaDataBlock(Collections.EMPTY_LIST, new MetaData(Collections.singletonMap(MetaData.SOURCE, (Object) "wiki:space.page")));
when(currentMacroBlock.getFirstBlock(any(BlockMatcher.class), any(Block.Axes.class))).thenReturn(metaDataBlock);
DocumentTableBlockDataSource source = this.componentManager.getComponentUnderTest();
source.setParameter("document", "wiki:space.page");
Assert.assertTrue(source.isDefinedChartSourceTheCurrentDocument(currentMacroBlock));
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class UserPreferencesConfigurationSourceTest method before.
@Override
public void before() throws Exception {
super.before();
DocumentAccessBridge documentAccessBridge = this.componentManager.getInstance(DocumentAccessBridge.class);
when(documentAccessBridge.getCurrentUserReference()).thenReturn(USER_DOCUMENT);
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
// Script setup.
ScriptMockSetup scriptMockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
final DocumentAccessBridge mockDocBridge = scriptMockSetup.bridge;
this.mockWikiModel = scriptMockSetup.wikiModel;
this.wikiMacroDocumentReference = new DocumentReference("wiki", "space", "macroPage");
this.wikiMacroManager = getComponentManager().getInstance(WikiMacroManager.class);
// Make sure the old XWiki Context is set up in the Execution Context since it's used in
// DefaultWikiMacro.execute().
this.xcontext = new HashMap<String, Object>();
Execution execution = getComponentManager().getInstance(Execution.class);
execution.getContext().setProperty("xwikicontext", this.xcontext);
ScriptContextManager scm = getComponentManager().getInstance(ScriptContextManager.class);
scm.getCurrentScriptContext().setAttribute("xcontext", this.xcontext, ScriptContext.ENGINE_SCOPE);
getMockery().checking(new Expectations() {
{
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki"));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki", "space", "document")));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockDocBridge).getCurrentUser();
will(returnValue("dummy"));
allowing(mockDocBridge).setCurrentUser(with(any(String.class)));
allowing(mockDocBridge).getCurrentUserReference();
will(returnValue(new DocumentReference("wiki", "XWiki", "dummy")));
allowing(mockWikiMacroFactory).isAllowed(with(any(DocumentReference.class)), with(any(WikiMacroVisibility.class)));
will(returnValue(true));
// This is the document containing the wiki macro that will be put in the context available in the macro
// Since we're not testing it here, it can be null.
allowing(mockDocBridge).getDocumentInstance(wikiMacroDocumentReference);
will(returnValue(null));
}
});
}
use of org.xwiki.bridge.DocumentAccessBridge 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.DocumentAccessBridge in project xwiki-platform by xwiki.
the class TemporaryChartImageWriterTest method getURL.
@Test
public void getURL() throws Exception {
WikiReference currentWikiReference = new WikiReference("wiki");
ModelContext modelContext = this.componentManager.getInstance(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference);
DocumentAccessBridge dab = this.componentManager.getInstance(DocumentAccessBridge.class);
when(dab.getDocumentURL(new DocumentReference("wiki", "space", "page"), "temp", null, null)).thenReturn("temp/Space/Page");
String location = this.componentManager.getComponentUnderTest().getURL(new ImageId(new ChartMacroParameters()));
Assert.assertTrue("Got: " + location, location.toString().matches("temp/Space/Page/chart/.*\\.png"));
}
Aggregations