Search in sources :

Example 1 with TemplateEngine

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

the class MVELTemplateTest method testTemplateHandlerChangeExtension.

@Test
public void testTemplateHandlerChangeExtension(TestContext should) {
    TemplateEngine engine = MVELTemplateEngine.create(vertx, "bempl");
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    context.put("context", new JsonObject().put("path", "/test-mvel-template2"));
    String tmplPath = "somedir/test-mvel-template2".replace('/', File.separatorChar);
    engine.render(context, tmplPath, should.asyncAssertSuccess(render -> {
        should.assertEquals("Cheerio badger and fox\nRequest path is /test-mvel-template2\n", 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) MVELTemplateEngine(io.vertx.ext.web.templ.mvel.MVELTemplateEngine) 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) Utils(io.vertx.core.impl.Utils) File(java.io.File) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) MVELTemplateEngine(io.vertx.ext.web.templ.mvel.MVELTemplateEngine) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 2 with TemplateEngine

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

the class MVELTemplateTest method testTemplateHandlerNoExtension.

@Test
public void testTemplateHandlerNoExtension(TestContext should) {
    TemplateEngine engine = MVELTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    context.put("context", new JsonObject().put("path", "/test-mvel-template2.templ"));
    String tmplPath = "somedir/test-mvel-template2".replace('/', File.separatorChar);
    engine.render(context, tmplPath, should.asyncAssertSuccess(render -> {
        should.assertEquals("Hello badger and fox\nRequest path is /test-mvel-template2.templ\n", 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) MVELTemplateEngine(io.vertx.ext.web.templ.mvel.MVELTemplateEngine) 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) Utils(io.vertx.core.impl.Utils) File(java.io.File) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) MVELTemplateEngine(io.vertx.ext.web.templ.mvel.MVELTemplateEngine) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 3 with TemplateEngine

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

the class MVELTemplateTest method testTemplateHandlerWithInclude.

@Test
public void testTemplateHandlerWithInclude(TestContext should) {
    // Cannot pass on windows due to
    // File file = new File(runtime.getRelPath().peek() + "/" + fileName);
    // in org.mvel2.templates.res.CompiledIncludeNode
    Assume.assumeFalse(Utils.isWindows());
    TemplateEngine engine = MVELTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    context.put("context", new JsonObject().put("path", "/test-mvel-template4.templ"));
    String tmplPath = "src/test/filesystemtemplates/test-mvel-template4.templ".replace('/', File.separatorChar);
    engine.render(context, tmplPath, should.asyncAssertSuccess(render -> {
        should.assertEquals("Hello badger and fox\n\nRequest path is /test-mvel-template4.templ\n", 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) MVELTemplateEngine(io.vertx.ext.web.templ.mvel.MVELTemplateEngine) 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) Utils(io.vertx.core.impl.Utils) File(java.io.File) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) MVELTemplateEngine(io.vertx.ext.web.templ.mvel.MVELTemplateEngine) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 4 with TemplateEngine

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

the class PebbleTemplateTest method testTemplateHandlerChangeExtension.

@Test
public void testTemplateHandlerChangeExtension(TestContext should) {
    TemplateEngine engine = PebbleTemplateEngine.create(vertx, "beb");
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/test-pebble-template2.peb"));
    engine.render(context, "somedir/test-pebble-template2", should.asyncAssertSuccess(render -> {
        should.assertEquals("Cheerio badger and foxRequest path is /test-pebble-template2.peb", 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) PebbleTemplateEngine(io.vertx.ext.web.templ.pebble.PebbleTemplateEngine) 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) HashMap(java.util.HashMap) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) File(java.io.File) ArrayList(java.util.ArrayList) TestExtension(io.vertx.ext.web.templ.extension.TestExtension) JsonArray(io.vertx.core.json.JsonArray) PebbleVertxLoader(io.vertx.ext.web.templ.pebble.impl.PebbleVertxLoader) PebbleEngine(com.mitchellbosecke.pebble.PebbleEngine) Locale(java.util.Locale) JsonObject(io.vertx.core.json.JsonObject) 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 5 with TemplateEngine

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

the class PebbleTemplateTest method testTemplateComplex.

@Test
public void testTemplateComplex(TestContext should) {
    TemplateEngine engine = PebbleTemplateEngine.create(vertx);
    String expected = "Hello.Hi fox.\nHi badger!\nFooter - badger";
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    engine.render(context, "src/test/filesystemtemplates/test-pebble-complex.peb", should.asyncAssertSuccess(render -> {
        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) PebbleTemplateEngine(io.vertx.ext.web.templ.pebble.PebbleTemplateEngine) 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) HashMap(java.util.HashMap) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) File(java.io.File) ArrayList(java.util.ArrayList) TestExtension(io.vertx.ext.web.templ.extension.TestExtension) JsonArray(io.vertx.core.json.JsonArray) PebbleVertxLoader(io.vertx.ext.web.templ.pebble.impl.PebbleVertxLoader) PebbleEngine(com.mitchellbosecke.pebble.PebbleEngine) Locale(java.util.Locale) JsonObject(io.vertx.core.json.JsonObject) 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)

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