use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class PebbleTemplateTest method testTemplateHandlerOnClasspath.
@Test
public void testTemplateHandlerOnClasspath(TestContext should) {
TemplateEngine engine = PebbleTemplateEngine.create(vertx);
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.peb", should.asyncAssertSuccess(render -> {
should.assertEquals("Hello badger and foxRequest path is /test-pebble-template2.peb", normalizeCRLF(render.toString()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class PebbleTemplateTest method testRenderJsonArrayAndJavaObjects.
@Test
public void testRenderJsonArrayAndJavaObjects(TestContext should) {
TemplateEngine engine = PebbleTemplateEngine.create(vertx);
JsonArray array = new JsonArray().add(new JsonObject().put("bar", "badger"));
ArrayList<String> javaList = new ArrayList<>();
HashMap<String, String> hashmap = new HashMap<>();
javaList.add("bar");
hashmap.put("foo", "fox");
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("array", array).put("arraylist", javaList).put("hashmap", hashmap).put("context", new JsonObject().put("path", "/test-pebble-template6.peb"));
final String templateExpected = "Hello badger and foxRequest path is /test-pebble-template6.peb" + "Java HashMap foo foxJsonArray size 1badgerArrayList size 1bar";
engine.render(context, "src/test/filesystemtemplates/test-pebble-template6.peb", should.asyncAssertSuccess(render -> {
should.assertEquals(templateExpected, normalizeCRLF(render.toString()));
}));
}
use of io.vertx.ext.web.common.template.TemplateEngine in project vertx-web by vert-x3.
the class ThymeleafTemplateTest method testCachingEnabled.
@Test
public void testCachingEnabled(TestContext should) throws IOException {
System.setProperty("vertxweb.environment", "production");
TemplateEngine engine = ThymeleafTemplateEngine.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 ThymeleafTemplateTest method testTemplateHandlerOnFileSystem.
@Test
public void testTemplateHandlerOnFileSystem(TestContext should) {
TemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
final JsonObject context = new JsonObject().put("foo", "badger").put("bar", "fox").put("context", new JsonObject().put("path", "/test-thymeleaf-template2.html"));
engine.render(context, "src/test/filesystemtemplates/test-thymeleaf-template3.html", should.asyncAssertSuccess(render -> {
final String expected = "<!doctype html>\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "<head>\n" + " <meta charset=\"utf-8\">\n" + "</head>\n" + "<body>\n" + "<p>badger</p>\n" + "<p>fox</p>\n" + "<p>/test-thymeleaf-template2.html</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 ThymeleafTemplateTest method testNoSuchTemplate.
@Test
public void testNoSuchTemplate(TestContext should) {
TemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
final JsonObject context = new JsonObject();
engine.render(context, "nosuchtemplate.html", should.asyncAssertFailure());
}
Aggregations