You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2004/04/07 23:15:33 UTC

cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester TestOptionDigestion.java

rdonkin     2004/04/07 14:15:33

  Added:       betwixt/src/test/org/apache/commons/betwixt/digester
                        TestOptionDigestion.java
  Log:
  Finely grained tests for option digestion rule
  
  Revision  Changes    Path
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestOptionDigestion.java
  
  Index: TestOptionDigestion.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
   
  package org.apache.commons.betwixt.digester;
  
  import org.apache.commons.betwixt.ElementDescriptor;
  import org.apache.commons.digester.Digester;
  import org.apache.commons.digester.Rule;
  import org.xml.sax.helpers.AttributesImpl;
  
  import junit.framework.TestCase;
  
  
  
  /**
   * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
   * @version $Revision: 1.1 $
   */
  public class TestOptionDigestion extends TestCase {
  
      private Digester digester;
      private OptionRule optionRule;
      private Rule nameRule;
      private Rule valueRule;
      private ElementDescriptor elementDescriptor;
  
      protected void setUp() throws Exception {
          super.setUp();
          elementDescriptor = new ElementDescriptor();
          digester = new Digester();
          digester.push(elementDescriptor);
          optionRule = new OptionRule();
          optionRule.setDigester(digester);
          nameRule = optionRule.getNameRule();
          valueRule = optionRule.getValueRule();
      }
  
      public void testGoodDigestion() throws Exception {
  
           optionRule.begin("","option", new AttributesImpl());
           nameRule.begin("","name", new AttributesImpl());
           nameRule.body("", "name", "one");
           nameRule.end("","name");
           valueRule.begin("","value", new AttributesImpl());
           valueRule.body("", "value", "ONE");
           valueRule.end("","value");
           optionRule.end("","option");
           
           assertEquals("Option set", "ONE", elementDescriptor.getOptions().getValue("one"));
      }
  
  
      public void testTwoDigestions() throws Exception {
  
           optionRule.begin("","option", new AttributesImpl());
           nameRule.begin("","name", new AttributesImpl());
           nameRule.body("", "name", "one");
           nameRule.end("","name");
           valueRule.begin("","value", new AttributesImpl());
           valueRule.body("", "value", "ONE");
           valueRule.end("","value");
           optionRule.end("","option");
           optionRule.begin("","option", new AttributesImpl());
           valueRule.begin("","value", new AttributesImpl());
           valueRule.body("", "value", "TWO");
           valueRule.end("","value");
           nameRule.begin("","name", new AttributesImpl());
           nameRule.body("", "name", "two");
           nameRule.end("","name");
           optionRule.end("","option");
           
           assertEquals("Option set", "ONE", elementDescriptor.getOptions().getValue("one"));
           assertEquals("Option set", "TWO", elementDescriptor.getOptions().getValue("two"));
           
      }
      
  
      public void testGracefulBadMapping() throws Exception {
  
           optionRule.begin("","option", new AttributesImpl());
           nameRule.begin("","name", new AttributesImpl());
           nameRule.body("", "name", "one");
           nameRule.end("","name");
           optionRule.end("","option");
           optionRule.begin("","option", new AttributesImpl());
           valueRule.begin("","value", new AttributesImpl());
           valueRule.body("", "value", "ONE");
           valueRule.end("","value");
           optionRule.end("","option");
           optionRule.begin("","option", new AttributesImpl());
           nameRule.begin("","name", new AttributesImpl());
           nameRule.body("", "name", "two");
           nameRule.end("","name");
           valueRule.begin("","value", new AttributesImpl());
           valueRule.body("", "value", "TWO");
           valueRule.end("","value");
           optionRule.end("","option");
           
           assertEquals("Option set", null, elementDescriptor.getOptions().getValue("one"));
           assertEquals("Option set", "TWO", elementDescriptor.getOptions().getValue("two"));
           
      } 
  }
  
  
  

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