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