Search in sources :

Example 1 with ReaderInputStream

use of org.restlet.engine.io.ReaderInputStream 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 2 with ReaderInputStream

use of org.restlet.engine.io.ReaderInputStream 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)

Aggregations

StringReader (java.io.StringReader)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 Test (org.junit.Test)2 ReaderInputStream (org.restlet.engine.io.ReaderInputStream)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 Attachment (org.xwiki.rest.model.jaxb.Attachment)2 Attachments (org.xwiki.rest.model.jaxb.Attachments)2 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)2 DocumentReference (org.xwiki.model.reference.DocumentReference)1 WikiAttachmentsResource (org.xwiki.rest.resources.wikis.WikiAttachmentsResource)1