KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > datatype > convertor > EnumConvertorBuilderTestCase


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.forms.datatype.convertor;
17
18 import javax.xml.parsers.DocumentBuilder JavaDoc;
19 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.cocoon.forms.FormsConstants;
24 import org.apache.excalibur.source.Source;
25 import org.apache.excalibur.source.impl.ResourceSource;
26 import org.w3c.dom.Document JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28
29 /**
30  * Test case for the {@link EnumConvertorBuilder} class.
31  *
32  * @version $Id: EnumConvertorBuilderTestCase.java 326838 2005-10-20 06:26:53Z sylvain $
33  */

34 public class EnumConvertorBuilderTestCase extends TestCase {
35
36     protected DocumentBuilder JavaDoc parser;
37
38     /* (non-Javadoc)
39      * @see junit.framework.TestCase#setUp()
40      */

41     protected void setUp() throws Exception JavaDoc {
42         super.setUp();
43         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
44         factory.setNamespaceAware(true);
45         parser = factory.newDocumentBuilder();
46     }
47
48     public EnumConvertorBuilderTestCase(String JavaDoc name) {
49         super(name);
50     }
51
52     /**
53      * Test the {@link EnumConvertorBuilder#build(org.w3c.dom.Element)
54      * build} method.
55      * @throws Exception
56      */

57     public void testBuild() throws Exception JavaDoc {
58         Source confSource = new ResourceSource("resource://org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml");
59         Document JavaDoc sample = parser.parse(confSource.getInputStream());
60         Element JavaDoc convertorElement = (Element JavaDoc) sample.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "convertor").item(0);
61         String JavaDoc enumClassName = convertorElement.getElementsByTagNameNS(FormsConstants.DEFINITION_NS, "enum").item(0).getFirstChild().getNodeValue();
62         EnumConvertorBuilder builder = new EnumConvertorBuilder();
63         Convertor convertor = builder.build(convertorElement);
64         assertTrue("The returned convertor is not an EnumConvertor",
65                 convertor instanceof EnumConvertor);
66         assertEquals("The convertor does not convert the expected class",
67                 Class.forName(enumClassName), convertor.getTypeClass());
68     }
69 }
70
Popular Tags