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