Search in sources :

Example 11 with CreateMediaParams

use of com.enonic.xp.content.CreateMediaParams 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)

Example 12 with CreateMediaParams

use of com.enonic.xp.content.CreateMediaParams 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 CreateMediaParams

use of com.enonic.xp.content.CreateMediaParams in project xp by enonic.

the class CreateMediaHandlerTest method createMediaAutoGenerateNameWithExistingName.

@Test
public void createMediaAutoGenerateNameWithExistingName() throws Exception {
    final ContentAlreadyExistsException exception = new ContentAlreadyExistsException(ContentPath.from("/a/b/my-content.jpg"), RepositoryId.from("some.repo"), Branch.from("draft"));
    Mockito.when(this.contentService.create(Mockito.any(CreateMediaParams.class))).thenThrow(exception).thenAnswer(mock -> createContent((CreateMediaParams) mock.getArguments()[0]));
    Mockito.when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content.jpg")))).thenReturn(true);
    Mockito.when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-1.jpg")))).thenReturn(true);
    Mockito.when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-2.jpg")))).thenReturn(true);
    runFunction("/test/CreateMediaHandlerTest.js", "createMediaAutoGenerateName");
}
Also used : CreateMediaParams(com.enonic.xp.content.CreateMediaParams) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) Test(org.junit.jupiter.api.Test)

Aggregations

CreateMediaParams (com.enonic.xp.content.CreateMediaParams)13 Test (org.junit.jupiter.api.Test)10 Content (com.enonic.xp.content.Content)8 ContentType (com.enonic.xp.schema.content.ContentType)7 Attachments (com.enonic.xp.attachment.Attachments)4 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 UpdateMediaParams (com.enonic.xp.content.UpdateMediaParams)2 PropertySet (com.enonic.xp.data.PropertySet)2 Attachment (com.enonic.xp.attachment.Attachment)1 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)1 ContentPath (com.enonic.xp.content.ContentPath)1 Media (com.enonic.xp.content.Media)1 ContentConfig (com.enonic.xp.core.impl.content.ContentConfig)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 ContentMapper (com.enonic.xp.lib.content.mapper.ContentMapper)1