Search in sources :

Example 31 with AttachmentReference

use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(ComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    // Attachment Reference Resolver Mock
    final AttachmentReferenceResolver<String> mockResolver = mockery.mock(AttachmentReferenceResolver.class);
    mockery.checking(new Expectations() {

        {
            allowing(mockResolver).resolve("Space.ExistingPage@my.png");
            will(returnValue(new AttachmentReference("my.png", new DocumentReference("wiki", "Space", "ExistingPage"))));
        }
    });
    DefaultComponentDescriptor<AttachmentReferenceResolver<String>> descriptorARS = new DefaultComponentDescriptor<AttachmentReferenceResolver<String>>();
    descriptorARS.setRoleType(AttachmentReferenceResolver.TYPE_STRING);
    descriptorARS.setRoleHint("current");
    componentManager.registerComponent(descriptorARS, mockResolver);
    // WikiModel Mock
    componentManager.registerComponent(MockWikiModel.getComponentDescriptor());
}
Also used : Expectations(org.jmock.Expectations) AttachmentReference(org.xwiki.model.reference.AttachmentReference) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) AttachmentReferenceResolver(org.xwiki.model.reference.AttachmentReferenceResolver) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 32 with AttachmentReference

use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.

the class CurrentMacroAttachmentReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    EntityReference result = new AttachmentReference("file", new DocumentReference("wiki", "Space", "Page"));
    EntityReferenceResolver<String> macroEntityReferenceResolver = mocker.getInstance(EntityReferenceResolver.TYPE_STRING, "macro");
    when(macroEntityReferenceResolver.resolve("reference", EntityType.ATTACHMENT, "parameter")).thenReturn(result);
    Assert.assertEquals(result, mocker.getComponentUnderTest().resolve("reference", "parameter"));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 33 with AttachmentReference

use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.

the class CurrentMacroEntityReferenceResolverTest method resolveWhenMetaDataBlock.

@Test
public void resolveWhenMetaDataBlock() throws Exception {
    DocumentReference baseReference = new DocumentReference("basewiki", "basespace", "basepage");
    EntityReference expectedReference = new AttachmentReference("file", baseReference);
    EntityReferenceResolver<String> currentEntityReferenceResolver = mocker.getInstance(EntityReferenceResolver.TYPE_STRING, "current");
    when(currentEntityReferenceResolver.resolve("basewiki:basespace.basepage", EntityType.DOCUMENT)).thenReturn(baseReference);
    when(currentEntityReferenceResolver.resolve("file", EntityType.ATTACHMENT, baseReference)).thenReturn(expectedReference);
    Block wordBlock = new WordBlock("whatever");
    MetaData metaData = new MetaData(Collections.<String, Object>singletonMap(MetaData.BASE, "basewiki:basespace.basepage"));
    new XDOM(Arrays.<Block>asList(new MetaDataBlock(Arrays.<Block>asList(wordBlock), metaData)));
    Assert.assertEquals(expectedReference, mocker.getComponentUnderTest().resolve("file", EntityType.ATTACHMENT, wordBlock));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) XDOM(org.xwiki.rendering.block.XDOM) MetaData(org.xwiki.rendering.listener.MetaData) WordBlock(org.xwiki.rendering.block.WordBlock) EntityReference(org.xwiki.model.reference.EntityReference) WordBlock(org.xwiki.rendering.block.WordBlock) Block(org.xwiki.rendering.block.Block) MetaDataBlock(org.xwiki.rendering.block.MetaDataBlock) DocumentReference(org.xwiki.model.reference.DocumentReference) MetaDataBlock(org.xwiki.rendering.block.MetaDataBlock) Test(org.junit.Test)

Example 34 with AttachmentReference

use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.

the class DocumentSolrMetadataExtractorTest method createMockAttachment.

private XWikiAttachment createMockAttachment(String fileName, String mimeType, Date date, byte[] content, String authorAlias, String authorDisplayName) throws Exception {
    XWikiAttachment attachment = mock(XWikiAttachment.class, fileName);
    when(attachment.getReference()).thenReturn(new AttachmentReference(fileName, this.documentReference));
    when(attachment.getFilename()).thenReturn(fileName);
    when(attachment.getMimeType(this.xcontext)).thenReturn(mimeType);
    when(attachment.getDate()).thenReturn(date);
    when(attachment.getLongSize()).thenReturn((long) content.length);
    when(attachment.getContentInputStream(this.xcontext)).thenReturn(new ByteArrayInputStream(content));
    String authorFullName = "XWiki." + authorAlias;
    DocumentReference authorReference = new DocumentReference("wiki", "XWiki", authorAlias);
    when(attachment.getAuthorReference()).thenReturn(authorReference);
    EntityReferenceSerializer<String> serializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    String authorStringReference = "wiki:" + authorFullName;
    when(serializer.serialize(authorReference)).thenReturn(authorStringReference);
    when(this.xcontext.getWiki().getPlainUserName(authorReference, this.xcontext)).thenReturn(authorDisplayName);
    return attachment;
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ByteArrayInputStream(java.io.ByteArrayInputStream) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 35 with AttachmentReference

use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.

the class SolrEntityReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    WikiReference wikiReference = new WikiReference("chess");
    assertReference(wikiReference);
    assertReference(new SpaceReference("Success", new SpaceReference("To", new SpaceReference("Path", wikiReference))));
    DocumentReference documentReference = new DocumentReference("chess", Arrays.asList("Path", "To", "Success"), "WebHome", Locale.FRENCH);
    assertReference(documentReference);
    assertReference(new AttachmentReference("image.png", documentReference));
    ObjectReference objectReference = new ObjectReference("App.Code.PlayerClass[13]", documentReference);
    assertReference(objectReference);
    assertReference(new ObjectPropertyReference("age", objectReference));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

AttachmentReference (org.xwiki.model.reference.AttachmentReference)64 DocumentReference (org.xwiki.model.reference.DocumentReference)44 Test (org.junit.Test)31 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)17 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)14 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)9 XWikiContext (com.xpn.xwiki.XWikiContext)8 EntityReference (org.xwiki.model.reference.EntityReference)7 Expectations (org.jmock.Expectations)6 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)4 XWikiException (com.xpn.xwiki.XWikiException)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 Mockery (org.jmock.Mockery)3 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)3 XDOMOfficeDocument (org.xwiki.officeimporter.document.XDOMOfficeDocument)3 ImageBlock (org.xwiki.rendering.block.ImageBlock)3