01: package info.jtrac.domain;
02:
03: import info.jtrac.domain.Field;
04: import info.jtrac.util.XmlUtils;
05: import junit.framework.TestCase;
06: import org.dom4j.Document;
07: import org.dom4j.Element;
08:
09: public class FieldTest extends TestCase {
10:
11: public void testSetValidName() {
12: Field field = new Field();
13: field.setName("cusInt01");
14: assertEquals(field.getName().toString(), "cusInt01");
15: }
16:
17: public void testSetInValidNameFails() {
18: Field field = new Field();
19: try {
20: field.setName("foo");
21: fail("How did we set an invalid name?");
22: } catch (Exception e) {
23: // expected
24: }
25: }
26:
27: public void testConstructFromXml() {
28: Document d = XmlUtils
29: .parse("<field name='cusInt01' label='Test Label'/>");
30: Field field = new Field(d.getRootElement());
31: assertEquals("cusInt01", field.getName().toString());
32: assertEquals("Test Label", field.getLabel());
33: assertEquals(field.isOptional(), false);
34: }
35:
36: public void testConstructFromXmlWithOptionalAttribute() {
37: Document d = XmlUtils
38: .parse("<field name='cusInt01' label='Test Label' optional='true'/>");
39: Field field = new Field(d.getRootElement());
40: assertTrue(field.isOptional());
41: }
42:
43: public void testGetAsXml() {
44: Field field = new Field();
45: field.setName("cusInt01");
46: field.setLabel("Test Label");
47: Element e = field.getAsElement();
48: assertEquals("cusInt01", e.attributeValue("name"));
49: assertEquals("Test Label", e.attributeValue("label"));
50: }
51:
52: }
|