1 4 package org.oddjob.designer.arooa; 5 6 import junit.framework.TestCase; 7 8 import org.oddjob.designer.elements.SimpleDE; 9 import org.oddjob.designer.model.DesignElementType; 10 import org.xml.sax.Attributes ; 11 12 15 public class DesignIHTest extends TestCase { 16 17 public void testText() { 18 class Test { 19 public String text() { return "test"; } 20 } 21 Test test = new Test(); 22 DesignIH dih = DesignIH.getHelper(test.getClass()); 23 assertEquals("text", "test", dih.text(test)); 24 } 25 26 public void testUnknown() { 27 class Test { 28 String unknown; 29 public void unknown(String unknown) { 30 this.unknown = unknown; 31 } 32 public String unknown() { 33 return unknown; 34 } 35 } 36 Test test = new Test(); 37 DesignIH dih = DesignIH.getHelper(test.getClass()); 38 dih.unknown(test, "test"); 39 assertEquals("text", "test", dih.unknown(test)); 40 } 41 42 public void testAttributes() { 43 class Test { 44 public String getThisTest() { 45 return "test1"; 46 } 47 public String getThatTest() { 48 return "test2"; 49 } 50 } 51 Test test = new Test(); 52 DesignIH dih = DesignIH.getHelper(test.getClass()); 53 Attributes atts = dih.attributes(test); 54 assertEquals("size", 2, atts.getLength()); 55 assertEquals("name 1", "thisTest", atts.getLocalName(0)); 56 assertEquals("value 1", "test1", atts.getValue(0)); 57 assertEquals("name 2", "thatTest", atts.getLocalName(1)); 58 assertEquals("value 2", "test2", atts.getValue(1)); 59 } 60 61 public void testDEAttributes() { 62 class Test { 63 public SimpleDE getThisTest() { 65 SimpleDE a = new SimpleDE(); 66 a.attribute("test1"); 67 return a; 68 } 69 public SimpleDE getThatTest() { 71 return new SimpleDE(); 72 } 73 public SimpleDE getNullTest() { 74 return null; 75 } 76 } 77 Test test = new Test(); 78 DesignIH dih = DesignIH.getHelper(test.getClass()); 79 Attributes atts = dih.attributes(test); 80 assertEquals("size", 1, atts.getLength()); 81 assertEquals("name 1", "thisTest", atts.getLocalName(0)); 82 assertEquals("value 1", "test1", atts.getValue(0)); 83 84 ElementWrapper[] ews = dih.elements(test); 85 assertEquals("elements", 0, ews.length); 86 } 87 88 public void testElements() { 89 class Test { 90 public ElementWrapper[] elements() { 91 return new ElementWrapper[] { 92 new ElementWrapper("thistest", 93 new Object () { 94 public String toString() { 95 return "test1"; 96 } 97 }), 98 new ElementWrapper( ("thattest"), 99 new Object () { 100 public String toString() { 101 return "test2"; 102 } 103 }) 104 }; 105 } 106 } 107 Test test = new Test(); 108 DesignIH dih = DesignIH.getHelper(test.getClass()); 109 ElementWrapper[] ews = dih.elements(test); 110 assertEquals("value 1", "test1", ews[0].getElement().toString()); 111 assertEquals("value 2", "test2", ews[1].getElement().toString()); 112 } 113 114 118 public void testNamedElements() { 119 class Test { 120 public Object [] elementsThisTest() { 121 return new Object [] { 122 new Object () { 123 public String toString() { 124 return "test1"; 125 } 126 } }; 127 } 128 public Object [] elementsThatTest() { 129 return new Object [] { 130 new Object () { 131 public String toString() { 132 return "test2"; 133 } 134 } }; 135 } 136 } 137 Test test = new Test(); 138 DesignIH dih = DesignIH.getHelper(test.getClass()); 139 ElementWrapper[] ews = dih.elements(test); 140 141 assertEquals(2, ews.length); 142 143 assertEquals("name 1", "thisTest", ews[0].getName()); 144 assertEquals("value 1", "test1", ews[0].getElement().toString()); 145 146 assertEquals("name 2", "thatTest", ews[1].getName()); 147 assertEquals("value 2", "test2", ews[1].getElement().toString()); 148 } 149 150 153 public void testHasDetailData1() { 154 class Test extends DesignElementType { 155 public Object elementFoo() { 156 return new Object (); 157 } 158 } 159 Test test = new Test(); 160 DesignIH dih = DesignIH.getHelper(test.getClass()); 161 assertTrue("detail data", dih.hasDetailData(test)); 162 } 163 164 168 public void testHasDetailData2() { 169 class Test extends DesignElementType { 170 public Object elementFoo() { 171 return null; 172 } 173 } 174 Test test = new Test(); 175 DesignIH dih = DesignIH.getHelper(test.getClass()); 176 assertFalse("detail data", dih.hasDetailData(test)); 177 } 178 179 183 public void testHasDetailData3() { 184 class Test extends DesignElementType { 185 public Object getFoo() { 186 return null; 187 } 188 } 189 Test test = new Test(); 190 DesignIH dih = DesignIH.getHelper(test.getClass()); 191 assertFalse("detail data", dih.hasDetailData(test)); 192 } 193 } 194 | Popular Tags |