Invoke extends AbstractTemplateFunction { @Override public String parseFunction(List<String> parts, IWikiModel model, char[] src, int beginIndex, int endIndex, boolean isSubst) throws IOException { if (parts.size() < 2) { throw new AssertionError("not enough arguments"); } ScribuntoEngine engine = model.createScribuntoEngine(); if (engine == null) { throw new AssertionError("no scribuntoEngine defined"); } final String moduleName = parts.get(0).trim(); final String functionName = parts.get(1).trim(); Frame parent = model.getFrame(); try { ScribuntoModule module = engine.fetchModuleFromParser(moduleName); final Frame frame = parent.newChild(module.pageName(), getParameters(parts, model), isSubst); return module.invoke(functionName, frame); } catch (ScribuntoException e) { logger.error("error invoking function", e); return null; } finally { model.setFrame(parent); } }  @Override String parseFunction(List<String> parts, IWikiModel model,
                                char[] src, int beginIndex, int endIndex, boolean isSubst); @Override String getFunctionDoc(); final static ITemplateFunction CONST; }
@Test public void testParseFunction() throws Exception { List<String> parts = Arrays.asList("moduleName", "method", "anotherParameter"); final String source = "source"; when(scribuntoModule.invoke(eq("method"), any(Frame.class))).thenReturn("expanded"); String result = subject.parseFunction(parts, model, source.toCharArray(), 0, source.length(), false); assertThat(result).isEqualTo("expanded"); }
@Test public void testParseFunctionWithExtraWhitespace() throws Exception { List<String> parts = Arrays.asList(" moduleName ", "method\n\n"); final String source = "source"; when(scribuntoModule.invoke(eq("method"), any(Frame.class))).thenReturn("expanded"); String result = subject.parseFunction(parts, model, source.toCharArray(), 0, source.length(), false); assertThat(result).isEqualTo("expanded"); }