ceki        2003/08/25 09:14:32

  Added:       tests/src/java/org/apache/joran JoranParserTestCase.java
                        SimpleStoreTestCase.java PatternTestCase.java
  Log:
  
  Simple test for Joran basics
  
  Revision  Changes    Path
  1.1                  
jakarta-log4j/tests/src/java/org/apache/joran/JoranParserTestCase.java
  
  Index: JoranParserTestCase.java
  ===================================================================
  /*
   * Created on Aug 24, 2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.joran;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  
  import org.w3c.dom.Document;
  
  import junit.framework.TestCase;
  
  /**
   * @author ceki
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class JoranParserTestCase extends TestCase {
  
        /**
         * Constructor for JoranParserTestCase.
         * @param name
         */
        public JoranParserTestCase(String name) {
                super(name);
        }
  
        /*
         * @see TestCase#setUp()
         */
        protected void setUp() throws Exception {
                super.setUp();
        }
  
        /*
         * @see TestCase#tearDown()
         */
        protected void tearDown() throws Exception {
                super.tearDown();
        }
  
    public void testLoop() throws Exception {
        System.out.println("Starting testLoop");
  
         DocumentBuilderFactory dbf = null;
  
     dbf = DocumentBuilderFactory.newInstance();
  
     DocumentBuilder docBuilder = dbf.newDocumentBuilder();
           
     //inputSource.setSystemId("dummy://log4j.dtd");
  
           Document doc = docBuilder.parse("file:input/joran/parser1.xml");
           
           JoranParser jp = new JoranParser(null);
           jp.parse(doc);
    }
  
  
  
  }
  
  
  
  1.1                  
jakarta-log4j/tests/src/java/org/apache/joran/SimpleStoreTestCase.java
  
  Index: SimpleStoreTestCase.java
  ===================================================================
  /*
   * Created on Aug 25, 2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.joran;
  
  import java.util.List;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  
  import junit.framework.TestCase;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  /**
   * @author ceki
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class SimpleStoreTestCase extends TestCase {
  
        /**
         * Constructor for SimpleStoreTestCase.
         * @param name
         */
        public SimpleStoreTestCase(String name) {
                super(name);
        }
  
        /*
         * @see TestCase#setUp()
         */
        protected void setUp() throws Exception {
                super.setUp();
        }
  
        /*
         * @see TestCase#tearDown()
         */
        protected void tearDown() throws Exception {
                super.tearDown();
        }
  
        public void test1() throws Exception {
  
                //Document doc = getW3Document("file:input/joran/parser1.xml");
  
                SimpleRuleStore srs = new SimpleRuleStore();
                srs.addRule(new Pattern("a/b"), new XAction());
  
                List r = srs.matchActions(new Pattern("a/b"));
                assertNotNull(r);
                assertEquals(1, r.size());
                if (!(r.get(0) instanceof XAction)) {
                        fail("Wring type");
                }
  
                srs = new SimpleRuleStore();
                srs.addRule(new Pattern("a/b"), new XAction());
                srs.addRule(new Pattern("a/b"), new YAction());
  
                r = srs.matchActions(new Pattern("a/b"));
                assertNotNull(r);
                assertEquals(2, r.size());
                if (!(r.get(0) instanceof XAction)) {
                        fail("Wrong type");
                }
                if (!(r.get(1) instanceof YAction)) {
                        fail("Wrong type");
                }
  
                //jp.parse(doc);
        }
  
        public void test2() throws Exception {
                SimpleRuleStore srs = new SimpleRuleStore();
                srs.addRule(new Pattern("*/b"), new XAction());
                List r = srs.matchActions(new Pattern("a/b"));
                assertNotNull(r);
                //System.out.println(r);
                assertEquals(1, r.size());
                if (!(r.get(0) instanceof XAction)) {
                        fail("Wring type");
                }
        }
  
        public void test3() throws Exception {
                SimpleRuleStore srs = new SimpleRuleStore();
                srs.addRule(new Pattern("*/b"), new XAction());
                srs.addRule(new Pattern("*/a/b"), new YAction());
  
                List r = srs.matchActions(new Pattern("a/b"));
                assertNotNull(r);
                //System.out.println("restulg list is: "+r);
                assertEquals(1, r.size());
                if (!(r.get(0) instanceof YAction)) {
                        fail("Wring type");
                }
        }
  
        public void test4() throws Exception {
                SimpleRuleStore srs = new SimpleRuleStore();
                srs.addRule(new Pattern("*/b"), new XAction());
                srs.addRule(new Pattern("*/a/b"), new YAction());
                srs.addRule(new Pattern("a/b"), new ZAction());
  
                List r = srs.matchActions(new Pattern("a/b"));
                assertNotNull(r);
                //System.out.println("restulg list is: "+r);
                assertEquals(1, r.size());
                if (!(r.get(0) instanceof ZAction)) {
                        fail("Wring type");
                }
        }
  
        Document getW3Document(String file) throws Exception {
                DocumentBuilderFactory dbf = null;
                dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = dbf.newDocumentBuilder();
                //inputSource.setSystemId("dummy://log4j.dtd");
                return docBuilder.parse(file);
        }
  
        class XAction extends Action {
                public void begin(Element e) {
                }
                public void end(Element e) {
                }
                public void finish() {
                }
        }
  
        class YAction extends Action {
                public void begin(Element e) {
                }
                public void end(Element e) {
                }
                public void finish() {
                }
        }
        class ZAction extends Action {
                public void begin(Element e) {
                }
                public void end(Element e) {
                }
                public void finish() {
                }
        }
  
  }
  
  
  1.1                  
jakarta-log4j/tests/src/java/org/apache/joran/PatternTestCase.java
  
  Index: PatternTestCase.java
  ===================================================================
  /*
   * Created on Aug 25, 2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.joran;
  
  import junit.framework.TestCase;
  
  /**
   * @author ceki
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class PatternTestCase extends TestCase {
  
        /**
         * Constructor for PatternTestCase.
         * @param name
         */
        public PatternTestCase(String name) {
                super(name);
        }
  
        /*
         * @see TestCase#setUp()
         */
        protected void setUp() throws Exception {
                super.setUp();
        }
  
        /*
         * @see TestCase#tearDown()
         */
        protected void tearDown() throws Exception {
                super.tearDown();
        }
  
        public void test1() {
                Pattern p = new Pattern("a");
                assertEquals(1, p.size());
                assertEquals("a", p.get(0));
        }
  
        public void test2() {
                Pattern p = new Pattern("a/b");
                assertEquals(2, p.size());
                assertEquals("a", p.get(0));
                assertEquals("b", p.get(1));
        }
  
        public void test3() {
                Pattern p = new Pattern("a123/b1234/cvvsdf");
                assertEquals(3, p.size());
                assertEquals("a123", p.get(0));
                assertEquals("b1234", p.get(1));
                assertEquals("cvvsdf", p.get(2));
        }
        
        public void test4() {
                Pattern p = new Pattern("/a123/b1234/cvvsdf");
                assertEquals(3, p.size());
                assertEquals("a123", p.get(0));
                assertEquals("b1234", p.get(1));
                assertEquals("cvvsdf", p.get(2));
        }
        
  
        public void test5() {
                Pattern p = new Pattern("//a");
                assertEquals(1, p.size());
                assertEquals("a", p.get(0));
        }
        
        public void test6() {
                        Pattern p = new Pattern("//a//b");
                        assertEquals(2, p.size());
                        assertEquals("a", p.get(0));
                assertEquals("b", p.get(1));
                }
        
        
  
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to