rwaldhoff    2002/10/22 09:03:05

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/core
                        DefaultTag.java
               jelly/src/test/org/apache/commons/jelly/core
                        TestSwitchTag.java testSwitchTag.jelly
  Log:
  add additional tests for the switch family of tags
  
  Revision  Changes    Path
  1.2       +7 -6      
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/DefaultTag.java
  
  Index: DefaultTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/DefaultTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultTag.java   22 Oct 2002 15:13:43 -0000      1.1
  +++ DefaultTag.java   22 Oct 2002 16:03:05 -0000      1.2
  @@ -95,10 +95,11 @@
           SwitchTag tag = (SwitchTag)findAncestorWithClass(SwitchTag.class);
           if(null == tag) {
               throw new JellyException("This tag must be enclosed inside a <switch> 
tag" );
  -        }
  +        }        
           if(tag.hasDefaultBeenEncountered()) {
               throw new JellyException("Only one <default> tag is allowed per 
<switch>.");
           }
  +        tag.defaultEncountered();
           if(tag.isFallingThru() || (!tag.hasSomeCaseMatched())) {
               tag.caseMatched();
               tag.setFallingThru(fallThru);
  
  
  
  1.2       +55 -8     
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestSwitchTag.java
  
  Index: TestSwitchTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/TestSwitchTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestSwitchTag.java        22 Oct 2002 15:13:43 -0000      1.1
  +++ TestSwitchTag.java        22 Oct 2002 16:03:05 -0000      1.2
  @@ -61,17 +61,16 @@
    */
   package org.apache.commons.jelly.core;
   
  -import java.io.File;
   import java.net.URL;
   
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  -import junit.textui.TestRunner;
   
   import org.apache.commons.jelly.Jelly;
   import org.apache.commons.jelly.JellyContext;
  +import org.apache.commons.jelly.JellyException;
  +import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.Script;
  -import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.XMLOutput;
   
   /**
  @@ -180,6 +179,54 @@
                      context.getVariable("a.default"));
       }
   
  +    public void testCaseWithoutSwitch() throws Exception {
  +        setUpScript("testSwitchTag.jelly");
  +        Script script = jelly.compileScript();
  +        context.setVariable("case.without.switch",new Boolean(true));
  +        try {
  +            script.run(context,xmlOutput);
  +            fail("Expected JellyException");
  +        } catch(JellyException e) {
  +            // expected
  +        }
  +    }
  +
  +    public void testDefaultWithoutSwitch() throws Exception {
  +        setUpScript("testSwitchTag.jelly");
  +        Script script = jelly.compileScript();
  +        context.setVariable("default.without.switch",new Boolean(true));
  +        try {
  +            script.run(context,xmlOutput);
  +            fail("Expected JellyException");
  +        } catch(JellyException e) {
  +            // expected
  +        }
  +    }
  +    
  +    public void testCaseWithoutValue() throws Exception {
  +        setUpScript("testSwitchTag.jelly");
  +        Script script = jelly.compileScript();
  +        context.setVariable("case.without.value",new Boolean(true));
  +        try {
  +            script.run(context,xmlOutput);
  +            fail("Expected MissingAttributeException");
  +        } catch(MissingAttributeException e) {
  +            // expected
  +        }
  +    }
  +    
  +    public void testMultipleDefaults() throws Exception {
  +        setUpScript("testSwitchTag.jelly");
  +        Script script = jelly.compileScript();
  +        context.setVariable("multiple.defaults",new Boolean(true));
  +        try {
  +            script.run(context,xmlOutput);
  +            fail("Expected JellyException");
  +        } catch(JellyException e) {
  +            // expected
  +        }
  +    }
  +    
       private Jelly jelly = null;
       private JellyContext context = null;
       private XMLOutput xmlOutput = null;
  
  
  
  1.2       +30 -0     
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/testSwitchTag.jelly
  
  Index: testSwitchTag.jelly
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/core/testSwitchTag.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testSwitchTag.jelly       22 Oct 2002 15:13:43 -0000      1.1
  +++ testSwitchTag.jelly       22 Oct 2002 16:03:05 -0000      1.2
  @@ -16,4 +16,34 @@
               <j:set var="a.default" value="true"/>
           </j:default>
       </j:switch>
  +    
  +    <j:if test="${case.without.switch}">
  +        <j:case value="this tag should cause an exception"/>
  +    </j:if>
  +    
  +    <j:if test="${default.without.switch}">
  +        <j:default/>
  +    </j:if>
  +
  +    <j:if test="${case.without.value}">
  +        <j:switch on="foo">
  +            <j:case>
  +                <!-- this should cause an exception (or even better, fail on 
validation) -->
  +            </j:case>
  +        </j:switch>
  +    </j:if>
  +    
  +    <j:if test="${multiple.defaults}">
  +        <j:switch on="foo">
  +            <j:case value="bar">
  +            </j:case>
  +            <j:default>
  +            </j:default>
  +            <j:default>
  +                <!-- this one should cause an exception (or even better, fail on 
validation) -->
  +            </j:default>
  +        </j:switch>
  +    </j:if>
  +    
  +
   </j:jelly>
  
  
  

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

Reply via email to