1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.configuration2;
19
20 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertSame;
23
24 import org.apache.commons.configuration2.ex.ConfigurationException;
25 import org.apache.commons.configuration2.io.ConfigurationLogger;
26 import org.apache.commons.configuration2.io.FileHandler;
27 import org.apache.commons.configuration2.resolver.CatalogResolver;
28 import org.junit.jupiter.api.AfterEach;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31
32
33
34
35 public class TestCatalogResolver {
36 private static final String CATALOG_FILES = "catalog.xml";
37 private static final String PUBLIC_FILE = "testResolver.xml";
38 private static final String REWRITE_SYSTEM_FILE = "test.properties.xml";
39 private static final String REWRITE_SCHEMA_FILE = "sample.xml";
40
41 private CatalogResolver resolver;
42 private XMLConfiguration config;
43
44
45
46
47
48
49
50 private void load(final String fileName) throws ConfigurationException {
51 final FileHandler handler = new FileHandler(config);
52 handler.load(fileName);
53 }
54
55 @BeforeEach
56 public void setUp() throws Exception {
57 resolver = new CatalogResolver();
58 resolver.setCatalogFiles(CATALOG_FILES);
59
60 config = new XMLConfiguration();
61 config.setEntityResolver(resolver);
62 }
63
64 @AfterEach
65 public void tearDown() throws Exception {
66 resolver = null;
67 config = null;
68 }
69
70 @Test
71 public void testDebug() throws Exception {
72 resolver.setDebug(true);
73
74
75 }
76
77 @Test
78 public void testLogger() throws Exception {
79 final ConfigurationLogger log = new ConfigurationLogger(this.getClass());
80 resolver.setLogger(log);
81 assertNotNull(resolver.getLogger());
82 assertSame(log, resolver.getLogger());
83 }
84
85 @Test
86 public void testPublic() {
87 assertDoesNotThrow(() -> load(PUBLIC_FILE));
88 }
89
90 @Test
91 public void testRewriteSystem() {
92 assertDoesNotThrow(() -> load(REWRITE_SYSTEM_FILE));
93 }
94
95
96
97
98 @Test
99 public void testSchemaResolver() {
100 assertDoesNotThrow(() -> load(REWRITE_SCHEMA_FILE));
101 }
102 }