use of com.tvd12.ezyhttp.server.core.view.TemplateResolver in project ezyhttp by youngmonkeys.
the class ApplicationContextBuilder method buildViewContext.
protected ViewContext buildViewContext(EzyBeanContext beanContext) {
ViewContext viewContext = beanContext.getSingleton(ViewContext.class);
if (viewContext == null) {
ViewContextBuilder viewContextBuilder = beanContext.getSingleton(ViewContextBuilder.class);
if (viewContextBuilder != null) {
TemplateResolver templateResolver = beanContext.getSingleton(TemplateResolver.class);
if (templateResolver == null) {
templateResolver = TemplateResolver.of(beanContext);
}
viewContext = viewContextBuilder.templateResolver(templateResolver).viewDialects(beanContext.getSingletonsOf(ViewDialect.class)).viewDecorators(beanContext.getSingletonsOf(ViewDecorator.class)).messageProviders(beanContext.getSingletonsOf(MessageProvider.class)).absentMessageResolver(beanContext.getSingleton(AbsentMessageResolver.class)).build();
}
}
if (viewContext != null) {
beanContext.getSingletonFactory().addSingleton(viewContext);
}
return viewContext;
}
use of com.tvd12.ezyhttp.server.core.view.TemplateResolver in project ezyhttp by youngmonkeys.
the class TemplateResolverTest method test.
@Test
public void test() {
// given
String prefix = RandomUtil.randomShortAlphabetString();
String suffix = RandomUtil.randomShortAlphabetString();
int cacheTTLMs = RandomUtil.randomInt();
boolean cacheable = RandomUtil.randomBoolean();
String templateMode = RandomUtil.randomShortAlphabetString();
String messagesLocation = RandomUtil.randomShortAlphabetString();
// when
TemplateResolver sut = TemplateResolver.builder().prefix(prefix).suffix(suffix).cacheTTLMs(cacheTTLMs).cacheable(cacheable).templateMode(templateMode).messagesLocation(messagesLocation).build();
// then
Asserts.assertEquals(prefix, sut.getPrefix());
Asserts.assertEquals(suffix, sut.getSuffix());
Asserts.assertEquals(cacheTTLMs, sut.getCacheTTLMs());
Asserts.assertEquals(cacheable, sut.isCacheable());
Asserts.assertEquals(templateMode, sut.getTemplateMode());
Asserts.assertEquals(messagesLocation, sut.getMessagesLocation());
}
use of com.tvd12.ezyhttp.server.core.view.TemplateResolver in project ezyhttp by youngmonkeys.
the class ThymeleafViewContextTest method test.
@Test
public void test() throws Exception {
// given
TemplateResolver resolver = TemplateResolver.builder().build();
ViewContext viewContext = new ThymeleafViewContextBuilder().templateResolver(resolver).build();
ServletContext servletContext = mock(ServletContext.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
PrintWriter writer = mock(PrintWriter.class);
when(response.getWriter()).thenReturn(writer);
View view = View.builder().template("index.html").build();
// when
viewContext.render(servletContext, request, response, view);
// then
Asserts.assertNotNull(viewContext);
}
use of com.tvd12.ezyhttp.server.core.view.TemplateResolver in project ezyhttp by youngmonkeys.
the class ThymeleafViewContextTest method renderWithViewDecorator.
@Test
public void renderWithViewDecorator() throws Exception {
// given
TemplateResolver resolver = TemplateResolver.builder().build();
ViewDecorator viewDecorator = mock(ViewDecorator.class);
ViewContext viewContext = new ThymeleafViewContextBuilder().templateResolver(resolver).viewDecorators(Collections.singletonList(viewDecorator)).build();
ServletContext servletContext = mock(ServletContext.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
PrintWriter writer = mock(PrintWriter.class);
when(response.getWriter()).thenReturn(writer);
View view = View.builder().template("index.html").build();
// when
viewContext.render(servletContext, request, response, view);
// then
Asserts.assertNotNull(viewContext);
verify(viewDecorator, times(1)).decorate(request, view);
}
use of com.tvd12.ezyhttp.server.core.view.TemplateResolver in project ezyhttp by youngmonkeys.
the class ThymeleafViewContextBuilderTest method test.
@Test
public void test() {
// given
TemplateResolver resolver = TemplateResolver.builder().build();
ViewContextBuilder sut = new ThymeleafViewContextBuilder().templateResolver(resolver);
// when
ViewContext viewContext = sut.build();
// then
Asserts.assertNotNull(viewContext);
}
Aggregations