|
1 |
| package com.agical.rdoc.velocity.render; |
|
2 |
| |
|
3 |
| import org.apache.velocity.context.Context; |
|
4 |
| |
|
5 |
| import com.agical.rdoc.core.DocumentationContext; |
|
6 |
| import com.agical.rdoc.core.TDDocService; |
|
7 |
| import com.agical.rdoc.core.impl.DocumentationContextWrapper; |
|
8 |
| import com.agical.rdoc.core.model.CodeBlock; |
|
9 |
| import com.agical.rdoc.core.model.SourceModel; |
|
10 |
| import com.agical.rdoc.core.model.SourceModelProvider; |
|
11 |
| import com.agical.rdoc.core.model.test.Test; |
|
12 |
| import com.agical.rdoc.core.model.test.TestCase; |
|
13 |
| import com.agical.rdoc.core.model.test.builder.TestSuite; |
|
14 |
| import com.agical.rdoc.velocity.VelocityManager; |
|
15 |
| import com.agical.rdoc.velocity.VelocityNodeRenderer; |
|
16 |
| |
|
17 |
| public class Renderer extends TDDocService implements VelocityNodeRenderer { |
|
18 |
| |
|
19 |
| private SourceModelProvider templateProvider; |
|
20 |
| private VelocityManager velocityManager; |
|
21 |
| |
|
22 |
5
| public Renderer() {
|
|
23 |
| } |
|
24 |
| |
|
25 |
1
| public String render(TestCase testCase) {
|
|
26 |
1
| SourceModel source = templateProvider.getSourceModel( testCase.getTestClass() );
|
|
27 |
1
| return evaluateClassLevel(source, "test");
|
|
28 |
| } |
|
29 |
| |
|
30 |
2
| private String evaluateClassLevel(SourceModel source, String modelName) {
|
|
31 |
2
| String template = source.getDocumentation();
|
|
32 |
2
| DocumentationContext documentationContext = DocumentationContext.NULL;
|
|
33 |
2
| return evaluate(template, modelName, documentationContext, source);
|
|
34 |
| } |
|
35 |
| |
|
36 |
11
| public String render(Test test) {
|
|
37 |
11
| String name = test.getName();
|
|
38 |
11
| DocumentationContext documentationContext = test.getDocumentationContext();
|
|
39 |
11
| SourceModel sourceModel = templateProvider.getSourceModel( test.getTestCase().getTestClass() );
|
|
40 |
11
| String template = sourceModel.getMethodDocumentation(name);
|
|
41 |
11
| CodeBlock source = sourceModel.getMethod(name);
|
|
42 |
| |
|
43 |
11
| return evaluate(template, "test", documentationContext, source);
|
|
44 |
| } |
|
45 |
| |
|
46 |
1
| public String render(TestSuite testSuite) {
|
|
47 |
1
| return evaluateClassLevel(templateProvider.getSourceModel(testSuite.getSuiteClass()), "suite");
|
|
48 |
| } |
|
49 |
| |
|
50 |
11
| public String evaluate(String template, String modelName, DocumentationContext documentationContext, Object source) {
|
|
51 |
11
| DocumentationContextWrapper testContext = new DocumentationContextWrapper(documentationContext);
|
|
52 |
11
| Context context = velocityManager.createContext();
|
|
53 |
11
| testContext.put( "source", source );
|
|
54 |
11
| context.put(modelName, testContext );
|
|
55 |
11
| return velocityManager.evaluate(template, context);
|
|
56 |
| } |
|
57 |
| |
|
58 |
5
| public void setTemplateProvider(SourceModelProvider templateProvider) {
|
|
59 |
5
| this.templateProvider = templateProvider;
|
|
60 |
| } |
|
61 |
| |
|
62 |
24
| public void setVelocityManager(VelocityManager velocityManager) {
|
|
63 |
24
| this.velocityManager = velocityManager;
|
|
64 |
| } |
|
65 |
| } |