use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class HTTLTemplateEngineTest method testCachingEnabled.
@Test
public void testCachingEnabled(TestContext should) throws IOException {
System.setProperty("vertxweb.environment", "production");
TemplateEngine engine = HTTLTemplateEngine.create(vertx);
File temp = File.createTempFile("template", ".httl", new File("target/classes"));
temp.deleteOnExit();
try (PrintWriter out = new PrintWriter(temp)) {
out.print("before");
out.flush();
}
engine.render(new JsonObject(), temp.getName(), should.asyncAssertSuccess(render -> {
should.assertEquals("before", 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.getName(), should.asyncAssertSuccess(render2 -> {
should.assertEquals("before", normalizeCRLF(render2.toString()));
}));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class FreeMarkerTemplateTest method testLang.
@Test
public void testLang(TestContext should) {
TemplateEngine engine = FreeMarkerTemplateEngine.create(vertx);
engine.render(new JsonObject(), "somedir/lang.ftl", should.asyncAssertSuccess(render -> {
should.assertEquals("Hello world\n", normalizeCRLF(render.toString()));
}));
engine.render(new JsonObject().put("lang", "el"), "somedir/lang.ftl", should.asyncAssertSuccess(render -> {
should.assertEquals("Γειά σου Κόσμε\n", normalizeCRLF(render.toString()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class FreeMarkerTemplateTest method testNoSuchTemplate.
@Test
public void testNoSuchTemplate(TestContext should) {
TemplateEngine engine = FreeMarkerTemplateEngine.create(vertx);
engine.render(new JsonObject(), "not-found", should.asyncAssertFailure());
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class FreeMarkerTemplateNoCacheTest method testCachingDisabled.
@Test
public void testCachingDisabled(TestContext should) throws Exception {
System.setProperty("vertxweb.environment", "development");
TemplateEngine engine = FreeMarkerTemplateEngine.create(vertx);
File temp = File.createTempFile("template", ".ftl", new File("target/classes"));
temp.deleteOnExit();
try (PrintWriter out = new PrintWriter(temp)) {
out.print("before");
out.flush();
}
engine.render(new JsonObject(), temp.getName(), should.asyncAssertSuccess(render -> {
should.assertEquals("before", FreeMarkerTemplateTest.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.getName(), should.asyncAssertSuccess(render2 -> {
should.assertEquals("after", FreeMarkerTemplateTest.normalizeCRLF(render2.toString()));
}));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class HandlebarsTemplateTest method testTemplateJsonArrayResolver.
@Test
public void testTemplateJsonArrayResolver(TestContext should) {
TemplateEngine engine = HandlebarsTemplateEngine.create(vertx);
JsonArray jsonArray = new JsonArray();
jsonArray.add("badger").add("fox").add(new JsonObject().put("name", "joe"));
String expected = "Iterator: badger,fox,{"name":"joe"}, Element by index:fox - joe - Out of bounds: - Size:3";
engine.render(new JsonObject().put("foo", jsonArray), "src/test/filesystemtemplates/test-handlebars-template5.hbs", should.asyncAssertSuccess(render -> {
should.assertEquals(expected, normalizeCRLF(render.toString()));
}));
}
Aggregations