Search in sources :

Example 26 with DocumentAccessBridge

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));
}
Also used : MetaData(org.xwiki.rendering.listener.MetaData) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) DocumentReference(org.xwiki.model.reference.DocumentReference) BlockMatcher(org.xwiki.rendering.block.match.BlockMatcher) MacroBlock(org.xwiki.rendering.block.MacroBlock) MetaDataBlock(org.xwiki.rendering.block.MetaDataBlock) Test(org.junit.Test)

Example 27 with DocumentAccessBridge

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);
}
Also used : DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge)

Example 28 with DocumentAccessBridge

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));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ScriptContextManager(org.xwiki.script.ScriptContextManager) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Execution(org.xwiki.context.Execution) WikiReference(org.xwiki.model.reference.WikiReference) WikiMacroVisibility(org.xwiki.rendering.macro.wikibridge.WikiMacroVisibility) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 29 with DocumentAccessBridge

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");
}
Also used : ModelContext(org.xwiki.model.ModelContext) DocumentDisplayerParameters(org.xwiki.display.internal.DocumentDisplayerParameters) DocumentDisplayer(org.xwiki.display.internal.DocumentDisplayer) XDOM(org.xwiki.rendering.block.XDOM) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) InputStreamReader(java.io.InputStreamReader) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Parser(org.xwiki.rendering.parser.Parser)

Example 30 with DocumentAccessBridge

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"));
}
Also used : ModelContext(org.xwiki.model.ModelContext) ChartMacroParameters(org.xwiki.rendering.macro.chart.ChartMacroParameters) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)56 DocumentReference (org.xwiki.model.reference.DocumentReference)39 Test (org.junit.Test)33 Expectations (org.jmock.Expectations)17 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)15 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)11 Before (org.junit.Before)10 XDOM (org.xwiki.rendering.block.XDOM)10 Execution (org.xwiki.context.Execution)7 SpaceReference (org.xwiki.model.reference.SpaceReference)7 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)6 MacroBlock (org.xwiki.rendering.block.MacroBlock)6 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)6 HashMap (java.util.HashMap)5 VelocityContext (org.apache.velocity.VelocityContext)5 Event (org.xwiki.eventstream.Event)5 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)5 VelocityEngine (org.xwiki.velocity.VelocityEngine)5 VelocityManager (org.xwiki.velocity.VelocityManager)5