1 |
|
package org.europa.together.application; |
2 |
|
|
3 |
|
import static com.google.code.beanmatchers.BeanMatchers.*; |
4 |
|
import java.util.HashMap; |
5 |
|
import java.util.Map; |
6 |
|
import org.europa.together.JUnit5Preperator; |
7 |
|
import org.europa.together.business.Logger; |
8 |
|
import org.europa.together.domain.LogLevel; |
9 |
|
import org.europa.together.utils.Constraints; |
10 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
11 |
|
import org.junit.jupiter.api.AfterAll; |
12 |
|
import org.junit.jupiter.api.AfterEach; |
13 |
|
import static org.junit.jupiter.api.Assertions.*; |
14 |
|
import org.junit.jupiter.api.Assumptions; |
15 |
|
import org.junit.jupiter.api.BeforeAll; |
16 |
|
import org.junit.jupiter.api.BeforeEach; |
17 |
|
import org.junit.jupiter.api.Test; |
18 |
|
import org.europa.together.business.TemplateRenderer; |
19 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
20 |
|
import org.springframework.beans.factory.annotation.Autowired; |
21 |
|
import org.springframework.test.context.ContextConfiguration; |
22 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
23 |
|
|
24 |
|
@SuppressWarnings("unchecked") |
25 |
|
@ExtendWith({JUnit5Preperator.class}) |
26 |
|
@ExtendWith(SpringExtension.class) |
27 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
|
|
| 93.5% |
Uncovered Elements: 4 (62) |
Complexity: 16 |
Complexity Density: 0.38 |
|
28 |
|
public class VelocityRendererTest { |
29 |
|
|
30 |
|
private static final Logger LOGGER |
31 |
|
= new LogbackLogger(VelocityRendererTest.class); |
32 |
|
private static final String FILE_PATH |
33 |
|
= "org/europa/together/velocity"; |
34 |
|
private static final String DIRECTORY |
35 |
|
= Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + FILE_PATH; |
36 |
|
|
37 |
|
@Autowired |
38 |
|
private TemplateRenderer instance; |
39 |
|
|
40 |
|
private Map<String, String> properties = new HashMap<>(); |
41 |
|
|
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
43 |
1 |
@BeforeAll... |
44 |
|
static void setUp() { |
45 |
1 |
Assumptions.assumeTrue(true, "Assumtion failed."); |
46 |
|
|
47 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
48 |
|
} |
49 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
50 |
1 |
@AfterAll... |
51 |
|
static void tearDown() { |
52 |
|
} |
53 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
54 |
8 |
@BeforeEach... |
55 |
|
void testCaseInitialization() { |
56 |
|
} |
57 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
58 |
8 |
@AfterEach... |
59 |
|
void testCaseTermination() { |
60 |
|
} |
61 |
|
|
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
63 |
1 |
@Test... |
64 |
|
void constructor() { |
65 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
66 |
|
|
67 |
1 |
assertThat(VelocityRenderer.class, hasValidBeanConstructor()); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
void generateContent() { |
72 |
1 |
LOGGER.log("TEST CASE: generateContent", LogLevel.DEBUG); |
73 |
|
|
74 |
1 |
assertEquals("Hello World?", |
75 |
|
instance.loadContentByStringResource("Hello World?", null)); |
76 |
|
} |
77 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
void generateContentWithProperties() { |
80 |
1 |
LOGGER.log("TEST CASE: generateContentWithProperties", LogLevel.DEBUG); |
81 |
|
|
82 |
1 |
instance = new VelocityRenderer(); |
83 |
1 |
if (properties != null) { |
84 |
1 |
properties.clear(); |
85 |
|
} |
86 |
1 |
properties.put("property_key", "value"); |
87 |
|
|
88 |
1 |
assertEquals("Hello World? : value", |
89 |
|
instance.loadContentByStringResource("Hello World? : $property_key", properties)); |
90 |
|
} |
91 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
92 |
1 |
@Test... |
93 |
|
void generateComplexContent() { |
94 |
1 |
LOGGER.log("TEST CASE: generateContentWithProperties", LogLevel.DEBUG); |
95 |
|
|
96 |
1 |
String template = "## single line comment \n" |
97 |
|
+ "#set( $var = \"Velocity\" ) \n" |
98 |
|
+ "Hello $var World?" |
99 |
|
+ "#if($property_key==\"value\") : $property_key #end"; |
100 |
|
|
101 |
1 |
instance = new VelocityRenderer(); |
102 |
1 |
if (properties != null) { |
103 |
1 |
properties.clear(); |
104 |
|
} |
105 |
1 |
properties.put("property_key", "value"); |
106 |
|
|
107 |
1 |
assertEquals("Hello Velocity World? : value ", |
108 |
|
instance.loadContentByStringResource(template, properties)); |
109 |
|
} |
110 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
111 |
1 |
@Test... |
112 |
|
void loadContentByClasspathResource() { |
113 |
1 |
LOGGER.log("TEST CASE: loadContentByClasspathResource", LogLevel.DEBUG); |
114 |
|
|
115 |
1 |
instance = new VelocityRenderer(); |
116 |
1 |
if (properties != null) { |
117 |
1 |
properties.clear(); |
118 |
|
} |
119 |
1 |
properties.put("property_key", "value"); |
120 |
|
|
121 |
1 |
String result |
122 |
|
= instance.loadContentByClasspathResource(FILE_PATH, "/TemplateWithProperties.vm", properties); |
123 |
1 |
assertEquals("Hello World? : value", result); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
126 |
1 |
@Test... |
127 |
|
void failLoadContentByClasspathResource() throws Exception { |
128 |
1 |
LOGGER.log("TEST CASE: failLoadContentByClasspathResource", LogLevel.DEBUG); |
129 |
|
|
130 |
1 |
instance = new VelocityRenderer(); |
131 |
1 |
assertThrows(Exception.class, () -> { |
132 |
1 |
instance.loadContentByClasspathResource(FILE_PATH, "notExist.vm", null); |
133 |
|
}); |
134 |
|
} |
135 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
1PASS
|
|
136 |
1 |
@Test... |
137 |
|
void loadContentByFileResource() { |
138 |
1 |
LOGGER.log("TEST CASE: loadContentByFileResource", LogLevel.DEBUG); |
139 |
|
|
140 |
1 |
instance = new VelocityRenderer(); |
141 |
1 |
if (properties != null) { |
142 |
1 |
properties.clear(); |
143 |
|
} |
144 |
1 |
properties.put("property_key", "value"); |
145 |
|
|
146 |
1 |
LOGGER.log("\n PATH: " + DIRECTORY + "\n", LogLevel.ERROR); |
147 |
|
|
148 |
1 |
String result |
149 |
|
= instance.loadContentByFileResource(DIRECTORY, "/TemplateWithProperties.vm", properties); |
150 |
1 |
assertEquals("Hello World? : value", result); |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
153 |
1 |
@Test... |
154 |
|
void failLoadContentByFileResource() throws Exception { |
155 |
1 |
LOGGER.log("TEST CASE: failLoadContentByFileResource", LogLevel.DEBUG); |
156 |
|
|
157 |
1 |
instance = new VelocityRenderer(); |
158 |
1 |
assertThrows(Exception.class, () -> { |
159 |
1 |
instance.loadContentByFileResource(DIRECTORY, "/notExist.vm", null); |
160 |
|
}); |
161 |
|
} |
162 |
|
} |