logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: jakarta-log4j/tests/src/java/org/apache/joran JoranParserTest.java
Date Tue, 23 Sep 2003 19:45:58 GMT
ceki        2003/09/23 12:45:58

  Modified:    tests/src/java/org/apache/joran JoranParserTest.java
  Added:       tests/input/joran newRule1.xml
               tests/src/java/org/apache/joran/action HelloAction.java
  Log:
  
  Testing parsing of new rules
  
  Revision  Changes    Path
  1.1                  jakarta-log4j/tests/input/joran/newRule1.xml
  
  Index: newRule1.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE log4j:configuration>
  
  <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  
    <newRule pattern="log4j:configuration/hello" actionClass="org.apache.joran.action.HelloAction"></newRule>
  
    <hello name="John Doe"></hello>
    
  </log4j:configuration>
  
  
  1.1                  jakarta-log4j/tests/src/java/org/apache/joran/action/HelloAction.java
  
  Index: HelloAction.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.joran.action;
  
  import org.apache.joran.ExecutionContext;
  import org.apache.log4j.Layout;
  import org.apache.log4j.Logger;
  
  import org.w3c.dom.Element;
  
  
  public class HelloAction extends Action {
    static final Logger logger = Logger.getLogger(HelloAction.class);
    Layout layout;
  
  
    public HelloAction() {
    }
    /**
     * Instantiates an layout of the given class and sets its name.
     *
     */
    public void begin(ExecutionContext ec, Element element) {
  
      String name = element.getAttribute("name");
      String str = "Hello "+name+".";
      ec.getObjectMap().put("hello", str);
    }
  
    /**
     * Once the children elements are also parsed, now is the time to activate
     * the appender options.
     */
    public void end(ExecutionContext ec, Element e) {
    }
  
    public void finish(ExecutionContext ec) {
    }
  }
  
  
  
  1.6       +29 -1     jakarta-log4j/tests/src/java/org/apache/joran/JoranParserTest.java
  
  Index: JoranParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/joran/JoranParserTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JoranParserTest.java	23 Sep 2003 18:52:51 -0000	1.5
  +++ JoranParserTest.java	23 Sep 2003 19:45:58 -0000	1.6
  @@ -65,6 +65,7 @@
   import org.apache.joran.action.LevelAction;
   import org.apache.joran.action.LoggerAction;
   import org.apache.joran.action.NestComponentIA;
  +import org.apache.joran.action.NewRuleAction;
   import org.apache.joran.action.ParamAction;
   import org.apache.joran.action.RootLoggerAction;
   
  @@ -229,7 +230,7 @@
       jp.parse(doc);
     }
   
  -  public void testNewConversionWord() throws Exception {
  +  public void xtestNewConversionWord() throws Exception {
       logger.debug("Starting testNewConversionWord");
   
       DocumentBuilderFactory dbf = null;
  @@ -265,5 +266,32 @@
       Appender appender = (Appender) appenderBag.get("A1");
       PatternLayout pl = (PatternLayout) appender.getLayout();
       assertEquals("org.apache.log4j.toto", pl.getRuleRegistry().get("toto"));
  +  }
  +  
  +  public void testNewRule1() throws Exception {
  +    logger.debug("Starting testNewConversionWord");
  +
  +    DocumentBuilderFactory dbf = null;
  +
  +    dbf = DocumentBuilderFactory.newInstance();
  +
  +    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
  +
  +    //inputSource.setSystemId("dummy://log4j.dtd");
  +    Document doc = docBuilder.parse("file:input/joran/newRule1.xml");
  +    RuleStore rs = new SimpleRuleStore();
  +    rs.addRule(
  +      new Pattern("log4j:configuration/newRule"),
  +      new NewRuleAction());
  +
  +    JoranParser jp = new JoranParser(rs);
  +    ExecutionContext ec = jp.getExecutionContext();
  +    HashMap omap = ec.getObjectMap();
  +    omap.put(ActionConst.APPENDER_BAG, new HashMap());
  +    ec.pushObject(LogManager.getLoggerRepository());
  +    jp.parse(doc);
  +
  +    String str = (String) ec.getObjectMap().get("hello");
  +    assertEquals("Hello John Doe.", str);
     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Mime
View raw message