001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.joran.event;
015
016import static org.junit.Assert.assertEquals;
017import static org.junit.Assert.assertTrue;
018
019import java.util.HashMap;
020
021import org.junit.Test;
022
023import ch.qos.logback.core.Context;
024import ch.qos.logback.core.ContextBase;
025import ch.qos.logback.core.joran.TrivialConfigurator;
026import ch.qos.logback.core.joran.action.Action;
027import ch.qos.logback.core.joran.spi.ElementSelector;
028import ch.qos.logback.core.joran.spi.JoranException;
029import ch.qos.logback.core.testUtil.CoreTestConstants;
030
031public class InPlayFireTest {
032
033    Context context = new ContextBase();
034    HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>();
035
036    @Test
037    public void testBasic() throws JoranException {
038        ListenAction listenAction = new ListenAction();
039
040        rulesMap.put(new ElementSelector("fire"), listenAction);
041        TrivialConfigurator gc = new TrivialConfigurator(rulesMap);
042
043        gc.setContext(context);
044        gc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/fire1.xml");
045
046        // for(SaxEvent se: listenAction.getSeList()) {
047        // System.out.println(se);
048        // }
049        assertEquals(5, listenAction.getSeList().size());
050        assertTrue(listenAction.getSeList().get(0) instanceof StartEvent);
051        assertTrue(listenAction.getSeList().get(1) instanceof StartEvent);
052        assertTrue(listenAction.getSeList().get(2) instanceof BodyEvent);
053        assertTrue(listenAction.getSeList().get(3) instanceof EndEvent);
054    }
055
056    @Test
057    public void testReplay() throws JoranException {
058        ListenAction listenAction = new ListenAction();
059
060        rulesMap.put(new ElementSelector("fire"), listenAction);
061        TrivialConfigurator gc = new TrivialConfigurator(rulesMap);
062
063        gc.setContext(context);
064        gc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/fire1.xml");
065
066        // for(SaxEvent se: listenAction.getSeList()) {
067        // System.out.println(se);
068        // }
069        assertEquals(5, listenAction.getSeList().size());
070        assertTrue(listenAction.getSeList().get(0) instanceof StartEvent);
071        assertTrue(listenAction.getSeList().get(1) instanceof StartEvent);
072        assertTrue(listenAction.getSeList().get(2) instanceof BodyEvent);
073        assertTrue(listenAction.getSeList().get(3) instanceof EndEvent);
074    }
075
076}