use of org.summerb.minicms.api.dto.Attachment in project summerb by skarpushin.
the class AttachmentServiceImplTest method testAttachment_expectMultipleResults.
@Test
public void testAttachment_expectMultipleResults() throws Exception {
Attachment a = new Attachment();
a.setArticleId(createTestArticle());
a.setName("test attachment");
a.setSize(123);
a.setContents(createValidContentsReader());
attachmentService.create(a);
a.setContents(createValidContentsReader());
a.setName("test attachment 2");
attachmentService.create(a);
PaginatedList<Attachment> result = attachmentService.query(new PagerParams(0, 100), Query.n().eq(Attachment.FN_ARTICLE_ID, a.getArticleId()));
assertEquals(2, result.getItems().size());
}
use of org.summerb.minicms.api.dto.Attachment in project summerb by skarpushin.
the class AttachmentServiceImplTest method testAttachment_expectCanRetrieveInputStream.
@Test
public void testAttachment_expectCanRetrieveInputStream() throws Exception {
Attachment a = new Attachment();
a.setArticleId(createTestArticle());
a.setName("test attachment");
a.setSize(123);
a.setContents(createValidContentsReader());
Attachment result = attachmentService.create(a);
InputStream b = attachmentService.getContentInputStream(result.getId());
assertStreamsEquals(createValidContentsReader(), b);
}
use of org.summerb.minicms.api.dto.Attachment in project summerb by skarpushin.
the class AttachmentServiceImplTest method testAttachment_expectCreatedAndRetrieved.
@Test
public void testAttachment_expectCreatedAndRetrieved() throws Exception {
Attachment a = new Attachment();
a.setArticleId(createTestArticle());
a.setName("test attachment");
a.setSize(123);
a.setContents(createValidContentsReader());
Attachment result = attachmentService.create(a);
assertNotNull(result);
assertNotNull(result.getId());
assertTrue(result.getId() > 0);
Attachment b = attachmentService.findById(result.getId());
assertNotNull(b);
// NOTE: By default we don't want to open stream
assertNull(b.getContents());
}
use of org.summerb.minicms.api.dto.Attachment in project summerb by skarpushin.
the class ArticleRenderingServiceImplTest method testRenderArticle_smokeTest.
@Test
public void testRenderArticle_smokeTest() throws Exception {
ArticleAbsoluteUrlBuilder articleAbsoluteUrlBuilder = new UrlBuilderTestImpl();
ArticleService articleService = Mockito.mock(ArticleService.class);
AttachmentService attachmentService = Mockito.mock(AttachmentService.class);
Article a1 = new Article();
a1.setId(1L);
a1.setArticleKey("a1");
a1.setAnnotation("Article annotation. Read other article first: ${article['a2']}");
a1.setContent("Article text. See: ${article['a2']}. And now - here is the screenshot: ${img['screenshot1.jpg']}");
when(articleService.findArticleByKeyAndLocale(eq("a1"), any(Locale.class))).thenReturn(a1);
Attachment att1 = new Attachment();
att1.setId(1L);
att1.setArticleId(1L);
att1.setName("screenshot1.jpg");
when(attachmentService.findArticleAttachments(1L)).thenReturn(new Attachment[] { att1 });
Article a2 = new Article();
a2.setId(1L);
a2.setArticleKey("a2");
a2.setTitle("Title of article 2");
a2.setAnnotation("Article annotation. Read other article first: ${article['a2']}");
a2.setContent("Article text. See: ${article['a2']}. And now - here is the screenshot: ${img['screenshot1.jpg']}");
when(articleService.findArticleByKeyAndLocale(eq("a2"), any(Locale.class))).thenReturn(a2);
ArticleRendererImpl fixture = new ArticleRendererImpl();
fixture.setArticleAbsoluteUrlBuilder(articleAbsoluteUrlBuilder);
fixture.setArticleService(articleService);
fixture.setAttachmentService(attachmentService);
fixture.setStringTemplateCompiler(new StringTemplateCompilerlImpl());
RenderedArticle result = fixture.renderArticle("a1", Locale.ENGLISH);
assertNotNull(result);
String a2href = "<a href=\"url-article:a2\" title=\"Title of article 2\">Title of article 2</a>";
assertEquals("Article annotation. Read other article first: " + a2href, result.getAnnotation());
assertEquals("Article text. See: " + a2href + ". And now - here is the screenshot: <img class=\"article-image\" src=\"url-att:screenshot1.jpg\" alt=\"screenshot1.jpg\" />", result.getContent());
}
use of org.summerb.minicms.api.dto.Attachment in project summerb by skarpushin.
the class AttachmentEventBusWireTapImpl method getDtoSafeForEventBus.
private Attachment getDtoSafeForEventBus(Attachment dto) {
try {
if (dto.getContents() == null) {
return dto;
}
InputStream contents = dto.getContents();
dto.setContents(null);
Attachment dto2 = DeepCopy.copyOrPopagateExcIfAny(dto);
dto.setContents(contents);
return dto2;
} catch (NotSerializableException e) {
throw new RuntimeException("Failed to identify the version of the Attachment DTO that is safe for eventBus", e);
}
}
Aggregations