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