use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class AttachVfsResourceReferenceSerializer method makeAbsolute.
@Override
protected URI makeAbsolute(URI uri) {
AttachmentReference attachmentReference = this.attachmentResolver.resolve(uri.getSchemeSpecificPart());
String scheme = uri.getScheme();
return URI.create(String.format("%s:%s", scheme, this.entitySerializer.serialize(attachmentReference)));
}
use of org.xwiki.model.reference.AttachmentReference in project celements-blog by celements.
the class ArticleEngineLuceneTest method testGetArticles.
@Test
public void testGetArticles() throws Exception {
ArticleLoadParameter param = new ArticleLoadParameter();
List<String> sortFields = Arrays.asList("field1", "field2");
param.setSortFields(sortFields);
String language = "de";
param.setLanguage(language);
int offset = 5;
param.setOffset(offset);
int limit = 10;
param.setLimit(limit);
LuceneQuery query = new LuceneQuery(Arrays.asList(LucenePlugin.DOCTYPE_WIKIPAGE));
LuceneSearchResult resultMock = createMockAndAddToDefault(LuceneSearchResult.class);
DocumentReference artDocRef = new DocumentReference("wiki", "blogSpace", "article");
XWikiDocument artDoc = new XWikiDocument(artDocRef);
artDoc.setSyntax(Syntax.XWIKI_1_0);
AttachmentReference attRef = new AttachmentReference("file", artDocRef);
expect(queryBuilderMock.build(same(param))).andReturn(query).once();
expect(searchServiceMock.searchWithoutChecks(same(query), eq(sortFields), eq(Arrays.asList("default", language)))).andReturn(resultMock).once();
expect(resultMock.setOffset(eq(offset))).andReturn(resultMock).once();
expect(resultMock.setLimit(eq(limit))).andReturn(resultMock).once();
expect(getWikiMock().getDocument(eq(artDocRef), same(getContext()))).andReturn(artDoc).once();
expect(resultMock.getResults()).andReturn(Arrays.<EntityReference>asList(artDocRef, attRef)).once();
replayDefault();
List<Article> ret = engine.getArticles(param);
verifyDefault();
assertNotNull(ret);
// empty because of EmptyArticleException
assertEquals(0, ret.size());
}
use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class XWikiMockitoTest method getEntityURLWithDefaultAction.
@Test
public void getEntityURLWithDefaultAction() throws Exception {
DocumentReference documentReference = new DocumentReference("tennis", Arrays.asList("Path", "To"), "Success");
AttachmentReference attachmentReference = new AttachmentReference("image.png", documentReference);
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
context.setURLFactory(urlFactory);
this.xwiki.getURL(documentReference, this.context);
verify(urlFactory).createURL("Path.To", "Success", "view", null, null, "tennis", this.context);
this.xwiki.getURL(attachmentReference, this.context);
verify(urlFactory).createAttachmentURL("image.png", "Path.To", "Success", "download", null, "tennis", this.context);
}
use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class DocumentCacheTest method testDocumentCacheSyncForAttachments.
@Test
public void testDocumentCacheSyncForAttachments() throws Exception {
Page page = new Page();
page.setSpace(TEST_SPACE);
page.setName("AttachementCacheSync");
AttachmentReference attachmentReference = new AttachmentReference("file.ext", new DocumentReference(getUtil().getCurrentWiki(), page.getSpace(), page.getName()));
// 1) Edit a page on XWiki 0
getUtil().switchExecutor(0);
page.setContent("content");
getUtil().rest().save(page);
// 2) Add attachment to the page on XWiki 1
getUtil().switchExecutor(1);
getUtil().rest().attachFile(attachmentReference, "content".getBytes(), true);
// ASSERT) The content in XWiki 0 should be the one set than in XWiki 1
// Since it can take time for the Cluster to propagate the change, we need to wait and set up a timeout.
getUtil().switchExecutor(0);
long t1 = System.currentTimeMillis();
long t2;
while (!hasAttachment(attachmentReference)) {
t2 = System.currentTimeMillis();
if (t2 - t1 > 10000L) {
Assert.fail("Failed to find attachment");
}
Thread.sleep(100);
}
}
use of org.xwiki.model.reference.AttachmentReference in project xwiki-platform by xwiki.
the class PDFURIResolverTest method resolveWhenMapItemExists.
@Test
public void resolveWhenMapItemExists() throws Exception {
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
AttachmentReference attachmentReference = new AttachmentReference("fileName", documentReference);
com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class);
XWikiDocument document = mock(XWikiDocument.class);
XWikiAttachment attachment = mock(XWikiAttachment.class);
XWikiContext context = mock(XWikiContext.class);
// Add an encoded space character to test that the URL is not decoded. The input URL (to be resolved) is
// expected to be encoded because the URL factory creates encoded URLs.
String url = "encoded+url";
when(context.get("pdfExportImageURLMap")).thenReturn(Collections.singletonMap(url, attachmentReference));
when(context.getWiki()).thenReturn(xwiki);
when(xwiki.getDocument(attachmentReference.extractReference(EntityType.DOCUMENT), context)).thenReturn(document);
when(document.getAttachment("fileName")).thenReturn(attachment);
when(attachment.getContentInputStream(context)).thenReturn(new ByteArrayInputStream("content".getBytes()));
PDFURIResolver resolver = new PDFURIResolver(context);
Source source = resolver.resolve(url, "base");
Assert.assertEquals(StreamSource.class, source.getClass());
Assert.assertEquals("content", IOUtils.readLines(((StreamSource) source).getInputStream()).get(0));
}
Aggregations