use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class RythmTemplateTest method testCachingEnabled.
@Test
public void testCachingEnabled(TestContext should) throws IOException {
System.setProperty("vertxweb.environment", "production");
TemplateEngine engine = RythmTemplateEngine.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", 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("before", normalizeCRLF(render2.toString()));
}));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class RythmTemplateTest method testTemplateHandlerOnClasspath.
@Test
public void testTemplateHandlerOnClasspath(TestContext should) {
TemplateEngine engine = RythmTemplateEngine.create(vertx);
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
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()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class RythmTemplateTest method testNoSuchTemplate.
@Test
public void testNoSuchTemplate(TestContext should) {
TemplateEngine engine = RythmTemplateEngine.create(vertx);
final JsonObject context = new JsonObject();
engine.render(context, "nosuchtemplate.html", should.asyncAssertFailure());
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class HandlebarsTemplateTest method testTemplatePerf.
@Test
public void testTemplatePerf(TestContext should) {
TemplateEngine engine = HandlebarsTemplateEngine.create(vertx);
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
final AtomicInteger cnt = new AtomicInteger(0);
final long t0 = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
engine.render(context, "somedir/test-handlebars-template2.hbs", should.asyncAssertSuccess(render -> {
should.assertEquals("Hello badger and fox", normalizeCRLF(render.toString()));
if (cnt.incrementAndGet() == 1000000) {
final long t1 = System.currentTimeMillis();
System.out.println(t1 - t0);
}
}));
}
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class HTTLTemplateEngineTest method testTemplateHandlerOnClasspath.
@Test
public void testTemplateHandlerOnClasspath(TestContext should) {
TemplateEngine engine = HTTLTemplateEngine.create(vertx);
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox");
engine.render(context, "somedir/test-httl-template1.httl", should.asyncAssertSuccess(render -> {
should.assertEquals("<!-- -->\nHello badger and fox\n", normalizeCRLF(render.toString()));
}));
}
Aggregations