1 16 17 package org.apache.batik.dom; 18 19 import org.w3c.dom.*; 20 21 import java.io.*; 22 import java.net.*; 23 import org.apache.batik.dom.util.*; 24 import org.apache.batik.util.*; 25 26 import org.apache.batik.test.*; 27 28 32 public class SetAttributeTest extends AbstractTest { 33 protected String testFileName; 34 protected String rootTag; 35 protected String targetId; 36 protected String targetAttribute; 37 protected String targetValue; 38 39 protected String parserClassName = XMLResourceDescriptor.getXMLParserClassName(); 40 41 public static String ERROR_GET_ELEMENT_BY_ID_FAILED 42 = "error.get.element.by.id.failed"; 43 44 public static String ENTRY_KEY_ID 45 = "entry.key.id"; 46 47 public SetAttributeTest(String testFileName, 48 String rootTag, 49 String targetId, 50 String targetAttribute, 51 String targetValue){ 52 this.testFileName = testFileName; 53 this.rootTag = rootTag; 54 this.targetId = targetId; 55 this.targetAttribute = targetAttribute; 56 this.targetValue = targetValue; 57 } 58 59 public String getParserClassName(){ 60 return parserClassName; 61 } 62 63 public void setParserClassName(String parserClassName){ 64 this.parserClassName = parserClassName; 65 } 66 67 public TestReport runImpl() throws Exception { 68 DocumentFactory df 69 = new SAXDocumentFactory(GenericDOMImplementation.getDOMImplementation(), 70 parserClassName); 71 72 File f = (new File(testFileName)); 73 URL url = f.toURL(); 74 Document doc = df.createDocument(null, 75 rootTag, 76 url.toString(), 77 url.openStream()); 78 79 80 Element e = doc.getElementById(targetId); 81 82 if(e == null){ 83 DefaultTestReport report = new DefaultTestReport(this); 84 report.setErrorCode(ERROR_GET_ELEMENT_BY_ID_FAILED); 85 report.addDescriptionEntry(ENTRY_KEY_ID, 86 targetId); 87 report.setPassed(false); 88 return report; 89 } 90 91 92 e.setAttribute(targetAttribute, targetValue); 93 if(targetValue.equals(e.getAttribute(targetAttribute))){ 94 return reportSuccess(); 95 } 96 DefaultTestReport report = new DefaultTestReport(this); 97 report.setErrorCode(TestReport.ERROR_TEST_FAILED); 98 report.setPassed(false); 99 return report; 100 } 101 } 102 103 | Popular Tags |