Search in sources :

Example 1 with ArticleRenderer

use of org.summerb.minicms.api.ArticleRenderer in project summerb by skarpushin.

the class ArticleRendererCachingImplTest method testRenderArticle_expectArticleCacheInvalidatedOnAttachmentChange.

@Test
public void testRenderArticle_expectArticleCacheInvalidatedOnAttachmentChange() 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 ra2v2 = new RenderedArticle();
    ra2v2.setId(1L);
    ra2v2.setLang("ru");
    ra2v2.setTitle("t2v2");
    ra2v2.setArticleKey("a2");
    ra2v2.setContent("c");
    ra2v2.setArticleReferences(Arrays.asList(3L));
    when(renderer.renderArticle("a2", locale)).thenReturn(ra2v2);
    Attachment att3 = new Attachment();
    att3.setArticleId(3L);
    fixture.onArticleAttachmentChanged(EntityChangedEvent.removedObject(att3));
    ra2v2 = fixture.renderArticle("a2", locale);
    assertEquals("t2v2", ra2v2.getTitle());
}
Also used : Locale(java.util.Locale) ArticleRenderer(org.summerb.minicms.api.ArticleRenderer) Attachment(org.summerb.minicms.api.dto.Attachment) EventBus(com.google.common.eventbus.EventBus) RenderedArticle(org.summerb.minicms.api.dto.consuming.RenderedArticle) Test(org.junit.Test)

Example 2 with ArticleRenderer

use of org.summerb.minicms.api.ArticleRenderer 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 3 with ArticleRenderer

use of org.summerb.minicms.api.ArticleRenderer 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)

Aggregations

EventBus (com.google.common.eventbus.EventBus)3 Locale (java.util.Locale)3 Test (org.junit.Test)3 ArticleRenderer (org.summerb.minicms.api.ArticleRenderer)3 RenderedArticle (org.summerb.minicms.api.dto.consuming.RenderedArticle)3 Article (org.summerb.minicms.api.dto.Article)2 Attachment (org.summerb.minicms.api.dto.Attachment)1