package core.framework.impl.template;
import core.framework.api.util.ClasspathResources;
import core.framework.api.util.Lists;
import core.framework.impl.template.source.ClasspathTemplateSource;
import org.junit.Assert;
import org.junit.Test;
import java.util.Optional;
/**
* @author neo
*/
public class HTMLTemplateTest {
@Test
public void process() {
HTMLTemplateBuilder builder = new HTMLTemplateBuilder(new ClasspathTemplateSource("template-test/template.html"), TestModel.class);
builder.message = key -> Optional.of(key + "_value");
HTMLTemplate template = builder.build();
TestModel model = new TestModel();
model.stringField = "string<";
model.numberField = 100;
model.items.addAll(Lists.newArrayList("a", "b", "c"));
model.children.add(child("child1", 1.0, true));
model.children.add(child("child2", 2.0, false));
model.htmlField = "<pre>html</pre>";
String result = template.process(new TemplateContext(model, new CDNManager()));
Assert.assertEquals(ClasspathResources.text("template-test/template-result.html").replaceAll("\r\n", "\n"), result);
}
private TestModelChild child(String stringField, Double doubleField, Boolean booleanField) {
TestModelChild child = new TestModelChild();
child.stringField = stringField;
child.doubleField = doubleField;
child.booleanField = booleanField;
return child;
}
}