use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class MVELTemplateTest method testNoSuchTemplate.
@Test
public void testNoSuchTemplate(TestContext should) {
TemplateEngine engine = MVELTemplateEngine.create(vertx);
engine.render(new JsonObject(), "nosuchtemplate.templ", should.asyncAssertFailure());
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class MVELTemplateTest method testCachingEnabled.
@Test
public void testCachingEnabled(TestContext should) throws IOException {
System.setProperty("vertxweb.environment", "production");
TemplateEngine engine = MVELTemplateEngine.create(vertx);
PrintWriter out;
File temp = File.createTempFile("template", ".templ", new File("target/classes"));
temp.deleteOnExit();
out = new PrintWriter(temp);
out.print("before");
out.flush();
out.close();
engine.render(new JsonObject(), temp.getParent() + File.separatorChar + temp.getName(), should.asyncAssertSuccess(render -> {
should.assertEquals("before", render.toString());
try {
PrintWriter out2 = new PrintWriter(temp);
out2.print("after");
out2.flush();
out2.close();
} catch (IOException e) {
should.fail(e);
}
engine.render(new JsonObject(), temp.getParent() + File.separatorChar + temp.getName(), should.asyncAssertSuccess(render2 -> {
should.assertEquals("before", render2.toString());
}));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class MVELTemplateTest method testTemplateHandlerOnClasspath.
@Test
public void testTemplateHandlerOnClasspath(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.templ".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()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class PebbleTemplateTest method testCachingEnabled.
@Test
public void testCachingEnabled(TestContext should) throws Exception {
System.setProperty("vertxweb.environment", "production");
TemplateEngine engine = PebbleTemplateEngine.create(vertx);
File temp = File.createTempFile("template", ".peb", 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 PebbleTemplateTest method noLocaleShouldUseDefaultLocale.
@Test
public void noLocaleShouldUseDefaultLocale(TestContext should) {
Locale.setDefault(Locale.US);
final TemplateEngine engine = PebbleTemplateEngine.create(vertx);
engine.render(new JsonObject(), "src/test/filesystemtemplates/test-pebble-template-i18n.peb", should.asyncAssertSuccess(render2 -> {
should.assertEquals("Hi", normalizeCRLF(render2.toString()));
}));
}
Aggregations