use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class ImageHandlerTest method setupContent.
private void setupContent() throws Exception {
final Attachment attachment = Attachment.create().name("enonic-logo.png").mimeType("image/png").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 AttachmentHandlerTest method setupMedia.
private void setupMedia() throws Exception {
final Attachment attachment = Attachment.create().name("logo.png").mimeType("image/png").label("small").build();
final Media content = createMedia("123456", "path/to/content", attachment);
when(this.contentService.getById(eq(content.getId()))).thenReturn(content);
when(this.contentService.getByPath(eq(content.getPath()))).thenReturn(content);
when(this.contentService.getBinaryKey(eq(content.getId()), eq(content.getMediaAttachment().getBinaryReference()))).thenReturn("98765");
this.mediaBytes = ByteSource.wrap(new byte[] { '0', '1', '2', '3', '4', '5', '6' });
when(this.contentService.getBinary(isA(ContentId.class), isA(BinaryReference.class))).thenReturn(this.mediaBytes);
}
use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class AttachmentHandlerTest method setup.
@BeforeEach
final void setup() throws Exception {
this.contentService = mock(ContentService.class);
this.handler = new AttachmentHandler(this.contentService);
this.handler.activate(mock(PortalConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
this.request = new PortalRequest();
this.request.setMethod(HttpMethod.GET);
this.request.setBranch(ContentConstants.BRANCH_MASTER);
this.request.setBaseUri("/site");
this.request.setContentPath(ContentPath.from("/path/to/content"));
this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
setupMedia();
}
use of com.enonic.xp.attachment.Attachment in project xp by enonic.
the class ImageUrlBuilderTest method init.
@BeforeEach
public void init() {
final PortalRequest portalRequest = new PortalRequest();
portalRequest.setBranch(Branch.from("draft"));
portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
portalRequest.setBaseUri("/site");
portalRequest.setContentPath(ContentPath.from("context/path"));
this.imageUrlParams = new ImageUrlParams().portalRequest(portalRequest).scale("testScale");
urlBuilder = new ImageUrlBuilder();
urlBuilder.setParams(imageUrlParams);
final Attachment attachment = Attachment.create().name("attachmentName").mimeType("attachmentMimeType").size(1).build();
media = Mockito.mock(Media.class);
final ContentId contentId = ContentId.from("testID");
Mockito.when(media.getId()).thenReturn(contentId);
Mockito.when(media.getName()).thenReturn(ContentName.from("testName"));
Mockito.when(media.getType()).thenReturn(ContentTypeName.imageMedia());
Mockito.when(media.getMediaAttachment()).thenReturn(attachment);
final ContentService contentService = Mockito.mock(ContentService.class);
Mockito.when(contentService.getByPath(Mockito.any())).thenReturn(media);
Mockito.when(contentService.getById(Mockito.any())).thenReturn(media);
Mockito.when(contentService.getBinaryKey(contentId, attachment.getBinaryReference())).thenReturn("binaryHash");
urlBuilder.contentService = contentService;
}
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