Search in sources :

Example 26 with Attachment

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

the class ImageHandlerTest method setupContentSvg.

private void setupContentSvg() throws Exception {
    final Attachment attachment = Attachment.create().name("enonic-logo.svg").mimeType("image/svg+xml").label("source").build();
    final Content content = createContent("123456", "path/to/image-name.svg", 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)

Example 27 with Attachment

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

the class ImageHandlerTest method mockCachableContent.

private void mockCachableContent() throws IOException {
    final Attachment attachment = Attachment.create().name("image-name.jpg").mimeType("image/jpeg").label("source").build();
    final Content content = createContent("123456", "path/to/image-name.jpg", 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)

Example 28 with Attachment

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

the class ImageHandlerTest method setupContentGif.

private void setupContentGif() throws Exception {
    final Attachment attachment = Attachment.create().name("enonic-logo.svg").mimeType("image/gif").label("source").build();
    final Content content = createContent("123456", "path/to/image-name.gif", 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)

Example 29 with Attachment

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

the class PortalUrlServiceImpl_processHtmlTest method process_single_media.

@Test
public void process_single_media() {
    // Creates a content with attachments
    final Attachment thumb = Attachment.create().label("thumb").name("a1.jpg").mimeType("image/jpg").build();
    final Attachment source = Attachment.create().label("source").name("a2.jpg").mimeType("image/jpg").build();
    final Attachments attachments = Attachments.from(thumb, source);
    final Content content = Content.create(ContentFixtures.newContent()).attachments(attachments).build();
    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
    Mockito.when(this.contentService.getBinaryKey(content.getId(), source.getBinaryReference())).thenReturn("binaryHash2");
    // Process an html text containing an inline link to this content
    ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"media://inline/" + content.getId() + "\">Media</a>");
    // Checks that the URL of the source attachment of the content is returned
    String processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/attachment/inline/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Media</a>", processedHtml);
    // Process an html text containing a download link to this content
    params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"media://download/" + content.getId() + "\">Media</a>");
    // Checks that the URL of the source attachment of the content is returned
    processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/attachment/download/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Media</a>", processedHtml);
    // Process an html text containing an inline link to this content in a img tag
    params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"/some/page\"><img src=\"media://inline/" + content.getId() + "\">Media</a>");
    // Checks that the URL of the source attachment of the content is returned
    processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/some/page\"><img src=\"/site/default/draft/context/path/_/attachment/inline/" + content.getId() + ":binaryHash2/" + source.getName() + "\">Media</a>", processedHtml);
}
Also used : Content(com.enonic.xp.content.Content) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Aggregations

Attachment (com.enonic.xp.attachment.Attachment)29 Content (com.enonic.xp.content.Content)14 BinaryReference (com.enonic.xp.util.BinaryReference)12 ByteSource (com.google.common.io.ByteSource)11 ContentId (com.enonic.xp.content.ContentId)10 Attachments (com.enonic.xp.attachment.Attachments)9 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 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 PortalResponse (com.enonic.xp.portal.PortalResponse)2 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)2 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)2