use of com.enonic.xp.content.CreateMediaParams in project xp by enonic.
the class CreateMediaHandlerTest method createMediaAsPDFDocument.
@Test
public void createMediaAsPDFDocument() {
Mockito.when(this.contentService.create(Mockito.any(CreateMediaParams.class))).thenAnswer(mock -> {
final CreateMediaParams params = (CreateMediaParams) mock.getArguments()[0];
final PropertySet attachmentSet = new PropertySet();
attachmentSet.addString("attachment", params.getName());
final PropertyTree propertyTree = new PropertyTree();
propertyTree.addSet("media", attachmentSet);
return Media.create().id(ContentId.from("dbc077af-fb97-4b17-a567-ad69e85f1010")).name(params.getName()).parentPath(params.getParent()).type(ContentTypeName.documentMedia()).displayName(params.getName()).valid(true).creator(PrincipalKey.ofAnonymous()).data(propertyTree).attachments(Attachments.create().add(Attachment.create().name("documentName.pdf").label("source").mimeType("application/pdf").size(653453).build()).build()).createdTime(Instant.parse("1975-01-08T00:00:00Z")).build();
});
runFunction("/test/CreateMediaHandlerTest.js", "createMediaAsPDF");
}
use of com.enonic.xp.content.CreateMediaParams in project xp by enonic.
the class AbstractContentSynchronizerTest method createMedia.
protected Media createMedia(final String name, final ContentPath parentPath) throws IOException {
final CreateMediaParams params = new CreateMediaParams().byteSource(loadImage("cat-small.jpg")).name("cat-small.jpg").mimeType("image/jpeg").parent(ContentPath.ROOT);
params.name(name).parent(parentPath);
return (Media) this.contentService.create(params);
}
use of com.enonic.xp.content.CreateMediaParams in project xp by enonic.
the class ContentServiceImplTest_media method create_media_image_invalid_file_name.
@Test
public void create_media_image_invalid_file_name() 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());
assertThrows(IllegalArgumentException.class, () -> this.contentService.create(createMediaParams));
}
use of com.enonic.xp.content.CreateMediaParams in project xp by enonic.
the class ContentServiceImplTest_media method create_media_image.
@Test
public void create_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());
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());
}
use of com.enonic.xp.content.CreateMediaParams in project xp by enonic.
the class ContentServiceImplTest_media method update_media_image_invalid_file_name.
@Test
public void update_media_image_invalid_file_name() 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);
// file ending with point is illegal on Windows
final UpdateMediaParams updateMediaParams = new UpdateMediaParams().content(content.getId()).name("dart-small.").byteSource(loadImage("darth-small.jpg"));
assertThrows(IllegalArgumentException.class, () -> this.contentService.update(updateMediaParams));
}
Aggregations