Search in sources :

Example 6 with TemplateEngine

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

the class PebbleTemplateTest method testNoSuchTemplate.

@Test
public void testNoSuchTemplate(TestContext should) {
    TemplateEngine engine = PebbleTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject();
    engine.render(context, "non-existing", should.asyncAssertFailure());
}
Also used : PebbleTemplateEngine(io.vertx.ext.web.templ.pebble.PebbleTemplateEngine) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 7 with TemplateEngine

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

the class ThymeleafTemplateNoCacheTest method testCachingDisabled.

@Test
public void testCachingDisabled(TestContext should) throws IOException {
    System.setProperty("vertxweb.environment", "development");
    TemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
    File temp = File.createTempFile("template", ".html", new File("target/classes"));
    temp.deleteOnExit();
    try (PrintWriter out = new PrintWriter(temp)) {
        out.print("before");
        out.flush();
    }
    engine.render(new JsonObject(), temp.getParent() + "/" + temp.getName(), should.asyncAssertSuccess(render -> {
        should.assertEquals("before", ThymeleafTemplateTest.normalizeCRLF(render.toString()));
        try (PrintWriter out2 = new PrintWriter(temp)) {
            out2.print("after");
            out2.flush();
        } catch (IOException e) {
            should.fail(e);
        }
        engine.render(new JsonObject(), temp.getParent() + "/" + temp.getName(), should.asyncAssertSuccess(render2 -> {
            should.assertEquals("after", ThymeleafTemplateTest.normalizeCRLF(render2.toString()));
        }));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) ThymeleafTemplateEngine(io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine) 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) 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) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 8 with TemplateEngine

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

the class RockerTemplateEngineTest method testNoSuchTemplate.

@Test
public void testNoSuchTemplate(TestContext should) {
    TemplateEngine engine = RockerTemplateEngine.create();
    final JsonObject context = new JsonObject();
    engine.render(context, "nosuchtemplate.rocker.html", should.asyncAssertFailure());
}
Also used : 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 9 with TemplateEngine

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

the class RockerTemplateEngineTest method testTemplateHandlerNoExtension.

@Test
public void testTemplateHandlerNoExtension(TestContext should) {
    TemplateEngine engine = RockerTemplateEngine.create();
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/TestRockerTemplate2"));
    engine.render(context, "somedir/TestRockerTemplate2", should.asyncAssertSuccess(render -> {
        should.assertEquals("Hello badger and fox\nRequest path is /TestRockerTemplate2\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 10 with TemplateEngine

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

the class RockerTemplateEngineTest method testTemplateHandlerChangeExtension.

@Test
public void testTemplateHandlerChangeExtension(TestContext should) {
    TemplateEngine engine = RockerTemplateEngine.create("rocker.raw");
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/TestRockerTemplate3"));
    engine.render(context, "somedir/TestRockerTemplate3", should.asyncAssertSuccess(render -> {
        should.assertEquals("\nCheerio badger and fox\nRequest path is /TestRockerTemplate3\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)

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