Search in sources :

Example 36 with AttachmentReference

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)));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference)

Example 37 with 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());
}
Also used : LuceneQuery(com.celements.search.lucene.query.LuceneQuery) AttachmentReference(org.xwiki.model.reference.AttachmentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) LuceneSearchResult(com.celements.search.lucene.LuceneSearchResult) DocumentReference(org.xwiki.model.reference.DocumentReference) AbstractComponentTest(com.celements.common.test.AbstractComponentTest) Test(org.junit.Test)

Example 38 with AttachmentReference

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);
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) XWikiURLFactory(com.xpn.xwiki.web.XWikiURLFactory) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 39 with AttachmentReference

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);
    }
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) Page(org.xwiki.rest.model.jaxb.Page) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test) AbstractClusterHttpTest(org.xwiki.test.cluster.framework.AbstractClusterHttpTest)

Example 40 with AttachmentReference

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));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) DocumentReference(org.xwiki.model.reference.DocumentReference) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) 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