KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > plugins > TestDeclaration


1 /* $Id: TestDeclaration.java 179714 2005-06-03 03:53:39Z skitching $
2  *
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.commons.digester.plugins;
20
21 import java.util.List JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26
27 import org.apache.commons.digester.Digester;
28
29 /**
30  * Test cases for basic PluginDeclarationRule behaviour.
31  */

32
33 public class TestDeclaration extends TestCase {
34     /** Standard constructor */
35     public TestDeclaration(String JavaDoc name) {
36         super(name);
37     }
38
39     /** Set up instance variables required by this test case. */
40     public void setUp() {}
41
42     /** Return the tests included in this test suite. */
43     public static Test suite() {
44
45         return (new TestSuite(TestDeclaration.class));
46
47     }
48
49     /** Tear down instance variables required by this test case.*/
50     public void tearDown() {}
51         
52     // --------------------------------------------------------------- Test cases
53

54     public void testPredeclaration() throws Exception JavaDoc {
55         // * tests that rules can be declared via a PluginDeclarationRule
56

57         Digester digester = new Digester();
58         PluginRules rc = new PluginRules();
59         digester.setRules(rc);
60         
61         PluginDeclarationRule pdr = new PluginDeclarationRule();
62         digester.addRule("root/plugin", pdr);
63         
64         PluginCreateRule pcr = new PluginCreateRule(Widget.class);
65         digester.addRule("root/widget", pcr);
66         digester.addSetNext("root/widget", "addChild");
67
68         Container root = new Container();
69         digester.push(root);
70         
71         try {
72             digester.parse(
73                 TestAll.getInputStream(this, "test3.xml"));
74         }
75         catch(Exception JavaDoc e) {
76             throw e;
77         }
78         
79         Object JavaDoc child;
80         List JavaDoc children = root.getChildren();
81         assertTrue(children != null);
82         assertEquals(2, children.size());
83         
84         child = children.get(0);
85         assertTrue(child != null);
86         assertEquals(TextLabel.class, child.getClass());
87         assertEquals("label1", ((TextLabel)child).getLabel());
88         
89         child = children.get(1);
90         assertTrue(child != null);
91         assertEquals(TextLabel.class, child.getClass());
92         assertEquals("label2", ((TextLabel)child).getLabel());
93     }
94 }
95
Popular Tags