Search in sources :

Example 11 with TemplateEngine

use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.

the class RockerTemplateEngineTest method testTemplateHandlerIncludes.

@Test
public void testTemplateHandlerIncludes(TestContext should) {
    TemplateEngine engine = RockerTemplateEngine.create();
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/TestRockerTemplate3"));
    engine.render(context, "somedir/Base", should.asyncAssertSuccess(render -> {
        should.assertEquals("Vert.x rules\n", normalizeCRLF(render.toString()));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) RunWith(org.junit.runner.RunWith) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) RockerTemplateEngine(io.vertx.ext.web.templ.rocker.RockerTemplateEngine) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) RockerTemplateEngine(io.vertx.ext.web.templ.rocker.RockerTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 12 with TemplateEngine

use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.

the class RockerTemplateEngineTest method testTemplateHandler.

@Test
public void testTemplateHandler(TestContext should) {
    TemplateEngine engine = RockerTemplateEngine.create();
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/TestRockerTemplate2.rocker.html"));
    engine.render(context, "somedir/TestRockerTemplate2.rocker.html", should.asyncAssertSuccess(render -> {
        should.assertEquals("Hello badger and fox\nRequest path is /TestRockerTemplate2.rocker.html\n", normalizeCRLF(render.toString()));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) RunWith(org.junit.runner.RunWith) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) RockerTemplateEngine(io.vertx.ext.web.templ.rocker.RockerTemplateEngine) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) RockerTemplateEngine(io.vertx.ext.web.templ.rocker.RockerTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 13 with TemplateEngine

use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.

the class RythmTemplateTest method testWithLocale.

@Test
public void testWithLocale(TestContext should) {
    TemplateEngine engine = RythmTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("lang", "en-gb");
    engine.render(context, "somedir/test-rythm-template2.html", should.asyncAssertSuccess(render -> {
        final String expected = "<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "<head>\n" + "<meta charset=\"UTF-8\">\n" + "<title>Title</title>\n" + "</head>\n" + "<body>\n" + "<p>badger</p>\n" + "<p>fox</p>\n" + "</body>\n" + "</html>\n";
        should.assertEquals(expected, normalizeCRLF(render.toString()));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) PrintWriter(java.io.PrintWriter) BeforeClass(org.junit.BeforeClass) FileSystemOptions(io.vertx.core.file.FileSystemOptions) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) File(java.io.File) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) RythmTemplateEngine(io.vertx.ext.web.templ.rythm.RythmTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) RythmTemplateEngine(io.vertx.ext.web.templ.rythm.RythmTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 14 with TemplateEngine

use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.

the class RythmTemplateTest method testTemplateHandlerOnFileSystem.

@Test
public void testTemplateHandlerOnFileSystem(TestContext should) {
    TemplateEngine engine = RythmTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    engine.render(context, "src/test/filesystemtemplates/test-rythm-template.html", should.asyncAssertSuccess(render -> {
        final String expected = "<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "<head>\n" + "<meta charset=\"UTF-8\">\n" + "<title>FS</title>\n" + "</head>\n" + "<body>\n" + "<p>badger</p>\n" + "<p>fox</p>\n" + "</body>\n" + "</html>\n";
        should.assertEquals(expected, normalizeCRLF(render.toString()));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) PrintWriter(java.io.PrintWriter) BeforeClass(org.junit.BeforeClass) FileSystemOptions(io.vertx.core.file.FileSystemOptions) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) File(java.io.File) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) RythmTemplateEngine(io.vertx.ext.web.templ.rythm.RythmTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) RythmTemplateEngine(io.vertx.ext.web.templ.rythm.RythmTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 15 with TemplateEngine

use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.

the class ThymeleafTemplateTest method testWithLocale.

@Test
public void testWithLocale(TestContext should) {
    TemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("lang", "en-gb").put("context", new JsonObject().put("path", "/test-thymeleaf-template2.html"));
    engine.render(context, "somedir/test-thymeleaf-template2.html", should.asyncAssertSuccess(render -> {
        final String expected = "<!doctype html>\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "<head>\n" + "  <meta charset=\"utf-8\">\n" + "</head>\n" + "<body>\n" + "<p>badger</p>\n" + "<p>fox</p>\n" + "<p>/test-thymeleaf-template2.html</p>\n" + "</body>\n" + "</html>\n";
        should.assertEquals(expected, normalizeCRLF(render.toString()));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) PrintWriter(java.io.PrintWriter) ThymeleafTemplateEngine(io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine) BeforeClass(org.junit.BeforeClass) FileSystemOptions(io.vertx.core.file.FileSystemOptions) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) IOException(java.io.IOException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) File(java.io.File) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) JsonObject(io.vertx.core.json.JsonObject) ThymeleafTemplateEngine(io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

TemplateEngine (io.vertx.ext.web.common.template.TemplateEngine)75 Test (org.junit.Test)74 JsonObject (io.vertx.core.json.JsonObject)70 TestContext (io.vertx.ext.unit.TestContext)57 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)57 RunWith (org.junit.runner.RunWith)57 File (java.io.File)53 IOException (java.io.IOException)53 PrintWriter (java.io.PrintWriter)53 Vertx (io.vertx.core.Vertx)52 VertxOptions (io.vertx.core.VertxOptions)52 FileSystemOptions (io.vertx.core.file.FileSystemOptions)52 BeforeClass (org.junit.BeforeClass)52 JsonArray (io.vertx.core.json.JsonArray)16 PebbleTemplateEngine (io.vertx.ext.web.templ.pebble.PebbleTemplateEngine)13 PebbleEngine (com.mitchellbosecke.pebble.PebbleEngine)11 TestExtension (io.vertx.ext.web.templ.extension.TestExtension)11 PebbleVertxLoader (io.vertx.ext.web.templ.pebble.impl.PebbleVertxLoader)11 ArrayList (java.util.ArrayList)11 Assert.assertNotNull (org.junit.Assert.assertNotNull)10