Search in sources :

Example 26 with Context

use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.

the class TemplateEngineTest method testDefaultTemplateResolver05.

@Test
public void testDefaultTemplateResolver05() {
    final TemplateEngine templateEngine = new TemplateEngine();
    final Context context = new Context();
    context.setLocale(Locale.ENGLISH);
    context.setVariable("one", "this value");
    final StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
    stringTemplateResolver.setResolvablePatterns(Collections.singleton("<div*"));
    templateEngine.addTemplateResolver(stringTemplateResolver);
    final DefaultTemplateResolver defaultTemplateResolver = new DefaultTemplateResolver();
    defaultTemplateResolver.setTemplate("<p>inserted!</p>");
    templateEngine.addTemplateResolver(defaultTemplateResolver);
    templateEngine.initialize();
    Assert.assertEquals("<div>some text <p><p>inserted!</p></p> other text</div>", templateEngine.process("<div>some text <p th:insert=\"nonexisting\">...</p> other text</div>", context));
}
Also used : Context(org.thymeleaf.context.Context) SpringTemplateEngine(org.thymeleaf.spring5.SpringTemplateEngine) StringTemplateResolver(org.thymeleaf.templateresolver.StringTemplateResolver) DefaultTemplateResolver(org.thymeleaf.templateresolver.DefaultTemplateResolver) Test(org.junit.Test)

Example 27 with Context

use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.

the class Spring5Reactive05Test method testEmpty.

@Test
public void testEmpty() throws Exception {
    final Context ctx1 = new Context();
    testTemplate("reactive05", null, ctx1, "reactive05-01");
}
Also used : Context(org.thymeleaf.context.Context) Test(org.junit.Test)

Example 28 with Context

use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.

the class Spring5Reactive05Test method testDataDriven01.

@Test
public void testDataDriven01() throws Exception {
    final List<Album> albums = AlbumRepository.findAllAlbums();
    final Context ctx1 = new Context();
    ctx1.setVariable("albums", new ReactiveDataDriverContextVariable(Flux.fromIterable(albums), 1));
    testTemplate("reactive05", null, ctx1, "reactive05-02");
}
Also used : Context(org.thymeleaf.context.Context) ReactiveDataDriverContextVariable(org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable) Album(org.thymeleaf.spring5.reactive.data.Album) Test(org.junit.Test)

Example 29 with Context

use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.

the class Spring5Reactive06Test method testDataDriven03.

@Test
public void testDataDriven03() throws Exception {
    final List<Album> albums = AlbumRepository.findAllAlbums();
    final Context ctx1 = new Context();
    ctx1.setVariable("albums", new ReactiveDataDriverContextVariable(Flux.fromIterable(albums), 100));
    testTemplate("reactive06", null, ctx1, "reactive06-02");
}
Also used : Context(org.thymeleaf.context.Context) ReactiveDataDriverContextVariable(org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable) Album(org.thymeleaf.spring5.reactive.data.Album) Test(org.junit.Test)

Example 30 with Context

use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.

the class Spring5Reactive08Test method testList.

@Test
public void testList() throws Exception {
    final List<Album> albums = AlbumRepository.findAllAlbums();
    final Context ctx1 = new Context();
    ctx1.setVariable("albums", albums);
    testTemplate("reactive08", Collections.singleton("#main"), ctx1, "reactive08-02");
}
Also used : Context(org.thymeleaf.context.Context) Album(org.thymeleaf.spring5.reactive.data.Album) Test(org.junit.Test)

Aggregations

Context (org.thymeleaf.context.Context)243 Test (org.junit.Test)179 Album (org.thymeleaf.spring5.reactive.data.Album)141 ReactiveDataDriverContextVariable (org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable)130 TemplateEngine (org.thymeleaf.TemplateEngine)30 Locale (java.util.Locale)24 Async (org.springframework.scheduling.annotation.Async)21 ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)13 SpringTemplateEngine (org.thymeleaf.spring5.SpringTemplateEngine)11 MockServletContext (org.springframework.mock.web.MockServletContext)10 RequestContext (org.springframework.web.servlet.support.RequestContext)10 Test (org.junit.jupiter.api.Test)9 WebContext (org.thymeleaf.context.WebContext)9 MessagingException (javax.mail.MessagingException)8 StringTemplateResolver (org.thymeleaf.templateresolver.StringTemplateResolver)7 DefaultTemplateResolver (org.thymeleaf.templateresolver.DefaultTemplateResolver)6 ServletContext (jakarta.servlet.ServletContext)5 ArrayList (java.util.ArrayList)5 MimeMessage (javax.mail.internet.MimeMessage)5 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)5