Search in sources :

Example 6 with Attachment

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);
}
Also used : Attachment(com.enonic.xp.attachment.Attachment)

Example 7 with Attachment

use of com.enonic.xp.attachment.Attachment in project xp by enonic.

the class AttachmentsMapper method serialize.

@Override
public void serialize(final MapGenerator gen) {
    for (Attachment attachment : attachments) {
        gen.map(attachment.getName());
        serializeAttachment(gen, attachment);
        gen.end();
    }
}
Also used : Attachment(com.enonic.xp.attachment.Attachment)

Example 8 with Attachment

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");
}
Also used : Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment) Test(org.junit.jupiter.api.Test)

Example 9 with Attachment

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));
}
Also used : Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment)

Example 10 with Attachment

use of com.enonic.xp.attachment.Attachment in project xp by enonic.

the class ImageHandlerTest method setupContentSvgz.

private void setupContentSvgz() throws Exception {
    final Attachment attachment = Attachment.create().name("enonic-logo.svgz").mimeType("image/svg+xml").label("source").build();
    final Content content = createContent("123456", "path/to/image-name.svgz", attachment);
    when(this.contentService.getById(eq(content.getId()))).thenReturn(content);
    when(this.contentService.getByPath(eq(content.getPath()))).thenReturn(content);
    final ByteSource imageBytes = ByteSource.wrap(new byte[0]);
    when(this.contentService.getBinary(isA(ContentId.class), isA(BinaryReference.class))).thenReturn(imageBytes);
    when(this.imageService.readImage(isA(ReadImageParams.class))).thenReturn(imageBytes);
}
Also used : ReadImageParams(com.enonic.xp.image.ReadImageParams) Content(com.enonic.xp.content.Content) ByteSource(com.google.common.io.ByteSource) Attachment(com.enonic.xp.attachment.Attachment) ContentId(com.enonic.xp.content.ContentId) BinaryReference(com.enonic.xp.util.BinaryReference)

Aggregations

Attachment (com.enonic.xp.attachment.Attachment)31 Content (com.enonic.xp.content.Content)14 BinaryReference (com.enonic.xp.util.BinaryReference)13 ByteSource (com.google.common.io.ByteSource)12 Attachments (com.enonic.xp.attachment.Attachments)10 ContentId (com.enonic.xp.content.ContentId)10 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)6 Media (com.enonic.xp.content.Media)6 ReadImageParams (com.enonic.xp.image.ReadImageParams)6 Test (org.junit.jupiter.api.Test)5 PropertyTree (com.enonic.xp.data.PropertyTree)4 PortalResponse (com.enonic.xp.portal.PortalResponse)4 ServletRequestUrlHelper.contentDispositionAttachment (com.enonic.xp.web.servlet.ServletRequestUrlHelper.contentDispositionAttachment)4 MediaType (com.google.common.net.MediaType)4 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)3 ContentPath (com.enonic.xp.content.ContentPath)2 ContentService (com.enonic.xp.content.ContentService)2 UpdateMediaParams (com.enonic.xp.content.UpdateMediaParams)2 Thumbnail (com.enonic.xp.icon.Thumbnail)2 PortalRequest (com.enonic.xp.portal.PortalRequest)2