KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > util > XMLUtilTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: XMLUtilTest.java 17:13:00 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.tools.util;
23
24 import java.io.File JavaDoc;
25 import java.util.List JavaDoc;
26
27 import javax.xml.parsers.DocumentBuilder JavaDoc;
28 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
29
30 import junit.framework.TestCase;
31
32 import org.objectweb.petals.tools.jbicommon.util.XMLUtil;
33 import org.w3c.dom.Document JavaDoc;
34 import org.w3c.dom.Node JavaDoc;
35
36 /**
37  * Test the XMLUtil
38  *
39  * @author ddesjardins - eBMWebsourcing
40  */

41 public class XMLUtilTest extends TestCase {
42
43     private Document JavaDoc document;
44
45     public void setUp() throws Exception JavaDoc {
46         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
47         DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
48         String JavaDoc baseDir = this.getClass().getResource(".").toString();
49         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
50         baseDir = baseDir.substring(baseDir.indexOf(":")+1);
51         document = builder.parse(new File JavaDoc(baseDir + "src" + File.separator
52                 + "test-data" + File.separator + "Axis2BCService.wsdl"));
53     }
54
55     public void testCreateAttribute() {
56         Node JavaDoc att = XMLUtil.createAttribute(document, "test", "test");
57         assertNotNull(att);
58     }
59
60     public void testCreateNode() {
61         Node JavaDoc att = XMLUtil.createNode(document, "test", "test-att", "test-val");
62         assertNotNull(att);
63     }
64
65     public void testGetAttributeValue() {
66         Node JavaDoc att = XMLUtil.createNode(document, "test", "test-att", "test-val");
67         String JavaDoc attVal = XMLUtil.getAttributeValue(att, "test-att");
68         assertNotNull(attVal);
69     }
70
71     public void testGetAttributeValue1() {
72         Node JavaDoc att = XMLUtil.createNode(document, "test", "test-att", "test-val");
73         String JavaDoc attVal = XMLUtil.getAttributeValue(att, "test");
74         assertNull(attVal);
75     }
76
77     public void testGetAttributeValue2() {
78         String JavaDoc attVal = XMLUtil.getAttributeValue(null, "test");
79         assertNull(attVal);
80     }
81
82     public void testGetFirstChild() {
83         Node JavaDoc fc = XMLUtil.getFirstChild(document.getFirstChild());
84         assertNotNull(fc);
85     }
86
87     public void testGetNextSibling() {
88         Node JavaDoc ns = XMLUtil.getNextSibling(document.getFirstChild()
89                 .getFirstChild());
90         assertNotNull(ns);
91     }
92
93 // public void testGetNode() {
94
// Node ns = XMLUtil.getNode(document, "*/types");
95
// assertNotNull(ns);
96
// }
97
//
98
// public void testGetNode1() {
99
// Node ns = XMLUtil.getNode(document, "*/test");
100
// assertNull(ns);
101
// }
102

103     public void testGetTextContent() {
104         Node JavaDoc ns = XMLUtil.getNextSibling(document.getFirstChild()
105                 .getFirstChild());
106         String JavaDoc text = XMLUtil.getTextContent(ns);
107         assertNotNull(text);
108     }
109
110
111     public void testGetTextContents() {
112         List JavaDoc<String JavaDoc> texts = XMLUtil.getTextContents(document.getChildNodes());
113         assertNotNull(texts);
114     }
115
116 }
117
Popular Tags