Search in sources :

Example 6 with Attachment

use of org.xwiki.rest.model.jaxb.Attachment in project xwiki-platform by xwiki.

the class SpacesResourceTest method testAttachments.

@Test
public void testAttachments() throws Exception {
    DocumentReference reference = new DocumentReference(getWiki(), getTestClassName(), getTestMethodName());
    this.testUtils.rest().delete(reference);
    this.testUtils.rest().savePage(reference);
    this.testUtils.rest().attachFile(new AttachmentReference("attachment.txt", reference), new ReaderInputStream(new StringReader("content")), true);
    // Matches Sandbox.WebHome@XWikLogo.png
    GetMethod getMethod = executeGet(String.format("%s", buildURI(SpaceAttachmentsResource.class, getWiki(), Arrays.asList(getTestClassName()))));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Attachments attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
    for (Attachment attachment : attachments.getAttachments()) {
        checkLinks(attachment);
    }
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ReaderInputStream(org.restlet.engine.io.ReaderInputStream) StringReader(java.io.StringReader) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Attachment(org.xwiki.rest.model.jaxb.Attachment) Attachments(org.xwiki.rest.model.jaxb.Attachments) DocumentReference(org.xwiki.model.reference.DocumentReference) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 7 with Attachment

use of org.xwiki.rest.model.jaxb.Attachment in project xwiki-platform by xwiki.

the class WikisResourceTest method testAttachments.

@Test
public void testAttachments() throws Exception {
    this.testUtils.rest().delete(reference);
    this.testUtils.rest().attachFile(new AttachmentReference(getTestClassName() + ".txt", reference), new ReaderInputStream(new StringReader("attachment content")), true);
    // Verify there are attachments in the whole wiki
    GetMethod getMethod = executeGet(buildURI(WikiAttachmentsResource.class, getWiki()).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Attachments attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertTrue(attachments.getAttachments().size() > 0);
    for (Attachment attachment : attachments.getAttachments()) {
        checkLinks(attachment);
    }
    // Verify we can search for a specific attachment name in the whole wiki
    getMethod = executeGet(String.format("%s?name=" + getTestClassName(), buildURI(WikiAttachmentsResource.class, getWiki())));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
    for (Attachment attachment : attachments.getAttachments()) {
        checkLinks(attachment);
    }
    // Verify we can search for all attachments in a given space (sandbox)
    // Also verify that a space can be looked up independtly of its case ("sandbox" will match the "Sandbox" space)
    getMethod = executeGet(String.format("%s?space=" + getTestClassName(), buildURI(WikiAttachmentsResource.class, getWiki())));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
    for (Attachment attachment : attachments.getAttachments()) {
        checkLinks(attachment);
    }
    // Verify we can search for an attachment in a given space (sandbox)
    getMethod = executeGet(String.format("%s?name=" + getTestClassName() + "&space=" + getTestClassName(), buildURI(WikiAttachmentsResource.class, getWiki())));
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    attachments = (Attachments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertEquals(getAttachmentsInfo(attachments), 1, attachments.getAttachments().size());
    for (Attachment attachment : attachments.getAttachments()) {
        checkLinks(attachment);
    }
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ReaderInputStream(org.restlet.engine.io.ReaderInputStream) StringReader(java.io.StringReader) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Attachment(org.xwiki.rest.model.jaxb.Attachment) Attachments(org.xwiki.rest.model.jaxb.Attachments) WikiAttachmentsResource(org.xwiki.rest.resources.wikis.WikiAttachmentsResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 8 with Attachment

use of org.xwiki.rest.model.jaxb.Attachment in project xwiki-platform by xwiki.

the class AbstractHttpTest method getAttachmentsInfo.

protected String getAttachmentsInfo(Attachments attachments) {
    StringBuffer sb = new StringBuffer();
    sb.append(String.format("Attachments: %d\n", attachments.getAttachments().size()));
    for (Attachment attachment : attachments.getAttachments()) {
        sb.append(String.format("* %s\n", attachment.getName()));
    }
    return sb.toString();
}
Also used : Attachment(org.xwiki.rest.model.jaxb.Attachment)

Aggregations

Attachment (org.xwiki.rest.model.jaxb.Attachment)8 Attachments (org.xwiki.rest.model.jaxb.Attachments)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 Test (org.junit.Test)4 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)4 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 StringReader (java.io.StringReader)2 URL (java.net.URL)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 PutMethod (org.apache.commons.httpclient.methods.PutMethod)2 ReaderInputStream (org.restlet.engine.io.ReaderInputStream)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 Link (org.xwiki.rest.model.jaxb.Link)2 XWikiException (com.xpn.xwiki.XWikiException)1 Document (com.xpn.xwiki.api.Document)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1