View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.joran.event;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertTrue;
18  
19  import java.util.HashMap;
20  
21  import org.junit.Test;
22  
23  import ch.qos.logback.core.Context;
24  import ch.qos.logback.core.ContextBase;
25  import ch.qos.logback.core.joran.TrivialConfigurator;
26  import ch.qos.logback.core.joran.action.Action;
27  import ch.qos.logback.core.joran.spi.ElementSelector;
28  import ch.qos.logback.core.joran.spi.JoranException;
29  import ch.qos.logback.core.testUtil.CoreTestConstants;
30  
31  public class InPlayFireTest {
32  
33      Context context = new ContextBase();
34      HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>();
35  
36      @Test
37      public void testBasic() throws JoranException {
38          ListenAction listenAction = new ListenAction();
39  
40          rulesMap.put(new ElementSelector("fire"), listenAction);
41          TrivialConfigurator gc = new TrivialConfigurator(rulesMap);
42  
43          gc.setContext(context);
44          gc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/fire1.xml");
45  
46          // for(SaxEvent se: listenAction.getSeList()) {
47          // System.out.println(se);
48          // }
49          assertEquals(5, listenAction.getSeList().size());
50          assertTrue(listenAction.getSeList().get(0) instanceof StartEvent);
51          assertTrue(listenAction.getSeList().get(1) instanceof StartEvent);
52          assertTrue(listenAction.getSeList().get(2) instanceof BodyEvent);
53          assertTrue(listenAction.getSeList().get(3) instanceof EndEvent);
54      }
55  
56      @Test
57      public void testReplay() throws JoranException {
58          ListenAction listenAction = new ListenAction();
59  
60          rulesMap.put(new ElementSelector("fire"), listenAction);
61          TrivialConfigurator gc = new TrivialConfigurator(rulesMap);
62  
63          gc.setContext(context);
64          gc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/fire1.xml");
65  
66          // for(SaxEvent se: listenAction.getSeList()) {
67          // System.out.println(se);
68          // }
69          assertEquals(5, listenAction.getSeList().size());
70          assertTrue(listenAction.getSeList().get(0) instanceof StartEvent);
71          assertTrue(listenAction.getSeList().get(1) instanceof StartEvent);
72          assertTrue(listenAction.getSeList().get(2) instanceof BodyEvent);
73          assertTrue(listenAction.getSeList().get(3) instanceof EndEvent);
74      }
75  
76  }