1 7 8 package org.dom4j.dtd; 9 10 import junit.textui.TestRunner; 11 12 import org.dom4j.AbstractTestCase; 13 14 41 public class AttributeDeclTest extends AbstractTestCase { 42 public static void main(String [] args) { 43 TestRunner.run(AttributeDeclTest.class); 44 } 45 46 49 58 public void testIdImpliedNone() { 59 MyTestAttributeDecl decl = new MyTestAttributeDecl("foo", "bar", "ID", "#IMPLIED", null, "<!ATTLIST foo bar ID #IMPLIED>"); 65 assertSameAttributeDecl(decl, new AttributeDecl("foo", "bar", "ID", 66 "#IMPLIED", null)); 67 } 68 69 78 public void testCDataFixedValue() { 79 MyTestAttributeDecl decl = new MyTestAttributeDecl("foo", "bar", "CDATA", "#FIXED", "goo", "<!ATTLIST foo bar CDATA #FIXED \"goo\">"); 85 assertSameAttributeDecl(decl, new AttributeDecl("foo", "bar", "CDATA", 86 "#FIXED", "goo")); 87 } 88 89 98 public void testCDataNoneValue() { 99 MyTestAttributeDecl decl = new MyTestAttributeDecl("foo", "bar", "CDATA", null, "goo", "<!ATTLIST foo bar CDATA \"goo\">"); 105 assertSameAttributeDecl(decl, new AttributeDecl("foo", "bar", "CDATA", 106 null, "goo")); 107 } 108 109 protected void assertSameAttributeDecl(MyTestAttributeDecl expected, 112 AttributeDecl actual) { 113 assertEquals("elementName is correct", expected.getElementName(), 114 actual.getElementName()); 115 116 assertEquals("attributeName is correct", expected.getAttributeName(), 117 actual.getAttributeName()); 118 119 assertEquals("type is correct", expected.getType(), actual.getType()); 120 121 assertEquals("valueDefault is correct", expected.getValueDefault(), 122 actual.getValueDefault()); 123 124 assertEquals("toString() is correct", expected.getText(), actual 125 .toString()); 126 } 127 128 132 protected static class MyTestAttributeDecl { 133 private String elName; 134 135 private String attName; 136 137 private String declType; 138 139 private String defaultValue; 140 141 private String declValue; 142 143 private String txt; 144 145 182 public MyTestAttributeDecl(String elementName, String attributeName, 183 String type, String valueDefault, String value, String text) { 184 elName = elementName; 185 186 attName = attributeName; 187 188 declType = type; 189 190 defaultValue = valueDefault; 191 192 declValue = value; 193 194 txt = text; 195 } 196 197 public String getElementName() { 198 return elName; 199 } 200 201 public String getAttributeName() { 202 return attName; 203 } 204 205 public String getType() { 206 return declType; 207 } 208 209 public String getValueDefault() { 210 return defaultValue; 211 } 212 213 public String getValue() { 214 return declValue; 215 } 216 217 public String getText() { 218 return txt; 219 } 220 } } 222 223 259 | Popular Tags |