Skip to content
stormcat24 edited this page Sep 5, 2014 · 3 revisions

Document to respond html by using templates and data files.

project.yaml

When configure template and data section at project.yaml, be able to respond to html.

template.root

Root directory of template file. Specify a relative path from project root path.

template.serviceClass

Specify ServiceClass implemented on Aeromock.

List of ServiceClass
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

data.root

Root directory of template data file. Specify a relative path from project root path.

Example

template:
  root: ../template
  serviceClass: jp.co.cyberagent.aeromock.template.freemarker.FreemarkerTemplateService

data:
  root: ./data

Configurtion file of each template engine

Configuration file is to control the behavior of template engine. Specification is different depending on template engine、so please check as follows.

Relation of template file to data file

Locate template file and data file at same hierarchy.

Example

template_root/path1/test.ftl -> data_root/path1/test.yaml

Template data file

Specification of template data file is the save as JSON API. In addition, there specialized specification on template data file.

__methods

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.

test.yaml
target:
  prop1: prop1Value
  __methods:
    - name: execute1
      value: execute1Value
    - name: execute2
      value:
        id: 100
        name: foobar
test.ftl
<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.

Example(Template file)
<span>${obj.execute("part1:part2:part3")}</span>
Example(Data file)
obj:
  __methods:
    - name: execute
      value: ${ARGUMENTS[0].split(":")[0]}

Common data file

Specification is the same as JSON API, but create data.groovy.

Debug data file

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.

image

Custom Response

Specification of custom response in template is the same as JSON-API.

Extended specification of template

Depending on template engine, there may be extended implementation. Please check the follows.

Clone this wiki locally