Search in sources :

Example 11 with Attachments

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

the class PortalUrlServiceImpl_attachmentUrlTest method createContent.

private Content createContent() {
    final Attachment a1 = Attachment.create().label("thumb").name("a1.jpg").mimeType("image/jpg").build();
    final Attachment a2 = Attachment.create().label("source").name("a2.jpg").mimeType("image/jpg").build();
    final Attachments attachments = Attachments.from(a1, a2);
    final Content content = Content.create(ContentFixtures.newContent()).attachments(attachments).build();
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
    Mockito.when(this.contentService.getBinaryKey(content.getId(), a1.getBinaryReference())).thenReturn("binaryHash1");
    Mockito.when(this.contentService.getBinaryKey(content.getId(), a2.getBinaryReference())).thenReturn("binaryHash2");
    return content;
}
Also used : Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments)

Example 12 with Attachments

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

the class ContentServiceImplTest_media method create_media_document.

@Test
public void create_media_document() throws Exception {
    final CreateMediaParams createMediaParams = new CreateMediaParams();
    createMediaParams.byteSource(loadImage("document.pdf")).name("document.pdf").mimeType("application/pdf").parent(ContentPath.ROOT);
    Mockito.when(this.xDataService.getFromContentType(Mockito.any(ContentType.class))).thenReturn(XDatas.empty());
    final Content content = this.contentService.create(createMediaParams);
    final Content storedContent = this.contentService.getById(content.getId());
    assertNotNull(storedContent.getName());
    assertNotNull(storedContent.getCreatedTime());
    assertNotNull(storedContent.getCreator());
    assertNotNull(storedContent.getModifiedTime());
    assertNotNull(storedContent.getModifier());
    assertNotNull(storedContent.getData().getString(ContentPropertyNames.MEDIA));
    final Attachments attachments = storedContent.getAttachments();
    assertEquals(1, attachments.getSize());
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Example 13 with Attachments

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

the class ContentServiceImplTest_media method create_media_image_invalid_file_name_allowed_by_config.

@Test
public void create_media_image_invalid_file_name_allowed_by_config() throws Exception {
    final CreateMediaParams createMediaParams = new CreateMediaParams();
    // file ending with point is illegal on Windows
    createMediaParams.byteSource(loadImage("cat-small.jpg")).name("cat-small.").parent(ContentPath.ROOT);
    Mockito.when(this.xDataService.getFromContentType(Mockito.any(ContentType.class))).thenReturn(XDatas.empty());
    final ContentConfig contentConfig = mock(ContentConfig.class);
    when(contentConfig.attachments_allowUnsafeNames()).thenReturn(true);
    contentService.initialize(contentConfig);
    final Content content = this.contentService.create(createMediaParams);
    final Content storedContent = this.contentService.getById(content.getId());
    final Attachments attachments = storedContent.getAttachments();
    assertEquals(1, attachments.getSize());
    assertEquals(attachments.get(0).getName(), "cat-small.");
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) Attachments(com.enonic.xp.attachment.Attachments) ContentConfig(com.enonic.xp.core.impl.content.ContentConfig) Test(org.junit.jupiter.api.Test)

Example 14 with Attachments

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

the class ContentServiceImplTest_media method update_media_image.

@Test
public void update_media_image() throws Exception {
    final CreateMediaParams createMediaParams = new CreateMediaParams();
    createMediaParams.byteSource(loadImage("cat-small.jpg")).name("Small cat").parent(ContentPath.ROOT);
    Mockito.when(this.xDataService.getFromContentType(Mockito.any(ContentType.class))).thenReturn(XDatas.empty());
    final Content content = this.contentService.create(createMediaParams);
    final Content storedContent = this.contentService.getById(content.getId());
    final UpdateMediaParams updateMediaParams = new UpdateMediaParams().content(content.getId()).name("dart-small").byteSource(loadImage("darth-small.jpg"));
    this.contentService.update(updateMediaParams);
    final Content updatedContent = this.contentService.getById(storedContent.getId());
    final Attachments attachments = updatedContent.getAttachments();
    assertNotNull(attachments);
    assertEquals(1, attachments.getSize());
    for (final Attachment attachment : attachments) {
        assertTrue(attachment.getName().startsWith("dart-small"));
    }
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) ContentType(com.enonic.xp.schema.content.ContentType) Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Aggregations

Attachments (com.enonic.xp.attachment.Attachments)14 Content (com.enonic.xp.content.Content)10 Attachment (com.enonic.xp.attachment.Attachment)8 Test (org.junit.jupiter.api.Test)8 CreateMediaParams (com.enonic.xp.content.CreateMediaParams)4 ContentType (com.enonic.xp.schema.content.ContentType)4 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)2 ServletRequestUrlHelper.contentDispositionAttachment (com.enonic.xp.web.servlet.ServletRequestUrlHelper.contentDispositionAttachment)2 ByteSource (com.google.common.io.ByteSource)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 UpdateMediaParams (com.enonic.xp.content.UpdateMediaParams)1 ContentConfig (com.enonic.xp.core.impl.content.ContentConfig)1 PropertySet (com.enonic.xp.data.PropertySet)1 Thumbnail (com.enonic.xp.icon.Thumbnail)1 BinaryReference (com.enonic.xp.util.BinaryReference)1