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.XMLOutput;
28  
29  /***
30   * A test to confirm that Jelly scripts fail to parse if they declare tags
31   * that do not exist
32   *
33   * @author Morgan Delagrange
34   * @version $Revision: 201966 $
35   */
36  public class TestNonexistentTags extends TestCase {
37       Jelly jelly = null;
38      JellyContext context = null;
39      XMLOutput xmlOutput = null;
40  
41      public TestNonexistentTags(String name) {
42          super(name);
43      }
44  
45      public static TestSuite suite() throws Exception {
46          return new TestSuite(TestNonexistentTags.class);
47      }
48  
49      public void setUp(String scriptName) throws Exception {
50          context = new JellyContext();
51          xmlOutput = XMLOutput.createDummyXMLOutput();
52  
53          jelly = new Jelly();
54  
55          String script = scriptName;
56          URL url = this.getClass().getResource(script);
57          if ( url == null ) {
58              throw new Exception(
59                  "Could not find Jelly script: " + script
60                  + " in package of class: " + this.getClass().getName()
61              );
62          }
63          jelly.setUrl(url);
64      }
65  
66      /***
67       * A script should fail to parse if it declares tags that don't exist.
68       */
69      public void testNonexistentTags() throws Exception {
70          setUp("nonexistentTags1.jelly");
71          try {
72              jelly.compileScript();
73              fail("Scripts should throw JellyException when it declares a nonexistent tag.");
74          } catch (JellyException e) {
75          }
76      }
77  
78  }