Class |
Line # |
Actions |
|||||
---|---|---|---|---|---|---|---|
AbstractVelocityTestCase | 35 | 20 | 0% | 12 | 32 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.devacfr.testing.jupiter; | |
20 | ||
21 | import java.io.IOException; | |
22 | import java.io.StringWriter; | |
23 | ||
24 | import org.apache.velocity.VelocityContext; | |
25 | import org.apache.velocity.app.VelocityEngine; | |
26 | import org.apache.velocity.context.Context; | |
27 | import org.apache.velocity.exception.MethodInvocationException; | |
28 | import org.apache.velocity.exception.ParseErrorException; | |
29 | import org.apache.velocity.exception.ResourceNotFoundException; | |
30 | import org.junit.jupiter.api.AfterEach; | |
31 | import org.junit.jupiter.api.BeforeEach; | |
32 | import org.slf4j.Logger; | |
33 | import org.slf4j.LoggerFactory; | |
34 | ||
35 | public abstract class AbstractVelocityTestCase extends MockitoTestCase { | |
36 | ||
37 | private final Logger log = LoggerFactory.getLogger(this.getClass()); | |
38 | ||
39 | private VelocityEngine engine = null; | |
40 | ||
41 | private String template = ""; | |
42 | ||
43 | private Context context = null; | |
44 | ||
45 | private String expected = null; | |
46 | ||
47 | 0 | protected final Logger getLog() { |
48 | 0 | return this.log; |
49 | } | |
50 | ||
51 | 0 | @BeforeEach |
52 | protected void setUp() throws Exception { | |
53 | 0 | this.setTemplate(""); |
54 | 0 | this.setContext(new VelocityContext()); |
55 | 0 | this.setExpected(""); |
56 | } | |
57 | ||
58 | 0 | @AfterEach |
59 | protected void tearDown() throws Exception { | |
60 | 0 | this.setEngine(null); |
61 | 0 | this.setTemplate(null); |
62 | 0 | this.setContext(null); |
63 | 0 | this.setExpected(null); |
64 | } | |
65 | ||
66 | /** | |
67 | * @return Returns the engine. | |
68 | */ | |
69 | 0 | protected VelocityEngine getEngine() { |
70 | 0 | return this.engine; |
71 | } | |
72 | ||
73 | /** | |
74 | * @param engine | |
75 | * The engine to set. | |
76 | */ | |
77 | 0 | protected void setEngine(final VelocityEngine engine) { |
78 | 0 | this.engine = engine; |
79 | } | |
80 | ||
81 | /** | |
82 | * @return Returns the template. | |
83 | */ | |
84 | 0 | protected String getTemplate() { |
85 | 0 | return this.template; |
86 | } | |
87 | ||
88 | /** | |
89 | * @param template | |
90 | * The template to set. | |
91 | */ | |
92 | 0 | protected void setTemplate(final String template) { |
93 | 0 | this.template = template; |
94 | } | |
95 | ||
96 | /** | |
97 | * @return Returns the context. | |
98 | */ | |
99 | 0 | protected Context getContext() { |
100 | 0 | return this.context; |
101 | } | |
102 | ||
103 | /** | |
104 | * @param context | |
105 | * The context to set. | |
106 | */ | |
107 | 0 | protected void setContext(final Context context) { |
108 | 0 | this.context = context; |
109 | } | |
110 | ||
111 | /** | |
112 | * @return Returns the expected. | |
113 | */ | |
114 | 0 | protected String getExpected() { |
115 | 0 | return this.expected; |
116 | } | |
117 | ||
118 | /** | |
119 | * @param expected | |
120 | * The expected to set. | |
121 | */ | |
122 | 0 | protected void setExpected(final String expected) { |
123 | 0 | this.expected = expected; |
124 | } | |
125 | ||
126 | 0 | protected void assertVelocity() |
127 | throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException, Exception { | |
128 | 0 | this.getEngine().init(); |
129 | ||
130 | 0 | final StringWriter writer = new StringWriter(); |
131 | 0 | assertTrue(this.getEngine().evaluate(this.getContext(), writer, this.getName(), this.getTemplate())); |
132 | ||
133 | 0 | assertEquals(this.getExpected(), String.valueOf(writer)); |
134 | } | |
135 | } |