use of org.summerb.microservices.articles.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;
}
use of org.summerb.microservices.articles.api.dto.consuming.RenderedArticle in project summerb by skarpushin.
the class ArticleController method get.
@RequestMapping(method = RequestMethod.GET, value = "/articles/{articleKey}")
public String get(Model model, @PathVariable("articleKey") String articleKey, HttpServletResponse respons, Locale locale) {
try {
RenderedArticle article = articleRenderer.renderArticle(articleKey, locale);
model.addAttribute(ATTR_ARTICLE, article);
} catch (Throwable t) {
log.debug("Failed to get article", t);
String msg = exceptionTranslator.buildUserMessage(t, CurrentRequestUtils.getLocale());
addPageMessage(model.asMap(), new PageMessage(msg, MessageSeverity.Danger));
}
return viewNameArticle;
}
use of org.summerb.microservices.articles.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());
}
use of org.summerb.microservices.articles.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());
}
Aggregations