|
1 |
| package com.agical.rdoc.velocity.render; |
|
2 |
| |
|
3 |
| import java.io.Serializable; |
|
4 |
| |
|
5 |
| import org.apache.velocity.Template; |
|
6 |
| import org.apache.velocity.context.Context; |
|
7 |
| |
|
8 |
| import com.agical.rdoc.core.TestSuitePostProcessor; |
|
9 |
| import com.agical.rdoc.core.model.TextFormatter; |
|
10 |
| import com.agical.rdoc.core.model.test.TestStructure; |
|
11 |
| import com.agical.rdoc.core.resourcemanager.ResourceManager; |
|
12 |
| import com.agical.rdoc.velocity.VelocityManager; |
|
13 |
| import com.agical.rdoc.velocity.VelocityManagerFactory; |
|
14 |
| import com.agical.rmock.core.hub.Hub; |
|
15 |
| |
|
16 |
| public class VelocityTestStructureRenderer implements TestSuitePostProcessor, Serializable { |
|
17 |
| private static final long serialVersionUID = 1L; |
|
18 |
| private transient ResourceManager resourceManager; |
|
19 |
| private final String theTemplateToRender; |
|
20 |
| private final String targetName; |
|
21 |
| private final TextFormatter textFormatter; |
|
22 |
| private transient VelocityManagerFactory velocityManagerFactory; |
|
23 |
| |
|
24 |
11
| public VelocityTestStructureRenderer(String theTemplateToRender, String targetName, TextFormatter formatter) {
|
|
25 |
11
| this.theTemplateToRender = theTemplateToRender;
|
|
26 |
11
| this.targetName = targetName;
|
|
27 |
11
| this.textFormatter = formatter;
|
|
28 |
| } |
|
29 |
| |
|
30 |
31
| public void setVelocityManagerFactory(VelocityManagerFactory velocityManagerFactory) {
|
|
31 |
31
| this.velocityManagerFactory = velocityManagerFactory;
|
|
32 |
| } |
|
33 |
| |
|
34 |
21
| public void setResourceManager(ResourceManager resourcecManager) {
|
|
35 |
21
| this.resourceManager = resourcecManager;
|
|
36 |
| } |
|
37 |
| |
|
38 |
11
| public void process(TestStructure testStructure, Hub hub) {
|
|
39 |
11
| hub.connect(textFormatter);
|
|
40 |
11
| VelocityManager velocityManager = velocityManagerFactory.create();
|
|
41 |
11
| hub.connect(velocityManager );
|
|
42 |
11
| Context context = velocityManager.createContext();
|
|
43 |
11
| Template template = velocityManager.getTemplate(theTemplateToRender);
|
|
44 |
11
| context.put("model", testStructure);
|
|
45 |
11
| VelocityTemplateConverter templateConverter = new VelocityTemplateConverter(context);
|
|
46 |
11
| resourceManager.write(templateConverter, template, targetName);
|
|
47 |
| } |
|
48 |
| } |