KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > digester > TestOptionDigestion


1 /*
2  * Copyright 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.betwixt.digester;
18
19 import junit.framework.TestCase;
20
21 import org.apache.commons.betwixt.ElementDescriptor;
22 import org.apache.commons.digester.Digester;
23 import org.apache.commons.digester.Rule;
24 import org.xml.sax.helpers.AttributesImpl JavaDoc;
25
26
27
28 /**
29  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
30  * @version $Revision: 1.2 $
31  */

32 public class TestOptionDigestion extends TestCase {
33
34     private Digester digester;
35     private OptionRule optionRule;
36     private Rule nameRule;
37     private Rule valueRule;
38     private ElementDescriptor elementDescriptor;
39
40     protected void setUp() throws Exception JavaDoc {
41         super.setUp();
42         elementDescriptor = new ElementDescriptor();
43         digester = new Digester();
44         digester.push(elementDescriptor);
45         optionRule = new OptionRule();
46         optionRule.setDigester(digester);
47         nameRule = optionRule.getNameRule();
48         valueRule = optionRule.getValueRule();
49     }
50
51     public void testGoodDigestion() throws Exception JavaDoc {
52
53          optionRule.begin("","option", new AttributesImpl JavaDoc());
54          nameRule.begin("","name", new AttributesImpl JavaDoc());
55          nameRule.body("", "name", "one");
56          nameRule.end("","name");
57          valueRule.begin("","value", new AttributesImpl JavaDoc());
58          valueRule.body("", "value", "ONE");
59          valueRule.end("","value");
60          optionRule.end("","option");
61          
62          assertEquals("Option set", "ONE", elementDescriptor.getOptions().getValue("one"));
63     }
64
65
66     public void testTwoDigestions() throws Exception JavaDoc {
67
68          optionRule.begin("","option", new AttributesImpl JavaDoc());
69          nameRule.begin("","name", new AttributesImpl JavaDoc());
70          nameRule.body("", "name", "one");
71          nameRule.end("","name");
72          valueRule.begin("","value", new AttributesImpl JavaDoc());
73          valueRule.body("", "value", "ONE");
74          valueRule.end("","value");
75          optionRule.end("","option");
76          optionRule.begin("","option", new AttributesImpl JavaDoc());
77          valueRule.begin("","value", new AttributesImpl JavaDoc());
78          valueRule.body("", "value", "TWO");
79          valueRule.end("","value");
80          nameRule.begin("","name", new AttributesImpl JavaDoc());
81          nameRule.body("", "name", "two");
82          nameRule.end("","name");
83          optionRule.end("","option");
84          
85          assertEquals("Option set", "ONE", elementDescriptor.getOptions().getValue("one"));
86          assertEquals("Option set", "TWO", elementDescriptor.getOptions().getValue("two"));
87          
88     }
89     
90
91     public void testGracefulBadMapping() throws Exception JavaDoc {
92
93          optionRule.begin("","option", new AttributesImpl JavaDoc());
94          nameRule.begin("","name", new AttributesImpl JavaDoc());
95          nameRule.body("", "name", "one");
96          nameRule.end("","name");
97          optionRule.end("","option");
98          optionRule.begin("","option", new AttributesImpl JavaDoc());
99          valueRule.begin("","value", new AttributesImpl JavaDoc());
100          valueRule.body("", "value", "ONE");
101          valueRule.end("","value");
102          optionRule.end("","option");
103          optionRule.begin("","option", new AttributesImpl JavaDoc());
104          nameRule.begin("","name", new AttributesImpl JavaDoc());
105          nameRule.body("", "name", "two");
106          nameRule.end("","name");
107          valueRule.begin("","value", new AttributesImpl JavaDoc());
108          valueRule.body("", "value", "TWO");
109          valueRule.end("","value");
110          optionRule.end("","option");
111          
112          assertEquals("Option set", null, elementDescriptor.getOptions().getValue("one"));
113          assertEquals("Option set", "TWO", elementDescriptor.getOptions().getValue("two"));
114          
115     }
116 }
117
Popular Tags