1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.spf4j.test.log;
17
18 import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableMap;
20 import java.util.Collections;
21 import java.util.List;
22 import org.junit.Assert;
23 import org.junit.Test;
24 import org.spf4j.log.Level;
25
26
27
28
29 public class LogConfigImplTest {
30
31
32 @Test
33 public void testLogConfigImpl() {
34 LogPrinter h1 = new LogPrinter(Level.INFO);
35 LogPrinter h2 = new LogPrinter(Level.DEBUG);
36 LogPrinter h3 = new LogPrinter(Level.DEBUG);
37 LogPrinter h4 = new LogPrinter(Level.ERROR);
38 LogPrinter h5 = new LogPrinter(Level.DEBUG);
39 LogConfigImpl cfg = new LogConfigImpl(ImmutableList.of(h1),
40 ImmutableMap.of("a.b", Collections.singletonList(h2),
41 "a.c", Collections.singletonList(h3),
42 "c.d", Collections.singletonList(h4)));
43 LogConsumer handler = cfg.getLogConsumer("a", Level.DEBUG);
44 Assert.assertNull(handler);
45 List<LogHandler> handlers = ((CompositeLogHandler) cfg.getLogConsumer("a", Level.INFO)).logHandlers;
46 Assert.assertSame(h1, handlers.get(0));
47 handlers = ((CompositeLogHandler) cfg.getLogConsumer("a.b", Level.INFO)).logHandlers;
48 Assert.assertSame(h2, handlers.get(0));
49 Assert.assertSame(h1, handlers.get(1));
50 cfg = (LogConfigImpl) cfg.add("a", h5);
51 handlers = ((CompositeLogHandler) cfg.getLogConsumer("a.b", Level.INFO)).logHandlers;
52 Assert.assertSame(h2, handlers.get(0));
53 Assert.assertSame(h5, handlers.get(1));
54 Assert.assertSame(h1, handlers.get(2));
55 cfg = cfg.remove("a", h5);
56 handlers = ((CompositeLogHandler) cfg.getLogConsumer("a.b", Level.INFO)).logHandlers;
57 Assert.assertSame(h2, handlers.get(0));
58 Assert.assertSame(h1, handlers.get(1));
59 }
60
61 }