1. Project Clover database Mon Dec 22 2025 14:59:38 CST
  2. Package org.europa.together.application

File VelocityRendererTest.java

 

Code metrics

8
42
12
1
161
127
16
0.38
3.5
12
1.33

Classes

Class Line # Actions
VelocityRendererTest 27 42 0% 16 4
0.935483993.5%
 

Contributing tests

This file is covered by 8 tests. .

Source view

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({SpringExtension.class, JUnit5Preperator.class})
26    @ContextConfiguration(locations = {"/applicationContext.xml"})
 
27    public class VelocityRendererTest {
28   
29    private static final Logger LOGGER
30    = new LogbackLogger(VelocityRendererTest.class);
31    private static final String FILE_PATH
32    = "org/europa/together/velocity";
33    private static final String DIRECTORY
34    = Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + FILE_PATH;
35   
36    @Autowired
37    private TemplateRenderer instance;
38   
39    private Map<String, String> properties = new HashMap<>();
40   
41    //<editor-fold defaultstate="collapsed" desc="Test Preparation">
 
42  1 toggle @BeforeAll
43    static void setUp() {
44  1 Assumptions.assumeTrue(true, "Assumtion failed.");
45   
46  1 LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG);
47    }
48   
 
49  1 toggle @AfterAll
50    static void tearDown() {
51    }
52   
 
53  8 toggle @BeforeEach
54    void testCaseInitialization() {
55    }
56   
 
57  8 toggle @AfterEach
58    void testCaseTermination() {
59    }
60    //</editor-fold>
61   
 
62  1 toggle @Test
63    void constructor() {
64  1 LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG);
65   
66  1 assertThat(VelocityRenderer.class, hasValidBeanConstructor());
67    }
68   
 
69  1 toggle @Test
70    void generateContent() {
71  1 LOGGER.log("TEST CASE: generateContent", LogLevel.DEBUG);
72   
73  1 assertEquals("Hello World?",
74    instance.loadContentByStringResource("Hello World?", null));
75    }
76   
 
77  1 toggle @Test
78    void generateContentWithProperties() {
79  1 LOGGER.log("TEST CASE: generateContentWithProperties", LogLevel.DEBUG);
80   
81  1 instance = new VelocityRenderer();
82  1 if (properties != null) {
83  1 properties.clear();
84    }
85  1 properties.put("property_key", "value");
86   
87  1 assertEquals("Hello World? : value",
88    instance.loadContentByStringResource("Hello World? : $property_key", properties));
89    }
90   
 
91  1 toggle @Test
92    void generateComplexContent() {
93  1 LOGGER.log("TEST CASE: generateContentWithProperties", LogLevel.DEBUG);
94   
95  1 String template = "## single line comment \n"
96    + "#set( $var = \"Velocity\" ) \n"
97    + "Hello $var World?"
98    + "#if($property_key==\"value\") : $property_key #end";
99   
100  1 instance = new VelocityRenderer();
101  1 if (properties != null) {
102  1 properties.clear();
103    }
104  1 properties.put("property_key", "value");
105   
106  1 assertEquals("Hello Velocity World? : value ",
107    instance.loadContentByStringResource(template, properties));
108    }
109   
 
110  1 toggle @Test
111    void loadContentByClasspathResource() {
112  1 LOGGER.log("TEST CASE: loadContentByClasspathResource", LogLevel.DEBUG);
113   
114  1 instance = new VelocityRenderer();
115  1 if (properties != null) {
116  1 properties.clear();
117    }
118  1 properties.put("property_key", "value");
119   
120  1 String result
121    = instance.loadContentByClasspathResource(FILE_PATH, "/TemplateWithProperties.vm", properties);
122  1 assertEquals("Hello World? : value", result);
123    }
124   
 
125  1 toggle @Test
126    void failLoadContentByClasspathResource() throws Exception {
127  1 LOGGER.log("TEST CASE: failLoadContentByClasspathResource", LogLevel.DEBUG);
128   
129  1 instance = new VelocityRenderer();
130  1 assertThrows(Exception.class, () -> {
131  1 instance.loadContentByClasspathResource(FILE_PATH, "notExist.vm", null);
132    });
133    }
134   
 
135  1 toggle @Test
136    void loadContentByFileResource() {
137  1 LOGGER.log("TEST CASE: loadContentByFileResource", LogLevel.DEBUG);
138   
139  1 instance = new VelocityRenderer();
140  1 if (properties != null) {
141  1 properties.clear();
142    }
143  1 properties.put("property_key", "value");
144   
145  1 LOGGER.log("\n PATH: " + DIRECTORY + "\n", LogLevel.ERROR);
146   
147  1 String result
148    = instance.loadContentByFileResource(DIRECTORY, "/TemplateWithProperties.vm", properties);
149  1 assertEquals("Hello World? : value", result);
150    }
151   
 
152  1 toggle @Test
153    void failLoadContentByFileResource() throws Exception {
154  1 LOGGER.log("TEST CASE: failLoadContentByFileResource", LogLevel.DEBUG);
155   
156  1 instance = new VelocityRenderer();
157  1 assertThrows(Exception.class, () -> {
158  1 instance.loadContentByFileResource(DIRECTORY, "/notExist.vm", null);
159    });
160    }
161    }