1 22 package org.objectweb.petals.tools.util; 23 24 import java.io.File ; 25 import java.util.List ; 26 27 import javax.xml.parsers.DocumentBuilder ; 28 import javax.xml.parsers.DocumentBuilderFactory ; 29 30 import junit.framework.TestCase; 31 32 import org.objectweb.petals.tools.jbicommon.util.XMLUtil; 33 import org.w3c.dom.Document ; 34 import org.w3c.dom.Node ; 35 36 41 public class XMLUtilTest extends TestCase { 42 43 private Document document; 44 45 public void setUp() throws Exception { 46 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 47 DocumentBuilder builder = factory.newDocumentBuilder(); 48 String 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 (baseDir + "src" + File.separator 52 + "test-data" + File.separator + "Axis2BCService.wsdl")); 53 } 54 55 public void testCreateAttribute() { 56 Node att = XMLUtil.createAttribute(document, "test", "test"); 57 assertNotNull(att); 58 } 59 60 public void testCreateNode() { 61 Node att = XMLUtil.createNode(document, "test", "test-att", "test-val"); 62 assertNotNull(att); 63 } 64 65 public void testGetAttributeValue() { 66 Node att = XMLUtil.createNode(document, "test", "test-att", "test-val"); 67 String attVal = XMLUtil.getAttributeValue(att, "test-att"); 68 assertNotNull(attVal); 69 } 70 71 public void testGetAttributeValue1() { 72 Node att = XMLUtil.createNode(document, "test", "test-att", "test-val"); 73 String attVal = XMLUtil.getAttributeValue(att, "test"); 74 assertNull(attVal); 75 } 76 77 public void testGetAttributeValue2() { 78 String attVal = XMLUtil.getAttributeValue(null, "test"); 79 assertNull(attVal); 80 } 81 82 public void testGetFirstChild() { 83 Node fc = XMLUtil.getFirstChild(document.getFirstChild()); 84 assertNotNull(fc); 85 } 86 87 public void testGetNextSibling() { 88 Node ns = XMLUtil.getNextSibling(document.getFirstChild() 89 .getFirstChild()); 90 assertNotNull(ns); 91 } 92 93 103 public void testGetTextContent() { 104 Node ns = XMLUtil.getNextSibling(document.getFirstChild() 105 .getFirstChild()); 106 String text = XMLUtil.getTextContent(ns); 107 assertNotNull(text); 108 } 109 110 111 public void testGetTextContents() { 112 List <String > texts = XMLUtil.getTextContents(document.getChildNodes()); 113 assertNotNull(texts); 114 } 115 116 } 117 | Popular Tags |