use of com.devonfw.cobigen.tempeng.freemarker.FreeMarkerTemplateEngine in project cobigen by devonfw.
the class FreeMarkerTemplateEngineTest method testBasicGeneration.
/**
* Tests a basic FreeMarker generation
*/
@Test
public void testBasicGeneration() {
// arrange
final File templateFolder = new File(testFileRootPath + "basicGeneration/").getAbsoluteFile();
TextTemplate template = new TextTemplate() {
@Override
public String getRelativeTemplatePath() {
return "template.ftl";
}
@Override
public Path getAbsoluteTemplatePath() {
return templateFolder.toPath().resolve("template.ftl");
}
};
HashMap<String, Object> model = new HashMap<>();
List<Object> fields = new ArrayList<>();
HashMap<Object, Object> fieldAttr = new HashMap<>();
fieldAttr.put("type", "A");
fields.add(fieldAttr);
fieldAttr = new HashMap<>();
fieldAttr.put("type", "B");
fields.add(fieldAttr);
fieldAttr = new HashMap<>();
fieldAttr.put("type", "C");
fields.add(fieldAttr);
HashMap<String, Object> fieldsAccessor = new HashMap<>();
fieldsAccessor.put("fields", fields);
model.put("pojo", fieldsAccessor);
// act
StringWriter out = new StringWriter();
FreeMarkerTemplateEngine templateEngine = new FreeMarkerTemplateEngine();
templateEngine.setTemplateFolder(templateFolder.toPath());
templateEngine.process(template, model, out, "UTF-8");
// assert
assertThat(out).hasToString("A,B,C,");
}
Aggregations