-
Notifications
You must be signed in to change notification settings - Fork 11
EN.03.04.Template
Document to respond html by using templates and data files.
When configure template
and data
section at project.yaml, be able to respond to html.
Root directory of template file. Specify a relative path from project root path.
Specify ServiceClass implemented on Aeromock.
Template Engine | FQDN of ServiceClass |
---|---|
Freemarker | jp.co.cyberagent.aeromock.template.freemarker.FreemarkerTemplateService |
Handlebars.java | jp.co.cyberagent.aeromock.template.handlebars.HandlebarsTemplateService |
Jade4j | jp.co.cyberagent.aeromock.template.jade4j.Jade4jTemplateService |
Velocity | jp.co.cyberagent.aeromock.template.velocity.VelocityTemplateService |
Groovy Templates | jp.co.cyberagent.aeromock.template.groovytemplate.GroovyTemplateService |
Thymeleaf | jp.co.cyberagent.aeromock.template.thymeleaf.ThymeleafTemplateService |
Root directory of template data file. Specify a relative path from project root path.
template:
root: ../template
serviceClass: jp.co.cyberagent.aeromock.template.freemarker.FreemarkerTemplateService
data:
root: ./data
Configuration file is to control the behavior of template engine. Specification is different depending on template engine、so please check as follows.
Locate template file and data file at same hierarchy.
template_root/path1/test.ftl -> data_root/path1/test.yaml
Specification of template data file is the save as JSON API. In addition, there specialized specification on template data file.
Basically data is a hash structure (java.util.Map), there is also data with Java method has required. By specifing __methods
property, be able to add method returns mock value to Java object dynamically.
The structure of __methods
is array of name
(method name) and value
(mock method value) pair. This mock method can be called regardless of the number of arguments.
target:
prop1: prop1Value
__methods:
- name: execute1
value: execute1Value
- name: execute2
value:
id: 100
name: foobar
<html>
<head></head>
<body>
<ul>
<li>target.prop1 = ${target.prop1}</li>
<li>target.exeucte1() = ${target.execute1()}</li>
<#assign execute2Result = target.execute2() >
<li>target.exeucte2().id = ${execute2Result.id}</li>
<li>target.exeucte2().name = ${execute2Result.name}</li>
</ul>
</body>
</html>
In addition, be able to refer to method arguments as ARGUMENTS
variable. ARGUMENTS
is array, so array index is required.
<span>${obj.execute("part1:part2:part3")}</span>
obj:
__methods:
- name: execute
value: ${ARGUMENTS[0].split(":")[0]}
Specification is the same as JSON API, but create data.groovy.
If you check the structure of data file applied to template, whenever send request with __debug=true
as request paramerter, output data as YAML format.
Specification of custom response in template is the same as JSON-API.
Depending on template engine, there may be extended implementation. Please check the follows.