mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
added test for defect templates
This commit is contained in:
@@ -57,11 +57,39 @@ public class FreemarkerTemplateTest extends TemplateTestBase
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Template getTemplate() throws IOException
|
public Template getFailureTemplate() throws IOException
|
||||||
|
{
|
||||||
|
return getTemplate("sonia/scm/template/002.ftl");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Template getHelloTemplate() throws IOException
|
||||||
|
{
|
||||||
|
return getTemplate("sonia/scm/template/004.ftl");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private Template getTemplate(String path) throws IOException
|
||||||
{
|
{
|
||||||
ServletContext context = mock(ServletContext.class);
|
ServletContext context = mock(ServletContext.class);
|
||||||
|
|
||||||
return new FreemarkerTemplateEngine(context).getTemplate(
|
return new FreemarkerTemplateEngine(context).getTemplate(path);
|
||||||
"sonia/scm/template/002.ftl");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ package sonia.scm.template;
|
|||||||
import com.github.mustachejava.DefaultMustacheFactory;
|
import com.github.mustachejava.DefaultMustacheFactory;
|
||||||
import com.github.mustachejava.Mustache;
|
import com.github.mustachejava.Mustache;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -48,13 +52,40 @@ public class MustacheTemplateTest extends TemplateTestBase
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Template getTemplate()
|
public Template getFailureTemplate() throws IOException
|
||||||
|
{
|
||||||
|
return getTemplate("sonia/scm/template/003.mustache");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Template getHelloTemplate()
|
||||||
|
{
|
||||||
|
return getTemplate("sonia/scm/template/001.mustache");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Template getTemplate(String path)
|
||||||
{
|
{
|
||||||
DefaultMustacheFactory factory = new DefaultMustacheFactory();
|
DefaultMustacheFactory factory = new DefaultMustacheFactory();
|
||||||
Mustache mustache = factory.compile("sonia/scm/template/001.mustache");
|
Mustache mustache = factory.compile(path);
|
||||||
|
|
||||||
return new MustacheTemplate("sonia/scm/template/001.mustache", mustache);
|
return new MustacheTemplate(path, mustache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,17 @@ public abstract class TemplateTestBase
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public abstract Template getTemplate() throws IOException;
|
public abstract Template getFailureTemplate() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public abstract Template getHelloTemplate() throws IOException;
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
@@ -72,8 +82,37 @@ public abstract class TemplateTestBase
|
|||||||
@Test
|
@Test
|
||||||
public void testRender() throws IOException
|
public void testRender() throws IOException
|
||||||
{
|
{
|
||||||
Template template = getTemplate();
|
Template template = getHelloTemplate();
|
||||||
|
|
||||||
|
assertEquals("Hello marvin!", execute(template));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Test(expected = IOException.class)
|
||||||
|
public void testRenderFailure() throws IOException
|
||||||
|
{
|
||||||
|
Template template = getFailureTemplate();
|
||||||
|
|
||||||
|
execute(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param template
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private String execute(Template template) throws IOException
|
||||||
|
{
|
||||||
Map<String, String> env = Maps.newHashMap();
|
Map<String, String> env = Maps.newHashMap();
|
||||||
|
|
||||||
env.put("name", "marvin");
|
env.put("name", "marvin");
|
||||||
@@ -82,6 +121,6 @@ public abstract class TemplateTestBase
|
|||||||
|
|
||||||
template.execute(writer, env);
|
template.execute(writer, env);
|
||||||
|
|
||||||
assertEquals("Hello marvin!", writer.toString());
|
return writer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Hello {{/name}}!
|
||||||
1
scm-webapp/src/test/resources/sonia/scm/template/004.ftl
Normal file
1
scm-webapp/src/test/resources/sonia/scm/template/004.ftl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Hello <#list a>!
|
||||||
Reference in New Issue
Block a user