KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > 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.woody.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.woody.Constants;
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 CVS $Id: EnumConvertorBuilderTestCase.java 30932 2004-07-29 17:35:38Z vgritsenko $
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         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
43         factory.setNamespaceAware(true);
44         parser = factory.newDocumentBuilder();
45     }
46
47     /* (non-Javadoc)
48      * @see junit.framework.TestCase#tearDown()
49      */

50     protected void tearDown() throws Exception JavaDoc {
51     }
52
53     public EnumConvertorBuilderTestCase(String JavaDoc name) {
54         super(name);
55     }
56
57     /**
58      * Test the {@link EnumConvertorBuilder#build(org.w3c.dom.Element)
59      * build} method.
60      * @throws Exception
61      */

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