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