Search in sources :

Example 51 with DocumentAccessBridge

use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.

the class XWikiLinkLabelGeneratorTest method generateWhenNestedPage.

@Test
public void generateWhenNestedPage() throws Exception {
    ResourceReference resourceReference = new DocumentResourceReference("WebHome");
    DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("space1", "NestedPage"), "WebHome");
    EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
    when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    DocumentModelBridge dmb = mock(DocumentModelBridge.class);
    when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb);
    when(dmb.getTitle()).thenReturn("My title");
    EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
    when(localSerializer.serialize(new SpaceReference("wiki", "space1", "NestedPage"))).thenReturn("space1.NestedPage");
    assertEquals("%l%la%n%na%N%NA " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (My title) " + "[wiki:space1.NestedPage.WebHome] NestedPage NestedPage Web Home Nested Page (My title)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 52 with DocumentAccessBridge

use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.

the class XWikiLinkLabelGeneratorTest method generateWhenDocumentFailsToLoad.

@Test
public void generateWhenDocumentFailsToLoad() throws Exception {
    ResourceReference resourceReference = new DocumentResourceReference("HelloWorld");
    DocumentReference documentReference = new DocumentReference("xwiki", "Main", "HelloWorld");
    EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
    when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    when(dab.getTranslatedDocumentInstance(documentReference)).thenThrow(new Exception("error"));
    EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local");
    when(localSerializer.serialize(new SpaceReference("xwiki", "Main"))).thenReturn("Main");
    assertEquals("%l%la%n%na%N%NA " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld) " + "[xwiki:Main.HelloWorld] Main HelloWorld Hello World Hello World (HelloWorld)", this.mocker.getComponentUnderTest().generate(resourceReference));
}
Also used : EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 53 with DocumentAccessBridge

use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.

the class DefaultWikiMacroManagerTest method registerAndUnregisterWikiMacroWhenGlobalVisibilityAndAllowed.

@Test
public void registerAndUnregisterWikiMacroWhenGlobalVisibilityAndAllowed() throws Exception {
    DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.GLOBAL);
    // Simulate a user who's allowed for the GLOBAL visibility
    WikiMacroFactory wikiMacroFactory = this.mocker.getInstance(WikiMacroFactory.class);
    when(wikiMacroFactory.isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.GLOBAL)).thenReturn(true);
    WikiMacroManager wikiMacroManager = this.mocker.getComponentUnderTest();
    assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
    EntityReferenceSerializer<String> serializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    when(serializer.serialize(this.authorReference)).thenReturn("authorwiki:authorspace.authorpage");
    // Test registration
    wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro);
    assertTrue(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
    // Verify that the WikiMacroManager has registered the macro against the root CM
    assertTrue(this.mocker.hasComponent(Macro.class, "testwikimacro"));
    // Verify that the user and wiki where the macro is located have been set in the context
    DocumentAccessBridge bridge = this.mocker.getInstance(DocumentAccessBridge.class);
    verify(bridge).setCurrentUser("authorwiki:authorspace.authorpage");
    ModelContext modelContext = this.mocker.getInstance(ModelContext.class);
    verify(modelContext).setCurrentEntityReference(wikiMacro.getDocumentReference());
    // Test unregistration
    wikiMacroManager.unregisterWikiMacro(wikiMacro.getDocumentReference());
    assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference()));
    // Verify that the WikiMacroManager has unregistered the macro from the root CM
    assertFalse(this.mocker.hasComponent(Macro.class, "testwikimacro"));
}
Also used : WikiMacroFactory(org.xwiki.rendering.macro.wikibridge.WikiMacroFactory) ModelContext(org.xwiki.model.ModelContext) Macro(org.xwiki.rendering.macro.Macro) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Test(org.junit.Test)

Example 54 with DocumentAccessBridge

use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.

the class DefaultSheetManagerTest method configure.

@Before
public void configure() throws Exception {
    documentAccessBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
    documentSheetBinder = getComponentManager().getInstance(SheetBinder.class, "document");
    classSheetBinder = getComponentManager().getInstance(SheetBinder.class, "class");
    modelBridge = getComponentManager().getInstance(ModelBridge.class);
    document = getMockery().mock(DocumentModelBridge.class);
    final Execution execution = getComponentManager().getInstance(Execution.class);
    getMockery().checking(new Expectations() {

        {
            allowing(execution).getContext();
            will(returnValue(context));
            allowing(document).getDocumentReference();
            will(returnValue(new DocumentReference(WIKI_NAME, "Space", "Page")));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) Execution(org.xwiki.context.Execution) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) SheetBinder(org.xwiki.sheet.SheetBinder) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 55 with DocumentAccessBridge

use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.

the class SpacePreferencesConfigurationSourceTest method before.

@Override
public void before() throws Exception {
    super.before();
    DocumentAccessBridge documentAccessBridge = this.componentManager.getInstance(DocumentAccessBridge.class);
    when(documentAccessBridge.getCurrentDocumentReference()).thenReturn(SPACE_DOCUMENT);
}
Also used : DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge)

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