|
1 | 1 | package net.lecousin.framework.core.tests.log;
|
2 | 2 |
|
3 | 3 | import java.io.File;
|
| 4 | +import java.io.InputStream; |
| 5 | +import java.net.MalformedURLException; |
| 6 | +import java.net.URL; |
4 | 7 | import java.nio.charset.StandardCharsets;
|
5 | 8 | import java.util.Calendar;
|
6 | 9 |
|
7 |
| -import org.junit.Assert; |
8 |
| -import org.junit.Test; |
9 |
| - |
10 | 10 | import net.lecousin.framework.application.Application;
|
11 | 11 | import net.lecousin.framework.application.LCCore;
|
12 | 12 | import net.lecousin.framework.concurrent.Task;
|
|
26 | 26 | import net.lecousin.framework.log.appenders.RollingFileAppender;
|
27 | 27 | import net.lecousin.framework.util.StringUtil;
|
28 | 28 |
|
| 29 | +import org.junit.Assert; |
| 30 | +import org.junit.Test; |
| 31 | + |
29 | 32 | public class TestLoggers extends LCCoreAbstractTest {
|
30 | 33 |
|
31 | 34 | @Test
|
@@ -102,7 +105,7 @@ public void test() throws Exception {
|
102 | 105 | expected.append(' ');
|
103 | 106 | expected.append("test");
|
104 | 107 | expected.append(' ');
|
105 |
| - expected.append(79); |
| 108 | + expected.append(82); |
106 | 109 | expected.append(' ');
|
107 | 110 | expected.append("TestLoggers.java");
|
108 | 111 | expected.append(' ');
|
@@ -193,4 +196,38 @@ private static void produceLogs(Logger log) {
|
193 | 196 | log.trace("this is trace");
|
194 | 197 | }
|
195 | 198 |
|
| 199 | + @Test |
| 200 | + public void testInvalidConfig() throws MalformedURLException { |
| 201 | + testInvalidConfig(""); |
| 202 | + testInvalidConfig("<!-- -->"); |
| 203 | + testInvalidConfig("<root></root>"); |
| 204 | + testInvalidConfig("<LoggingConfiguration><unexpected/></LoggingConfiguration>"); |
| 205 | + testInvalidConfig("<LoggingConfiguration><Appender>"); |
| 206 | + testInvalidConfig("<LoggingConfiguration><Appender></Appender></LoggingConfiguration>"); |
| 207 | + testInvalidConfig("<LoggingConfiguration><Appender class=\"hello\"></Appender></LoggingConfiguration>"); |
| 208 | + testInvalidConfig("<LoggingConfiguration><Appender name=\"hello\"></Appender></LoggingConfiguration>"); |
| 209 | + testInvalidConfig("<LoggingConfiguration><Appender name=\"hello\" class=\"" + getClass().getName() + "\"></Appender></LoggingConfiguration>"); |
| 210 | + testInvalidConfig("<LoggingConfiguration><Logger>"); |
| 211 | + testInvalidConfig("<LoggingConfiguration><Logger toto=\"1\"></Logger></LoggingConfiguration>"); |
| 212 | + testInvalidConfig("<LoggingConfiguration><Logger level=\"UNKNOWN\"></Logger></LoggingConfiguration>"); |
| 213 | + testInvalidConfig("<LoggingConfiguration><Logger name=\"test\" level=\"WARN\"></Logger></LoggingConfiguration>"); |
| 214 | + testInvalidConfig("<LoggingConfiguration><Logger name=\"test\" level=\"WARN\" appender=\"unknown\"></Logger></LoggingConfiguration>"); |
| 215 | + testInvalidConfig("<LoggingConfiguration><Logger name=\"test\" level=\"WARN\" appender=\"console\"><!----><unexpected/></Logger></LoggingConfiguration>"); |
| 216 | + testInvalidConfig("<LoggingConfiguration><Default>"); |
| 217 | + testInvalidConfig("<LoggingConfiguration><Default></Default></LoggingConfiguration>"); |
| 218 | + testInvalidConfig("<LoggingConfiguration><Default toto=\"1\"></Default></LoggingConfiguration>"); |
| 219 | + testInvalidConfig("<LoggingConfiguration><Default appender=\"unknown\"></Default></LoggingConfiguration>"); |
| 220 | + testInvalidConfig("<LoggingConfiguration><Default appender=\"console\"><!----><unexpected/></Default></LoggingConfiguration>"); |
| 221 | + } |
| 222 | + |
| 223 | + private static void testInvalidConfig(String config) throws MalformedURLException { |
| 224 | + URL url = new URL("string://UTF-8/" + config); |
| 225 | + try (InputStream in = url.openStream()) { |
| 226 | + LCCore.getApplication().getLoggerFactory().configure(in); |
| 227 | + throw new AssertionError("Error expected to configure loggers: " + config); |
| 228 | + } catch (Exception e) { |
| 229 | + // ok |
| 230 | + } |
| 231 | + } |
| 232 | + |
196 | 233 | }
|
0 commit comments