private DefaultMustacheFactory initParallel() { DefaultMustacheFactory cf = createMustacheFactory(); cf.setExecutorService(Executors.newCachedThreadPool()); return cf; }
public void testObjectArray() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#values}}{{.}}{{/values}}{{^values}}Test2{{/values}}"), "testObjectArray"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { Integer[] values = new Integer[]{1, 2, 3}; }).close(); assertEquals("123", sw.toString()); }
public void testSuperField() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#values}}Test1{{/values}}{{^values}}Test2{{/values}}"), "testIterator"); StringWriter sw = new StringWriter(); m.execute(sw, new SuperClass() { }).close(); // Values ignored as if it didn't exist at all assertEquals("Test1", sw.toString()); }
public void testComment() throws IOException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile(new StringReader("{{#process}}{{!comment}}{{/process}}"), ""); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { TemplateFunction process = s -> s.replace("{", "["); }); assertEquals("[[!comment}}", sw.toString()); }
public void testInvalidDelimiters() { try { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{=toolong}}"), "testInvalidDelimiters"); fail("Not invalid"); } catch (MustacheException e) { // Success } }
public void testPrivate() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#values}}Test1{{/values}}{{^values}}Test2{{/values}}"), "testPrivate"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { private String values = "value"; private String values() { return "value"; } }).close(); // Values ignored as if it didn't exist at all assertEquals("Test2", sw.toString()); }
private StringWriter execute(String name, List<Object> objects) { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile(name); StringWriter sw = new StringWriter(); m.execute(sw, objects); return sw; }
public void testVariableInhertiance() throws IOException { DefaultMustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile("issue_201/chat.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object()).close(); assertEquals("<script src=\"test\"></script>", sw.toString()); }
public void testEmptyString() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#values}}Test1{{/values}}{{^values}}Test2{{/values}}"), "testEmptyString"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { String values = ""; }).close(); assertEquals("Test2", sw.toString()); }
public void testRelativePathFail() throws IOException { MustacheFactory mf = createMustacheFactory(); try { Mustache compile = mf.compile("relative/pathfail.html"); fail("Should have failed to compile"); } catch (MustacheException e) { // Success } }
public void testRootCheck() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = createMustacheFactory(); try { Mustache m = c.compile("../../../pom.xml"); fail("Should have failed to compile"); } catch (MustacheException e) { // Success } }
public void testIdentitySimple() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile("simple.html"); StringWriter sw = new StringWriter(); m.identity(sw); assertEquals(getContents(root, "simple.html").replaceAll("\\s+", ""), sw.toString().replaceAll( "\\s+", "")); }
public void testPartialWithTF() throws MustacheException, IOException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile("partialintemplatefunction.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { public TemplateFunction i() { return s -> s; } }); assertEquals("This is not interesting.", sw.toString()); }
public void testSingleCurly() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{value } }}"), "testSingleCurly"); StringWriter sw = new StringWriter(); m.execute(sw, new HashMap<String, String>() {{ put("value }", "test"); }}).close(); // Values ignored as if it didn't exist at all assertEquals("test", sw.toString()); }
public void testRelativePathsSameDir() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/paths.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "relative/paths.txt"), sw.toString()); }
public void testRelativePathsDotDotDir() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/dotdot.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "uninterestingpartial.html"), sw.toString()); }
public void testReadme() throws MustacheException, IOException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile("items.html"); StringWriter sw = new StringWriter(); long start = System.currentTimeMillis(); m.execute(sw, new Context()); long diff = System.currentTimeMillis() - start; assertEquals(getContents(root, "items.txt"), sw.toString()); }
public void testRelativePathsRootDir() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/rootpath.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "relative/paths.txt"), sw.toString()); }
public void testPathsWithExtension() throws IOException { MustacheFactory mf = createMustacheFactory(); Mustache compile = mf.compile("relative/extension.html"); StringWriter sw = new StringWriter(); compile.execute(sw, "").close(); assertEquals(getContents(root, "relative/paths.txt"), sw.toString()); }
public void testReadmeSerial() throws MustacheException, IOException { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile("items2.html"); StringWriter sw = new StringWriter(); long start = System.currentTimeMillis(); m.execute(sw, new Context()); long diff = System.currentTimeMillis() - start; assertEquals(getContents(root, "items.txt"), sw.toString()); assertTrue("Should be a little bit more than 4 seconds: " + diff, diff > 3999 && diff < 6000); }