Search in sources :

Example 1 with ThymeleafViewContextBuilder

use of com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder 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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TemplateResolver(com.tvd12.ezyhttp.server.core.view.TemplateResolver) ViewContext(com.tvd12.ezyhttp.server.core.view.ViewContext) ThymeleafViewContextBuilder(com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) View(com.tvd12.ezyhttp.server.core.view.View) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 2 with ThymeleafViewContextBuilder

use of com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder 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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TemplateResolver(com.tvd12.ezyhttp.server.core.view.TemplateResolver) ViewContext(com.tvd12.ezyhttp.server.core.view.ViewContext) ThymeleafViewContextBuilder(com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ViewDecorator(com.tvd12.ezyhttp.server.core.view.ViewDecorator) View(com.tvd12.ezyhttp.server.core.view.View) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 3 with ThymeleafViewContextBuilder

use of com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder 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);
}
Also used : TemplateResolver(com.tvd12.ezyhttp.server.core.view.TemplateResolver) ThymeleafViewContextBuilder(com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder) ViewContext(com.tvd12.ezyhttp.server.core.view.ViewContext) ViewContextBuilder(com.tvd12.ezyhttp.server.core.view.ViewContextBuilder) ThymeleafViewContextBuilder(com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder) Test(org.testng.annotations.Test)

Example 4 with ThymeleafViewContextBuilder

use of com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder in project ezyhttp by youngmonkeys.

the class ThymeleafViewContextTest method renderWithDialectButNotViewDialect.

@Test
public void renderWithDialectButNotViewDialect() throws Exception {
    // given
    TemplateResolver resolver = TemplateResolver.builder().build();
    ViewDialect viewDialect = mock(ViewDialect.class);
    ViewContext viewContext = new ThymeleafViewContextBuilder().templateResolver(resolver).viewDialects(Collections.singletonList(viewDialect)).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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TemplateResolver(com.tvd12.ezyhttp.server.core.view.TemplateResolver) ViewContext(com.tvd12.ezyhttp.server.core.view.ViewContext) ThymeleafViewContextBuilder(com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ViewDialect(com.tvd12.ezyhttp.server.core.view.ViewDialect) View(com.tvd12.ezyhttp.server.core.view.View) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 5 with ThymeleafViewContextBuilder

use of com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder in project ezyhttp by youngmonkeys.

the class ThymeleafViewContextTest method renderWithViewDialect.

@Test
public void renderWithViewDialect() throws Exception {
    // given
    TemplateResolver resolver = TemplateResolver.builder().build();
    ViewContext viewContext = new ThymeleafViewContextBuilder().templateResolver(resolver).viewDialects(Collections.singletonList(new VewHelloDialect())).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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TemplateResolver(com.tvd12.ezyhttp.server.core.view.TemplateResolver) ViewContext(com.tvd12.ezyhttp.server.core.view.ViewContext) ThymeleafViewContextBuilder(com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) View(com.tvd12.ezyhttp.server.core.view.View) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Aggregations

TemplateResolver (com.tvd12.ezyhttp.server.core.view.TemplateResolver)5 ViewContext (com.tvd12.ezyhttp.server.core.view.ViewContext)5 ThymeleafViewContextBuilder (com.tvd12.ezyhttp.server.thymeleaf.ThymeleafViewContextBuilder)5 Test (org.testng.annotations.Test)5 View (com.tvd12.ezyhttp.server.core.view.View)4 PrintWriter (java.io.PrintWriter)4 ServletContext (javax.servlet.ServletContext)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ViewContextBuilder (com.tvd12.ezyhttp.server.core.view.ViewContextBuilder)1 ViewDecorator (com.tvd12.ezyhttp.server.core.view.ViewDecorator)1 ViewDialect (com.tvd12.ezyhttp.server.core.view.ViewDialect)1