Search in sources :

Example 31 with TemplateEngine

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

the class JadeTemplateTest method testTemplateHandlerOnFileSystem.

@Test
public void testTemplateHandlerOnFileSystem(TestContext should) {
    TemplateEngine engine = JadeTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    context.put("context", new JsonObject().put("path", "/test-jade-template3.jade"));
    engine.render(context, "src/test/filesystemtemplates/test-jade-template3.jade", should.asyncAssertSuccess(render -> {
        should.assertEquals("<!DOCTYPE html><html><head><title>badger/test-jade-template3.jade</title></head><body></body></html>", 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) Assert.assertNotNull(org.junit.Assert.assertNotNull) 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) JadeTemplateEngine(io.vertx.ext.web.templ.jade.JadeTemplateEngine) File(java.io.File) JsonObject(io.vertx.core.json.JsonObject) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JadeTemplateEngine(io.vertx.ext.web.templ.jade.JadeTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 32 with TemplateEngine

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

the class JadeTemplateTest method testTemplateHandlerOnClasspath.

@Test
public void testTemplateHandlerOnClasspath(TestContext should) {
    TemplateEngine engine = JadeTemplateEngine.create(vertx);
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    context.put("context", new JsonObject().put("path", "/test-jade-template2.jade"));
    engine.render(context, "somedir/test-jade-template2.jade", should.asyncAssertSuccess(render -> {
        should.assertEquals("<!DOCTYPE html><html><head><title>badger/test-jade-template2.jade</title></head><body></body></html>", 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) Assert.assertNotNull(org.junit.Assert.assertNotNull) 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) JadeTemplateEngine(io.vertx.ext.web.templ.jade.JadeTemplateEngine) File(java.io.File) JsonObject(io.vertx.core.json.JsonObject) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JadeTemplateEngine(io.vertx.ext.web.templ.jade.JadeTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 33 with TemplateEngine

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

the class JadeTemplateTest method testTemplateHandlerChangeExtension.

@Test
public void testTemplateHandlerChangeExtension(TestContext should) {
    TemplateEngine engine = JadeTemplateEngine.create(vertx, "made");
    final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
    context.put("context", new JsonObject().put("path", "/test-jade-template2.jade"));
    engine.render(context, "somedir/test-jade-template2", should.asyncAssertSuccess(render -> {
        should.assertEquals("<!DOCTYPE html><html><head><title>aardvark/test-jade-template2.jade</title></head><body></body></html>", 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) Assert.assertNotNull(org.junit.Assert.assertNotNull) 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) JadeTemplateEngine(io.vertx.ext.web.templ.jade.JadeTemplateEngine) File(java.io.File) JsonObject(io.vertx.core.json.JsonObject) TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) JadeTemplateEngine(io.vertx.ext.web.templ.jade.JadeTemplateEngine) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 34 with TemplateEngine

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

the class TemplateHandlerImplTest method testSimpleTemplate.

@Test
public void testSimpleTemplate() {
    TemplateEngine templateEngine = mock(TemplateEngine.class);
    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.normalizedPath()).thenReturn("/about");
    Route currentRoute = mock(Route.class);
    when(currentRoute.getPath()).thenReturn("/");
    when(routingContext.currentRoute()).thenReturn(currentRoute);
    TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
    templateHandler.handle(routingContext);
    verify(templateEngine).render(any(JsonObject.class), eq("templates/about"), any());
}
Also used : TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) TemplateHandlerImpl(io.vertx.ext.web.handler.impl.TemplateHandlerImpl) RoutingContext(io.vertx.ext.web.RoutingContext) JsonObject(io.vertx.core.json.JsonObject) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler) Route(io.vertx.ext.web.Route) Test(org.junit.Test)

Example 35 with TemplateEngine

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

the class TemplateHandlerImplTest method testTurnOffIndex.

@Test
public void testTurnOffIndex() {
    TemplateEngine templateEngine = mock(TemplateEngine.class);
    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.normalizedPath()).thenReturn("/");
    Route currentRoute = mock(Route.class);
    when(currentRoute.getPath()).thenReturn("/");
    when(routingContext.currentRoute()).thenReturn(currentRoute);
    TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
    templateHandler.setIndexTemplate(null);
    templateHandler.handle(routingContext);
    verify(templateEngine).render(any(JsonObject.class), eq("templates/"), any());
}
Also used : TemplateEngine(io.vertx.ext.web.common.template.TemplateEngine) TemplateHandlerImpl(io.vertx.ext.web.handler.impl.TemplateHandlerImpl) RoutingContext(io.vertx.ext.web.RoutingContext) JsonObject(io.vertx.core.json.JsonObject) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler) Route(io.vertx.ext.web.Route) 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