| 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"}) |
| |
|
| 93.5% |
Uncovered Elements: 4 (62) |
Complexity: 16 |
Complexity Density: 0.38 |
|
| 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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 42 |
1 |
@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 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 49 |
1 |
@AfterAll... |
| 50 |
|
static void tearDown() { |
| 51 |
|
} |
| 52 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 53 |
8 |
@BeforeEach... |
| 54 |
|
void testCaseInitialization() { |
| 55 |
|
} |
| 56 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 57 |
8 |
@AfterEach... |
| 58 |
|
void testCaseTermination() { |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 62 |
1 |
@Test... |
| 63 |
|
void constructor() { |
| 64 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
| 65 |
|
|
| 66 |
1 |
assertThat(VelocityRenderer.class, hasValidBeanConstructor()); |
| 67 |
|
} |
| 68 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 69 |
1 |
@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 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
| 77 |
1 |
@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 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 91 |
1 |
@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 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 110 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 125 |
1 |
@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 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
1PASS
|
|
| 135 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 152 |
1 |
@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 |
|
} |