KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > jaxp > SourceTransformerTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.servicemix.jbi.jaxp;
18
19 import javax.xml.namespace.QName JavaDoc;
20 import javax.xml.transform.dom.DOMSource JavaDoc;
21
22 import junit.framework.TestCase;
23
24 import org.apache.servicemix.jbi.util.DOMUtil;
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28
29 public class SourceTransformerTest extends TestCase {
30
31     private SourceTransformer transformer = new SourceTransformer();
32     
33     /*
34      * Test method for 'org.apache.servicemix.jbi.jaxp.SourceTransformer.toDOMNode(Source)'
35      */

36     public void testToDOMNodeSource() throws Exception JavaDoc {
37         Node JavaDoc node = transformer.toDOMNode(new StringSource(
38                 "<definition xmlns:tns='http://foo.bar.com'><value>tns:bar</value></definition>"));
39         
40         assertNotNull(node);
41         assertTrue(node instanceof Document JavaDoc);
42         Document JavaDoc doc = (Document JavaDoc) node;
43         Element JavaDoc e = (Element JavaDoc) doc.getDocumentElement().getFirstChild();
44         QName JavaDoc q = DOMUtil.createQName(e, e.getFirstChild().getNodeValue());
45         assertEquals("http://foo.bar.com", q.getNamespaceURI());
46     }
47     
48     public void testToDOMSourceFromStream() throws Exception JavaDoc {
49         DOMSource JavaDoc domsource = transformer.toDOMSourceFromStream(new StringSource(
50             "<definition xmlns:tns='http://foo.bar.com'><value>Jürgen</value></definition>"));
51         assertNotNull(domsource);
52     }
53
54 }
55
Popular Tags