1 |
|
package org.europa.together.application; |
2 |
|
|
3 |
|
import static com.google.code.beanmatchers.BeanMatchers.*; |
4 |
|
import java.io.File; |
5 |
|
import org.europa.together.JUnit5Preperator; |
6 |
|
import org.europa.together.business.Logger; |
7 |
|
import org.europa.together.business.XmlTools; |
8 |
|
import org.europa.together.domain.LogLevel; |
9 |
|
import org.europa.together.utils.Constraints; |
10 |
|
import org.europa.together.utils.FileUtils; |
11 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
12 |
|
import org.junit.jupiter.api.AfterAll; |
13 |
|
import org.junit.jupiter.api.AfterEach; |
14 |
|
import static org.junit.jupiter.api.Assertions.*; |
15 |
|
import org.junit.jupiter.api.Assumptions; |
16 |
|
import org.junit.jupiter.api.BeforeAll; |
17 |
|
import org.junit.jupiter.api.BeforeEach; |
18 |
|
import org.junit.jupiter.api.Test; |
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"}) |
|
|
| 97.5% |
Uncovered Elements: 5 (201) |
Complexity: 33 |
Complexity Density: 0.2 |
|
28 |
|
public class SaxToolsTest { |
29 |
|
|
30 |
|
private static final Logger LOGGER |
31 |
|
= new LogbackLogger(SaxToolsTest.class); |
32 |
|
private static final String FILE_PATH |
33 |
|
= "org/europa/together/xml"; |
34 |
|
private static final String DIRECTORY |
35 |
|
= Constraints.SYSTEM_APP_DIR + "/target/test-classes/" + FILE_PATH; |
36 |
|
|
37 |
|
private static final File DTD |
38 |
|
= new File(Constraints.SYSTEM_APP_DIR + "/simple.dtd"); |
39 |
|
private static final File SCHEMA |
40 |
|
= new File(Constraints.SYSTEM_APP_DIR + "/simple.xsd"); |
41 |
|
|
42 |
|
@Autowired |
43 |
|
private XmlTools xmlTools; |
44 |
|
|
45 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
46 |
1 |
@BeforeAll... |
47 |
|
static void setUp() { |
48 |
1 |
try { |
49 |
1 |
FileUtils.copyFile(new File(DIRECTORY + "/simple.dtd"), DTD); |
50 |
1 |
FileUtils.copyFile(new File(DIRECTORY + "/simple.xsd"), SCHEMA); |
51 |
|
} catch (Exception ex) { |
52 |
0 |
LOGGER.catchException(ex); |
53 |
0 |
Assumptions.assumeTrue(false, "XML grammar definition files faild to copy."); |
54 |
|
} |
55 |
|
|
56 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
57 |
|
} |
58 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
59 |
1 |
@AfterAll... |
60 |
|
static void tearDown() { |
61 |
1 |
if (DTD.exists()) { |
62 |
1 |
DTD.delete(); |
63 |
|
} |
64 |
1 |
if (SCHEMA.exists()) { |
65 |
1 |
SCHEMA.delete(); |
66 |
|
} |
67 |
|
} |
68 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
69 |
25 |
@BeforeEach... |
70 |
|
void testCaseInitialization() { |
71 |
|
} |
72 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
73 |
25 |
@AfterEach... |
74 |
|
void testCaseTermination() { |
75 |
|
} |
76 |
|
|
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
void constructor() { |
80 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
81 |
|
|
82 |
1 |
assertThat(SaxTools.class, hasValidBeanConstructor()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
void parseXmlString() throws Exception { |
87 |
1 |
LOGGER.log("TEST CASE: parseXmlString", LogLevel.DEBUG); |
88 |
|
|
89 |
1 |
xmlTools = new SaxTools(); |
90 |
1 |
String xml = FileUtils.readFileStream(new File(DIRECTORY + "/test_wellformed.xml")); |
91 |
1 |
String output = xmlTools.parseXmlString(xml); |
92 |
1 |
String compare = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
93 |
|
+ "\n" |
94 |
|
+ "<root xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n" |
95 |
|
+ "\n" |
96 |
|
+ " <!-- COMMENT -->\n" |
97 |
|
+ " <![CDATA[cdata element content]]>\n" |
98 |
|
+ "\n" |
99 |
|
+ " <node>\n" |
100 |
|
+ " <child>child 1</child>\n" |
101 |
|
+ " <child>child 2</child>\n" |
102 |
|
+ " <child>child 2</child>\n" |
103 |
|
+ " </node>\n" |
104 |
|
+ "\n" |
105 |
|
+ " <attribute value=\"attribute a\">attribute node</attribute>\n" |
106 |
|
+ "\n" |
107 |
|
+ " <emptyTag />\n" |
108 |
|
+ "\n" |
109 |
|
+ " <char>\n" |
110 |
|
+ " <escape><</escape>\n" |
111 |
|
+ " <escape>></escape>\n" |
112 |
|
+ " <escape>'</escape>\n" |
113 |
|
+ " <escape>"</escape>\n" |
114 |
|
+ " </char>\n" |
115 |
|
+ "</root>\n"; |
116 |
|
|
117 |
1 |
assertNotNull(output); |
118 |
1 |
assertEquals(compare, output); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
void failParseXmlString() { |
123 |
1 |
LOGGER.log("TEST CASE: failParseXmlString", LogLevel.DEBUG); |
124 |
|
|
125 |
1 |
xmlTools = new SaxTools(); |
126 |
1 |
assertNull(xmlTools.parseXmlString(null)); |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
129 |
1 |
@Test... |
130 |
|
void parseXmlFile() { |
131 |
1 |
LOGGER.log("TEST CASE: parseXmlFile", LogLevel.DEBUG); |
132 |
|
|
133 |
1 |
xmlTools = new SaxTools(); |
134 |
1 |
String output = xmlTools.parseXmlFile(new File(DIRECTORY + "/test_wellformed.xml")); |
135 |
1 |
String compare = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
136 |
|
+ "\n" |
137 |
|
+ "<root xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n" |
138 |
|
+ "\n" |
139 |
|
+ " <!-- COMMENT -->\n" |
140 |
|
+ " <![CDATA[cdata element content]]>\n" |
141 |
|
+ "\n" |
142 |
|
+ " <node>\n" |
143 |
|
+ " <child>child 1</child>\n" |
144 |
|
+ " <child>child 2</child>\n" |
145 |
|
+ " <child>child 2</child>\n" |
146 |
|
+ " </node>\n" |
147 |
|
+ "\n" |
148 |
|
+ " <attribute value=\"attribute a\">attribute node</attribute>\n" |
149 |
|
+ "\n" |
150 |
|
+ " <emptyTag />\n" |
151 |
|
+ "\n" |
152 |
|
+ " <char>\n" |
153 |
|
+ " <escape><</escape>\n" |
154 |
|
+ " <escape>></escape>\n" |
155 |
|
+ " <escape>'</escape>\n" |
156 |
|
+ " <escape>"</escape>\n" |
157 |
|
+ " </char>\n" |
158 |
|
+ "</root>\n"; |
159 |
|
|
160 |
1 |
assertNotNull(output); |
161 |
1 |
assertEquals(compare, output); |
162 |
|
} |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
164 |
1 |
@Test... |
165 |
|
void failParsingXmlFile() { |
166 |
1 |
LOGGER.log("TEST CASE: failParseXmlFile", LogLevel.DEBUG); |
167 |
|
|
168 |
1 |
xmlTools = new SaxTools(); |
169 |
1 |
assertNull(xmlTools.parseXmlFile(null)); |
170 |
|
} |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
172 |
1 |
@Test... |
173 |
|
void isWellFormed() { |
174 |
1 |
LOGGER.log("TEST CASE: isWellFormed", LogLevel.DEBUG); |
175 |
|
|
176 |
1 |
xmlTools = new SaxTools(); |
177 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_wellformed.xml")); |
178 |
1 |
assertTrue(xmlTools.isWellFormed()); |
179 |
|
} |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
181 |
1 |
@Test... |
182 |
|
void isNotWellFormed() { |
183 |
1 |
LOGGER.log("TEST CASE: isNotWellFormed", LogLevel.DEBUG); |
184 |
|
|
185 |
1 |
xmlTools = new SaxTools(); |
186 |
|
|
187 |
1 |
LOGGER.log("Case Sensitive call", LogLevel.DEBUG); |
188 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_non_wellformed_01.xml")); |
189 |
1 |
assertFalse(xmlTools.isWellFormed()); |
190 |
|
|
191 |
1 |
LOGGER.log("Missing close TAG call", LogLevel.DEBUG); |
192 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_non_wellformed_02.xml")); |
193 |
1 |
assertFalse(xmlTools.isWellFormed()); |
194 |
|
|
195 |
1 |
LOGGER.log("Mixted TAG order call", LogLevel.DEBUG); |
196 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_non_wellformed_03.xml")); |
197 |
1 |
assertFalse(xmlTools.isWellFormed()); |
198 |
|
|
199 |
1 |
LOGGER.log("no ROOT Element call", LogLevel.DEBUG); |
200 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_non_wellformed_04.xml")); |
201 |
1 |
assertFalse(xmlTools.isWellFormed()); |
202 |
|
|
203 |
1 |
LOGGER.log("character escape failure call", LogLevel.DEBUG); |
204 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_non_wellformed_05.xml")); |
205 |
1 |
assertFalse(xmlTools.isWellFormed()); |
206 |
|
} |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
208 |
1 |
@Test... |
209 |
|
void failPrettyPrint() { |
210 |
1 |
LOGGER.log("TEST CASE: failPrettyPrint", LogLevel.DEBUG); |
211 |
|
|
212 |
1 |
xmlTools = new SaxTools(); |
213 |
1 |
xmlTools.parseXmlFile(null); |
214 |
1 |
assertNull(xmlTools.prettyPrintXml()); |
215 |
|
} |
216 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
217 |
1 |
@Test... |
218 |
|
|
219 |
|
void prettyPrintXml() { |
220 |
1 |
LOGGER.log("TEST CASE: prettyPrint", LogLevel.DEBUG); |
221 |
|
|
222 |
1 |
String reference = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
223 |
|
+ "\n" |
224 |
|
+ "<!DOCTYPE EmployeeInfo SYSTEM \"simple.dtd\">\n" |
225 |
|
+ "<!-- THIs Is AN XML COMMENT -->\n" |
226 |
|
+ "<EmployeeInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" |
227 |
|
+ " xmlns:e=\"http://www.sample.com/EmployeeInfo\" \n" |
228 |
|
+ " xsi:schemaLocation=\"http://www.sample.com/EmployeeInfo simple.xsd\">\n" |
229 |
|
+ " <!-- THIs Is AN XML COMMENT -->\n" |
230 |
|
+ " <![CDATA[some stuff]]>\n" |
231 |
|
+ " <Employee EmployeeNumber=\"1\">\n" |
232 |
|
+ " <!-- THIs Is AN XML COMMENT -->\n" |
233 |
|
+ " <Name>Masashi Okamura</Name>\n" |
234 |
|
+ " <Department>Design Department</Department>\n" |
235 |
|
+ " <Telephone>03-1452-4567</Telephone>\n" |
236 |
|
+ " <Email>okamura@xmltr.co.jp\n" |
237 |
|
+ " <!-- THIs Is AN XML COMMENT --></Email>\n" |
238 |
|
+ " <Email>okamura@xmltr.co.jp</Email>\n" |
239 |
|
+ " <XXX>\n" |
240 |
|
+ " <ABC>03-1452-4567</ABC>\n" |
241 |
|
+ " <!-- THIs Is AN XML COMMENT -->\n" |
242 |
|
+ " </XXX>\n" |
243 |
|
+ " </Employee>\n" |
244 |
|
+ "</EmployeeInfo>\n"; |
245 |
|
|
246 |
1 |
xmlTools = new SaxTools(); |
247 |
1 |
String input = xmlTools.parseXmlFile(new File(DIRECTORY + "/test_pretty_print_01.xml")); |
248 |
1 |
String output = xmlTools.prettyPrintXml(); |
249 |
1 |
assertNotEquals(input, output); |
250 |
1 |
assertEquals(reference, output); |
251 |
|
} |
252 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1PASS
|
|
253 |
1 |
@Test... |
254 |
|
void prettyPrintXmlInlineDtd() { |
255 |
1 |
LOGGER.log("TEST CASE: prettyPrintXmlInlineDtd", LogLevel.DEBUG); |
256 |
|
|
257 |
1 |
try { |
258 |
1 |
xmlTools = new SaxTools(); |
259 |
1 |
String input = xmlTools.parseXmlFile(new File(DIRECTORY + "/test_pretty_print_02.xml")); |
260 |
1 |
assertTrue(xmlTools.isWellFormed()); |
261 |
|
|
262 |
1 |
String output = xmlTools.prettyPrintXml(); |
263 |
1 |
String reference = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
264 |
|
+ "\n" |
265 |
|
+ "<!DOCTYPE EmployeeInfo [\n" |
266 |
|
+ " <!ELEMENT EmployeeInfo (Employee)*>\n" |
267 |
|
+ " <!ELEMENT Employee (Name,Department,Telephone,Email)>\n" |
268 |
|
+ " <!ELEMENT Name (#PCDATA)>\n" |
269 |
|
+ " <!ELEMENT Department (#PCDATA)>\n" |
270 |
|
+ " <!ELEMENT Telephone (#PCDATA)>\n" |
271 |
|
+ " <!ELEMENT Email (#PCDATA)>\n" |
272 |
|
+ " <!ATTLIST Employee EmployeeNumber CDATA #REQUIRED>\n" |
273 |
|
+ "]>\n" |
274 |
|
+ "<EmployeeInfo>\n" |
275 |
|
+ " <![CDATA[some stuff]]>\n" |
276 |
|
+ " <Employee EmployeeNumber=\"105\">\n" |
277 |
|
+ " <Name>Masashi Okamura</Name>\n" |
278 |
|
+ " <Department>Design Department</Department>\n" |
279 |
|
+ " <Telephone>03-1452-4567</Telephone>\n" |
280 |
|
+ " <Email>okamura@xmltr.co.jp</Email>\n" |
281 |
|
+ " </Employee>\n" |
282 |
|
+ " <!-- THIs Is AN XML COMMENT -->\n" |
283 |
|
+ "</EmployeeInfo>\n"; |
284 |
|
|
285 |
1 |
assertNotEquals(input, output); |
286 |
1 |
assertEquals(reference, output); |
287 |
|
|
288 |
|
} catch (Exception ex) { |
289 |
0 |
LOGGER.catchException(ex); |
290 |
|
} |
291 |
|
} |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
293 |
1 |
@Test... |
294 |
|
void writeXmlToFile() throws Exception { |
295 |
1 |
LOGGER.log("TEST CASE: writeXmlToFile", LogLevel.DEBUG); |
296 |
|
|
297 |
1 |
xmlTools = new SaxTools(); |
298 |
1 |
String newFilePath = DIRECTORY + "/new_xml_file.xml"; |
299 |
1 |
String xmlFileContent = xmlTools.parseXmlFile(new File(DIRECTORY + "/test_wellformed.xml")); |
300 |
|
|
301 |
1 |
xmlTools.writeXmlToFile(xmlFileContent, newFilePath); |
302 |
|
|
303 |
1 |
File file = new File(newFilePath); |
304 |
1 |
assertTrue(file.exists()); |
305 |
1 |
file.delete(); |
306 |
1 |
assertFalse(file.exists()); |
307 |
|
} |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
309 |
1 |
@Test... |
310 |
|
void failWriteXmlToFile() throws Exception { |
311 |
1 |
LOGGER.log("TEST CASE: failWriteXmlToFile", LogLevel.DEBUG); |
312 |
|
|
313 |
1 |
xmlTools = new SaxTools(); |
314 |
1 |
assertThrows(Exception.class, () -> { |
315 |
1 |
xmlTools.writeXmlToFile("", null); |
316 |
|
}); |
317 |
|
} |
318 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
319 |
1 |
@Test... |
320 |
|
void noGrammar() { |
321 |
1 |
LOGGER.log("TEST CASE: noGrammar", LogLevel.DEBUG); |
322 |
|
|
323 |
1 |
xmlTools = new SaxTools(); |
324 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_no_grammar.xml")); |
325 |
1 |
assertTrue(xmlTools.isWellFormed()); |
326 |
1 |
assertFalse(xmlTools.isValid()); |
327 |
|
} |
328 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
329 |
1 |
@Test... |
330 |
|
void failValidation() { |
331 |
1 |
LOGGER.log("TEST CASE: failValidation", LogLevel.DEBUG); |
332 |
|
|
333 |
1 |
xmlTools = new SaxTools(); |
334 |
1 |
xmlTools.parseXmlFile(new File("")); |
335 |
1 |
assertFalse(xmlTools.isWellFormed()); |
336 |
1 |
assertFalse(xmlTools.isValid()); |
337 |
|
} |
338 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
339 |
1 |
@Test... |
340 |
|
void validInternalDtd() { |
341 |
1 |
LOGGER.log("TEST CASE: validInternalDtd", LogLevel.DEBUG); |
342 |
|
|
343 |
1 |
xmlTools = new SaxTools(); |
344 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_dtd_valid_internal.xml")); |
345 |
1 |
assertTrue(xmlTools.isWellFormed()); |
346 |
1 |
assertTrue(xmlTools.isValid()); |
347 |
|
} |
348 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
349 |
1 |
@Test... |
350 |
|
void invalidDtd() { |
351 |
1 |
LOGGER.log("TEST CASE: invalidDtd", LogLevel.DEBUG); |
352 |
|
|
353 |
1 |
xmlTools = new SaxTools(); |
354 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_dtd_invalid.xml")); |
355 |
1 |
assertTrue(xmlTools.isWellFormed()); |
356 |
1 |
assertFalse(xmlTools.isValid()); |
357 |
|
} |
358 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
359 |
1 |
@Test... |
360 |
|
void vValidDtd() { |
361 |
1 |
LOGGER.log("TEST CASE: invalidDtd", LogLevel.DEBUG); |
362 |
|
|
363 |
1 |
xmlTools = new SaxTools(); |
364 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_dtd_valid.xml")); |
365 |
1 |
assertTrue(xmlTools.isWellFormed()); |
366 |
1 |
assertTrue(xmlTools.isValid()); |
367 |
|
} |
368 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
369 |
1 |
@Test... |
370 |
|
void failSetSchema() { |
371 |
1 |
LOGGER.log("TEST CASE: failSetSchema", LogLevel.DEBUG); |
372 |
|
|
373 |
1 |
xmlTools = new SaxTools(); |
374 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_schema_valid.xml")); |
375 |
1 |
assertTrue(xmlTools.isWellFormed()); |
376 |
|
|
377 |
1 |
LOGGER.log("CASE 1: NULL", LogLevel.DEBUG); |
378 |
1 |
xmlTools.setSchemaFile(null); |
379 |
1 |
assertFalse(xmlTools.hasExternalSchemaFile()); |
380 |
|
|
381 |
1 |
LOGGER.log("CASE 2: Schema File not exist", LogLevel.DEBUG); |
382 |
1 |
xmlTools.setSchemaFile(new File(DIRECTORY + "/no_schema.xsd")); |
383 |
1 |
assertFalse(xmlTools.hasExternalSchemaFile()); |
384 |
|
} |
385 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
386 |
1 |
@Test... |
387 |
|
void setSchema() { |
388 |
1 |
LOGGER.log("TEST CASE: setSchema", LogLevel.DEBUG); |
389 |
|
|
390 |
1 |
xmlTools = new SaxTools(); |
391 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_schema_valid.xml")); |
392 |
1 |
assertFalse(xmlTools.hasExternalSchemaFile()); |
393 |
|
|
394 |
1 |
xmlTools.setSchemaFile(new File(DIRECTORY + "/simple.xsd")); |
395 |
1 |
assertTrue(xmlTools.hasExternalSchemaFile()); |
396 |
|
|
397 |
1 |
assertTrue(xmlTools.isWellFormed()); |
398 |
1 |
assertTrue(xmlTools.isValid()); |
399 |
|
} |
400 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
401 |
1 |
@Test... |
402 |
|
void resetExternalSchemaFile() { |
403 |
1 |
LOGGER.log("TEST CASE: resetExternalSchemaFile", LogLevel.DEBUG); |
404 |
|
|
405 |
1 |
xmlTools = new SaxTools(); |
406 |
1 |
assertFalse(xmlTools.hasExternalSchemaFile()); |
407 |
|
|
408 |
1 |
xmlTools.setSchemaFile(new File(DIRECTORY + "/simple.xsd")); |
409 |
1 |
assertTrue(xmlTools.hasExternalSchemaFile()); |
410 |
|
|
411 |
1 |
xmlTools.resetExternalSchema(); |
412 |
1 |
assertFalse(xmlTools.hasExternalSchemaFile()); |
413 |
|
} |
414 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
415 |
1 |
@Test... |
416 |
|
void invalidSchema() { |
417 |
1 |
LOGGER.log("TEST CASE: invalidSchema", LogLevel.DEBUG); |
418 |
|
|
419 |
1 |
xmlTools = new SaxTools(); |
420 |
1 |
xmlTools.parseXmlFile(new File(DIRECTORY + "/test_schema_invalid.xml")); |
421 |
1 |
xmlTools.setSchemaFile(new File(DIRECTORY + "/simple.xsd")); |
422 |
1 |
assertTrue(xmlTools.isWellFormed()); |
423 |
1 |
assertFalse(xmlTools.isValid()); |
424 |
|
} |
425 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
426 |
1 |
@Test... |
427 |
|
void validSchemaByWebResorce() { |
428 |
1 |
LOGGER.log("TEST CASE: validSchemaByWebResorce", LogLevel.DEBUG); |
429 |
|
|
430 |
1 |
xmlTools = new SaxTools(); |
431 |
|
|
432 |
1 |
String xmlFile = Constraints.SYSTEM_APP_DIR |
433 |
|
+ "/target/test-classes/org/europa/together/xml/spring.xml"; |
434 |
1 |
xmlTools.parseXmlFile(new File(xmlFile)); |
435 |
|
|
436 |
1 |
xmlTools.prettyPrintXml(); |
437 |
|
|
438 |
1 |
assertTrue(xmlTools.isWellFormed()); |
439 |
1 |
assertTrue(xmlTools.isValid()); |
440 |
|
} |
441 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
442 |
1 |
@Test... |
443 |
|
void xsltTransformation() { |
444 |
1 |
LOGGER.log("TEST CASE: xsltTransformation", LogLevel.DEBUG); |
445 |
|
|
446 |
1 |
xmlTools = new SaxTools(); |
447 |
1 |
String xml = DIRECTORY + "/xml_datasource.xml"; |
448 |
1 |
String xslt = DIRECTORY + "/template.xslt"; |
449 |
1 |
String transformed = xmlTools.transformXslt(new File(xml), new File(xslt)); |
450 |
|
|
451 |
|
|
452 |
1 |
String out = xmlTools.shrinkContent(transformed); |
453 |
|
|
454 |
1 |
LOGGER.log(">>> XSLT; \n " + out, LogLevel.DEBUG); |
455 |
1 |
assertEquals(857, out.length()); |
456 |
|
} |
457 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
458 |
1 |
@Test... |
459 |
|
void failTransformation() { |
460 |
1 |
LOGGER.log("TEST CASE: failXsltTransformation", LogLevel.DEBUG); |
461 |
|
|
462 |
1 |
xmlTools = new SaxTools(); |
463 |
1 |
assertEquals("", xmlTools.transformXslt(null, null)); |
464 |
|
} |
465 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
466 |
1 |
@Test... |
467 |
|
void shrinkXml() throws Exception { |
468 |
1 |
LOGGER.log("TEST CASE: shrinkXml", LogLevel.DEBUG); |
469 |
|
|
470 |
1 |
String file = Constraints.SYSTEM_APP_DIR |
471 |
|
+ "/target/test-classes/org/europa/together/xml/shrink.xml"; |
472 |
1 |
String orgin = FileUtils.readFileStream(new File(file)); |
473 |
|
|
474 |
1 |
xmlTools = new SaxTools(); |
475 |
1 |
String transform = xmlTools.shrinkContent(orgin); |
476 |
|
|
477 |
1 |
assertNotEquals(orgin, transform); |
478 |
1 |
xmlTools.parseXmlString(transform); |
479 |
1 |
assertTrue(xmlTools.isWellFormed()); |
480 |
|
} |
481 |
|
} |