1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.commons.jelly.test.xml;
18  
19  import java.net.URL;
20  
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  
24  import org.apache.commons.jelly.Jelly;
25  import org.apache.commons.jelly.JellyContext;
26  import org.apache.commons.jelly.JellyException;
27  import org.apache.commons.jelly.Script;
28  import org.apache.commons.jelly.XMLOutput;
29  
30  /***
31   * A test to confirm that Jelly scripts fail to parse if they declare tags
32   * that do not exist
33   *
34   * @author Morgan Delagrange
35   * @version $Revision: 1.6 $
36   */
37  public class TestNonexistentTags extends TestCase {
38       Jelly jelly = null;
39      JellyContext context = null;
40      XMLOutput xmlOutput = null;
41  
42      public TestNonexistentTags(String name) {
43          super(name);
44      }
45  
46      public static TestSuite suite() throws Exception {
47          return new TestSuite(TestNonexistentTags.class);
48      }
49  
50      public void setUp(String scriptName) throws Exception {
51          context = new JellyContext();
52          xmlOutput = XMLOutput.createDummyXMLOutput();
53  
54          jelly = new Jelly();
55  
56          String script = scriptName;
57          URL url = this.getClass().getResource(script);
58          if ( url == null ) {
59              throw new Exception(
60                  "Could not find Jelly script: " + script
61                  + " in package of class: " + this.getClass().getName()
62              );
63          }
64          jelly.setUrl(url);
65      }
66  
67      /***
68       * A script should fail to parse if it declares tags that don't exist.
69       */
70      public void testNonexistentTags() throws Exception {
71          setUp("nonexistentTags1.jelly");
72          try {
73              Script script = jelly.compileScript();
74              fail("Scripts should throw JellyException when it declares a nonexistent tag.");
75          } catch (JellyException e) {
76          }
77      }
78  
79  }