01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.cocoon.forms.datatype.convertor;
18:
19: import javax.xml.parsers.DocumentBuilder;
20: import javax.xml.parsers.DocumentBuilderFactory;
21:
22: import junit.framework.TestCase;
23:
24: import org.apache.cocoon.forms.FormsConstants;
25: import org.apache.excalibur.source.Source;
26: import org.apache.excalibur.source.impl.ResourceSource;
27: import org.w3c.dom.Document;
28: import org.w3c.dom.Element;
29:
30: /**
31: * Test case for the {@link EnumConvertorBuilder} class.
32: *
33: * @version $Id: EnumConvertorBuilderTestCase.java 449149 2006-09-23 03:58:05Z crossley $
34: */
35: public class EnumConvertorBuilderTestCase extends TestCase {
36:
37: protected DocumentBuilder parser;
38:
39: /* (non-Javadoc)
40: * @see junit.framework.TestCase#setUp()
41: */
42: protected void setUp() throws Exception {
43: super .setUp();
44: DocumentBuilderFactory factory = DocumentBuilderFactory
45: .newInstance();
46: factory.setNamespaceAware(true);
47: parser = factory.newDocumentBuilder();
48: }
49:
50: public EnumConvertorBuilderTestCase(String name) {
51: super (name);
52: }
53:
54: /**
55: * Test the {@link EnumConvertorBuilder#build(org.w3c.dom.Element)
56: * build} method.
57: * @throws Exception
58: */
59: public void testBuild() throws Exception {
60: Source confSource = new ResourceSource(
61: "resource://org/apache/cocoon/forms/datatype/convertor/EnumConvertorTestCase.conf.xml");
62: Document sample = parser.parse(confSource.getInputStream());
63: Element convertorElement = (Element) sample
64: .getElementsByTagNameNS(FormsConstants.DEFINITION_NS,
65: "convertor").item(0);
66: String enumClassName = convertorElement.getElementsByTagNameNS(
67: FormsConstants.DEFINITION_NS, "enum").item(0)
68: .getFirstChild().getNodeValue();
69: EnumConvertorBuilder builder = new EnumConvertorBuilder();
70: Convertor convertor = builder.build(convertorElement);
71: assertTrue("The returned convertor is not an EnumConvertor",
72: convertor instanceof EnumConvertor);
73: assertEquals(
74: "The convertor does not convert the expected class",
75: Class.forName(enumClassName), convertor.getTypeClass());
76: }
77: }
|