use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class GetAttachmentStreamHandlerTest method getById_AttachmentNotFound.
@Test
public void getById_AttachmentNotFound() throws Exception {
final Content content = TestDataFixtures.newContent();
final Attachment attachment = content.getAttachments().byName("document.pdf");
Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
Mockito.when(this.contentService.getBinary(content.getId(), attachment.getBinaryReference())).thenReturn(ByteSource.wrap(ATTACHMENT_DATA));
runFunction("/test/GetAttachmentStreamHandlerTest.js", "getAttachmentStreamById_AttachmentNotFound");
}
use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class GetAttachmentStreamHandlerTest method mockAttachmentBinary.
private void mockAttachmentBinary() {
final Content content = TestDataFixtures.newContent();
final Attachment attachment = content.getAttachments().byName("document.pdf");
Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
Mockito.when(this.contentService.getBinary(content.getId(), attachment.getBinaryReference())).thenReturn(ByteSource.wrap(ATTACHMENT_DATA));
}
use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class TestDataFixtures method newAttachments.
public static Attachments newAttachments() {
final Attachment a1 = Attachment.create().name("logo.png").mimeType("image/png").label("small").size(6789).build();
final Attachment a2 = Attachment.create().name("document.pdf").mimeType("application/pdf").size(12345).build();
return Attachments.from(a1, a2);
}
use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class AttachmentHandlerWorker method resolveAttachment.
private Attachment resolveAttachment(final Content content, final String name) {
final Attachments attachments = content.getAttachments();
final Attachment attachment = attachments.byName(name);
if (attachment != null) {
return attachment;
}
throw WebException.notFound(String.format("Attachment [%s] not found for [%s]", name, content.getPath()));
}
use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class AttachmentUrlBuilder method resolveAttachment.
private Attachment resolveAttachment(final Content content) {
final Attachments attachments = content.getAttachments();
final Attachment attachment;
if (this.params.getName() != null) {
attachment = attachments.byName(this.params.getName());
if (attachment == null) {
throw new IllegalArgumentException("Could not find attachment with name [" + this.params.getName() + "] on content [" + content.getId() + "]");
}
} else {
final String label = this.params.getLabel() != null ? this.params.getLabel() : "source";
attachment = attachments.byLabel(label);
if (attachment == null) {
throw new IllegalArgumentException("Could not find attachment with label [" + label + "] on content [" + content.getId() + "]");
}
}
return attachment;
}
Aggregations