Search in sources :

Example 6 with RenderedArticle

use of org.summerb.minicms.api.dto.consuming.RenderedArticle 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());
}
Also used : Locale(java.util.Locale) ArticleService(org.summerb.minicms.api.ArticleService) StringTemplateCompilerlImpl(org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl) ArticleAbsoluteUrlBuilder(org.summerb.minicms.api.ArticleAbsoluteUrlBuilder) Article(org.summerb.minicms.api.dto.Article) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) ArticleRendererImpl(org.summerb.minicms.impl.ArticleRendererImpl) Attachment(org.summerb.minicms.api.dto.Attachment) UrlBuilderTestImpl(integr.org.summerb.minicms.impl.UrlBuilderTestImpl) AttachmentService(org.summerb.minicms.api.AttachmentService) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) Test(org.junit.Test)

Example 7 with RenderedArticle

use of org.summerb.minicms.api.dto.consuming.RenderedArticle in project summerb by skarpushin.

the class ArticleRendererCachingImplTest method testRenderArticle_expectNewVersionWillBeReturnedAfterEvent.

@Test
public void testRenderArticle_expectNewVersionWillBeReturnedAfterEvent() throws Exception {
    ArticleRendererCachingImpl fixture = new ArticleRendererCachingImpl();
    fixture.setEventBus(mock(EventBus.class));
    ArticleRenderer renderer = mock(ArticleRenderer.class);
    fixture.setArticleRenderer(renderer);
    fixture.afterPropertiesSet();
    Locale locale = new Locale("ru");
    mockTest(renderer, locale);
    // force cache
    RenderedArticle ra3v1 = fixture.renderArticle("a3", locale);
    assertEquals("t3v1", ra3v1.getTitle());
    RenderedArticle ra3v2 = new RenderedArticle();
    ra3v2.setId(3L);
    ra3v2.setLang("ru");
    ra3v2.setTitle("t3v2");
    ra3v2.setArticleKey("a3");
    ra3v2.setContent("c");
    when(renderer.renderArticle("a3", locale)).thenReturn(ra3v2);
    ra3v1 = fixture.renderArticle("a3", locale);
    assertEquals("t3v1", ra3v1.getTitle());
    Article a3 = new Article();
    a3.setArticleKey("a3");
    a3.setLang("ru");
    fixture.onArticleChanged(EntityChangedEvent.updated(a3));
    ra3v1 = fixture.renderArticle("a3", locale);
    assertEquals("t3v2", ra3v1.getTitle());
}
Also used : Locale(java.util.Locale) ArticleRenderer(org.summerb.minicms.api.ArticleRenderer) Article(org.summerb.minicms.api.dto.Article) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) EventBus(com.google.common.eventbus.EventBus) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) Test(org.junit.Test)

Example 8 with RenderedArticle

use of org.summerb.minicms.api.dto.consuming.RenderedArticle in project summerb by skarpushin.

the class ArticleRendererCachingImplTest method testRenderArticle_expectDependentWillBeEvictedAsWell.

@Test
public void testRenderArticle_expectDependentWillBeEvictedAsWell() throws Exception {
    ArticleRendererCachingImpl fixture = new ArticleRendererCachingImpl();
    fixture.setEventBus(mock(EventBus.class));
    ArticleRenderer renderer = mock(ArticleRenderer.class);
    fixture.setArticleRenderer(renderer);
    fixture.afterPropertiesSet();
    Locale locale = new Locale("ru");
    mockTest(renderer, locale);
    // force cache
    fixture.renderArticle("a1", locale);
    fixture.renderArticle("a2", locale);
    fixture.renderArticle("a3", locale);
    RenderedArticle ra1v2 = new RenderedArticle();
    ra1v2.setId(1L);
    ra1v2.setLang("ru");
    ra1v2.setTitle("t1v2");
    ra1v2.setArticleKey("a1");
    ra1v2.setContent("c");
    ra1v2.setArticleReferences(Arrays.asList(2L, 3L));
    when(renderer.renderArticle("a1", locale)).thenReturn(ra1v2);
    Article a3 = new Article();
    a3.setArticleKey("a3");
    a3.setLang("ru");
    fixture.onArticleChanged(EntityChangedEvent.updated(a3));
    ra1v2 = fixture.renderArticle("a1", locale);
    assertEquals("t1v2", ra1v2.getTitle());
}
Also used : Locale(java.util.Locale) ArticleRenderer(org.summerb.minicms.api.ArticleRenderer) Article(org.summerb.minicms.api.dto.Article) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) EventBus(com.google.common.eventbus.EventBus) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) Test(org.junit.Test)

Example 9 with RenderedArticle

use of org.summerb.minicms.api.dto.consuming.RenderedArticle in project summerb by skarpushin.

the class ArticleRendererCachingImpl method renderArticle.

@Override
public RenderedArticle renderArticle(String articleKey, Locale locale) {
    Preconditions.checkArgument(StringUtils.hasText(articleKey));
    Preconditions.checkArgument(locale != null);
    ArticleCacheKey cacheKey = new ArticleCacheKey(articleKey, locale);
    RenderedArticle ret = cache.getUnchecked(cacheKey);
    // DeepCopy.copy(ret);
    return ret;
}
Also used : RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle)

Aggregations

RenderedArticle (org.summerb.minicms.api.dto.consuming.RenderedArticle)9 Locale (java.util.Locale)4 Test (org.junit.Test)4 Article (org.summerb.minicms.api.dto.Article)4 EventBus (com.google.common.eventbus.EventBus)3 ArticleRenderer (org.summerb.minicms.api.ArticleRenderer)3 Attachment (org.summerb.minicms.api.dto.Attachment)2 UrlBuilderTestImpl (integr.org.summerb.minicms.impl.UrlBuilderTestImpl)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ArticleAbsoluteUrlBuilder (org.summerb.minicms.api.ArticleAbsoluteUrlBuilder)1 ArticleService (org.summerb.minicms.api.ArticleService)1 AttachmentService (org.summerb.minicms.api.AttachmentService)1 ArticleRendererImpl (org.summerb.minicms.impl.ArticleRendererImpl)1 StringTemplate (org.summerb.stringtemplate.api.StringTemplate)1 StringTemplateCompilerlImpl (org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl)1 PageMessage (org.summerb.webappboilerplate.model.PageMessage)1