use of com.tvd12.ezyhttp.server.core.view.View in project ezyhttp by youngmonkeys.
the class ViewTest method putKeyValuesToVariableTest.
@Test
public void putKeyValuesToVariableTest() {
// given
Map<String, Object> map = EzyMapBuilder.mapBuilder().put("a", "1").put("b", 2).toMap();
View sut = View.builder().template("abc").build();
sut.putKeyValuesToVariable("hello", map);
// when
// then
Asserts.assertEquals(sut.getVariable("hello"), map);
}
use of com.tvd12.ezyhttp.server.core.view.View in project ezyhttp by youngmonkeys.
the class ViewTest method ofTest.
@Test
public void ofTest() {
// given
View sut = View.of("home.html");
sut.setLocale(Locale.CANADA);
// when
// then
Asserts.assertEquals("home.html", sut.getTemplate());
Asserts.assertEquals(sut.getLocale(), Locale.CANADA);
}
use of com.tvd12.ezyhttp.server.core.view.View in project ezyhttp by youngmonkeys.
the class ViewTest method putKeyValuesToVariableByBuilderTest.
@Test
public void putKeyValuesToVariableByBuilderTest() {
// given
View sut = View.builder().template("abc").putKeyValueToVariable("hello", "a", "1").putKeyValueToVariable("hello", "b", 2).build();
// when
// then
Map<String, Object> map = EzyMapBuilder.mapBuilder().put("a", "1").put("b", 2).toMap();
Asserts.assertEquals(sut.getVariable("hello"), map);
}
use of com.tvd12.ezyhttp.server.core.view.View in project ezyhttp by youngmonkeys.
the class ThymeleafViewContext method render.
@Override
public void render(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, View view) throws IOException {
for (ViewDecorator viewDecorator : viewDecorators) {
viewDecorator.decorate(request, view);
}
WebContext ctx = new WebContext(request, response, servletContext, view.getLocale());
ctx.setVariables(view.getVariables());
templateEngine.process(view.getTemplate(), ctx, response.getWriter());
}
use of com.tvd12.ezyhttp.server.core.view.View 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);
}
Aggregations