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());
}
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"));
}
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));
}
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;
}
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));
}
Aggregations